Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_933_Regression / MessengerServer.cpp
blobaf48c1b83ce8b8d029a3f050814d652af0840c2c
1 #include "Messenger_i.h"
2 #include "ace/Get_Opt.h"
4 const ACE_TCHAR *ior_output_file = ACE_TEXT("Messenger.ior");
6 int
7 parse_args (int argc, ACE_TCHAR *argv[])
9 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
10 int c;
12 while ((c = get_opts ()) != -1)
13 switch (c)
15 case 'o':
16 ior_output_file = get_opts.opt_arg ();
17 break;
19 case '?':
20 default:
21 ACE_ERROR_RETURN ((LM_ERROR,
22 "usage: %s "
23 "-o <iorfile>"
24 "\n",
25 argv [0]),
26 -1);
28 // Indicates successful parsing of the command line
29 return 0;
32 int
33 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
35 try {
36 // Initialize orb
37 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
39 if (parse_args (argc, argv) != 0)
40 return 1;
42 //Get reference to Root POA
43 CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
44 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
46 // Activate POA Manager
47 PortableServer::POAManager_var mgr = poa->the_POAManager();
48 mgr->activate();
50 // Create an object
51 Messenger_i messenger_servant (orb.in ());
53 // Register the servant with the RootPOA, obtain its object
54 // reference, stringify it, and write it to a file.
55 PortableServer::ObjectId_var oid =
56 poa->activate_object( &messenger_servant );
57 CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
58 CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
59 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
60 if (output_file == 0)
61 ACE_ERROR_RETURN ((LM_ERROR,
62 "Cannot open output file for writing IOR: %s\n",
63 ior_output_file),
64 1);
65 ACE_OS::fprintf (output_file, "%s", str.in ());
66 ACE_OS::fclose (output_file);
68 // Accept requests
69 orb->run();
70 orb->destroy();
72 catch( const CORBA::Exception & ex)
74 ex._tao_print_exception ("Caught CORBA exception: ");
75 return 1;
78 return 0;