00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <OB/CORBA.h>
00024 #include <OB/CosNaming.h>
00025 #include <ServerTime_impl.h>
00026
00027 CORBA::ORB_ptr orb;
00028
00029 int main (int argc, char *argv [])
00030 {
00031 JTCInitialize initialize;
00032 try {
00033 CosNaming::Name name;
00034 CosNaming::NamingContext_var inc;
00035 CosNaming::NamingContext_var myinc;
00036 PortableServer::POA_var poa;
00037 PortableServer::POAManager_var mgr;
00038 CORBA::ORB_var orbVar = CORBA::ORB_init(argc, argv);
00039 orb = (CORBA::ORB_ptr) orbVar;
00040 try {
00041 CORBA::Object_var nms = orb->resolve_initial_references ("NameService");
00042 inc = CosNaming::NamingContext::_narrow (nms);
00043 assert (!CORBA::is_nil (inc));
00044 name.length (1);
00045 printf ("Binding %s to 'ServerTime' naming context\n", argv [0]);
00046 name [0].id = CORBA::string_dup ("ServerTime");
00047 name [0].kind = CORBA::string_dup ("");
00048 try {
00049 myinc = inc->bind_new_context (name);
00050 }
00051 catch (const CosNaming::NamingContext::AlreadyBound &) {
00052
00053 CORBA::Object_var ncb = inc->resolve (name);
00054 myinc = CosNaming::NamingContext::_narrow (ncb);
00055 }
00056 catch (...) {
00057 cout << "Fatal error: some exception while calling NameService!" << endl;
00058 }
00059 }
00060 catch (...) {
00061 cout << "Fatal error: could not contact NameService!" << endl;
00062 return -1;
00063 }
00064 try {
00065 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
00066 poa = PortableServer::POA::_narrow (obj);
00067 mgr = poa->the_POAManager ();
00068 mgr->activate ();
00069 }
00070 catch (...) {
00071 cout << "Fatal error: could not activate POAManager!" << endl;
00072 return -1;
00073 }
00074 try {
00075 ServerTime::Time_impl *pTime = new ServerTime::Time_impl ();
00076 PortableServer::ObjectId_var iid = poa->activate_object(pTime);
00077 {
00078 ServerTime::Time_var client = pTime->_this ();
00079
00080
00081 CosNaming::Name name;
00082 name.length (1);
00083 name [0].id = CORBA::string_dup ("Time");
00084 name [0].kind = CORBA::string_dup ("");
00085 myinc->rebind (name, client);
00086 }
00087 orb->run ();
00088 }
00089 catch (...) {
00090 cout << "Fatal error: could not create client!" << endl;
00091 return -1;
00092 }
00093 }
00094 catch(CORBA::SystemException&) {
00095 cerr << "Caught CORBA::SystemException." << endl;
00096 }
00097 catch(CORBA::Exception&) {
00098 cerr << "Caught CORBA::Exception." << endl;
00099 }
00100 catch(...) {
00101 cerr << "Caught unknown exception." << endl;
00102 }
00103 try {
00104 orb->shutdown (true);
00105 orb->destroy ();
00106 }
00107 catch(...) {
00108 cerr << "Caught unknown exception." << endl;
00109 }
00110 return 0;
00111 }
00112