本文整理汇总了C++中SimpleClient::run方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleClient::run方法的具体用法?C++ SimpleClient::run怎么用?C++ SimpleClient::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleClient
的用法示例。
在下文中一共展示了SimpleClient::run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
// Checks command-line arguments.
if (argc < 2)
{
ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
return -1;
}
else
{
ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
}
//Creates and initializes the SimpleClient object
SimpleClient client;
if (client.init(argc,argv) == 0)
{
ACE_DEBUG((LM_DEBUG,"Cannot init client"));
return -1;
}
else
{
//Must log into manager before we can really do anything
client.login();
}
try
{
//List all components of type "*Mount*" the Manager knows of.
ACS_SHORT_LOG((LM_INFO, "Listing all components of type *Mount*"));
maci::HandleSeq seq;
//See the doxygen documentation for maci.idl to understand what these parameters
//are.
maci::ComponentInfoSeq_var components = client.manager()->get_component_info(client.handle(),
seq,
"*",
"*Mount*",
false);
for (CORBA::ULong i = static_cast<CORBA::ULong>(0); i < components->length(); i++)
{
//just print out all known mount components
ACS_SHORT_LOG((LM_INFO,"%s (%s)", components[i].name.in(), components[i].type.in()));
}
// Now get the specific component we have requested from the command-line
ACS_SHORT_LOG((LM_INFO, "Getting component: %s", argv[1]));
//getComponent can throw an exception if it fails
MOUNT_ACS::Mount_var mount = client.getComponent<MOUNT_ACS::Mount>(argv[1], 0, true);
//Prints the descriptor of the requested component
ACS_SHORT_LOG((LM_DEBUG, "Requesting descriptor()... "));
ACS::CharacteristicComponentDesc_var descriptor = mount->descriptor();
ACS_SHORT_LOG((LM_DEBUG, "Got descriptor()."));
ACS_SHORT_LOG((LM_INFO,"Descriptor:"));
ACS_SHORT_LOG((LM_INFO,"\tname: %s", descriptor->name.in()));
//Get the reference to the actAz double property
ACS_SHORT_LOG((LM_INFO, "Getting component property: %s:actAz", argv[1]));
ACS::ROdouble_var actAz = mount->actAz();
if (actAz.ptr() != ACS::ROdouble::_nil())
{
//Get the current value of the property synchronously
ACSErr::Completion_var completion;
CORBA::Double val = actAz->get_sync(completion.out());
ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
//Create the CBdouble property
ACS_SHORT_LOG((LM_INFO, "Trying to narrow CB for actAz... "));
MyCBdouble myCallback("actAz");
//Activate it as a CORBA object
ACS::CBdouble_var cb = myCallback._this();
ACS_SHORT_LOG((LM_INFO, "OK"));
//Invoke the asynchronous method.
ACS_SHORT_LOG((LM_INFO, "Call get_async for actAz..."));
ACS::CBDescIn desc;
actAz->get_async(cb.in(), desc); //returns control immediately
//Here some other useful things should be done
//while the asyncrhonous reply comes
//...
//...
//...
//Enter main loop and stays there for a fixed amount of time (1s)
//This is done to give the asynchronous method a chance to finish.
ACE_Time_Value tv(1);
client.run(tv);
}//if
}
catch(maciErrType::CannotGetComponentExImpl &_ex) // can be thrown by getComponent<..>(...)
{
_ex.log();
return -1;
}
//.........这里部分代码省略.........
示例2: main
/*
* Main procedure
*/
int main(int argc, char *argv[])
{
//Checks command-line arguments.
if (argc < 2)
{
ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
return -1;
}
else
{
ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
}
//Creates and initializes the SimpleClient object
SimpleClient client;
if (client.init(argc,argv) == 0)
{
ACE_DEBUG((LM_DEBUG,"Cannot init client"));
return -1;
}
else
{
//Must log into manager before we can really do anything
client.login();
}
//Create an instance of our user-defined callback class
MyCBdouble myCallback("refTemp");
try
{
//Get the specific component we have requested on the command-line
FRIDGE::FridgeControl_var fridge = client.getComponent<FRIDGE::FridgeControl>(argv[1], 0, true);
//Get one of the component's BACI properties
ACS::RWdouble_var refTemperature = fridge->refTemperature();
if (refTemperature.ptr() != ACS::RWdouble::_nil())
{
ACSErr::Completion_var completion;
//Just synchronously reading the value of refTemp
CORBA::Double val = refTemperature->get_sync(completion.out());
ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
//Activate the callback as a CORBA object
ACS::CBdouble_var cb = myCallback._this();
ACS_SHORT_LOG((LM_INFO, "OK"));
ACS::CBDescIn desc;
desc.id_tag = 2;
ACS_SHORT_LOG((LM_INFO, "Trying to create monitor for refTemperature..."));
//Create the actual monitor
ACS::Monitordouble_var md = refTemperature->create_monitor(cb.in(), desc);
if (md.ptr() != ACS::Monitordouble::_nil())
{
ACS_SHORT_LOG((LM_INFO, "OK"));
//Set the timer trigger to one second.
md->set_timer_trigger(10000000);
}
else
{
ACS_SHORT_LOG((LM_INFO, "Failed"));
}
//Give the callback some time to run.
ACE_Time_Value time(20);
client.run(time);
//Must explicitly destroy the callback before exiting
md->destroy();
//Give the callback time to be really destroyed
ACE_OS::sleep(15);
}
}
catch(maciErrType::CannotGetComponentExImpl &_ex)
{
_ex.log();
return -1;
}
catch(...)
{
ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
"main");
uex.log();
return -1;
}//try-catch
try
{
//Must release components and logout from manager
ACS_SHORT_LOG((LM_INFO,"Releasing..."));
client.releaseComponent(argv[1]);
client.logout();
}
catch(maciErrType::CannotReleaseComponentExImpl &_ex)
//.........这里部分代码省略.........