00001
00176
#ifndef _ORBINIT_GUARD
00177
#define _ORBINIT_GUARD
00178
00179
#include <string>
00180
#include <exception>
00181
#include <stdexcept>
00182
#include <vector>
00183
#include <map>
00184
00185
#include "BP_CORBA.h"
00186
#include "BPExceptions.h"
00187
#include "SysHook.h"
00188
#include "SignalController.h"
00189
#include "InitCommand.h"
00190
#include "ServantFactory.h"
00191
#include "OrbRunStrategy.h"
00192
00193
00194
00198 #define _ORBINIT_CMDLINE_OPTIONS_PFX "-BP"
00199
00200
00210 class OrbInit :
public virtual SysHook
00211 {
00212
public:
00217 class InitializationError:
public std::exception
00218 {
00219
public:
00224 InitializationError(std::string theMsg): msg(theMsg) {};
00225
00231
InitializationError(
const InitializationError& err);
00232
00237 virtual const char*
what() const throw()
00238 {
00239
return(msg.c_str());
00240 };
00241
00243 virtual ~InitializationError() throw() {};
00244
00245
private:
00246
const std::string msg;
00247 };
00248
00249
00260 enum InitState
00261 {
00262 PRE_ORB_INIT,
00263 POST_ORB_INIT,
00264 POST_POA_INIT,
00265 RUNNING,
00266 SHUTTING_DOWN
00267 };
00268
00269
00273
OrbInit(
int argc,
char** argv);
00274
00279
virtual ~OrbInit();
00280
00281
00291
void addServantFactory(
ServantFactory* factory)
00292
throw(
BoilerPlate::IllegalStateException);
00293
00307
void addPreORBInitCommand(
PreInitCommand* command)
00308
throw(
BoilerPlate::IllegalStateException);
00309
00322
void addPostORBInitCommand(
PostORBInitCommand* command)
00323
throw(
BoilerPlate::IllegalStateException);
00324
00337
void addPostPOAInitCommand(
PostInitCommand* command)
00338
throw(
BoilerPlate::IllegalStateException);
00339
00353
void addPreShutdownCommand(
PostInitCommand* command)
00354
throw(
BoilerPlate::IllegalStateException);
00355
00371
void setOrbRunStrategy(
OrbRunStrategy* strategy)
00372
throw(
BoilerPlate::IllegalStateException);
00373
00389
void initialize(
int argc,
char** argv)
00390
throw(InitializationError);
00391
00392
00408
void buildServants()
00409 throw(InitializationError,
00410 BoilerPlate::IllegalStateException,
00411
ServantFactory::ServantBuildException
00412 );
00413
00430
void acceptMessages()
00431 throw(CORBA::SystemException, std::runtime_error);
00432
00436 virtual
void shutDown() throw(CORBA::SystemException);
00437
00440 virtual
void run() throw(CORBA::SystemException);
00441
00450 virtual
void holdRequests(
bool wait)
00451 throw(PortableServer::POAManager::AdapterInactive);
00452
00455 virtual
void activate()
00456 throw(PortableServer::POAManager::AdapterInactive);
00457
00466 virtual
void discardRequests(
bool wait)
00467 throw(PortableServer::POAManager::AdapterInactive);
00468
00469
00477 SignalController& getSignalController()
00478 {
00479
return(*_sigcontroller);
00480 }
00481
00482
private:
00483
void _initializeORB(
int,
char**) throw(InitializationError);
00484
void _initializeRootPOA() throw(InitializationError);
00485
void _buildServants()
00486 throw(InitializationError,
ServantFactory::ServantBuildException);
00487
00488
void _initializeConfigMap(
int,
char**)
00489 throw(InitializationError);
00490
00491
void _runPreORBInitCommands() throw(InitializationError);
00492
void _runPostORBInitCommands() throw(InitializationError);
00493
void _runPostRootPOAInitCommands() throw(InitializationError);
00494
void _runPostRunCommands() throw(InitializationError);
00495
00496
void _write_pid_file();
00497
00498
00499 CORBA::ORB_var _orb;
00500 PortableServer::POA_var _rootpoa;
00501 PortableServer::POAManager_var _manager;
00502
bool _hasBeenInitialized;
00503 std::vector<
ServantFactory*> _factories;
00504
00505
00506 std::vector<
PreInitCommand*> _preinitCommands;
00507 std::vector<
PostORBInitCommand*> _postORBInitCommands;
00508 std::vector<
PostInitCommand*> _postRootPOACommands;
00509 std::vector<
PostInitCommand*> _postRunCommands;
00510
00511
00512 ConfMap nsServantIdMap;
00513
00514
00515 InitState _state;
00516
00517
OrbRunStrategy *_runStrategy;
00518
SignalController *_sigcontroller;
00519
00520 };
00521
00522 #endif