Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2925_Regression / server.cpp
blob385b4856c5d2fd26fe6e2012505d4bdf3bac0b14
2 #include "ace/Get_Opt.h"
3 #include "orbsvcs/PortableGroup/GOA.h"
4 #include "tao/Policy_Manager.h"
5 #include "Hello_Impl.h"
7 #define HELLO_CALL_NUMBER 100
9 const ACE_TCHAR *uipmc_url = 0;
10 const ACE_TCHAR *ior_output_file = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("u:o:"));
16 const unsigned char full_success = 0x03;
17 unsigned char success = 0;
21 int c = get_opts ();
22 if (success == full_success && c == -1)
23 break;
25 if (c == -1)
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s"
28 " -u <url>"
29 " -o <iorfile>"
30 "\n",
31 argv [0]),
32 -1);
34 switch (c)
36 case 'u':
37 uipmc_url = get_opts.opt_arg ();
38 success |= 0x01;
39 break;
40 case 'o':
41 ior_output_file = get_opts.opt_arg ();
42 success |= 0x02;
43 break;
46 while (true);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
55 MessageLog logger(HELLO_CALL_NUMBER);
57 try
59 CORBA::ORB_var orb =
60 CORBA::ORB_init (argc, argv);
62 CORBA::Object_var poa_object =
63 orb->resolve_initial_references("RootPOA");
65 PortableGroup::GOA_var root_poa =
66 PortableGroup::GOA::_narrow (poa_object.in ());
68 if (CORBA::is_nil (root_poa.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR,
70 " (%P|%t) Panic: nil RootPOA\n"),
71 1);
73 PortableServer::POAManager_var poa_manager =
74 root_poa->the_POAManager ();
76 // servant
77 Hello_Impl* hello_impl;
78 ACE_NEW_RETURN (hello_impl,
79 Hello_Impl (orb.in (), &logger),
80 1);
81 PortableServer::ServantBase_var owner_transfer (hello_impl);
83 if (parse_args (argc, argv) != 0)
84 return 2;
86 // create UIPMC reference
87 CORBA::String_var multicast_url =
88 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(uipmc_url));
89 CORBA::Object_var miop_ref =
90 orb->string_to_object (multicast_url.in ());
92 // create id
93 PortableServer::ObjectId_var id =
94 root_poa->create_id_for_reference (miop_ref.in ());
96 // activate Hello Object
97 root_poa->activate_object_with_id (id.in (),
98 hello_impl);
100 CORBA::String_var ior =
101 orb->object_to_string (miop_ref.in ());
103 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
105 // If the ior_output_file exists, output the ior to it
106 if (ior_output_file != 0)
108 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
110 if (output_file == 0)
112 ACE_ERROR_RETURN ((LM_ERROR,
113 "Cannot open output file for writing IOR: %s",
114 ior_output_file),
118 ACE_OS::fprintf (output_file, "%s", ior.in ());
119 ACE_OS::fclose (output_file);
122 poa_manager->activate ();
124 orb->run ();
126 root_poa->destroy (true, true);
128 orb->destroy ();
130 if (logger.report_statistics () == 0)
131 ACE_ERROR_RETURN ((LM_ERROR,
132 "\n (%P|%t) ERROR: No single call got through to the server\n"),
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Exception caught in server main ():");
138 return 4;
141 ACE_DEBUG ((LM_DEBUG,
142 "\n (%P|%t) server finished successfully..\n"));
143 return 0;