Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Property / server.cpp
blob7b73e2d140bd987c722c5b0602f4f7f626361ac7
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * Test server for the CosPropertyService
8 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "server.h"
16 // Main program
18 int
19 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
21 try
23 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
25 CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA");
27 PortableServer::POA_var root_poa =
28 PortableServer::POA::_narrow (poa_object.in ());
30 if (CORBA::is_nil (root_poa.in ()))
31 ACE_ERROR_RETURN ((LM_ERROR,
32 " (%P|%t) Panic: nil RootPOA\n"),
33 1);
35 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
37 // Using naming server.
38 TAO_Naming_Client my_name_client;
39 if (my_name_client.init (orb.in ()) < 0)
40 return 1;
42 // Create PropertySetDef object and register.
43 TAO_PropertySetDef *propsetdef_impl = 0;
44 ACE_NEW_RETURN (propsetdef_impl,
45 TAO_PropertySetDef,
46 -1);
47 CosPropertyService::PropertySetDef_var propsetdef =
48 propsetdef_impl->_this ();
50 CosNaming::Name propsetdef_name (1);
51 propsetdef_name.length (1);
52 propsetdef_name[0].id = CORBA::string_dup ("PropertySetDef");
53 my_name_client->bind (propsetdef_name,
54 propsetdef.in ());
55 CORBA::Any any_val;
57 // Make this IOR as one of the properties in there.
58 any_val <<= propsetdef.in ();
60 CORBA::Object_var ior = CosPropertyService::PropertySetDef::_duplicate (propsetdef.in());
61 CORBA::Object_ptr ior_ptr = ior.in ();
62 any_val <<= ior_ptr;
64 propsetdef_impl->define_property_with_mode ("PropertySetDef_IOR",
65 any_val,
66 CosPropertyService::fixed_readonly);
68 // Create PropertySet factory and then register.
69 TAO_PropertySetFactory *propset_factory_impl;
70 ACE_NEW_RETURN (propset_factory_impl,
71 TAO_PropertySetFactory,
72 -1);
73 CosPropertyService::PropertySetFactory_var propset_factory =
74 propset_factory_impl->_this ();
76 CosNaming::Name propset_factory_name (1);
77 propset_factory_name.length (1);
78 propset_factory_name[0].id = CORBA::string_dup ("PropertySetFactory");
79 my_name_client->bind (propset_factory_name,
80 propset_factory.in ());
82 poa_manager->activate ();
84 // Run the ORB Event loop.
85 orb->run ();
87 root_poa->destroy (true, true);
89 orb->destroy ();
91 catch (const CORBA::SystemException& sysex)
93 sysex._tao_print_exception ("System Exception");
94 return 1;
96 catch (const CORBA::UserException& userex)
98 userex._tao_print_exception ("User Exception");
99 return 1;
101 ACE_DEBUG ((LM_DEBUG,
102 "\nServer is terminating"));
103 return 0;