Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_1020_Regression / server.cpp
blob5785226c0189ddfad2a586065ed991af10dd6099
1 #include "Server_i.h"
2 #include "ORB_Task.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/ORB_Core.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[]);
12 int
13 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
15 try
17 CORBA::ORB_var orb =
18 CORBA::ORB_init (argc, argv);
20 CORBA::Object_var poa_object =
21 orb->resolve_initial_references("RootPOA");
23 PortableServer::POA_var root_poa =
24 PortableServer::POA::_narrow (poa_object.in ());
26 if (CORBA::is_nil (root_poa.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR,
28 " (%P|%t) Panic: nil RootPOA\n"),
29 1);
31 PortableServer::POAManager_var poa_manager =
32 root_poa->the_POAManager ();
34 CORBA::Object_var object =
35 orb->resolve_initial_references ("PolicyCurrent");
37 if (parse_args (argc, argv) != 0)
38 return 1;
40 PortableServer::Servant_var<Server> impl;
42 Server * tmp;
43 // ACE_NEW_RETURN is the worst possible way to handle
44 // exceptions (think: what if the constructor allocates memory
45 // and fails?), but I'm not in the mood to fight for a more
46 // reasonable way to handle allocation errors in ACE.
47 ACE_NEW_RETURN (tmp,
48 Server(orb.in()),
49 1);
50 impl = tmp;
53 PortableServer::ObjectId_var id =
54 root_poa->activate_object (impl.in ());
56 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
58 Test::Server_var server =
59 Test::Server::_narrow (object_act.in ());
61 CORBA::String_var ior =
62 orb->object_to_string (server.in ());
64 // If the ior_output_file exists, output the ior to it
65 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
66 if (output_file == 0)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "Cannot open output file for writing IOR: %s",
69 ior_output_file),
70 1);
71 ACE_OS::fprintf (output_file, "%s", ior.in ());
72 ACE_OS::fclose (output_file);
74 poa_manager->activate ();
76 ORB_Task task(orb.in());
77 task.activate(THR_NEW_LWP | THR_JOINABLE, 4, 1);
79 task.wait();
81 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
83 root_poa->destroy (true, true);
85 orb->destroy ();
87 catch (const CORBA::Exception& ex)
89 ex._tao_print_exception ("Exception caught:");
90 return 1;
93 return 0;
96 int
97 parse_args (int argc, ACE_TCHAR *argv[])
99 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
100 int c;
102 while ((c = get_opts ()) != -1)
103 switch (c)
105 case 'o':
106 ior_output_file = get_opts.opt_arg ();
107 break;
109 case '?':
110 default:
111 ACE_ERROR_RETURN ((LM_ERROR,
112 "usage: %s "
113 "-o <iorfile> "
114 "\n",
115 argv [0]),
116 -1);
118 // Indicates successful parsing of the command line
119 return 0;