Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Miop / McastHello / server.cpp
blob91edae7d56203249972fd3a0f5e9a2a535bc9598
1 #include "McastHello.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/PortableGroup/MIOP.h"
5 #include "orbsvcs/PortableGroup/GOA.h"
7 static const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 // Use a multicast address in the administrative "site local" range, 239.255.0.0 to
10 // 239.255.255.255. The range 224.255.0.0 to 238.255.255.255 should also be valid
11 // too.
12 //static const char *group_ior = "corbaloc:miop:1.0@1.0-TestDomain-1/239.255.0.1:16000";
13 static const ACE_TCHAR *group_ior = ACE_TEXT("corbaloc:miop:1.0@1.0-TestDomain-1/224.1.239.2:1234");
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'o':
25 ior_output_file = get_opts.opt_arg ();
26 break;
28 case 'g':
29 group_ior = get_opts.opt_arg ();
30 break;
32 case '?':
33 default:
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "usage: %s "
36 "-o <iorfile>"
37 "-g <group ior corbaloc>"
38 "\n",
39 argv [0]),
40 -1);
42 // Indicates successful parsing of the command line
43 return 0;
46 int
47 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
49 try
51 CORBA::ORB_var orb =
52 CORBA::ORB_init (argc, argv);
54 CORBA::Object_var poa_object =
55 orb->resolve_initial_references("RootPOA");
57 PortableGroup::GOA_var root_poa =
58 PortableGroup::GOA::_narrow (poa_object.in ());
60 if (CORBA::is_nil (root_poa.in ()))
61 ACE_ERROR_RETURN ((LM_ERROR,
62 " (%P|%t) Panic: nil RootPOA\n"),
63 1);
65 PortableServer::POAManager_var poa_manager =
66 root_poa->the_POAManager ();
68 if (parse_args (argc, argv) != 0)
69 return 1;
71 CORBA::Object_var group1 =
72 orb->string_to_object (group_ior);
74 // Output the Group IOR to the <ior_output_file>
75 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
76 if (output_file == 0)
77 ACE_ERROR_RETURN ((LM_ERROR,
78 "Cannot open output file for writing IOR: %s",
79 ior_output_file),
80 1);
81 ACE_OS::fprintf (output_file, "%s", ACE_TEXT_ALWAYS_CHAR (group_ior));
82 ACE_OS::fclose (output_file);
84 PortableServer::ObjectId_var id =
85 root_poa->create_id_for_reference (group1.in ());
87 // Create and activate an instance of our servant.
88 McastHello server_impl (orb.in (), 0);
90 root_poa->activate_object_with_id (id.in (),
91 &server_impl);
94 poa_manager->activate ();
96 orb->run ();
98 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
100 root_poa->destroy (true, true);
102 orb->destroy ();
104 // Validate that our servants got the right requests.
105 if (server_impl.get_status () == 0)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "Multicast Servant did not receive expected requests!\n"),
109 else
110 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Success!\n"));
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Exception caught:");
115 return 1;
118 return 0;