Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / DevGuideExamples / AMH_AMI / inner_server.cpp
blob739ee5c0da22a50e010ed817ee13541f344f35c5
1 #include "amh_ami_pch.h"
3 #include "inner_i.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include <iostream>
7 #include <fstream>
9 int dont_crash = 1;
11 const ACE_TCHAR *ior_output_file = ACE_TEXT ("inner.ior");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("c:o:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'c':
23 dont_crash = 0;
24 break;
25 case 'o':
26 ior_output_file = get_opts.opt_arg ();
27 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-o <iorfile> "
33 "-c "
34 "\n",
35 argv [0]),
36 -1);
38 // Indicates successful parsing of the command line
39 return 0;
42 int
43 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
45 try {
46 // Initialize the ORB.
47 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
49 if (parse_args (argc, argv) != 0)
50 return 1;
52 //Get reference to the RootPOA.
53 CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
54 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
56 // Activate the POAManager.
57 PortableServer::POAManager_var mgr = poa->the_POAManager();
58 mgr->activate();
60 // Create a servant.
61 PortableServer::Servant_var<Inner_i> servant = new Inner_i(dont_crash);
63 // Register the servant with the RootPOA, obtain its object
64 // reference, stringify it, and write it to a file.
65 PortableServer::ObjectId_var oid = poa->activate_object( servant.in() );
66 obj = poa->id_to_reference( oid.in() );
67 CORBA::String_var str = orb->object_to_string( obj.in() );
68 ACE_CString iorname (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
69 std::ofstream iorFile (iorname.c_str());
70 iorFile << str.in() << std::endl;
71 iorFile.close();
72 std::cout << "IOR written to " << iorname << std::endl;
74 // Accept requests from clients.
75 orb->run();
76 orb->destroy();
78 return 0;
80 catch(const CORBA::Exception& ex) {
81 std::cerr << "CORBA exception: " << ex << std::endl;
84 return 1;