📄 event_service.cpp
字号:
// Event_Service.cpp,v 1.47 2003/11/04 05:21:30 dhinton Exp
#include "Event_Service.h"
#include "ace/Get_Opt.h"
#include "ace/Auto_Ptr.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/OS_main.h"
#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Sched/Config_Scheduler.h"
#include "orbsvcs/Event/Module_Factory.h"
#include "orbsvcs/Event/Event_Channel.h"
#include "orbsvcs/Event/EC_Default_Factory.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "tao/BiDir_GIOP/BiDirGIOP.h"
#include "ace/OS_NS_strings.h"
ACE_RCSID(Event_Service, Event_Service, "Event_Service.cpp,v 1.47 2003/11/04 05:21:30 dhinton Exp")
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
TAO_EC_Default_Factory::init_svcs ();
Event_Service event_service;
return event_service.run (argc, argv);
}
// ****************************************************************
Event_Service::Event_Service (void)
: module_factory_ (0),
sched_impl_ (0),
ec_impl_ (0),
scheduler_type_ (ES_SCHED_NONE),
event_service_type_ (ES_NEW),
use_bidir_giop_ (0)
{
}
Event_Service::~Event_Service (void)
{
delete this->ec_impl_;
this->ec_impl_ = 0;
delete this->sched_impl_;
this->sched_impl_ = 0;
delete this->module_factory_;
this->module_factory_ = 0;
}
int
Event_Service::run (int argc, ACE_TCHAR* argv[])
{
ACE_TRY_NEW_ENV
{
// Make a copy of command line parameter.
ACE_Argv_Type_Converter command(argc, argv);
// Initialize ORB.
this->orb_ =
CORBA::ORB_init (command.get_argc(), command.get_ASCII_argv(), "" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (this->parse_args (command.get_argc(), command.get_TCHAR_argv()) == -1)
return 1;
CORBA::Object_var root_poa_object =
this->orb_->resolve_initial_references("RootPOA"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (root_poa_object.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the root POA.\n"),
1);
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (root_poa_object.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::Object_var naming_obj =
this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (naming_obj.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the Naming Service.\n"),
1);
CosNaming::NamingContext_var naming_context =
CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecScheduler::Scheduler_var scheduler;
// This is the name we (potentially) register the Scheduling
// Service in the Naming Service.
CosNaming::Name schedule_name (1);
schedule_name.length (1);
schedule_name[0].id = CORBA::string_dup ("ScheduleService");
// The old EC always needs a scheduler. If none is
// specified, we default to a local scheduler
if (this->scheduler_type_ == ES_SCHED_LOCAL ||
(this->scheduler_type_ == ES_SCHED_NONE &&
this->event_service_type_ != ES_NEW))
{
// Create a local scheduler instance
ACE_NEW_RETURN (this->sched_impl_,
ACE_Config_Scheduler,
1);
scheduler = this->sched_impl_->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// Register the servant with the Naming Context....
naming_context->rebind (schedule_name, scheduler.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
else if (this->scheduler_type_ == ES_SCHED_GLOBAL)
{
// Get reference to a scheduler from naming service
CORBA::Object_var tmp =
naming_context->resolve (schedule_name ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
scheduler = RtecScheduler::Scheduler::_narrow (tmp.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (scheduler.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to resolve the Scheduling Service.\n"),
1);
}
switch (this->event_service_type_)
{
case ES_NEW:
{
TAO_EC_Event_Channel_Attributes attr (root_poa.in (),
root_poa.in ());
if (this->scheduler_type_ != ES_SCHED_NONE)
{
attr.scheduler = scheduler.in ();
}
TAO_EC_Event_Channel* ec;
ACE_NEW_RETURN (ec,
TAO_EC_Event_Channel (attr),
1);
this->ec_impl_ = ec;
ec->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
break;
case ES_OLD_REACTIVE:
{
ACE_NEW_RETURN (this->module_factory_,
TAO_Reactive_Module_Factory,
1);
ACE_NEW_RETURN (this->ec_impl_,
ACE_EventChannel (scheduler.in (),
1,
ACE_DEFAULT_EVENT_CHANNEL_TYPE,
this->module_factory_),
1);
}
break;
case ES_OLD_MT:
{
ACE_NEW_RETURN (this->module_factory_,
TAO_Default_Module_Factory,
1);
ACE_NEW_RETURN (this->ec_impl_,
ACE_EventChannel (scheduler.in (),
1,
ACE_DEFAULT_EVENT_CHANNEL_TYPE,
this->module_factory_),
1);
}
break;
}
RtecEventChannelAdmin::EventChannel_var ec;
// If the servant name is empty and we don't use BiDIR GIOP, activate the
// servant under the default POA, else create a new child POA with persistent policies
// the needed policies
int persistent = ACE_OS::strcmp(this->servant_name_.c_str(), "");
if ((persistent == 0) && (this->use_bidir_giop_ == 0))
{
// Notice that we activate *this* object with the POA, but we
// forward all the requests to the underlying EC
// implementation.
ec = this->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
else
{
int index = 0;
// Create child POA
CORBA::PolicyList policies (3);
if (persistent == 1)
{
policies[index++] =
root_poa->create_id_assignment_policy (PortableServer::USER_ID
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
policies[index++] =
root_poa->create_lifespan_policy (PortableServer::PERSISTENT
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
if (this->use_bidir_giop_ == 1)
{
CORBA::Any pol;
pol <<= BiDirPolicy::BOTH;
policies[index++] =
this->orb_->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
pol
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
policies.length (index);
ACE_CString child_poa_name = "childPOA";
PortableServer::POA_var child_poa =
root_poa->create_POA (child_poa_name.c_str (),
poa_manager.in (),
policies
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Creation of persistentPOA is over. Destroy the Policy objects.
for (CORBA::ULong i = 0;
i < policies.length ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -