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_Undo__
00026 #define __ZTSWatcher_Undo__
00027 #include "zconfig.h"
00028
00029 #include "ZTSWatcher.h"
00030
00031 #ifndef ZCONFIG_TSWatcher_Undo_Debug
00032 # define ZCONFIG_TSWatcher_Undo_Debug 1
00033 #endif
00034
00035
00036 #pragma mark -
00037 #pragma mark * ZTSWatcher_Undo
00038
00039 class ZTSWatcher_Undo : public ZTSWatcher
00040 {
00041 public:
00042 enum { kDebug = ZCONFIG_TSWatcher_Undo_Debug };
00043
00044 ZTSWatcher_Undo(ZRef<ZTSWatcher> iWatcher);
00045 virtual ~ZTSWatcher_Undo();
00046
00047
00048 virtual void AllocateIDs(size_t iCount, uint64& oBaseID, size_t& oCountIssued);
00049
00050 virtual void DoIt(
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 int64 Open(bool iWaitForDoIt);
00064 void Commit(int64 iMarker, bool iWaitForDoIt);
00065 void GoTo(int64 iMarker, bool iWaitForDoIt);
00066
00067 private:
00068 class PQuery;
00069
00070 class PTuple;
00071
00072 PTuple& pGetPTuple(uint64 iID);
00073 PTuple* pGetPTupleExtant(uint64 iID);
00074
00075 void pRegisterAQC(AddedQueryCombo& ioAQC);
00076
00077 void Callback();
00078 static void sCallback(void* iRefcon);
00079
00080 ZRef<ZTSWatcher> fWatcher;
00081 Callback_t fCallback;
00082 void* fRefcon;
00083 ZMutexNR fMutex_CallDoIt;
00084 ZMutexNR fMutex_Save;
00085 ZCondition fCondition_Save;
00086
00087 enum { eMode_Normal, eMode_Save, eMode_Discard } fMode;
00088
00089 bool* fHasChangesPtr;
00090
00091 std::map<int64, PQuery> fPQueries;
00092 std::map<uint64, PTuple> fPTuples;
00093 };
00094
00095 #endif // __ZTSWatcher_Undo__