00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __XACTION_H__
00025 #define __XACTION_H__
00026
00027 #include <list>
00028 #include <string>
00029 #include "sink.h"
00030 #include "view.h"
00031
00032 BEGIN_NAMESPACE( classad )
00033
00034 class ClassAd;
00035 class ClassAdCollection;
00036
00037 class XactionRecord {
00038 public:
00039 XactionRecord( ) { op = -1; key = ""; rec = 0; }
00040 bool operator==( const XactionRecord &xrec ) { return false; }
00041 bool operator< ( const XactionRecord &xrec ) { return false; }
00042
00043 int op;
00044 std::string key;
00045 ClassAd *rec;
00046 ClassAd *backup;
00047 };
00048
00049 typedef std::list<XactionRecord> CollectionOpList;
00050
00051 class ServerTransaction {
00052 public:
00053 ServerTransaction( );
00054 ~ServerTransaction( );
00055
00056 inline void SetCollectionServer( ClassAdCollection *c ) { server=c; }
00057 inline void GetCollectionServer( ClassAdCollection *&c ){ c=server; }
00058 inline void SetXactionName( const std::string &n ) { xactionName = n; }
00059 inline void GetXactionName(std::string &n ) const { n = xactionName; }
00060 inline void SetLocalXaction( bool l ) { local = l; }
00061 inline bool GetLocalXaction( ) const { return( local ); }
00062
00063 void ClearRecords( );
00064 void AppendRecord( int, const std::string &, ClassAd * );
00065 bool Commit( );
00066 bool Log( FILE *fp, ClassAdUnParser *unp );
00067 ClassAd *ExtractErrorCause( );
00068
00069 enum { ABSENT, ACTIVE, COMMITTED };
00070
00071 private:
00072 std::string xactionName;
00073 bool local;
00074 ClassAdCollection *server;
00075 CollectionOpList opList;
00076
00077 int xactionErrno;
00078 std::string xactionErrMsg;
00079 ClassAd *xactionErrCause;
00080 };
00081
00082
00083 class Sock;
00084
00085 class ClientTransaction {
00086 public:
00087 ClientTransaction( );
00088 ~ClientTransaction( );
00089
00090 inline void SetServerAddr( const std::string &a, int p ) { addr=a; port=p; }
00091 inline void GetServerAddr( std::string &a, int &p ) const { a=addr; p=port; }
00092 inline void SetXactionName( const std::string &n ) { xactionName = n; }
00093 inline void GetXactionName( std::string &n ) const { n = xactionName; }
00094 inline void SetXactionState( char s ) { state = s; }
00095 inline char GetXactionState( ) const { return( state ); }
00096
00097 bool LogCommit( FILE *, ClassAdUnParser *unp );
00098 bool LogAckCommit( FILE *, ClassAdUnParser *unp );
00099 bool LogAbort( FILE *, ClassAdUnParser *unp );
00100
00101 enum { ACTIVE, PENDING };
00102
00103 private:
00104 std::string xactionName, addr;
00105 int port;
00106 char state;
00107 };
00108
00109
00110 END_NAMESPACE
00111
00112 #endif