Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Callback / server.cpp
blob61182c9d451f4940d51b368053666af34f9e3994
1 #include "ace/Log_Msg.h"
2 #include "server_i.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
8 const ACE_TCHAR *cert_file = ACE_TEXT("cacert.pem");
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
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 ACE_TString env (ACE_TEXT("SSL_CERT_FILE="));
42 env += cert_file;
43 ACE_OS::putenv ( ACE_TEXT_ALWAYS_CHAR(env.c_str ()));
46 // Initialize the ORB
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv);
51 if (parse_args (argc, argv) != 0)
52 return 1;
55 // Get the Root POA.
57 CORBA::Object_var obj =
58 orb->resolve_initial_references ("RootPOA");
60 PortableServer::POA_var poa =
61 PortableServer::POA::_narrow (obj.in ());
64 // Create the server, get object reference,
65 // and create "stringified" IOR.
67 server_i *tmp = 0;
68 ACE_NEW_RETURN (tmp,
69 server_i (orb.in ()),
70 -1);
71 PortableServer::ServantBase_var theServer = tmp;
73 PortableServer::ObjectId_var oid =
74 poa->activate_object (theServer.in ());
75 CORBA::Object_var server_obj =
76 poa->id_to_reference (oid.in ());
77 CORBA::String_var server_IORString =
78 orb->object_to_string (server_obj.in ());
81 // Write the IOR to a file.
83 // Output the IOR to the <ior_output_file>
84 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
85 if (output_file == 0)
86 ACE_ERROR_RETURN ((LM_ERROR,
87 "Cannot open output file for writing IOR\n"),
88 -1);
89 ACE_OS::fprintf (output_file, "%s", server_IORString.in ());
90 ACE_OS::fclose (output_file);
93 // Activate the POA manager.
95 PortableServer::POAManager_var mgr =
96 poa->the_POAManager ();
97 mgr->activate ();
99 ACE_DEBUG ((LM_INFO,
100 ACE_TEXT ("(%P) calling orb->run () ...\n")));
102 orb->run ();
104 poa->destroy (true, true);
106 orb->destroy ();
108 catch (const CORBA::Exception& ex)
110 ex._tao_print_exception (ACE_TEXT ("Caught exception\n"));
112 return -1;
115 return 0;