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

VestaSourceSRPC.C

Go to the documentation of this file.
00001 // Copyright (C) 2004, Kenneth C. Schalk
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 // VestaSourceSRPC.C - shared code used by repository client APIs
00020 
00021 // Last modified on Fri Apr 22 13:23:37 EDT 2005 by ken@xorian.net
00022 
00023 #include "VestaSourceSRPC.H"
00024 #include "VDirSurrogate.H"
00025 
00026 static MultiSRPC* g_vssmulti;
00027 
00028 // default repository
00029 static Text g_default_host;
00030 static Text g_default_intf;
00031 
00032 using std::cerr;
00033 using std::endl;
00034 
00035 extern "C"
00036 {
00037   void 
00038   VestaSourceSRPC_init_inner() throw()
00039   {
00040     try {
00041       g_default_intf =
00042         VestaConfig::get_Text("Repository", "VestaSourceSRPC_port");
00043       // Sanity check on the port
00044       if(g_default_intf.Empty())
00045         {
00046           cerr << "Fatal: [Repository]VestaSourceSRPC_port is empty"
00047                << endl;
00048           abort();
00049         }
00050       g_default_host =
00051         VestaConfig::get_Text("Repository", "VestaSourceSRPC_host");
00052       // Sanity check on the host.
00053       if(g_default_host.Empty())
00054         {
00055           cerr << "Fatal: [Repository]VestaSourceSRPC_host is empty"
00056                << endl;
00057           abort();
00058         }
00059       if(g_default_host.FindChar(':') != -1)
00060         {
00061           cerr << "Fatal: [Repository]VestaSourceSRPC_host contains a colon"
00062                << endl;
00063           abort();
00064         }
00065       g_vssmulti = NEW(MultiSRPC);
00066       AccessControl::commonInit();
00067     } catch (VestaConfig::failure f) {
00068       cerr << "VestaConfig::failure " << f.msg << endl;
00069       // This is a fatal error
00070       abort();
00071     }
00072   }
00073 }
00074 
00075 static void VestaSourceSRPC_init() throw()
00076 {
00077   static pthread_once_t vssonce = PTHREAD_ONCE_INIT;
00078   pthread_once(&vssonce, VestaSourceSRPC_init_inner);
00079 }
00080 
00081 Text VestaSourceSRPC::defaultHost() throw()
00082 {
00083   VestaSourceSRPC_init();
00084   return g_default_host;
00085 }
00086 Text VestaSourceSRPC::defaultInterface() throw()
00087 {
00088   VestaSourceSRPC_init();
00089   return g_default_intf;
00090 }
00091 
00092 MultiSRPC::ConnId VestaSourceSRPC::Start(SRPC *&srpc) throw (SRPC::failure)
00093 {
00094   VestaSourceSRPC_init();
00095   return g_vssmulti->Start(VestaSourceSRPC::defaultHost(),
00096                            VestaSourceSRPC::defaultInterface(),
00097                            srpc);
00098 }
00099 
00100 MultiSRPC::ConnId VestaSourceSRPC::Start(SRPC *&srpc,
00101                         const Text &host_interface)
00102   throw (SRPC::failure)
00103 {
00104   VestaSourceSRPC_init();
00105   Text host, intf;
00106   int colon = host_interface.FindChar(':');
00107   if(colon == -1)
00108     {
00109       host = host_interface;
00110       intf = VestaSourceSRPC::defaultInterface();
00111     }
00112   else
00113     {
00114       host = host_interface.Sub(0, colon);
00115       intf = host_interface.Sub(colon+1);
00116     }
00117   if(host.Empty())
00118     host = VestaSourceSRPC::defaultHost();
00119   if(intf.Empty())
00120     intf = VestaSourceSRPC::defaultInterface();
00121 
00122   return g_vssmulti->Start(host, intf, srpc);
00123 }
00124 
00125 MultiSRPC::ConnId VestaSourceSRPC::Start(SRPC *&srpc,
00126                                          Text hostname, Text interface)
00127   throw (SRPC::failure)
00128 {
00129   VestaSourceSRPC_init();
00130   if(hostname.Empty())
00131     hostname = VestaSourceSRPC::defaultHost();
00132   if(interface.Empty())
00133     interface = VestaSourceSRPC::defaultInterface();
00134 
00135   return g_vssmulti->Start(hostname, interface, srpc);
00136 }
00137   
00138 void VestaSourceSRPC::End(MultiSRPC::ConnId id) throw()
00139 {
00140   VestaSourceSRPC_init();
00141   g_vssmulti->End(id);
00142 }
00143 
00144 // Common code for sending an AccessControl::Identity
00145 void VestaSourceSRPC::send_identity(SRPC* srpc, AccessControl::Identity who)
00146   throw(SRPC::failure)
00147 {
00148   VestaSourceSRPC_init();
00149   if (who == NULL) {
00150     who = AccessControl::self();
00151   }
00152   who->send(srpc);
00153 }

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