summaryrefslogtreecommitdiff
path: root/TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp')
-rw-r--r--TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp140
1 files changed, 87 insertions, 53 deletions
diff --git a/TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp b/TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp
index c716c0b1467..7b82c142e95 100644
--- a/TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp
+++ b/TAO/tests/Cubit/TAO/IDL_Cubit/svr.cpp
@@ -55,63 +55,97 @@ parse_args (int argc, char *argv[])
int
main (int argc, char *argv[])
{
- CORBA::Environment env;
- char *orb_name = "internet";
-
- CORBA::ORB_ptr orb_ptr = CORBA::ORB_init (argc, argv, orb_name, env);
-
- if (env.exception () != 0)
+ TAO_TRY
{
- env.print_exception ("ORB init");
- return 1;
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Initialize the Object Adapter
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references("RootPOA");
+ if (CORBA::is_nil(poa_object.in()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize the POA.\n"),
+ 1);
+
+ PortableServer::POA_var root_poa =
+ PortableServer::POA::_narrow (poa_object, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ PortableServer::POAManager_var poa_manager =
+ root_poa->the_POAManager (TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ PortableServer::PolicyList policies (2);
+ policies.length (2);
+ policies[0] =
+ root_poa->create_id_assignment_policy (PortableServer::USER_ID,
+ TAO_TRY_ENV);
+ policies[1] =
+ root_poa->create_lifespan_policy (PortableServer::PERSISTENT,
+ TAO_TRY_ENV);
+
+ // We use a different POA, otherwise the user would have to
+ // change the object key each time it invokes the server.
+ PortableServer::POA_var good_poa =
+ root_poa->create_POA ("RootPOA_is_BAD",
+ poa_manager.in (),
+ policies,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Parse remaining command line and verify parameters.
+ parse_args (argc, argv);
+
+ // create a factory implementation
+ Cubit_Factory_i factory_impl;
+
+ PortableServer::ObjectId_var id =
+ PortableServer::string_to_ObjectId ("factory");
+ good_poa->activate_object_with_id (id.in (),
+ &factory_impl,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ if (TAO_debug_level > 0)
+ {
+ CORBA::Object_var obj =
+ good_poa->id_to_reference (id.in (), TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ CORBA::String_var str =
+ orb->object_to_string (obj.in (),
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "The IOR is: <%s>\n", str.in ()));
+ }
+
+ poa_manager->activate (TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Handle requests for this object until we're killed, or one of
+ // the methods asks us to exit.
+ if (orb->run () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run"), -1);
+
+ root_poa->destroy (CORBA::B_TRUE,
+ CORBA::B_TRUE,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV
}
-
- // Initialize the Object Adapter
- CORBA::POA_ptr oa_ptr = orb_ptr->POA_init (argc, argv, "POA");
-
- if (oa_ptr == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Unable to initialize the POA.\n"),
- 1);
-
- // Parse remaining command line and verify parameters.
- parse_args (argc, argv);
-
- // create a factory implementation
- Cubit_Factory_ptr factory;
-
- ACE_NEW_RETURN (factory, Cubit_Factory_i ("factory", num_of_objs), 1);
-
- if (TAO_debug_level > 0)
+ TAO_CATCH (CORBA::SystemException, sysex)
{
- // Stringify the objref we'll be implementing, and print it to
- // stdout. Someone will take that string and give it to a
- // client. Then release the object.
-
- CORBA::String str;
-
- str = orb_ptr->object_to_string (factory, env);
-
- if (env.exception () != 0)
- {
- env.print_exception ("object2string");
- return 1;
- }
-
- ACE_OS::puts ((char *) str);
- ACE_OS::fflush (stdout);
- //dmsg1 ("Object Created at: '%ul'", obj);
- dmsg1 ("listening as object '%s'", str);
+ TAO_TRY_ENV.print_exception ("System Exception");
+ return -1;
}
-
- // Handle requests for this object until we're killed, or one of the
- // methods asks us to exit.
- if (orb_ptr->run () == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run"), -1);
-
- // Free resources
- CORBA::release (oa_ptr);
- CORBA::release (orb_ptr);
+ TAO_CATCH (CORBA::UserException, userex)
+ {
+ TAO_TRY_ENV.print_exception ("User Exception");
+ return -1;
+ }
+ TAO_ENDTRY;
return 0;
}