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 ("*****@*****.**", "urgent", message.inout()); message = CORBA::string_dup("Where can I get TAO?"); messenger->send_message ("*****@*****.**", "OCI's Distribution of TAO", message.inout()); message = CORBA::string_dup( "Please contact [email protected] regarding your request."); messenger->send_message ("*****@*****.**", "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; }
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; }
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; }
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; }
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; // Find the Naming Service & the Message Server name in it CORBA::Object_var obj = orb->string_to_object(ior_input_file); // Narrow 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()); std::cout << "Message was sent" << std::endl; std::cout << "Now try the same thing with the simple name." << std::endl; obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root = CosNaming::NamingContextExt::_narrow(obj.in()); obj = root->resolve_str("Simple/Messenger"); messenger = Messenger::_narrow(obj.in()); messenger->send_message( "ACE User", "TAO Test", message.inout()); std::cout << "Message was sent" << std::endl; } catch(const CORBA::Exception& ex) { std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; return 1; } return 0; }
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; }
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 ("*****@*****.**", "OCI's Distribution of TAO", message.inout()); } } catch(const CORBA::Exception& ex) { std::cerr << "Caught exception: " << ex << std::endl; return 1; } return 0; }
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; }
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; }
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; }
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; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { PortableInterceptor::ORBInitializer_var orb_initializer = new ClientInitializer; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); // 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; } // Obtain a reference to the CodecFactory. CORBA::Object_var obj2 = orb->resolve_initial_references ("CodecFactory"); IOP::CodecFactory_var codec_factory; if(CORBA::is_nil(obj2.in())) { std::cerr << "Error: codec_factory" << std::endl; ACE_OS::exit(1); } else { codec_factory = IOP::CodecFactory::_narrow (obj2.in ()); std::cout << "got codec factory" << std::endl; } // Set up a structure that contains information necessary to // create a GIOP 1.2 CDR encapsulation Codec. IOP::Encoding encoding; encoding.format = IOP::ENCODING_CDR_ENCAPS; encoding.major_version = 1; encoding.minor_version = 2; // Obtain the CDR encapsulation Codec. IOP::Codec_var codec = codec_factory->create_codec (encoding); CORBA::Long uid = 64321; CORBA::Any uid_as_any; uid_as_any <<= uid; CORBA::OctetSeq client_uid = *codec->encode (uid_as_any); messenger->send_message( client_uid ); } catch(const CORBA::Exception& ex) { std::cerr << "Exception in MessengerClient: " << ex << std::endl; return 1; } std::cout << "message was sent" << std::endl; return 0; }
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!" ); int try_count = 0; int succeeded = 0; for (; try_count < number_of_tries; ++try_count) { ACE_DEBUG ((LM_INFO, "(%P|%t) - Sending message <%d> to server\n", try_count)); try { messenger->send_message( "TAO User", "Test 1", message.inout() ); ACE_DEBUG ((LM_INFO, "(%P|%t) - Successfully received response for message <%d> to server\n", try_count)); ++succeeded; // 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); } catch (const CORBA::Exception&) { // Swallow } } if (succeeded == number_of_succeed) { ACE_DEBUG ((LM_INFO, "(%P|%t) - <%d> Messages where send to the server, <%d> succeeded\n", try_count, succeeded)); } else { ACE_ERROR ((LM_INFO, "(%P|%t) - ERROR: <%d> Messages where send to the server, <%d> succeeded, should be <%d>\n", try_count, succeeded, number_of_succeed)); } orb->destroy (); } catch(const CORBA::Exception& ex) { std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl; return 1; } return 0; }
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 obj = orb->string_to_object( ior ); Messenger_var messenger = Messenger::_narrow( obj.in() ); CORBA::String_var message = CORBA::string_dup( "Terminating messenger service!" ); messenger->send_message( "Chief of Security", "New Directive", message.inout() ); messenger->shutdown("Chief of Security"); Security::QOP qop = Security::SecQOPIntegrityAndConfidentiality; CORBA::Any want_protection; want_protection <<= qop; CORBA::Policy_var policy = orb->create_policy (Security::SecQOPPolicy, want_protection); Security::EstablishTrust establish_trust; establish_trust.trust_in_client = 0; establish_trust.trust_in_target = 1; CORBA::Any want_trust; want_trust <<= establish_trust; CORBA::Policy_var policy2 = orb->create_policy (Security::SecEstablishTrustPolicy, want_trust); CORBA::PolicyList policy_list (2); policy_list.length (1); policy_list[0] = CORBA::Policy::_duplicate (policy.in ()); policy_list.length (2); policy_list[1] = CORBA::Policy::_duplicate (policy2.in ()); CORBA::Object_var object = obj->_set_policy_overrides (policy_list, CORBA::SET_OVERRIDE); Messenger_var messenger2 = Messenger::_narrow( object.in() ); message = CORBA::string_dup( "Terminating messenger service!" ); messenger2->send_message( "Chief of Security", "New Directive", message.inout() ); messenger2->shutdown("Chief of Security"); orb->destroy(); } catch(const CORBA::Exception& ex) { ex._tao_print_exception("Client: main block"); return 1; } return 0; }
int TestClient::svc() { // Every invocation of svc increates the thread count instance_++; int threadNum = instance_; size_t vec_size = iors_.size(); ACE_DEBUG((LM_DEBUG, "* Client Thread started (%d.%d.%d.%d)\n", threadNum, iterations_, vec_size, requestCount_)); int i = 0; size_t objIter = 0; int requestIter = 0; ACE_TString currentIOR; ACE_OS::srand(static_cast<u_int> (ACE_OS::time())); try { int holdingCount = 0; int noProfileCount = 0; // For each iteration for (i = 1; i <= iterations_; i++) { // For each object reference read from file for (objIter = 1; objIter <= vec_size; objIter++) { requestIter = -1; // Get a imr_test_var currentIOR = iors_[objIter - 1]; CORBA::Object_var obj = orb_->string_to_object(currentIOR.c_str()); if (CORBA::is_nil(obj.in()) == false) { requestIter = 0; Messenger_var test = Messenger::_narrow(obj.in()); if (CORBA::is_nil(test.in()) == false) { // Calculate the number of requests int newReqCount (randomRequests_ == false ? requestCount_ : (int)((((double)ACE_OS::rand() / (double)RAND_MAX) * (double)(requestCount_ - 1)) + .5) + 1); // For each request for (requestIter = 1; requestIter <= newReqCount; requestIter++) { try { ::CORBA::Long instance = test->send_message(threadNum, i, objIter, requestIter); ACE_UNUSED_ARG (instance); } catch (const CORBA::SystemException& ex) { // If these exceptions are expected record the number of instances, otherwise rethrow if (expectHolding_ == true && ex.minor() == TAO_POA_HOLDING) { ACE_ERROR((LM_ERROR, "Caught expected holding exception with (%d.%d.%d)\n", threadNum, objIter, requestIter)); holdingCount++; } else { throw; } if (expectNoProfile_ == true && ex.minor() == TAO_INVOCATION_SEND_REQUEST_MINOR_CODE) { ACE_ERROR((LM_ERROR, "Caught expected holding exception with (%d.%d.%d)\n", threadNum, objIter, requestIter)); noProfileCount++; } else { throw; } } // catch } // for request // We are done with our non-nil narrowed obj ref if (shutdownOrb_ == true) test->shutdownOrb(); } // if narrow } // if obj } // for obj } // for iter // Report expected exceptions if (holdingCount > 0) { ACE_DEBUG((LM_DEBUG,"Client thread %d received %d holding error(s).\n", threadNum, holdingCount)); } if (noProfileCount > 0) { ACE_DEBUG((LM_DEBUG,"Client thread %d received %d no profile error(s).\n", threadNum, noProfileCount)); } return 0; } // try catch (const CORBA::Exception& ex) { ACE_ERROR((LM_ERROR,"CORBA client error with (%d.%d.%d.%d):%s\n", threadNum, i, objIter, requestIter, currentIOR.c_str())); ex._tao_print_exception (""); } return 1; }
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; }