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

ShortIdClient.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 //
00020 // ShortIdClient.C
00021 // Last modified on Mon May 23 21:40:36 EDT 2005 by ken@xorian.net  
00022 //      modified on Thu Jul 20 14:24:29 PDT 2000 by mann  
00023 //      modified on Mon Apr 28 17:30:27 PDT 1997 by heydon
00024 //
00025 // Client code, using Roy's SRPC package
00026 //
00027 
00028 #include "ShortIdBlock.H"
00029 #include "ShortIdSRPC.H"
00030 #include "SRPC.H"
00031 #include "VestaConfig.H"
00032 #include <Thread.H>
00033 #include <pthread.h>
00034 #include <assert.h>
00035 
00036 using std::cerr;
00037 using std::endl;
00038 
00039 // Module globals
00040 static pthread_once_t once = PTHREAD_ONCE_INIT;
00041 static SRPC* srpc;
00042 static Basics::mutex mu;  // protects srpc
00043 
00044 extern "C"
00045 {
00046   static void
00047   ShortIdClientImport()
00048   {
00049     Text port, host;
00050     try {
00051         port = VestaConfig::get_Text("Repository", "ShortIdSRPC_port");
00052         host = VestaConfig::get_Text("Repository", "ShortIdSRPC_host");
00053         srpc = NEW_CONSTR(SRPC, (SRPC::caller, port, host));
00054     } catch (VestaConfig::failure f) {
00055         cerr << f.msg << endl;
00056         throw;  // meant to be uncaught and fatal
00057     }
00058   }
00059 }
00060 
00061 ShortIdBlock*
00062 ShortIdBlock::acquire(bool leafflag) throw(SRPC::failure)
00063 {
00064     pthread_once(&once, ShortIdClientImport);
00065     ShortIdBlock *bk = NEW(ShortIdBlock);
00066     int size = sizeof(bk->bits);
00067     mu.lock();
00068     srpc->start_call(ShortIdSRPC::AcquireShortIdBlock,
00069                      ShortIdSRPC::version);
00070     srpc->send_int((int) leafflag);
00071     srpc->send_end();
00072     bk->start = bk->next = (ShortId) srpc->recv_int();
00073     bk->leaseExpires = (time_t) srpc->recv_int();
00074     srpc->recv_bytes_here((char *) bk->bits, size);
00075     assert(size == sizeof(bk->bits));
00076     srpc->recv_end();
00077     mu.unlock();
00078     return bk;
00079 }
00080 
00081 bool
00082 ShortIdBlock::renew(ShortIdBlock* bk) throw(SRPC::failure)
00083 {
00084     pthread_once(&once, ShortIdClientImport);
00085     mu.lock();
00086     srpc->start_call(ShortIdSRPC::RenewShortIdBlock,
00087                      ShortIdSRPC::version);
00088     srpc->send_int((int) bk->start);
00089     srpc->send_end();
00090     bk->leaseExpires = (time_t) srpc->recv_int();
00091     bool res = (bool) srpc->recv_int();
00092     srpc->recv_end();
00093     mu.unlock();
00094     return res;
00095 }
00096 
00097 void
00098 ShortIdBlock::release(ShortIdBlock* bk) throw(SRPC::failure)
00099 {
00100     pthread_once(&once, ShortIdClientImport);
00101     mu.lock();
00102     srpc->start_call(ShortIdSRPC::ReleaseShortIdBlock,
00103                      ShortIdSRPC::version);
00104     srpc->send_int((int) bk->start);
00105     srpc->send_end();
00106     srpc->recv_end();
00107     mu.unlock();
00108 }
00109 
00110 int
00111 ShortIdBlock::keepDerived(ShortIdsFile ds, time_t dt, bool force)
00112   throw(SRPC::failure)
00113 {
00114     pthread_once(&once, ShortIdClientImport);
00115     mu.lock();
00116     srpc->start_call(ShortIdSRPC::KeepDerived,
00117                      ShortIdSRPC::version);
00118     srpc->send_int((int) ds);
00119     srpc->send_int((int) dt);
00120     srpc->send_int((int) force);
00121     srpc->send_end();
00122     int res = srpc->recv_int();
00123     srpc->recv_end();
00124     mu.unlock();
00125     return res;
00126 }
00127 
00128 void
00129 ShortIdBlock::checkpoint() throw(SRPC::failure)
00130 {
00131     pthread_once(&once, ShortIdClientImport);
00132     mu.lock();
00133     srpc->start_call(ShortIdSRPC::Checkpoint,
00134                      ShortIdSRPC::version);
00135     srpc->send_end();
00136     srpc->recv_end();
00137     mu.unlock();
00138 }
00139 
00140 void
00141 ShortIdBlock::getWeedingState(ShortIdsFile& ds, time_t& dt,
00142                               ShortIdsFile& ss, time_t& st,
00143                               bool& sourceWeedInProgress,
00144                               bool& deletionsInProgress,
00145                               bool& deletionsDone,
00146                               bool& checkpointInProgress)
00147   throw(SRPC::failure)
00148 {
00149     pthread_once(&once, ShortIdClientImport);
00150     mu.lock();
00151     srpc->start_call(ShortIdSRPC::GetWeedingState,
00152                      ShortIdSRPC::version);
00153     srpc->send_end();
00154     ds = (ShortIdsFile) srpc->recv_int();
00155     dt = (time_t) srpc->recv_int();
00156     ss = (ShortIdsFile) srpc->recv_int();
00157     st = (time_t) srpc->recv_int();
00158     sourceWeedInProgress = (bool) srpc->recv_int();
00159     deletionsInProgress = (bool) srpc->recv_int();
00160     deletionsDone = (bool) srpc->recv_int();
00161     checkpointInProgress = (bool) srpc->recv_int();
00162     srpc->recv_end();
00163     mu.unlock();
00164 }
00165 

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