Pagina Principale   Moduli   Lista dei namespaces   Gerarchia delle classi   Lista in ordine alfabetico   Lista dei composti   Lista dei files   Membri dei namespaces   Membri dei composti   Membri dei files   Esempi  

/home/fbassi/devel/projects/reti/ObjectManager/objectmanager-server.cc

Vai alla documentazione di questo file.
00001 /*
00002  *    FBFS Distributed Object Repository
00003  *    Copyright (C) 2001 Francesco V. Bassi
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; either version 2 of the License, or
00008  *    (at your option) any later version.
00009  *
00010  *    This program 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
00013  *    GNU General Public License for more details.
00014  *
00015  *    You should have received a copy of the GNU General Public License
00016  *    along with this program; if not, write to the Free Software
00017  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00025 #define PROJECT_NAME "fbfs"
00026 #define MODULE_NAME "OM"
00027 
00028 #include <iostream.h>
00029 #include <signal.h>
00030 
00031 #include "../utils/NameServer.h"
00032 #include "ObjectManager_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, "objectmanager-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::ObjectManager_i* object = new fbfs::ObjectManager_i(prefs, orb);
00058 
00059         PortableServer::ObjectId_var object_id = poa->activate_object(object);
00060 
00061         // Obtain a reference to the object, and register it in
00062         // the naming service.
00063         obj = object->_this();
00064         if( !utils::NameServer::bindObjectToName(server_context, server_name, server_kind, orb, obj) )
00065             return 1;
00066 
00067         // Now the naming service retains a reference to the object.
00068         // I can remove the reference obtained with object->_this();
00069         object->_remove_ref();
00070 
00071         PortableServer::POAManager_var pman = poa->the_POAManager();
00072         pman->activate();
00073 
00074         // Attiva un signal handler sul sigquit
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 }

Generato il Thu Feb 15 13:24:56 2001 per A Simple Distributed Object Repository with CORBA & C++. da doxygen1.2.3 scritto da Dimitri van Heesch, © 1997-2000