00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #define PROJECT_NAME "fbfs"
00026 #define MODULE_NAME "NameServer"
00027
00028 #include <iostream.h>
00029 #include <signal.h>
00030
00031 #include "../utils/NameServer.h"
00032 #include "NameServer_i.h"
00033
00034 CORBA::ORB_ptr orbptr;
00035 const char* server_name;
00036 const char* server_context;
00037 const char* server_kind;
00038
00039 void catch_sigterm(int sig);
00040
00041 int main(int argc, char **argv)
00042 {
00043 try {
00044 utils::Prefs prefs(argc, argv, "nameserver-server.cfg");
00045
00046 string context = prefs.get("context");
00047 server_context = context.c_str();
00048 string name = prefs.get("name");
00049 server_name = name.c_str();
00050 server_kind=MODULE_NAME;
00051
00052 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
00053
00054 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00055 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
00056
00057 fbfs::NameServer_i* object = new fbfs::NameServer_i(prefs, orb);
00058
00059 PortableServer::ObjectId_var object_id = poa->activate_object(object);
00060
00061
00062
00063 obj = object->_this();
00064 if( !utils::NameServer::bindObjectToName(server_context, server_name, server_kind, orb, obj) )
00065 return 1;
00066
00067
00068
00069 object->_remove_ref();
00070
00071 PortableServer::POAManager_var pman = poa->the_POAManager();
00072 pman->activate();
00073
00074
00075 orbptr = orb;
00076 signal(SIGTERM, catch_sigterm);
00077
00078 orb->run();
00079 orb->destroy();
00080 }
00081 catch(CORBA::SystemException&) {
00082 cerr << "Caught CORBA::SystemException." << endl;
00083 }
00084 catch(CORBA::Exception&) {
00085 cerr << "Caught CORBA::Exception." << endl;
00086 }
00087 catch(omniORB::fatalException& fe) {
00088 cerr << "Caught omniORB::fatalException:" << endl;
00089 cerr << " file: " << fe.file() << endl;
00090 cerr << " line: " << fe.line() << endl;
00091 cerr << " mesg: " << fe.errmsg() << endl;
00092 }
00093 catch(...) {
00094 cerr << "Caught unknown exception." << endl;
00095 }
00096
00097 return 0;
00098 }
00099
00100 void catch_sigterm( int sig ) {
00101 utils::NameServer::unbindObject(server_context, server_name, server_kind, orbptr);
00102 orbptr->shutdown(true);
00103 }