本文整理汇总了C++中ACE_Time_Value::set方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Time_Value::set方法的具体用法?C++ ACE_Time_Value::set怎么用?C++ ACE_Time_Value::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Time_Value
的用法示例。
在下文中一共展示了ACE_Time_Value::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
ACE_System_Time::get_local_system_time (ACE_Time_Value &time_out)
{
ACE_TRACE ("ACE_System_Time::get_local_system_time");
time_out.set (ACE_OS::time (0), 0);
return 0;
}
示例2: period
int
main (int argc, char *argv[])
{
// First you need a handler for the timeout.
My_Handler my_handler;
// This is the timeout period in seconds.
ACE_Time_Value period (ACE_DEFAULT_TIMEOUT);
if (argc > 1)
period.set (ACE_OS::atoi (argv[1]));
// Set up the periodic interval timer.
if (ACE_Reactor::instance ()->schedule_timer
(&my_handler,
"hello",
period,
period) == -1)
ACE_ERROR_RETURN ((LM_DEBUG,
"%p\n",
"schedule_timer"),
-1);
// Set up an ACE signal handler.
if (ACE_Reactor::instance ()->register_handler
(SIGINT,
&my_handler) == -1)
ACE_ERROR_RETURN ((LM_DEBUG,
"%p\n",
"register_handler"),
-1);
// Set up a non-ACE signal handler. When this goes off, the Reactor
// should return from its <run_event_loop> method.
ACE_Sig_Action sig ((ACE_SignalHandler) my_signal_function,
SIGQUIT);
ACE_UNUSED_ARG (sig);
ACE_DEBUG ((LM_DEBUG,
"starting event loop that runs until you've typed ^C a total of 10 times or ^\\ once.\n"));
// This call executes the reactor events until we're finished.
int result = ACE_Reactor::run_event_loop ();
ACE_DEBUG ((LM_DEBUG,
"result = %d\n",
result));
// Make sure to remove my_handler before exiting main() since
// otherwise weird things can happen...
if (ACE_Reactor::instance ()->cancel_timer (&my_handler) == -1)
ACE_ERROR_RETURN ((LM_DEBUG,
"%p\n",
"cancel_timer"),
-1);
return 0;
}
示例3: get_opts
int
parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:p:ci:s:f:"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'f':
filter = get_opts.opt_arg ();
break;
case 'k':
monitor_ior = get_opts.opt_arg ();
break;
case 'p':
{
if (monitor_point == 0)
{
ACE_NEW_THROW_EX (monitor_point,
::Monitor::NameList,
CORBA::NO_MEMORY ());
}
monitor_point->length (monitor_point->length () + 1);
(*monitor_point)[monitor_point->length () - 1] =
CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ()));
break;
}
case 'c':
mp_clear = true;
break;
case 'i':
n_iterations = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 's':
sleep_time.set(ACE_OS::atoi (get_opts.opt_arg ()), 0);
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-k <ior> "
"-p <point> "
"-i <iterations> "
"-c clear "
"-s <sleeptime> "
"-f <filter> "
"\n",
argv [0]),
-1);
}
// Indicates successful parsing of the command line
return 0;
}
示例4: timeout
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Reactor_Notify_Test"));
int test_result = 0; // Innocent until proven guilty
if (0 == run_notify_purge_test ())
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("purge_pending_notifications test OK\n")));
}
else
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("purge_pending_notifications test FAIL\n")));
test_result = 1;
}
#if defined (ACE_HAS_THREADS)
if (0 != run_quiet_notify_test ())
test_result = 1;
ACE_Time_Value timeout (SHORT_TIMEOUT);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) running tests with notify pipe enabled")
ACE_TEXT (" and time-out = %d seconds\n"),
timeout.sec ()));
run_test (0, timeout);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) running tests with notify pipe disabled")
ACE_TEXT (" and time-out = %d seconds\n"),
timeout.sec ()));
run_test (1, timeout);
timeout.set (LONG_TIMEOUT, 0);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) running tests with reactor notification ")
ACE_TEXT ("pipe enabled\n")
ACE_TEXT (" and time-out = %d seconds\n"),
timeout.sec ()));
run_test (0, timeout);
#else
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return test_result;
}
示例5: usleep
void yarp::os::impl::sleepThread(ACE_Time_Value& sleep_period)
{
#ifdef YARP_HAS_ACE
if (sleep_period.usec() < 0 || sleep_period.sec() < 0)
sleep_period.set(0,0);
ACE_OS::sleep(sleep_period);
#else
if (sleep_period.tv_usec < 0 || sleep_period.tv_sec < 0) {
sleep_period.tv_usec = 0;
sleep_period.tv_sec = 0;
}
usleep(sleep_period.tv_sec * 1000000 + sleep_period.tv_usec );
#endif
}
示例6: tv
void
EC_Schedule::build_supplier_qos (
int i,
RtecEventChannelAdmin::SupplierQOS& qos,
int& shutdown_event_type)
{
char name[128];
ACE_OS::sprintf (name, "EC_Schedule::Supplier::%04x", i);
RtecScheduler::handle_t rt_info =
this->scheduler_->create (name);
ACE_Time_Value tv (0, this->burst_pause_);
RtecScheduler::Period_t rate = tv.usec () * 10;
// 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, 2000);
TimeBase::TimeT time;
ORBSVCS_Time::Time_Value_to_TimeT (time, tv);
this->scheduler_->set (rt_info,
RtecScheduler::VERY_HIGH_CRITICALITY,
time, time, time,
rate,
RtecScheduler::VERY_LOW_IMPORTANCE,
time,
1,
RtecScheduler::OPERATION);
int type_start = this->supplier_type_start_ + i*this->supplier_type_shift_;
int supplier_id = i + 1;
shutdown_event_type = type_start + this->supplier_type_count_;
ACE_SupplierQOS_Factory qos_factory;
for (int j = 0; j != this->supplier_type_count_; ++j)
qos_factory.insert (supplier_id,
type_start + j,
rt_info, 1);
qos_factory.insert (supplier_id,
shutdown_event_type,
rt_info, 1);
qos = qos_factory.get_SupplierQOS ();
}
示例7: push_structured_event
virtual void push_structured_event(CosNotification::StructuredEvent const& event)
throw(CosEventComm::Disconnected)
{
cout << "domain_name: " << event.header.fixed_header.event_type.domain_name
<< " type_name: " << event.header.fixed_header.event_type.type_name << " " << flush;
if (false) {
Miro::Client client;
DynamicAny::DynAnyFactory_var daf =
client.resolveInit<DynamicAny::DynAnyFactory>("DynAnyFactory");
DynamicAny::DynAny_var da = daf->create_dyn_any(event.remainder_of_body);
CORBA::TypeCode_var tc = da->type();
if (tc->kind() == CORBA::tk_struct) {
CORBA::String_var name = tc->name();
CORBA::String_var id = tc->id();
DynamicAny::DynStruct_var ds =
DynamicAny::DynStruct::_narrow(da);
for (CORBA::ULong i = 0; i < ds->component_count(); ++i) {
DynamicAny::DynAny_var member = ds->current_component();
CORBA::String_var name = ds->current_member_name();
if (std::string("timestamp") == name.in()) {
long long int i = member->get_ulonglong();
ACE_Time_Value t;
ORBSVCS_Time::Absolute_TimeT_to_Time_Value(t, i);
cout << "latency: " << ACE_OS::gettimeofday() - t << endl;
break;
}
ds->next();
}
}
else {
cerr << "unknown event layout" << endl;
}
}
ACE_Time_Value t;
t.set(time_out);
ACE_OS::sleep(t);
cout << "waking up after sleep" << endl;
}
示例8: get_opts
int
parseArgs(int& argc, char* argv[])
{
int rc = 0;
int c;
ACE_Get_Opt get_opts (argc, argv, "c:t:?");
while ((c = get_opts()) != -1) {
switch (c) {
break;
case 'c':
channelName = get_opts.optarg;
break;
case 'v':
verbose = true;
break;
case 't':
timeout.set(atof(get_opts.optarg));
case '?':
default:
rc = 1;
}
}
if (rc) {
cerr << "usage: " << argv[0] << "[-t timeout [-c channel_name] [-v?]" << endl
<< " -c <channel name> name of the event channel (default: NotifyEventChannel)" << endl
<< " -t <sec> timeout (default: 5s)" << endl
<< " -v verbose mode" << endl
<< " -? help: emit this text and stop" << endl;
}
if (verbose) {
cerr << "timeout: " << timeout << endl
<< "channel name: " << channelName << endl;
}
return rc;
}
示例9: time_out
int CoAPWrapper::time_out(ACE_Time_Value& tm)
{
struct timeval tv, *timeout;
int result;
coap_tick_t now;
coap_queue_t *nextpdu;
coap_context_t *ctx;
if (coap_ctx_ == 0 )
return 0;
ctx = coap_ctx_;
nextpdu = coap_peek_next( ctx );
coap_ticks(&now);
while ( nextpdu && nextpdu->t <= now )
{
coap_retransmit( ctx, coap_pop_next( ctx ) );
nextpdu = coap_peek_next( ctx );
}
if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME )
{
/* set timeout if there is a pdu to send before our automatic timeout occurs */
tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND;
timeout = &tv;
}
else
{
tv.tv_usec = 0;
tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
timeout = &tv;
}
tm.set(*timeout);
return 0;
}
示例10: open
int SocketTwoWayStream::open(const Contact& address) {
if (address.getPort()==-1) {
return -1;
}
String host = address.getHost();
#ifdef YARP_HAS_ACE
ACE_SOCK_Connector connector;
if (address.getHost() == "localhost") {
// ACE does not like localhost. At all.
NameConfig config;
host = config.getHostName(true);
}
ACE_INET_Addr addr(address.getPort(),host.c_str());
ACE_Time_Value openTimeout;
ACE_Time_Value *timeout = NULL;
if (address.hasTimeout()) {
openTimeout.set(address.getTimeout());
timeout = &openTimeout;
}
int result = connector.connect(stream,addr,timeout,ACE_Addr::sap_any,1);
#else
TcpConnector connector;
int result = connector.connect(stream, address);
#endif
if (result>=0) {
happy = true;
} else {
YARP_SPRINTF2(Logger::get(),
debug,
"TCP connection to tcp://%s:%d failed to open",
host.c_str(),
address.getPort());
}
updateAddresses();
return result;
}
示例11: send_recv
int PlatConnMgrEx::send_recv(const void * send_buf, int send_len
, void * recv_buf, int recv_len, const unsigned int uin)
{
int ip_idx = get_ip_idx(uin);
int index = get_index(ip_idx, uin);
ACE_SOCK_Stream* conn = get_conn(index, ip_idx);
if (conn == NULL)
{
ACE_DEBUG((LM_ERROR, "[%D] PlatConnMgrEx get conn failed"
",can't get a useful conn"
",index=%d,ip_idx=%d,uin=%u\n"
, index, ip_idx, uin
));
return -1;
}
ACE_Guard<ACE_Thread_Mutex> guard(conn_lock_[ip_idx][index]);// 加锁需要放在获取的后面
if (conn_[ip_idx][index] == NULL) // 加锁后增加一次非法判断
{
ACE_DEBUG((LM_ERROR, "[%D] PlatConnMgrEx send_recv failed"
",conn is null"
",index=%d,ip_idx=%d,uin=%u\n"
, index, ip_idx, uin
));
return -1;
}
conn_use_flag_[ip_idx][index] = 1;
//清除原缓冲 add by awayfang 2010-03-02
ACE_Time_Value zero;
zero.set(0);
int max_recv_len = recv_len;
int tmp_ret = conn_[ip_idx][index]->recv(recv_buf, max_recv_len, &zero);//不等待直接返返回
// 检测到连接关闭时, 重建连接
if((tmp_ret < 0 && errno != ETIME) // 连接上无数据的情况,会返回超时,不需重连
|| tmp_ret == 0) // 连接已经被对端关闭, 处于close wait状态
{
ACE_DEBUG((LM_INFO, "[%D] PlatConnMgrEx send_recv connection close detected,"
"uin=%u,ip=%s,index=%d\n", uin, ip_[ip_idx], index));
init_conn(index, ip_idx);
if(conn_[ip_idx][index] == NULL)
{
ACE_DEBUG((LM_ERROR, "[%D] PlatConnMgrEx send_recv reconnect failed,"
"index=%d,ip_idx=%d\n", index, ip_idx));
return -1;
}
}
ACE_DEBUG((LM_TRACE, "[%D] PlatConnMgrEx send_recv msg"
",index=%d,ip_idx=%d,uin=%u\n", index, ip_idx, uin));
int ret = conn_[ip_idx][index]->send(send_buf, send_len, &time_out_);
if (ret <= 0) //异常或者对端关闭
{
ACE_DEBUG((LM_ERROR, "[%D] PlatConnMgrEx send_recv send msg failed"
",index=%d,ip_idx=%d,ret=%d,uin=%u,errno=%d\n", index, ip_idx, ret, uin, errno));
//关闭连接
fini(index, ip_idx);
Stat::instance()->incre_stat(STAT_CODE_SEND_FAIL);
return ret;
}
//
ret = conn_[ip_idx][index]->recv(recv_buf, recv_len, &time_out_);
if (ret <= 0) //异常或者对端关闭
{
ACE_DEBUG((LM_ERROR, "[%D] PlatConnMgrEx send_recv recv msg failed"
",index=%d,ip_idx=%d,ret=%d,uin=%u,errno=%d\n", index, ip_idx, ret, uin, errno));
//关闭连接
fini(index, ip_idx);
Stat::instance()->incre_stat(STAT_CODE_RECV_FAIL);
return ret;
}
ACE_DEBUG((LM_TRACE, "[%D] PlatConnMgrEx send_recv msg succ"
",index=%d,ip_idx=%d,ret=%d,uin=%u\n", index, ip_idx, ret, uin));
conn_use_flag_[ip_idx][index] = 0;//退出前清理使用状态
return ret;
}
示例12: if
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
ACE_UNUSED_ARG (config_run);
//TAO_EC_Default_Factory::init_svcs ();
TAO_EC_Kokyu_Factory::init_svcs ();
try
{
// ORB initialization boiler plate...
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
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");
PortableServer::POA_var poa =
PortableServer::POA::_narrow (object.in ());
PortableServer::POAManager_var poa_manager =
poa->the_POAManager ();
poa_manager->activate ();
// ****************************************************************
// Create an scheduling service
POA_RtecScheduler::Scheduler* sched_impl = 0;
if (ACE_OS::strcasecmp(sched_type.c_str(), "rms") == 0)
{
ACE_DEBUG ((LM_DEBUG, "Creating RMS scheduler\n"));
ACE_NEW_RETURN (sched_impl,
RECONFIG_RMS_SCHED_TYPE,
1);
}
else if (ACE_OS::strcasecmp(sched_type.c_str(), "muf") == 0)
{
ACE_DEBUG ((LM_DEBUG, "Creating MUF scheduler\n"));
ACE_NEW_RETURN (sched_impl,
RECONFIG_MUF_SCHED_TYPE,
1);
}
RtecScheduler::Scheduler_var scheduler =
sched_impl->_this ();
// ****************************************************************
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);
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this ();
// ****************************************************************
// Create a consumer, intialize its RT_Info structures, and
// connnect to the event channel....
Consumer consumer_impl1, consumer_impl2;
RtecScheduler::handle_t consumer1_rt_info =
scheduler->create ("consumer1");
RtecScheduler::handle_t consumer2_rt_info =
scheduler->create ("consumer2");
//consumer's rate will get propagated from the supplier.
//so no need to specify a period here. Specifying
//criticality is crucial since it propagates from
//consumer to supplier.
ACE_Time_Value tv (0,0);
TimeBase::TimeT tmp;
ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv);
scheduler->set (consumer1_rt_info,
RtecScheduler::VERY_LOW_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_LOW_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
scheduler->set (consumer2_rt_info,
RtecScheduler::VERY_HIGH_CRITICALITY,
tmp, tmp, tmp,
time_val_to_period (tv),
RtecScheduler::VERY_HIGH_IMPORTANCE,
tmp,
0,
RtecScheduler::OPERATION);
//.........这里部分代码省略.........
示例13: while
int Publisher_impl::Worker::svc (void)
{
double data = 0.0;
bool doShutdown = false;
unsigned long iteration = 0;
ACE_Time_Value tv;
tv.set(0.01);
while (!terminated)
{
data += 0.01;
++iteration;
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex, 0);
doShutdown = subscribers.size() > 0;
for (vector<_Subscriber>::iterator iter = subscribers.begin();
iter != subscribers.end(); ++iter)
{
if (!iter->unsubscribed)
{
doShutdown = false;
try
{
if (!CORBA::is_nil(iter->subscriber.in ()))
iter->subscriber->onData(data);
else
iter->unsubscribed = true;
++iter->count;
}
catch (...)
{
iter->unsubscribed = true;
}
}
}
}
if (iteration % 200 == 0)
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex, 0);
for (vector<_Subscriber>::iterator iter = subscribers.begin();
iter != subscribers.end(); ++iter)
{
if (!iter->unsubscribed)
{
try
{
iter->subscriber->isAlive();
}
catch (...)
{
iter->unsubscribed = true;
}
}
}
}
if (doShutdown)
owner->shutdown();
else
ACE_OS::sleep(tv);
}
return 0;
}
示例14: the_name
//.........这里部分代码省略.........
}
else if (0 == ACE_OS::strcmp (*argv, ACE_TEXT ("--kindsep")))
{
if (!--argc)
{
ACE_DEBUG ((LM_DEBUG,
"Error: --kindsep requires a character\n"));
failed = true;
}
else if (1 != ACE_OS::strlen(*(++argv)))
{
ACE_DEBUG ((LM_DEBUG,
"Error: --kindsep takes a single character (not %s)\n", *argv));
failed = true;
}
else
kindsep = (*argv)[0];
}
else if (0 == ACE_OS::strcmp(*argv, ACE_TEXT ("--rtt")))
{
if (rtt != ACE_Time_Value::zero)
{
ACE_DEBUG ((LM_DEBUG,
"Error: --rtt given more than once\n"));
failed = true;
}
else if (!--argc || !ACE_OS::ace_isdigit (ACE_TEXT_ALWAYS_CHAR (*(++argv))[0]))
{
ACE_DEBUG ((LM_DEBUG,
"Error: --rtt requires a number\n"));
failed = true;
}
else
rtt.set(ACE_OS::atoi (ACE_TEXT_ALWAYS_CHAR (*argv)), 0);
}
else if (0 == ACE_OS::strcmp (*argv, ACE_TEXT ("--destroy")))
{
destroy = true;
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Unknown option %s\n", *argv));
failed = true;
}
}
}
if (!name || failed)
{
ACE_DEBUG ((LM_DEBUG,
"\nUsage:\n %s --name <name>\n"
"optional:\n"
" --ns <ior>\n"
" --ctxsep <character>\n"
" --kindsep <character>\n"
" --destroy\n"
" --quiet\n"
" --rtt <seconds> {Sets the relative round trip timeout policy}\n\n",
"where <name> uses the --ctxsep character (defaults to /)\n"
"to separate sub-contexts and --kindsep (defaults to .)\n"
"to separate ID & Kind. Will destroy a naming context\n"
"before unbinding if --destroy is given, otherwise it\n"
"will orphan them. Connects to default NameService\n"
"unless --ns is given. Displays all ID/Kinds found\n"
"on path unless --quiet is given.\n",
示例15: schedule_name
//.........这里部分代码省略.........
// Register the servant with the Naming Context....
naming_context->rebind (schedule_name, scheduler.in ());
#endif /* 0 */
// ****************************************************************
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_DEBUG ((LM_DEBUG, "EC activated\n"));
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this ();
// ****************************************************************
// 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");
// 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);
RtecScheduler::handle_t consumer_rt_info2 =
scheduler->create ("consumer_event_2");
// 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_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);