src_other/tuplebase/ZTBRep.h

00001 /*  @(#) $Id: ZTBRep.h,v 1.10 2007/07/15 20:08: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__
00026 #define __ZTBRep__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZCompat_NonCopyable.h"
00030 #include "ZTBQuery.h"
00031 #include "ZTuple.h"
00032 #include "ZTxn.h"
00033 
00034 class ZTBRepTransaction;
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZTBRep
00039 
00040 class ZTBRep : public ZRefCountedWithFinalization,
00041                                 private ZTxnTarget,
00042                                 ZooLib::NonCopyable
00043         {
00044 public:
00045         virtual ~ZTBRep();
00046 
00047 // Our protocol
00048         ZTBRepTransaction* FindOrCreateTransaction(const ZTxn& iTxn);
00049 
00050         typedef void (*Callback_AllocateIDs_t)(void* iRefcon, uint64 iBaseID, size_t iCount);
00051         virtual void AllocateIDs(size_t iCount,
00052                                         Callback_AllocateIDs_t iCallback_AllocateIDs, void* iRefcon) = 0;
00053 
00054         virtual ZTBRepTransaction* CreateTransaction() = 0;
00055 
00056 private:
00057 // From ZTxnTarget
00058         virtual void TxnAbortPreValidate(int32 iTxnID);
00059         virtual void TxnValidate(int32 iTxnID, ValidateCallbackProc iCallback, void* iRefcon);
00060         virtual void TxnAbortPostValidate(int32 iTxnID, bool iValidationSucceeded);
00061         virtual void TxnCommit(int32 iTxnID, CommitCallbackProc iCallback, void* iRefcon);
00062 
00063         ZMutex fMutex_Transactions;
00064         std::map<int32, ZTBRepTransaction*> fTransactions;
00065         };
00066 
00067 // =================================================================================================
00068 #pragma mark -
00069 #pragma mark * ZTBRepTransaction
00070 
00071 class ZTBRepTransaction : ZooLib::NonCopyable
00072         {
00073 protected:
00074         ~ZTBRepTransaction() {}
00075 
00076 public:
00077         virtual ZRef<ZTBRep> GetTBRep() = 0;
00078 
00079         typedef void (*Callback_Search_t)(void* iRefcon, std::vector<uint64>& ioResults);
00080         virtual void Search(const ZTBQuery& iQuery, Callback_Search_t iCallback, void* iRefcon) = 0;
00081 
00082         typedef void (*Callback_Count_t)(void* iRefcon, size_t iResult);
00083         virtual void Count(const ZTBQuery& iQuery, Callback_Count_t iCallback, void* iRefcon) = 0;
00084 
00085         typedef void (*Callback_GetTuple_t)(void* iRefcon, size_t iCount, const uint64* ioIDs, const ZTuple* iTuples);
00086         virtual void GetTuples(size_t iCount, const uint64* iIDs,
00087                                         Callback_GetTuple_t iCallback_Get, void* iRefcon) = 0;
00088 
00089         virtual void SetTuple(uint64 iID, const ZTuple& iTuple) = 0;
00090 
00091         virtual void AbortPreValidate() = 0;
00092 
00093         typedef void (*Callback_Validate_t)(bool iSucceeded, void* iRefcon);
00094         virtual void Validate(Callback_Validate_t iCallback_Validate, void* iRefcon) = 0;
00095 
00096         virtual void AcceptFailure() = 0;
00097 
00098         virtual void CancelPostValidate() = 0;
00099 
00100         typedef void (*Callback_Commit_t)(void* iRefcon);
00101         virtual void Commit(Callback_Commit_t iCallback_Commit, void* iRefcon) = 0;
00102         };
00103 
00104 #endif // __ZTBRep__

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