Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DebugC.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Fri Apr 22 22:29:15 EDT 2005 by ken@xorian.net
00020 //      modified on Wed Sep  2 12:49:37 PDT 1998 by heydon
00021 
00022 // from vesta/basics
00023 #include <Basics.H>
00024 
00025 // from vesta/srpc
00026 #include <SRPC.H>
00027 #include <MultiSRPC.H>
00028 
00029 // from vesta/cache-common
00030 #include <CacheConfig.H>
00031 #include <CacheIntf.H>
00032 #include <ReadConfig.H>
00033 #include <CacheState.H>
00034 #include <Debug.H>
00035 
00036 // local includes
00037 #include "ParCacheC.H"
00038 #include "DebugC.H"
00039 
00040 using std::cout;
00041 using std::endl;
00042 
00043 // constructor
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 // destructor
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         // start the connection
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         // print call
00074         if (this->debug >= level) {
00075             Debug::Lock();
00076             cout << Debug::Timestamp() << "CALLED -- " << name << endl;
00077             cout << endl;
00078             Debug::Unlock();
00079         }
00080         
00081         // send arguments
00082         srpc->start_call(id, CacheIntf::Version);
00083         srpc->send_end();
00084 
00085         // receive results
00086         srpc->recv_end();
00087 
00088         // print return
00089         if (this->debug >= level) {
00090             Debug::Lock();
00091             cout << Debug::Timestamp() << "RETURNED -- " << name << endl;
00092             cout << endl;
00093             Debug::Unlock();
00094         }
00095 
00096         // end the connection
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(/*OUT*/ CacheId &id)
00111   const throw (SRPC::failure)
00112 {
00113     MultiSRPC::ConnId cid = -1;
00114 
00115     try {
00116         // start the connection
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         // send arguments
00125         srpc->start_call(CacheIntf::GetCacheIdProc, CacheIntf::Version);
00126         srpc->send_end();
00127 
00128         // receive results
00129         id.Recv(*srpc);
00130         srpc->recv_end();
00131 
00132         // end the connection
00133         this->conns->End(cid);
00134     }
00135     catch (SRPC::failure) {
00136         this->conns->End(cid);
00137         throw;
00138     }
00139 }
00140 
00141 void DebugC::GetCacheState(/*OUT*/ CacheState &state)
00142   const throw (SRPC::failure)
00143 {
00144     MultiSRPC::ConnId cid = -1;
00145 
00146     try {
00147         // start the connection
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         // send arguments
00156         srpc->start_call(CacheIntf::GetCacheStateProc, CacheIntf::Version);
00157         srpc->send_end();
00158 
00159         // receive results
00160         state.Recv(*srpc);
00161         srpc->recv_end();
00162 
00163         // end the connection
00164         this->conns->End(cid);
00165     }
00166     catch (SRPC::failure) {
00167         this->conns->End(cid);
00168         throw;
00169     }
00170 }
00171 void DebugC::GetCacheInstance(/*OUT*/ FP::Tag &instance_fp)
00172      const throw (SRPC::failure)
00173 {
00174     MultiSRPC::ConnId cid = -1;
00175     try {
00176         // start the connection
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         // send (no) arguments
00185         srpc->start_call(CacheIntf::GetCacheInstanceProc, CacheIntf::Version);
00186         srpc->send_end();
00187 
00188         // receive results
00189         instance_fp.Recv(*srpc);
00190         srpc->recv_end();
00191 
00192         // end the connection
00193         this->conns->End(cid);
00194     }
00195     catch (SRPC::failure) {
00196         this->conns->End(cid);
00197         throw;
00198     }    
00199 }

Generated on Mon May 8 00:48:30 2006 for Vesta by  doxygen 1.4.2