00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "VestaSourceSRPC.H"
00024 #include "VDirSurrogate.H"
00025
00026 static MultiSRPC* g_vssmulti;
00027
00028
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
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
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
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
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 }