Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / DevGuideExamples / GettingStarted / MessengerServer.cpp
bloba02b63f384b3e4022c1aa17c9d9a2b4fa44e3250
1 #include "started_pch.h"
3 #include "Messenger_i.h"
4 #include <iostream>
5 #include <fstream>
6 #include "ace/Get_Opt.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT ("Messenger.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <iorfile>"
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
38 try {
39 // Initialize the ORB.
40 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
42 if (parse_args (argc, argv) != 0)
43 return 1;
45 //Get reference to the RootPOA.
46 CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
47 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
49 // Activate the POAManager.
50 PortableServer::POAManager_var mgr = poa->the_POAManager();
51 mgr->activate();
53 // Create a servant.
54 PortableServer::Servant_var<Messenger_i> servant = new Messenger_i();
56 // Register the servant with the RootPOA, obtain its object
57 // reference, stringify it, and write it to a file.
58 PortableServer::ObjectId_var oid = poa->activate_object( servant.in() );
59 obj = poa->id_to_reference( oid.in() );
60 CORBA::String_var str = orb->object_to_string( obj.in() );
61 std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(ior_output_file) );
62 iorFile << str.in() << std::endl;
63 iorFile.close();
64 std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;
66 // Accept requests from clients.
67 orb->run();
68 orb->destroy();
70 return 0;
72 catch(const CORBA::Exception& ex) {
73 std::cerr << "CORBA exception: " << ex << std::endl;
76 return 1;