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/Echo/echo-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 
00020 #define PROJECT_NAME "fbfs"
00021 #define MODULE_NAME "Echo"
00022 
00023 #include <iostream.h>
00024 #include <signal.h>
00025 
00026 #include "../utils/NameServer.h"
00027 #include "Echo_i.h"
00028 
00029 CORBA::ORB_ptr orbptr;
00030 char* server_name;
00031 char* server_context;
00032 char* server_kind;
00033 
00034 void catch_sigterm(int sig);
00035 
00036 int main(int argc, char **argv)
00037 {
00038     try {
00039         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
00040 
00041         CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00042         PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
00043 
00044         fbfs::Echo_i* object = new fbfs::Echo_i();
00045 
00046         PortableServer::ObjectId_var object_id = poa->activate_object(object);
00047 
00048         if( argc != 3 ) {
00049             cerr << "Usage: " << argv[0] << " <context> <name>" << endl;
00050             return 1;
00051         }
00052         server_context=argv[1];
00053         server_name=argv[2];
00054         server_kind=MODULE_NAME;
00055         
00056         // Obtain a reference to the object, and register it in
00057         // the naming service.
00058         obj = object->_this();
00059         if( !utils::NameServer::bindObjectToName(server_context, server_name, server_kind, orb, obj) )
00060             return 1;
00061 
00062         // Now the naming service retains a reference to the object.
00063         // I can remove the reference obtained with object->_this();
00064         object->_remove_ref();
00065 
00066         PortableServer::POAManager_var pman = poa->the_POAManager();
00067         pman->activate();
00068 
00069         // Attiva un signal handler sul sigquit
00070         orbptr = orb;
00071         signal(SIGTERM, catch_sigterm);
00072 
00073         orb->run();
00074         orb->destroy();
00075     }
00076     catch(CORBA::SystemException&) {
00077         cerr << "Caught CORBA::SystemException." << endl;
00078     }
00079     catch(CORBA::Exception&) {
00080         cerr << "Caught CORBA::Exception." << endl;
00081     }
00082     catch(omniORB::fatalException& fe) {
00083         cerr << "Caught omniORB::fatalException:" << endl;
00084         cerr << "  file: " << fe.file() << endl;
00085         cerr << "  line: " << fe.line() << endl;
00086         cerr << "  mesg: " << fe.errmsg() << endl;
00087     }
00088     catch(...) {
00089         cerr << "Caught unknown exception." << endl;
00090     }
00091 
00092     return 0;
00093 }
00094 
00095 void catch_sigterm( int sig ) {
00096     utils::NameServer::unbindObject(server_context, server_name, server_kind, orbptr);
00097     orbptr->shutdown(true); 
00098 }

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