client.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include "Hello.hh"
00003 
00004 int
00005 main (int argc, char **argv)
00006 {
00007   try {
00008     // Initialize the ORB
00009     CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
00010 
00011     // Expect IOR as command-line argument
00012     if (argc != 2) {
00013       std::cerr << "Usage: client IOR" << std::endl;
00014       throw 0;                  // neat trick used to exit try block
00015     }
00016 
00017     // Destringify the IOR
00018     CORBA::Object_var obj = orb->string_to_object (argv[1]);
00019     if (CORBA::is_nil (obj)) {
00020       std::cerr << "Nil World reference" << std::endl;
00021       throw 0;
00022     }
00023 
00024     // Narrow an Object to a World
00025     Hello::World_var world = Hello::World::_narrow (obj);
00026     if (CORBA::is_nil (world)) {
00027       std::cerr << "Invalid World reference" << std::endl;
00028       throw 0;
00029     }
00030 
00031     // Say hello to the world
00032     CORBA::String_var s = world->hello ();
00033     std::cout << "World said \"" << s << "\"" << std::endl;
00034   }
00035   catch (const CORBA::Exception & e)
00036   {
00037     std::cerr << "Client caught CORBA exception: " << std::endl;
00038     return 100;
00039   }
00040   catch ( ...) {
00041     // Logical error; message already displayed
00042     return 1;
00043   }
00044   return 0;
00045 }


agentsystem_examples
Author(s): k-okada
autogenerated on Mon Oct 6 2014 12:08:22