src_other/tuplebase/ZTSWatcher_AutoReconnect.h

00001 /*  @(#) $Id: ZTSWatcher_AutoReconnect.h,v 1.3 2007/07/21 18:18:09 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_AutoReconnect__
00026 #define __ZTSWatcher_AutoReconnect__
00027 #include "zconfig.h"
00028 
00029 #include "ZCompat_NonCopyable.h"
00030 #include "ZTSWatcher.h"
00031 #include "ZTSWatcherFactory.h"
00032 
00033 #ifndef ZCONFIG_ZTSWatcher_AutoReconnect_Debug
00034 #       define ZCONFIG_ZTSWatcher_AutoReconnect_Debug 1
00035 #endif
00036 
00037 // =================================================================================================
00038 #pragma mark -
00039 #pragma mark * ZTSWatcher_AutoReconnect
00040 
00041 class ZTSWatcher_AutoReconnect : public ZTSWatcher
00042         {
00043 public:
00044         enum { kDebug = ZCONFIG_ZTSWatcher_AutoReconnect_Debug };
00045 
00046         ZTSWatcher_AutoReconnect(ZRef<ZTSWatcherFactory> iFactory);
00047         virtual ~ZTSWatcher_AutoReconnect();
00048 
00049 // From ZTSWatcher
00050         virtual bool AllocateIDs(size_t iCount, uint64& oBaseID, size_t& oCountIssued);
00051 
00052         virtual bool Sync(
00053                 const uint64* iRemovedIDs, size_t iRemovedIDsCount,
00054                 const uint64* iAddedIDs, size_t iAddedIDsCount,
00055                 const int64* iRemovedQueries, size_t iRemovedQueriesCount,
00056                 const AddedQueryCombo* iAddedQueries, size_t iAddedQueriesCount,
00057                 std::vector<uint64>& oAddedIDs,
00058                 std::vector<uint64>& oChangedTupleIDs, std::vector<ZTuple>& oChangedTuples,
00059                 const uint64* iWrittenTupleIDs, const ZTuple* iWrittenTuples, size_t iWrittenTuplesCount,
00060                 std::map<int64, std::vector<uint64> >& oChangedQueries);
00061 
00062         virtual void SetCallback(Callback_t iCallback, void* iRefcon);
00063 
00064 // Our protocol
00065         enum EStatus
00066                 {
00067                 eStatus_Dead,
00068                 eStatus_Failed,
00069                 eStatus_Established
00070                 };
00071 
00072         virtual void NotifyStatusChange(EStatus iStatus);
00073 
00074 private:
00075         bool pEnsureConnection();
00076         bool pReestablishConnection();
00077         bool pEstablishConnection();
00078 
00079         void pUpdateRegistrations(
00080                 const uint64* iRemovedIDs, size_t iRemovedIDsCount,
00081                 const uint64* iAddedIDs, size_t iAddedIDsCount,
00082                 const int64* iRemovedQueries, size_t iRemovedQueriesCount,
00083                 const AddedQueryCombo* iAddedQueries, size_t iAddedQueriesCount);
00084 
00085         bool pAllocateIDs(size_t iCount, uint64& oBaseID, size_t& oCountIssued);
00086 
00087         bool pSync(
00088                 const uint64* iRemovedIDs, size_t iRemovedIDsCount,
00089                 const uint64* iAddedIDs, size_t iAddedIDsCount,
00090                 const int64* iRemovedQueries, size_t iRemovedQueriesCount,
00091                 const AddedQueryCombo* iAddedQueries, size_t iAddedQueriesCount,
00092                 std::vector<uint64>& oAddedIDs,
00093                 std::vector<uint64>& oChangedTupleIDs, std::vector<ZTuple>& oChangedTuples,
00094                 const uint64* iWrittenTupleIDs, const ZTuple* iWrittenTuples, size_t iWrittenTuplesCount,
00095                 std::map<int64, std::vector<uint64> >& oChangedQueries);
00096 
00097         void Callback();
00098         static void sCallback(void* iRefcon);
00099 
00100 private:
00101         ZMutex fMutex;
00102         ZRef<ZTSWatcherFactory> fFactory;
00103         ZRef<ZTSWatcher> fTSWatcher;
00104         EStatus fStatus;
00105         bool fConnectionFailed;
00106         Callback_t fCallback;
00107         void* fRefcon;
00108         set<uint64> fTupleIDs;
00109         set<AddedQueryCombo> fQueries;
00110         };
00111 
00112 #endif // __ZTSWatcher_AutoReconnect__

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