diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-06-21 22:54:25 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-06-21 22:54:25 +0000 |
commit | c489facc3cbe2292a7edc78920d6d316b9250a65 (patch) | |
tree | 8d91b9d20428fdeda025b5d46255de4b8cc440cb /TAO/examples/Content_Server/AMI_Observer/client.cpp | |
parent | faa66c456d64718a1a4080f40126842b16da1f59 (diff) | |
download | ATCD-c489facc3cbe2292a7edc78920d6d316b9250a65.tar.gz |
ChangeLogTag:Wed Jun 21 15:51:10 2000 Ossama Othman <ossama@uci.edu>
Diffstat (limited to 'TAO/examples/Content_Server/AMI_Observer/client.cpp')
-rw-r--r-- | TAO/examples/Content_Server/AMI_Observer/client.cpp | 153 |
1 files changed, 102 insertions, 51 deletions
diff --git a/TAO/examples/Content_Server/AMI_Observer/client.cpp b/TAO/examples/Content_Server/AMI_Observer/client.cpp index 53cfc089aeb..f81d307bc7f 100644 --- a/TAO/examples/Content_Server/AMI_Observer/client.cpp +++ b/TAO/examples/Content_Server/AMI_Observer/client.cpp @@ -8,7 +8,19 @@ #include "Push_Web_ServerC.h" #include "Push_Iterator_Handler.h" -ACE_RCSID(AMI_Observer, client, "$Id$") +ACE_RCSID (AMI_Observer, client, "$Id$") + +// Obtain reference to Iterator_Factory +Web_Server::Iterator_Factory_ptr +get_iterator (CORBA::ORB_ptr orb, + CORBA::Environment &ACE_TRY_ENV); + +// Perform file requests +void invoke_requests (int argc, + char *argv[], + int *request_count, + Web_Server::Iterator_Factory_ptr f, + CORBA::Environment &ACE_TRY_ENV); int main (int argc, char *argv[]) @@ -18,7 +30,8 @@ main (int argc, char *argv[]) { if (argc < 2) ACE_ERROR_RETURN ((LM_ERROR, - "Usage: client filename [filename ...]\n"), + ACE_TEXT ("Usage: client filename ") + ACE_TEXT ("[filename ...]\n")), -1); // Initialize the ORB. @@ -43,40 +56,18 @@ main (int argc, char *argv[]) mgr->activate (ACE_TRY_ENV); ACE_TRY_CHECK; - // Get a reference to the Name Service. - obj = orb->resolve_initial_references ("NameService", - ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Narrow to a Naming Context - CosNaming::NamingContext_var nc = - CosNaming::NamingContext::_narrow (obj.in (), ACE_TRY_ENV); - ACE_TRY_CHECK; - - if (CORBA::is_nil (obj.in ())) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Nil reference to Name Service\n"), - -1); - } - - // Create a name. - CosNaming::Name name; - name.length (1); - name[0].id = CORBA::string_dup ("Push_Iterator_Factory"); - name[0].kind = CORBA::string_dup (""); - - obj = nc->resolve (name, ACE_TRY_ENV); + // Get an Iterator_Factory reference. + Web_Server::Iterator_Factory_var factory = + ::get_iterator (orb.in (), + ACE_TRY_ENV); ACE_TRY_CHECK; - // Now narrow to an Iterator_Factory reference. - Web_Server::Iterator_Factory_var factory = - Web_Server::Iterator_Factory::_narrow (obj.in ()); if (CORBA::is_nil (factory.in ())) { ACE_ERROR_RETURN ((LM_ERROR, - "Object pointed to by:\n %s\n" - "is not an Iterator_Factory object.\n", + ACE_TEXT ("Object pointed to by:\n %s\n") + ACE_TEXT ("is not an Iterator_Factory") + ACE_TEXT ("object.\n"), argv[1]), -1); } @@ -86,24 +77,12 @@ main (int argc, char *argv[]) int request_count = 0; // Activate and run the reply handlers. - for (int i = 0; - i < argc - 1; // Don't include the program name. - ++i) - { - Push_Iterator_Handler *handler = 0; - ACE_NEW_RETURN (handler, - Push_Iterator_Handler, - -1); - - // Transfer ownership to the POA. - PortableServer::ServantBase_var tmp_handler (handler); - - handler->run (&request_count, - argv[i + 1], - factory.in (), - ACE_TRY_ENV); - ACE_TRY_CHECK; - } + ::invoke_requests (argc, + argv, + &request_count, + factory.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; // 1 millisecond delay to reduce "busy waiting" in ORB event // loop. @@ -131,14 +110,15 @@ main (int argc, char *argv[]) ACE_CATCH (Web_Server::Error_Result, exc) { ACE_ERROR_RETURN ((LM_ERROR, - "Caught Web Server exception with status %d\n", + ACE_TEXT ("Caught Web Server exception ") + ACE_TEXT ("status %d\n"), exc.status), -1); } ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Caught unexpected exception:"); + ACE_TEXT ("Caught unexpected exception:")); return -1; } @@ -149,3 +129,74 @@ main (int argc, char *argv[]) return 0; } + +Web_Server::Iterator_Factory_ptr +get_iterator (CORBA::ORB_ptr o, + CORBA::Environment &ACE_TRY_ENV) +{ + CORBA::ORB_var orb = CORBA::ORB::_duplicate (o); + + // Get a reference to the Name Service. + CORBA::Object_var obj = + orb->resolve_initial_references ("NameService", + ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + // Narrow to a Naming Context + CosNaming::NamingContext_var nc = + CosNaming::NamingContext::_narrow (obj.in (), ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + if (CORBA::is_nil (obj.in ())) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Nil reference to Name Service\n"))); + return Web_Server::Iterator_Factory::_nil (); + } + + // Create a name. + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("Push_Iterator_Factory"); + name[0].kind = CORBA::string_dup (""); + + obj = nc->resolve (name, ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + Web_Server::Iterator_Factory_ptr factory = + Web_Server::Iterator_Factory::_narrow (obj.in ()); + + return factory; +} + +void invoke_requests (int argc, + char *argv[], + int *request_count, + Web_Server::Iterator_Factory_ptr f, + CORBA::Environment &ACE_TRY_ENV) +{ + Web_Server::Iterator_Factory_var factory = + Web_Server::Iterator_Factory::_duplicate (f); + + // Activate and run the reply handlers. + for (int i = 0; + i < argc - 1; // Don't include the program name. + ++i) + { + Push_Iterator_Handler *handler = 0; + ACE_NEW_THROW_EX (handler, + Push_Iterator_Handler, + CORBA::NO_MEMORY ()); + ACE_CHECK; + + // Transfer ownership to the POA. + PortableServer::ServantBase_var tmp (handler); + + // This ends up being an AMI call, so it won't block. + handler->run (request_count, + argv[i + 1], + factory.in (), + ACE_TRY_ENV); + ACE_CHECK; + } +} |