Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_1476_Regression / server.cpp
bloba8b9b72d0f4912ad218ee6e489e712c223e9c92a
1 #include "Sender_i.h"
2 #include "Server_Task.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
7 int number_of_oneways = 10;
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
21 case 'n' :
22 number_of_oneways = ACE_OS::atoi (get_opts.opt_arg ());
23 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-o <iorfile>"
29 "-n <number of oneways>"
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 try
43 CORBA::ORB_var orb =
44 CORBA::ORB_init (argc, argv);
46 CORBA::Object_var poa_object =
47 orb->resolve_initial_references("RootPOA");
49 if (CORBA::is_nil (poa_object.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR,
51 " (%P|%t) Unable to initialize the POA.\n"),
52 1);
54 PortableServer::POA_var root_poa =
55 PortableServer::POA::_narrow (poa_object.in ());
57 PortableServer::POAManager_var poa_manager =
58 root_poa->the_POAManager ();
60 if (parse_args (argc, argv) != 0)
61 return 1;
63 Sender_i *sender_impl;
64 ACE_NEW_RETURN (sender_impl,
65 Sender_i (orb.in ()),
66 1);
67 PortableServer::ServantBase_var receiver_owner_transfer(sender_impl);
69 PortableServer::ObjectId_var id =
70 root_poa->activate_object (sender_impl);
72 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
74 Test::Sender_var sender =
75 Test::Sender::_narrow (object.in ());
77 CORBA::String_var ior =
78 orb->object_to_string (sender.in ());
80 // If the ior_output_file exists, output the ior to it
81 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
82 if (output_file == 0)
83 ACE_ERROR_RETURN ((LM_ERROR,
84 "Cannot open output file for writing IOR: %s",
85 ior_output_file),
86 1);
87 ACE_OS::fprintf (output_file, "%s", ior.in ());
88 ACE_OS::fclose (output_file);
90 poa_manager->activate ();
92 Server_Task server_task (orb.in (),
93 ACE_Thread_Manager::instance ());
95 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1) == -1)
97 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
99 ACE_Thread_Manager::instance ()->wait ();
101 ACE_DEBUG ((LM_DEBUG, "Now terminating test\n"));
103 CORBA::ULong activeobjects = sender_impl->get_active_objects ();
104 if (((number_of_oneways * activeobjects) !=
105 sender_impl->get_number_received ()) && activeobjects != 0)
107 ACE_ERROR ((LM_ERROR, "Error, expected %d oneways, received %d\n",
108 number_of_oneways,
109 sender_impl->get_number_received()));
111 else
113 if (sender_impl->get_number_received () == 0)
115 ACE_ERROR ((LM_ERROR, "Error: Received no calls\n"));
117 else
119 ACE_DEBUG ((LM_DEBUG, "Corrected amount received\n"));
123 root_poa->destroy (true, true);
125 orb->destroy ();
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Exception caught:");
130 return 1;
133 return 0;