Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / DevGuideExamples / AMH / MessengerServer.cpp
blob0ff769116388c28be5cb96d2f71e992298abf65f
1 #include "amh_pch.h"
3 #include "ace/Get_Opt.h"
4 #include "AMH_Messenger_i.h"
5 #include <iostream>
6 #include <fstream>
8 ACE_TString ior_output_file;
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.optarg;
21 break;
22 break;
23 case '?':
24 default:
25 std::cerr << "usage: " << argv[0] << "-o <iorfile>" << std::endl;
26 return -1;
27 break;
29 // Indicates successful parsing of the command line
30 return 0;
33 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
35 try {
36 // Initialize the ORB.
37 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
39 if (parse_args(argc, argv) != 0) {
40 return 1;
43 //Get reference to the RootPOA.
44 CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
45 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
47 // Activate the POAManager.
48 PortableServer::POAManager_var mgr = poa->the_POAManager();
49 mgr->activate();
51 // Create a servant.
52 PortableServer::Servant_var<AMH_Messenger_i> servant = new AMH_Messenger_i;
54 // Register the servant with the RootPOA, obtain its object
55 // reference, stringify it, and write it to a file.
56 PortableServer::ObjectId_var oid = poa->activate_object( servant.in() );
57 obj = poa->id_to_reference( oid.in() );
58 CORBA::String_var str = orb->object_to_string( obj.in() );
59 std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR(ior_output_file.c_str()));
60 iorFile << str.in() << std::endl;
61 iorFile.close();
62 std::cout << "IOR written to file Messenger.ior" << std::endl;
64 // Accept requests from clients.
65 orb->run();
66 orb->destroy();
68 return 0;
70 catch(const CORBA::Exception& ex) {
71 std::cerr << "CORBA exception: " << ex << std::endl;
74 return 1;