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 __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
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
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__