本文整理汇总了C++中Messenger_var类的典型用法代码示例。如果您正苦于以下问题:C++ Messenger_var类的具体用法?C++ Messenger_var怎么用?C++ Messenger_var使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Messenger_var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
try {
if (argc <= 1) {
std::cerr << "Error: Must specify the name of an IOR file." << std::endl;
return 1;
}
ACE_TString ior = ACE_TEXT("file://");
ior += argv[1];
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj = orb->string_to_object(ior.c_str());
Messenger_var messenger = Messenger::_narrow(obj.in());
if (CORBA::is_nil(messenger.in())) {
std::cerr << "Unable to get a Messenger reference." << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup("Hello!");
messenger->send_message("TAO User", "TAO Test", message.inout());
std::cout << "message was sent" << std::endl;
std::cout << "Reply was : " << message.in() << std::endl;
return 0;
} catch(const CORBA::Exception& ex) {
std::cerr << "Client main() Caught Exception: " << ex << std::endl;
}
return 1;
}
示例2: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
//Get reference to Root POA
CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::Name name;
name.length( 1 );
name[0].id = CORBA::string_dup("example");
try {
obj = root->resolve(name);
}
catch(const CosNaming::NamingContext::NotFound&) {
CosNaming::NamingContext_var dummy = root->bind_new_context(name);
}
// Bind the Messenger object
name.length(2);
name[1].id = CORBA::string_dup("Messenger");
// Create an object
PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
obj = poa->id_to_reference(oid.in());
Messenger_var messenger = Messenger::_narrow(obj.in());
root->rebind(name, messenger.in());
std::cout << "Messenger object bound in Naming Service" << std::endl;
// Accept requests
orb->run();
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例3: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
try
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var rootObj =
orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootContext =
CosNaming::NamingContext::_narrow(rootObj.in());
CosNaming::Name name;
name.length (1);
name[0].id = CORBA::string_dup ("MessengerService");
CORBA::Object_var messengerObj = rootContext->resolve(name);
if (CORBA::is_nil(messengerObj.in())) {
std::cerr << "Nil Messenger reference" << std::endl;
return 1;
}
// Narrow
Messenger_var messenger = Messenger::_narrow(messengerObj.in());
if (CORBA::is_nil(messenger.in ())) {
std::cerr << "Argument is not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup(
"We are experiencing network problems.");
messenger->send_message ("[email protected]",
"urgent",
message.inout());
message = CORBA::string_dup("Where can I get TAO?");
messenger->send_message ("[email protected]",
"OCI's Distribution of TAO",
message.inout());
message = CORBA::string_dup(
"Please contact [email protected] regarding your request.");
messenger->send_message ("[email protected]",
"OCI's Distribution of TAO",
message.inout());
}
catch(const CORBA::Exception& ex) {
std::cerr << "Caught a CORBA exception: " << ex << std::endl;
return 1;
}
std::cout << "MessengerClient: success" << std::endl;
return 0;
}
示例4: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
// Find the Naming Service
CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContextExt_var root =
CosNaming::NamingContextExt::_narrow(naming_obj.in());
if (CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
return 1;
}
// Resolve the Messenger object
CosNaming::Name name;
name.length( 2 );
name[0].id = CORBA::string_dup( "example" );
name[1].id = CORBA::string_dup( "Messenger" );
CORBA::Object_var obj = CORBA::Object::_nil();
while (CORBA::is_nil(obj.in())) {
try {
obj = root->resolve_str("example/Messenger");
} catch (const CosNaming::NamingContext::NotFound&) {
// Sleep for a second and try again
ACE_OS::sleep(1);
}
}
// Narrow the Messenger object reference
Messenger_var messenger = Messenger::_narrow(obj.in());
if (CORBA::is_nil(messenger.in())) {
std::cerr << "Not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup("Hello!");
// Send a message
messenger->send_message("TAO User", "TAO Test", message.inout());
std::cout << "Message was sent" << std::endl;
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "Caught a CORBA exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例5: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
try
{
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
CORBA::Object_var rootObj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootNC =
CosNaming::NamingContext::_narrow(rootObj.in());
// Get reference to Root POA.
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Create an object
PortableServer::Servant_var<Messenger_i> messenger_servant =
new Messenger_i(orb.in());
Messenger_var messenger = messenger_servant->_this();
CosNaming::Name name;
name.length (1);
name[0].id = CORBA::string_dup("MessengerService");
rootNC->rebind(name, messenger.in());
CORBA::String_var str = orb->object_to_string (messenger.in());
std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
iorFile << str.in () << std::endl;
iorFile.close ();
std::cout << "IOR written to file " << ior_output_file << std::endl;
// Accept requests
orb->run();
}
catch(const CORBA::Exception& ex)
{
std::cerr << "MessengerServer::Caught exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例6: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
// Detection of closed on read currently not working certain platforms.
#if defined (sun) || defined (AIX) || defined (__FreeBSD_version)
return 2;
#endif
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
if (parse_args (argc, argv) != 0)
return 1;
// Destringify ior
CORBA::Object_var obj = orb->string_to_object( ior );
if (CORBA::is_nil(obj.in())) {
std::cerr << "Nil Messenger reference" << std::endl;
return 1;
}
// Narrow
Messenger_var messenger = Messenger::_narrow( obj.in() );
if (CORBA::is_nil(messenger.in())) {
std::cerr << "Argument is not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup( "Hello!" );
messenger->send_message( "TAO User", "Test 1", message.inout() );
// Force server to abort to verify it will be brought
// back up when send_message() is called.
messenger->abort(2);
ACE_OS::sleep(seconds_between_requests);
ACE_DEBUG ((LM_INFO,
"(%P|%t) - Sending another message after abort of server\n"));
messenger->send_message( "TAO User", "Test 2", message.inout() );
std::cout << "messages were sent" << std::endl;
}
catch(const CORBA::Exception& ex) {
std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例7: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
try {
// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
// Create a smart proxy factory. It will register itself with the
// smart proxy factory adapter so it can be used to create
// Messenger proxies. It must be created on the heap, but is
// otherwise unused here.
new Smart_Messenger_Proxy_Factory(orb.in());
// Convert the contents of the Messenger.ior file to an object reference.
CORBA::Object_var obj = orb->string_to_object(ior);
if (CORBA::is_nil(obj.in())) {
std::cerr << "Nil Messenger reference" << std::endl;
return 1;
}
// Narrow the object reference to a Messenger object reference.
Messenger_var messenger = Messenger::_narrow(obj.in());
if (CORBA::is_nil(messenger.in())) {
std::cerr << "Not a Messenger object reference" << std::endl;
return 1;
}
// Create a message and send it to the Messenger.
CORBA::String_var message = CORBA::string_dup("Hello!");
messenger->send_message ("TAO User", "TAO Test", message.inout());
std::cout << "Message was sent" << std::endl;
// Release resources.
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "Caught a CORBA exception: " << ex << std::endl;
return 1;
}
catch(...) {
std::cerr << "Caught an unknown exception type" << std::endl;
return 1;
}
return 0;
}
示例8: ACE_ASSERT
void
ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
// Find the Naming Service
CORBA::Object_var naming_obj =
info->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(naming_obj.in());
if( CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
ACE_ASSERT(false);
}
// Resolve the Messenger object
CosNaming::Name name;
name.length( 1 );
name[0].id = CORBA::string_dup( "Messenger" );
CORBA::Object_var obj = CORBA::Object::_nil();
while ( CORBA::is_nil( obj.in() ) ) {
try {
obj = root->resolve( name );
} catch (const CosNaming::NamingContext::NotFound&) {
// Sleep for a second and try again
ACE_OS::sleep(1);
}
}
Messenger_var messenger = Messenger::_narrow( obj.in() );
if( CORBA::is_nil( messenger.in() ) ) {
std::cerr << "Not a Messenger reference" << std::endl;
ACE_ASSERT(false);
}
// allocate slot
slot_ = info->allocate_slot_id();
// get PICurrent
CORBA::Object_var current_obj = info->resolve_initial_references("PICurrent");
current_ =
PortableInterceptor::Current::_narrow(current_obj.in());
// Create and register the request interceptors.
PortableInterceptor::ClientRequestInterceptor_var ci =
new ClientInterceptor(messenger, current_.in(), slot_);
info->add_client_request_interceptor (ci.in());
}
示例9: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
// Get reference to Root POA.
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Create an object
PortableServer::Servant_var<Messenger_i> messenger_servant =
new Messenger_i;
// Write its stringified reference to a file
PortableServer::ObjectId_var oid = poa->activate_object(messenger_servant.in());
obj = poa->id_to_reference(oid.in());
Messenger_var messenger = Messenger::_narrow(obj.in());
CORBA::String_var str = orb->object_to_string(messenger.in());
std::ofstream fout(ACE_TEXT_ALWAYS_CHAR(ior_output_file));
fout << str.in() << std::endl;
fout.close();
std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;
// Accept requests
orb->run();
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "CORBA::Exception " << ex << std::endl;
return 1;
}
return 0;
}
示例10: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
try
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
CORBA::Object_var obj = orb->string_to_object( ior );
if (CORBA::is_nil(obj.in())) {
std::cerr << "Nil Messenger reference" << std::endl;
return 1;
}
// Narrow
Messenger_var messenger = Messenger::_narrow( obj.in() );
if (CORBA::is_nil(messenger.in())) {
std::cerr << "Argument is not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup(
"Where can I get TAO?");
for (int i=0; i<3; i++) {
messenger->send_message ("[email protected]",
"OCI's Distribution of TAO",
message.inout());
}
}
catch(const CORBA::Exception& ex)
{
std::cerr << "Caught exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例11: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
try {
// Initialize the ORB.
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
if (parse_args (argc, argv) != 0)
return 1;
// Read and destringify the Messenger object's IOR.
CORBA::Object_var obj = orb->string_to_object( ior );
if( CORBA::is_nil( obj.in() ) ) {
std::cerr << "Could not get Messenger IOR." << std::endl;
return 1;
}
// Narrow the IOR to a Messenger object reference.
Messenger_var messenger = Messenger::_narrow( obj.in() );
if( CORBA::is_nil( messenger.in() ) ) {
std::cerr << "IOR was not a Messenger object reference." << std::endl;
return 1;
}
// Send a message the the Messenger object.
CORBA::String_var msg = CORBA::string_dup( "Hello!" );
messenger->send_message( "TAO User", "TAO Test", msg.inout() );
// Print the Messenger's reply.
std::cout << "Reply: " << msg.in() << std::endl;
return 0;
}
catch(const CORBA::Exception& ex) {
std::cerr << "CORBA exception: " << ex << std::endl;
}
return 1;
}
示例12: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv );
if (parse_args (argc, argv) != 0)
return 1;
CORBA::Object_var obj =
orb->string_to_object (ior);
// Narrow the Messenger object reference
Messenger_var messenger = Messenger::_narrow(obj.in());
if (CORBA::is_nil(messenger.in())) {
ACE_ERROR((LM_ERROR, " ERROR: Client cannot get a Messenger reference\n"));
return 1;
}
CORBA::String_var message = CORBA::string_dup("Hello!");
// Send a message
messenger->send_message("user", "TAO Test", message.inout());
ACE_DEBUG((LM_DEBUG, "CLIENT: Message was sent\n"));
orb->destroy();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Caught exception:");
return 1;
}
return 0;
}
示例13: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
try {
// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
// Converts the contents of the file to an object reference
CORBA::Object_var obj = orb->string_to_object (ior);
if (CORBA::is_nil (obj.in())) {
std::cerr << "Nill Messenger reference" << std::endl;
return 1;
}
// Narrow the object reference to a Messenger object reference
Messenger_var messenger = Messenger::_narrow(obj.in());
if (CORBA::is_nil (messenger.in())) {
std::cerr << "Not a Messenger object reference" << std::endl;
return 1;
}
// Create a message and send it to the Messenger
CORBA::String_var message = CORBA::string_dup("Hello!");
messenger->send_message ("TAO User", "TAO Test", message.inout());
orb->destroy();
std::cout << "Message was sent" << std::endl;
}
catch(const CORBA::Exception& ex) {
std::cerr << "Client Caught a CORBA exception: " << ex << std::endl;
return 1;
}
std::cout << "Message was sent" << std::endl;
return 0;
}
示例14: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize the ORB.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Find the Naming Service.
CORBA::Object_var obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());
// Find the EventChannel.
obj = root_context->resolve_str("CosEventService");
// Downcast the object reference to a TypedEventChannel reference.
CosTypedEventChannelAdmin::TypedEventChannel_var ec =
CosTypedEventChannelAdmin::TypedEventChannel::_narrow(obj.in ());
if (CORBA::is_nil(ec.in())) {
std::cerr << "Could not resolve TypedEventChannel." << std::endl;
return 1;
}
// Get a SupplierAdmin object from the EventChannel.
CosTypedEventChannelAdmin::TypedSupplierAdmin_var supplierAdmin =
ec->for_suppliers();
// Get a ProxyPushConsumer from the SupplierAdmin.
CosTypedEventChannelAdmin::TypedProxyPushConsumer_var consumer =
supplierAdmin->obtain_typed_push_consumer(::_tc_Messenger->id());
// Connect to the ProxyPushConsumer as a PushSupplier
// (passing a nil PushSupplier object reference to it because
// we don't care to be notified about disconnects).
consumer->connect_push_supplier(CosEventComm::PushSupplier::_nil());
// Obtain the interface from the event channel
CORBA::Object_var messenger_obj = consumer->get_typed_consumer();
// Narrow the interface
Messenger_var messenger = Messenger::_narrow(messenger_obj.in () );
// Create an event (just a string in this case).
const CORBA::String_var eventData = CORBA::string_dup("Hello, world.");
// Send one event per second. (approx)
while (1) {
messenger->send_message("King Lizard",
"Proclamations",
eventData.in());
ACE_Time_Value event_delay(0, 1000 * EVENT_DELAY_MS);
orb->run(event_delay);
}
}
catch(const CORBA::Exception& ex)
{
std::cerr << "Caught CORBA::Exception. " << std::endl << ex << std::endl;
}
return 1;
}
示例15: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
ClientInitializer* temp_initializer = new ClientInitializer;
PortableInterceptor::ORBInitializer_var orb_initializer =
temp_initializer;
PortableInterceptor::register_orb_initializer (orb_initializer.in ());
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");
// Now that the ORB is initialized (and subsequently the
// PICurrent), we can set the slot data on the PICurrent for our
// interceptor initializer.
temp_initializer->set_slot_data ();
CORBA::Object_var naming_obj =
orb->resolve_initial_references( "NameService" );
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow( naming_obj.in() );
if ( CORBA::is_nil(root.in() ) ) {
std::cerr << "Couldn't find Naming Service." << std::endl;
return 1;
}
// get Messenger
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup( "Messenger" );
CORBA::Object_var obj = CORBA::Object::_nil();
while ( CORBA::is_nil( obj.in() ) ) {
try {
obj = root->resolve( name );
} catch (const CosNaming::NamingContext::NotFound&) {
// Sleep for a second and try again
ACE_OS::sleep(1);
}
}
Messenger_var messenger = Messenger::_narrow( obj.in() );
if( CORBA::is_nil( messenger.in() ) ) {
std::cerr << "Not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup( "Hello!" );
messenger->send_message( "TAO User", "TAO Test", message.inout() );
}
catch(const CORBA::Exception& ex)
{
std::cerr << "Caught CORBA exception: " << ex << std::endl;
return 1;
}
return 0;
}