00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __ZTBRep_Client__
00026 #define __ZTBRep_Client__ 1
00027 #include "zconfig.h"
00028
00029 #include "ZTBRep.h"
00030
00031 #include "ZStream.h"
00032 #include "ZTime.h"
00033
00034 #include <deque>
00035 #include <set>
00036 #include <vector>
00037
00038
00039 #pragma mark -
00040 #pragma mark * ZTBRep_Client
00041
00042 class ZTBRep_Client : public ZTBRep
00043 {
00044 protected:
00045 ZTBRep_Client();
00046 virtual ~ZTBRep_Client();
00047
00048 public:
00049
00050 virtual void AllocateIDs(size_t iCount,
00051 Callback_AllocateIDs_t iCallback_AllocateIDs, void* iRefcon);
00052
00053 virtual ZTBRepTransaction* CreateTransaction();
00054
00055
00056 bool Reader(const ZStreamR& iStream);
00057 bool Writer(const ZStreamW& iStream);
00058
00059 void Live();
00060 void Fail();
00061
00062 private:
00063 class Transaction;
00064 friend class Transaction;
00065
00066 class TransTuple;
00067 class TransSearch_t;
00068 class TransCount_t;
00069
00070 void Trans_Search(Transaction* iTransaction, const ZTBQuery& iQuery,
00071 ZTBRepTransaction::Callback_Search_t iCallback, void* iRefcon);
00072
00073 void Trans_Count(Transaction* iTransaction, const ZTBQuery& iQuery,
00074 ZTBRepTransaction::Callback_Count_t iCallback, void* iRefcon);
00075
00076 void Trans_GetTuples(Transaction* iTransaction, size_t iCount, const uint64* iIDs,
00077 ZTBRepTransaction::Callback_GetTuple_t iCallback, void* iRefcon);
00078
00079 void Trans_SetTuple(Transaction* iTransaction, uint64 iID, const ZTuple& iTuple);
00080
00081 void Trans_AbortPreValidate(Transaction* iTransaction);
00082
00083 void Trans_Validate(Transaction* iTransaction,
00084 ZTBRepTransaction::Callback_Validate_t iCallback_Validate, void* iRefcon);
00085
00086 void Trans_AcceptFailure(Transaction* iTransaction);
00087
00088 void Trans_CancelPostValidate(Transaction* iTransaction);
00089
00090 void Trans_Commit(Transaction* iTransaction,
00091 ZTBRepTransaction::Callback_Commit_t iCallback_Commit, void* iRefcon);
00092
00093 TransTuple* pGetTransTuple(Transaction* iTransaction, uint64 iID);
00094
00095 void pFailTransactions(vector<Transaction*>& iTransactions);
00096 void pDoStuff();
00097
00098 void pReader(const ZStreamR& iStream);
00099 void pWriter(const ZStreamW& iStream);
00100
00101 ZMutex fMutex_Structure;
00102 ZCondition fCondition_Sender;
00103 ZCondition fCondition_Transaction;
00104
00105 bool fLive;
00106 uint64 fNextFakeID;
00107
00108 ZTime fTime_LastRead;
00109 bool fPingRequested;
00110 bool fPingSent;
00111
00112 std::vector<std::pair<uint64, size_t> > fIDs;
00113 struct AllocateIDRequest_t
00114 {
00115 size_t fCount;
00116 Callback_AllocateIDs_t fCallback;
00117 void* fRefcon;
00118 };
00119 size_t fIDsNeeded;
00120 std::deque<AllocateIDRequest_t> fAllocateIDPending;
00121
00122 std::vector<Transaction*> fTransactions_Create_Unsent;
00123 std::vector<Transaction*> fTransactions_Create_Unacked;
00124 std::vector<Transaction*> fTransactions_Created;
00125
00126 std::vector<Transaction*> fTransactions_Validate_Unsent;
00127 std::vector<Transaction*> fTransactions_Validate_Unacked;
00128 std::vector<Transaction*> fTransactions_Validated;
00129 std::vector<Transaction*> fTransactions_Failed;
00130
00131 std::vector<Transaction*> fTransactions_Aborted_Unsent;
00132
00133 std::vector<Transaction*> fTransactions_Commit_Unsent;
00134 std::vector<Transaction*> fTransactions_Commit_Unacked;
00135
00136 std::set<Transaction*> fTransactions_NeedWork;
00137 };
00138
00139 #endif // __ZTBRep_Client__