📄 ecm_supplier.cpp
字号:
supplier->consumer_proxy ()->push(event ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ACE_DEBUG ((LM_DEBUG, "(%t) supplier push event\n"));
ACE_OS::sleep (tv);
}
}
ACE_CATCH (CORBA::SystemException, sys_ex)
{
ACE_PRINT_EXCEPTION (sys_ex, "SYS_EX");
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "NON SYS EX");
}
ACE_ENDTRY;
return 0;
}
void
ECMS_Driver::connect_suppliers (RtecEventChannelAdmin::EventChannel_ptr channel
ACE_ENV_ARG_DECL)
{
for (int i = 0; i < this->n_suppliers_; ++i)
{
char buf[BUFSIZ];
ACE_OS::sprintf (buf, "supplier_%02d", i);
ACE_NEW (this->suppliers_[i], Test_Supplier (this));
this->suppliers_[i]->connect (buf,
this->event_a_,
this->event_b_,
channel
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
}
void
ECMS_Driver::activate_suppliers (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
{
for (int i = 0; i < this->n_suppliers_; ++i)
{
this->suppliers_[i]->activate ();
}
}
void
ECMS_Driver::disconnect_suppliers (ACE_ENV_SINGLE_ARG_DECL)
{
for (int i = 0; i < this->n_suppliers_; ++i)
{
this->suppliers_[i]->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
}
int
ECMS_Driver::parse_args (int argc, char *argv [])
{
ACE_Get_Opt get_opt (argc, argv, "ds:n:t:h:p:b:");
int opt;
while ((opt = get_opt ()) != EOF)
{
switch (opt)
{
case 's':
this->n_suppliers_ = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'n':
this->event_count_ = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 't':
this->event_period_ = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'b':
this->event_size_ = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'h':
{
char* aux;
char* arg = ACE_OS::strtok_r (get_opt.opt_arg (), ",", &aux);
this->event_a_ = ACE_ES_EVENT_UNDEFINED + ACE_OS::atoi (arg);
arg = ACE_OS::strtok_r (0, ",", &aux);
this->event_b_ = ACE_ES_EVENT_UNDEFINED + ACE_OS::atoi (arg);
}
break;
case 'p':
this->pid_file_name_ = get_opt.opt_arg ();
break;
case '?':
default:
ACE_DEBUG ((LM_DEBUG,
"Usage: %s "
"[ORB options] "
"-s <nsuppliers> "
"-n <event count> "
"-t <event period (usecs)> "
"-h <eventa,eventb> "
"-p <pid file name> "
"\n",
argv[0]));
return -1;
}
}
if (this->event_count_ <= 0)
{
ACE_DEBUG ((LM_DEBUG,
"%s: event count (%d) is out of range, "
"reset to default (%d)\n",
argv[0], this->event_count_,
100));
this->event_count_ = 100;
}
if (this->event_size_ < 0)
{
ACE_DEBUG ((LM_DEBUG,
"%s: event size (%d) is out of range, "
"reset to default (%d)\n",
argv[0], this->event_size_,
32));
this->event_count_ = 32;
}
if (this->n_suppliers_ <= 0)
{
this->n_suppliers_ = 1;
ACE_ERROR_RETURN ((LM_ERROR,
"%s: number of suppliers out of range, "
"reset to default (%d)\n",
argv[0], 1), -1);
}
return 0;
}
Test_Supplier::Test_Supplier (ECMS_Driver *driver)
: driver_ (driver),
supplier_ (this)
{
}
void
Test_Supplier::connect (const char* name,
int event_a,
int event_b,
RtecEventChannelAdmin::EventChannel_ptr ec
ACE_ENV_ARG_DECL)
{
this->supplier_id_ = ACE::crc32 (name);
ACE_DEBUG ((LM_DEBUG,
"ID for <%s> is %04.4x\n",
name,
this->supplier_id_));
ACE_SupplierQOS_Factory qos;
qos.insert (this->supplier_id_,
event_a,
0, 1);
qos.insert (this->supplier_id_,
event_b,
0, 1);
qos.insert (this->supplier_id_,
ACE_ES_EVENT_SHUTDOWN,
0, 1);
RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
ec->for_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->consumer_proxy_ =
supplier_admin->obtain_push_consumer (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
RtecEventComm::PushSupplier_var objref =
this->supplier_._this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->consumer_proxy_->connect_push_supplier (objref.in (),
qos.get_SupplierQOS ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
void
Test_Supplier::disconnect (ACE_ENV_SINGLE_ARG_DECL)
{
if (CORBA::is_nil (this->consumer_proxy_.in ()))
return;
RtecEventChannelAdmin::ProxyPushConsumer_var proxy =
this->consumer_proxy_._retn ();
ACE_TRY
{
proxy->disconnect_push_consumer (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::OBJECT_NOT_EXIST, ex)
{
// Ignore, the EC can shutdown before we get a chance to
// disconnect
}
ACE_CATCH (CORBA::TRANSIENT, ex)
{
// Ignore, the EC can shutdown before we get a chance to
// disconnect
}
ACE_CATCHANY
{
ACE_RE_THROW;
}
ACE_ENDTRY;
}
int
Test_Supplier::svc ()
{
return this->driver_->supplier_task (this, this->cookie_);
}
void
Test_Supplier::disconnect_push_supplier (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((CORBA::SystemException))
{
this->consumer_proxy_ =
RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
}
int Test_Supplier::supplier_id (void) const
{
return this->supplier_id_;
}
RtecEventChannelAdmin::ProxyPushConsumer_ptr
Test_Supplier::consumer_proxy (void)
{
return this->consumer_proxy_.in ();
}
int
main (int argc, char *argv [])
{
ECMS_Driver driver;
return driver.run (argc, argv);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -