src_other/tuplebase/ZTSWatcher_Latent.h

00001 /*  @(#) $Id: ZTSWatcher_Latent.h,v 1.7 2007/07/15 20:36:15 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2007 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 __ZTSWatcher_Latent__
00026 #define __ZTSWatcher_Latent__
00027 #include "zconfig.h"
00028 
00029 #include "ZTSWatcher.h"
00030 
00031 #ifndef ZCONFIG_TSWatcher_Latent_Debug
00032 #       define ZCONFIG_TSWatcher_Latent_Debug 1
00033 #endif
00034 
00035 // =================================================================================================
00036 #pragma mark -
00037 #pragma mark * ZTSWatcher_Latent
00038 
00039 class ZTSWatcher_Latent : public ZTSWatcher
00040         {
00041 public:
00042         enum { kDebug = ZCONFIG_TSWatcher_Latent_Debug };
00043 
00044         ZTSWatcher_Latent(ZRef<ZTSWatcher> iTSWatcher);
00045         virtual ~ZTSWatcher_Latent();
00046 
00047 // From ZTSWatcher
00048         virtual bool AllocateIDs(size_t iCount, uint64& oBaseID, size_t& oCountIssued);
00049 
00050         virtual bool Sync(
00051                 const uint64* iRemovedIDs, size_t iRemovedIDsCount,
00052                 const uint64* iAddedIDs, size_t iAddedIDsCount,
00053                 const int64* iRemovedQueries, size_t iRemovedQueriesCount,
00054                 const AddedQueryCombo* iAddedQueries, size_t iAddedQueriesCount,
00055                 std::vector<uint64>& oAddedIDs,
00056                 std::vector<uint64>& oChangedTupleIDs, std::vector<ZTuple>& oChangedTuples,
00057                 const uint64* iWrittenTupleIDs, const ZTuple* iWrittenTuples, size_t iWrittenTuplesCount,
00058                 std::map<int64, std::vector<uint64> >& oChangedQueries);
00059 
00060         virtual void SetCallback(Callback_t iCallback, void* iRefcon);
00061 
00062 // Our protocol
00063         void Save(bool iWaitForSync);
00064         void Discard(bool iWaitForSync);
00065 
00066         bool HasChanges(bool iWaitForSync);
00067 
00068 private:
00069         class PQuery;
00070 
00071         class PTuple;
00072 
00073         PTuple& pGetPTuple(uint64 iID);
00074         PTuple* pGetPTupleExtant(uint64 iID);
00075 
00076         void pRegisterAQC(AddedQueryCombo& ioAQC);
00077 
00078         void Callback();
00079         static void sCallback(void* iRefcon);
00080 
00081         ZRef<ZTSWatcher> fTSWatcher;
00082         Callback_t fCallback;
00083         void* fRefcon;
00084         ZMutex fMutex_CallSync;
00085         ZMutex fMutex_Save;
00086         ZCondition fCondition_Save;
00087 
00088         enum { eMode_Normal, eMode_Save, eMode_Discard } fMode;
00089 
00090         bool* fHasChangesPtr;
00091 
00092         std::map<int64, PQuery> fPQueries;
00093         std::map<uint64, PTuple> fPTuples;
00094         };
00095 
00096 #endif // __ZTSWatcher_Latent__

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