service.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 527 行 · 第 1/2 页
CPP
527 行
// Service.cpp,v 1.16 2003/10/13 21:43:26 venkita Exp
#include "orbsvcs/Sched/Reconfig_Scheduler.h"
#include "orbsvcs/Runtime_Scheduler.h"
#include "orbsvcs/Event/Module_Factory.h"
#include "orbsvcs/Event/Event_Channel.h"
#include "orbsvcs/Event_Service_Constants.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "orbsvcs/Event/EC_Default_Factory.h"
#include "Consumer.h"
#include "Supplier.h"
#include "Schedule.h"
#include "ace/Get_Opt.h"
#include "ace/Sched_Params.h"
#include "ace/Auto_Ptr.h"
ACE_RCSID(EC_Examples, Service, "Service.cpp,v 1.16 2003/10/13 21:43:26 venkita Exp")
int config_run = 0;
int parse_args (int argc, char *argv[]);
typedef TAO_Reconfig_Scheduler<TAO_MUF_FAIR_Reconfig_Sched_Strategy, TAO_SYNCH_MUTEX> RECONFIG_SCHED_TYPE;
int
main (int argc, char* argv[])
{
TAO_EC_Default_Factory::init_svcs ();
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
// ORB initialization boiler plate...
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (parse_args (argc, argv) == -1)
{
ACE_ERROR ((LM_ERROR,
"Usage: Service [-o IOR_file_name]\n"));
return 1;
}
CORBA::Object_var object =
orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POA_var poa =
PortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POAManager_var poa_manager =
poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
#if 0
// Obtain a reference to the naming service...
CORBA::Object_var naming_obj =
orb->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CosNaming::NamingContext_var naming_context =
CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
#endif /* 0 */
// ****************************************************************
// Create an scheduling service
POA_RtecScheduler::Scheduler* sched_impl = 0;
if (config_run)
{
ACE_NEW_RETURN (sched_impl,
RECONFIG_SCHED_TYPE,
1);
}
else
{
ACE_NEW_RETURN (sched_impl,
RECONFIG_SCHED_TYPE (configs_size,
configs,
infos_size,
infos,
0, 0,
0),
1);
}
RtecScheduler::Scheduler_var scheduler =
sched_impl->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
#if 0
// Bind the scheduler with the naming service so clients
// (consumers and suppliers) can resolve it, some (old)
// implementations of the EC will try to do the same thing
// (yikes!)
CosNaming::Name schedule_name (1);
schedule_name.length (1);
schedule_name[0].id = CORBA::string_dup ("ScheduleService");
// Register the servant with the Naming Context....
naming_context->rebind (schedule_name, scheduler.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
#endif /* 0 */
// ****************************************************************
#if 0
// Create an event channel implementation...
TAO_Default_Module_Factory module_factory;
ACE_EventChannel event_channel_impl (scheduler.in (),
1,
ACE_DEFAULT_EVENT_CHANNEL_TYPE,
&module_factory);
RtecEventChannelAdmin::EventChannel_var event_channel =
event_channel_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
#else
TAO_EC_Event_Channel_Attributes attributes (poa.in (),
poa.in ());
attributes.scheduler = scheduler.in (); // no need to dup
TAO_EC_Event_Channel ec_impl (attributes);
ACE_DEBUG ((LM_DEBUG, "activating EC\n"));
ec_impl.activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "EC activated\n"));
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
#endif /* 0 */
// ****************************************************************
// Create a consumer, intialize its RT_Info structures, and
// connnect to the event channel....
Consumer consumer_impl;
RtecScheduler::handle_t consumer_rt_info1 =
scheduler->create ("consumer_event_1" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Let's say that the execution time for event 1 is 2
// milliseconds...
ACE_Time_Value tv (0, 2000);
TimeBase::TimeT time;
ORBSVCS_Time::Time_Value_to_TimeT (time, tv);
scheduler->set (consumer_rt_info1,
RtecScheduler::VERY_HIGH_CRITICALITY,
time, time, time,
0,
RtecScheduler::VERY_LOW_IMPORTANCE,
time,
0,
RtecScheduler::OPERATION
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecScheduler::handle_t consumer_rt_info2 =
scheduler->create ("consumer_event_2" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Let's say that the execution time for event 2 is 1
// milliseconds...
tv.set (0, 1000);
ORBSVCS_Time::Time_Value_to_TimeT (time, tv);
scheduler->set (consumer_rt_info2,
RtecScheduler::VERY_LOW_CRITICALITY,
time, time, time,
0,
RtecScheduler::VERY_LOW_IMPORTANCE,
time,
0,
RtecScheduler::OPERATION
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_ConsumerQOS_Factory consumer_qos;
consumer_qos.start_disjunction_group ();
// The types int the range [0,ACE_ES_EVENT_UNDEFINED) are
// reserved for the EC...
consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED,
consumer_rt_info1);
consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED + 1,
consumer_rt_info2);
// The canonical protocol to connect to the EC
RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
event_channel->for_consumers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy =
consumer_admin->obtain_push_supplier (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecEventComm::PushConsumer_var consumer =
consumer_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "connecting consumer\n"));
supplier_proxy->connect_push_consumer (consumer.in (),
consumer_qos.get_ConsumerQOS ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "consumer connected\n"));
// ****************************************************************
Supplier supplier_impl;
RtecScheduler::handle_t supplier_rt_info1 =
scheduler->create ("supplier_event_1" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// The execution times are set to reasonable values, but
// actually they are changed on the real execution, i.e. we
// lie to the scheduler to obtain right priorities; but we
// don't care if the set is schedulable.
tv.set (0, 10000);
TimeBase::TimeT tmp;
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
RtecScheduler::Period_t rate = ACE_U64_TO_U32(tmp);
scheduler->set (supplier_rt_info1,
RtecScheduler::VERY_HIGH_CRITICALITY,
0, 0, 0,
rate,
RtecScheduler::VERY_LOW_IMPORTANCE,
0,
1,
RtecScheduler::OPERATION
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecScheduler::handle_t supplier_rt_info2 =
scheduler->create ("supplier_event_2" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// The execution times are set to reasonable values, but
// actually they are changed on the real execution, i.e. we
// lie to the scheduler to obtain right priorities; but we
// don't care if the set is schedulable.
tv.set (0, 20000);
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
rate = ACE_U64_TO_U32(tmp);
scheduler->set (supplier_rt_info2,
RtecScheduler::VERY_HIGH_CRITICALITY,
0, 0, 0,
rate,
RtecScheduler::VERY_LOW_IMPORTANCE,
0,
1,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?