Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Null_Cipher / server.cpp
blob64e2e62e4bb9ea5f276d21a7a74e69a0e432fe74
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "Foo_i.h"
5 #include "ace/SString.h"
7 const ACE_TCHAR *ior_output_file = 0;
8 const char *cert_file = "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;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "Usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 CORBA::Object_var obj =
44 orb->resolve_initial_references ("RootPOA");
46 if (CORBA::is_nil (obj.in ()))
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "(%P|%t) ERROR: Unable to initialize the "
49 "POA.\n"),
50 1);
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (obj.in ());
55 PortableServer::POAManager_var poa_manager =
56 root_poa->the_POAManager ();
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 Foo_i *server_impl = 0;
63 ACE_NEW_RETURN (server_impl,
64 Foo_i (orb.in ()),
65 -1);
67 PortableServer::ServantBase_var owner_transfer (server_impl);
69 Foo_var server =
70 server_impl->_this ();
72 CORBA::String_var ior =
73 orb->object_to_string (server.in ());
75 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
77 // If the ior_output_file exists, output the ior to it
78 if (ior_output_file != 0)
80 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
81 if (output_file == 0)
82 ACE_ERROR_RETURN ((LM_ERROR,
83 "Cannot open output file for writing IOR: %s",
84 ior_output_file),
85 1);
86 ACE_OS::fprintf (output_file, "%s", ior.in ());
87 ACE_OS::fclose (output_file);
90 poa_manager->activate ();
92 orb->run ();
94 ACE_DEBUG ((LM_DEBUG,
95 "\n"
96 "Event loop finished.\n"));
98 root_poa->destroy (1, 1);
100 orb->destroy ();
102 catch (const CORBA::Exception& ex)
104 ex._tao_print_exception ("Caught exception:");
105 return 1;
108 return 0;