Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

omniEvents.cc

Go to the documentation of this file.
00001 // -*- Mode: C++; -*-
00002 //                            Package   : omniEvents
00003 //  omniEvents.cc             Created   : 1/4/98
00004 //                            Author    : Paul Nader (pwn)
00005 //
00006 //    Copyright (C) 1998 Paul Nader.
00007 //
00008 //    This file is part of the omniOEvents application.
00009 //
00010 //    omniEvents is free software; you can redistribute it and/or
00011 //    modify it under the terms of the GNU Lesser General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 2.1 of the License, or (at your option) any later version.
00014 //
00015 //    omniEvents is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    Lesser General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU Lesser General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // Description:
00025 //    Event Services Channel Factory implementation. The factory registers
00026 //    itself with the naming service. Clients wishing to create event
00027 //    channels can either use the factory by resolving its name with the
00028 //    naming service or create in-process channels.
00029 //      
00030 
00031 /*
00032   $Log: omniEvents.cc,v $
00033   Revision 1.4  2003/11/14 14:04:33  alextingle
00034   Improved helpfulness of usage and error messages.
00035 
00036   Revision 1.3  2003/11/03 22:42:02  alextingle
00037   Removed all platform specific switches. Now uses autoconf,
00038   config.h. No longer removes arguments as they are processed. This
00039   enables the application to accept options with no whitespace before
00040   the argument.
00041   E.g. `omniEvents -s1234 -l/var/log' now works as expected.
00042 
00043   Revision 1.1.1.1.2.1  2002/09/28 22:20:51  shamus13
00044   Added ifdefs to enable omniEvents to compile
00045   with both omniORB3 and omniORB4. If __OMNIORB4__
00046   is defined during compilation, omniORB4 headers
00047   and command line option syntax is used, otherwise
00048   fall back to omniORB3 style.
00049 
00050   Revision 1.1.1.1  2002/09/25 19:00:34  shamus13
00051   Import of OmniEvents source tree from release 2.1.1
00052 
00053   Revision 1.5  2000/08/30 04:37:03  naderp
00054   Port to omniORB 3.0.1.
00055 
00056   Revision 1.4  2000/03/06 13:19:09  naderp
00057   Initialising EventChannelFactory with port number.
00058 
00059   Revision 1.3  2000/03/06 04:12:56  naderp
00060   No longer pre-generating factory key.
00061   Removed internal dependency between factory and naming service.
00062 
00063   Revision 1.2  2000/03/02 04:21:36  naderp
00064   Printing factory IOR.
00065 
00066   Revision 1.1  1999/11/02 02:29:40  naderp
00067   Added <signal.h>.
00068 
00069   Revision 1.0  1999/11/01 17:06:59  naderp
00070   omniEvents 2.0
00071   Added logfile initialisation and creation of default factory.
00072 
00073 Revision 0.5  99/08/27  17:04:15  17:04:15  naderp (Paul Nader)
00074 Changed filename to omniEvents.cc
00075 
00076 Revision 0.4  99/08/27  11:48:49  11:48:49  naderp (Paul Nader)
00077 Partitioned EventChannelFactory_i from CosEvent_i.
00078 
00079 Revision 0.3  99/04/23  16:03:51  16:03:51  naderp (Paul Nader)
00080 gcc port.
00081 Ignore unix SIGPIPE if connections are severed.
00082 
00083 Revision 0.2  99/04/23  09:33:11  09:33:11  naderp (Paul Nader)
00084 Windows Port.
00085 
00086 Revision 0.1  98/11/25  14:07:33  14:07:33  naderp (Paul Nader)
00087 Initial Revision
00088 
00089 */
00090 
00091 #ifdef HAVE_CONFIG_H
00092 #  include "config.h"
00093 #endif
00094 
00095 #ifdef HAVE_GETOPT
00096 #  include <unistd.h>
00097 extern char* optarg;
00098 extern int optind;
00099 #else
00100 #  include "getopt.h"
00101 #endif
00102 
00103 #include "naming.h"
00104 #include "omniEventsLog.h"
00105 #include "EventChannelFactory.h"
00106 #include "Orb.h"
00107 
00108 #ifdef HAVE_SIGNAL_H
00109 #  include <signal.h>
00110 #endif
00111 
00112 #include <stdio.h> // for sprintf
00113 
00114 void removeArgs(int& argc, char** argv, int idx, int nargs);
00115 void insertArgs(int& argc, char**& argv, int idx, int nargs);
00116 void usage();
00117 
00118 int
00119 main(int argc, char **argv)
00120 {
00121   //
00122   // Process Options
00123   int c;
00124   int port = 0;
00125   int first = 0;
00126   char *logDir = NULL;
00127   char *factoryName = (char *) "EventChannelFactory";
00128   char *factoryKind = (char *) "EventChannelFactory";
00129 
00130   while ((c = getopt(argc,argv,"O:s:l:N:K:h")) != EOF)
00131   {
00132      switch (c)
00133      {
00134         case 's': first = 1;
00135                   port = atoi(optarg);
00136                   if (port <= 0)
00137                   {
00138                      cerr << "\nError: port must be a positive integer" << endl;
00139                      usage();
00140                   }
00141                   break;
00142 
00143         case 'l': logDir = optarg;
00144                   break;
00145 
00146         case 'N': factoryName = optarg;
00147                   break;
00148 
00149         case 'K': factoryKind = optarg;
00150                   break;
00151 
00152         case 'O': break;
00153 
00154         case 'h':
00155         default : usage();
00156                   break;
00157      }
00158   }
00159 
00160   using namespace OmniEvents;
00161 
00162   //
00163   // Create log file instance.
00164   omniEventsLog logfile(port, logDir);
00165 
00166   //
00167   // Add a fake command line option to tell the BOA which port to use.
00168   port = logfile.getPort();
00169   insertArgs(argc, argv, 1, 2);
00170 
00171   //
00172   // Initialise orb & POAs.
00173   argv[1] = strdup("-ORBendPoint");
00174   argv[2] = new char[32 + 1];
00175   sprintf(argv[2], "giop:::%d", port);
00176   Orb::inst().init(argc,argv);
00177   {
00178     PortableServer::POAManager_var pman;
00179     pman=Orb::inst()._RootPOA->the_POAManager();
00180     pman->activate();
00181     pman=Orb::inst()._omniINSPOA->the_POAManager();
00182     pman->activate();
00183   }
00184 
00185   //
00186   // Create a default factory.
00187   EventChannelFactory_i *factory = NULL;
00188   if (first)
00189   {
00190      //
00191      // Create Event Channel Factory.
00192      factory = new EventChannelFactory_i(port);
00193 
00194      //
00195      // Create Name
00196      CosNaming::Name *name = new CosNaming::Name;
00197      name->length(1);
00198      (*name)[0].id = CORBA::string_dup (factoryName);
00199      (*name)[0].kind = CORBA::string_dup (factoryKind);
00200 
00201      //
00202      // Register Event Channel Factory with the Naming Service.
00203      bindName2Object(Orb::inst()._NameService.in(), *name, factory->_this());
00204   }
00205 
00206   //
00207   // If omniEvents is restarting then the omniEventsLog object
00208   // will take care of creating the factory and any subordinate
00209   // event channels, proxies, etc under it.
00210   logfile.init(factory);
00211 
00212   //
00213   // Print the factory IOR.
00214   if (! CORBA::is_nil (factory->_this()))
00215   {
00216      char *iorstr;
00217      iorstr = Orb::inst()._orb->object_to_string(factory->_this());
00218      cout << "Channel Factory is " << iorstr << "\n";
00219      delete iorstr;
00220   }
00221 
00222 #ifdef HAVE_SIGNAL_H
00223   // Ignore broken pipes
00224   signal(SIGPIPE, SIG_IGN);
00225 #endif
00226 
00227   //
00228   // Use the main thread to collect orphaned responses.
00229   Orb::inst().run();
00230 
00231   return 0;
00232 }
00233 
00234 void
00235 removeArgs(int& argc, char** argv, int idx, int nargs)
00236 {
00237   if ((idx+nargs) > argc) return;
00238   for (int i = idx+nargs; i < argc; i++) {
00239     argv[i-nargs] = argv[i];
00240   }
00241   argc -= nargs;
00242 }
00243 
00244 void
00245 insertArgs(int& argc, char**& argv, int idx, int nargs)
00246 {
00247   char** newArgv = new char*[argc+nargs];
00248   int i;
00249   for (i = 0; i < idx; i++) {
00250     newArgv[i] = argv[i];
00251   }
00252   for (i = idx; i < argc; i++) {
00253     newArgv[i+nargs] = argv[i];
00254   }
00255   argv = newArgv;
00256   argc += nargs;
00257 }
00258 
00259 void
00260 usage()
00261 {
00262    cerr << "\nusage: omniEvents [-s port] [-l logdir] [-N name] [-K kind] [-h]\n" << endl;
00263    cerr << "         -s configure server port, create persistency log file" << endl;
00264    cerr << "         -l full path to log and data directory" << endl;
00265    cerr << "         -N name specify factory name [\"EventChannelFactory\"]" << endl;
00266    cerr << "         -K kind specify factory kind [\"EventChannelFactory\"]" << endl;
00267    cerr << "         -h     display usage" << endl;
00268    cerr << "\nUse -s option to start omniEvents for the first time." << endl;
00269    cerr << "Use -l option to specify the directory where the log/data files are kept.\n";
00270    cerr << "You can also set the environment variable " << OMNIEVENTS_LOGDIR_ENV_VAR << endl;
00271    cerr << "to specify the directory where the log/data files are kept.\n" << endl;
00272    exit(-1);
00273 }

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15