src_other/tuplebase/ZTBRep_Client.h

00001 /*  @(#) $Id: ZTBRep_Client.h,v 1.8 2007/07/15 20:23:21 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // From ZTBRep
00050         virtual void AllocateIDs(size_t iCount,
00051                                         Callback_AllocateIDs_t iCallback_AllocateIDs, void* iRefcon);
00052 
00053         virtual ZTBRepTransaction* CreateTransaction();
00054 
00055 // Our protocol
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__

Generated on Thu Jul 26 11:21:56 2007 for ZooLib by  doxygen 1.4.7