src_other/tuplebase/ZTSWatcher_Undo.h

00001 /*  @(#) $Id: $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2007 Andrew Green
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_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 // From ZTSWatcher
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 // Our protocol 
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__

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