00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <Basics.H>
00024
00025
00026 #include <SRPC.H>
00027 #include <MultiSRPC.H>
00028
00029
00030 #include <CacheConfig.H>
00031 #include <CacheIntf.H>
00032 #include <ReadConfig.H>
00033 #include <CacheState.H>
00034 #include <Debug.H>
00035
00036
00037 #include "ParCacheC.H"
00038 #include "DebugC.H"
00039
00040 using std::cout;
00041 using std::endl;
00042
00043
00044 DebugC::DebugC(CacheIntf::DebugLevel debug,
00045 bool use_rt, unsigned int rt_secs) throw ()
00046 : debug(debug), use_read_timeout(use_rt), read_timeout_seconds(rt_secs)
00047 {
00048 Text serverPort(ReadConfig::TextVal(Config_CacheSection, "Port"));
00049 this->conns = NEW_CONSTR(MultiSRPC, (serverPort));
00050 }
00051
00052
00053 DebugC::~DebugC() throw ()
00054 {
00055 if (this->conns != (MultiSRPC *)NULL)
00056 delete this->conns;
00057 }
00058
00059 void DebugC::NullCall(CacheIntf::ProcIds id, char *name,
00060 CacheIntf::DebugLevel level) const throw (SRPC::failure)
00061 {
00062 MultiSRPC::ConnId cid = -1;
00063
00064 try {
00065
00066 SRPC *srpc;
00067 cid = this->conns->Start(*ParCacheC::Locate(), srpc);
00068 if(use_read_timeout)
00069 {
00070 srpc->enable_read_timeout(read_timeout_seconds);
00071 }
00072
00073
00074 if (this->debug >= level) {
00075 Debug::Lock();
00076 cout << Debug::Timestamp() << "CALLED -- " << name << endl;
00077 cout << endl;
00078 Debug::Unlock();
00079 }
00080
00081
00082 srpc->start_call(id, CacheIntf::Version);
00083 srpc->send_end();
00084
00085
00086 srpc->recv_end();
00087
00088
00089 if (this->debug >= level) {
00090 Debug::Lock();
00091 cout << Debug::Timestamp() << "RETURNED -- " << name << endl;
00092 cout << endl;
00093 Debug::Unlock();
00094 }
00095
00096
00097 this->conns->End(cid);
00098 }
00099 catch (SRPC::failure) {
00100 this->conns->End(cid);
00101 throw;
00102 }
00103 }
00104
00105 void DebugC::FlushAll() const throw (SRPC::failure)
00106 {
00107 NullCall(CacheIntf::FlushAllProc, "FlushAll", CacheIntf::MPKFileFlush);
00108 }
00109
00110 void DebugC::GetCacheId( CacheId &id)
00111 const throw (SRPC::failure)
00112 {
00113 MultiSRPC::ConnId cid = -1;
00114
00115 try {
00116
00117 SRPC *srpc;
00118 cid = this->conns->Start(*ParCacheC::Locate(), srpc);
00119 if(use_read_timeout)
00120 {
00121 srpc->enable_read_timeout(read_timeout_seconds);
00122 }
00123
00124
00125 srpc->start_call(CacheIntf::GetCacheIdProc, CacheIntf::Version);
00126 srpc->send_end();
00127
00128
00129 id.Recv(*srpc);
00130 srpc->recv_end();
00131
00132
00133 this->conns->End(cid);
00134 }
00135 catch (SRPC::failure) {
00136 this->conns->End(cid);
00137 throw;
00138 }
00139 }
00140
00141 void DebugC::GetCacheState( CacheState &state)
00142 const throw (SRPC::failure)
00143 {
00144 MultiSRPC::ConnId cid = -1;
00145
00146 try {
00147
00148 SRPC *srpc;
00149 cid = this->conns->Start(*ParCacheC::Locate(), srpc);
00150 if(use_read_timeout)
00151 {
00152 srpc->enable_read_timeout(read_timeout_seconds);
00153 }
00154
00155
00156 srpc->start_call(CacheIntf::GetCacheStateProc, CacheIntf::Version);
00157 srpc->send_end();
00158
00159
00160 state.Recv(*srpc);
00161 srpc->recv_end();
00162
00163
00164 this->conns->End(cid);
00165 }
00166 catch (SRPC::failure) {
00167 this->conns->End(cid);
00168 throw;
00169 }
00170 }
00171 void DebugC::GetCacheInstance( FP::Tag &instance_fp)
00172 const throw (SRPC::failure)
00173 {
00174 MultiSRPC::ConnId cid = -1;
00175 try {
00176
00177 SRPC *srpc;
00178 cid = this->conns->Start(*ParCacheC::Locate(), srpc);
00179 if(use_read_timeout)
00180 {
00181 srpc->enable_read_timeout(read_timeout_seconds);
00182 }
00183
00184
00185 srpc->start_call(CacheIntf::GetCacheInstanceProc, CacheIntf::Version);
00186 srpc->send_end();
00187
00188
00189 instance_fp.Recv(*srpc);
00190 srpc->recv_end();
00191
00192
00193 this->conns->End(cid);
00194 }
00195 catch (SRPC::failure) {
00196 this->conns->End(cid);
00197 throw;
00198 }
00199 }