Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Big_Reply / server.cpp
blob020e73d21204baa19a5ae3784aa2641eed1b4dd3
1 #include "ace/Get_Opt.h"
2 #include "Big_Reply_i.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Task.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 // We can change this value if wanted..
10 const CORBA::ULong data_size = 4000000;
12 class OrbTask : public ACE_Task_Base
14 public:
15 OrbTask(const CORBA::ORB_ptr orb)
16 : orb_(CORBA::ORB::_duplicate(orb))
20 virtual int svc()
22 try
24 this->orb_->run ();
26 catch (const CORBA::Exception&)
29 return 0;
32 private:
33 CORBA::ORB_var orb_;
36 static int n_threads = 1;
38 int
39 parse_args (int argc, ACE_TCHAR *argv[])
41 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:t:"));
42 int c;
44 while ((c = get_opts ()) != -1)
45 switch (c)
47 case 'o':
48 ior_output_file = get_opts.opt_arg ();
49 break;
50 case 't':
51 n_threads = ACE_OS::atoi(get_opts.opt_arg());
52 break;
53 case '?':
54 default:
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "usage: %s "
57 "-o <iorfile>"
58 "-i <no_iterations>"
59 "\n",
60 argv [0]),
61 -1);
63 // Indicates successful parsing of the command line
64 return 0;
67 int
68 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
70 ACE_DEBUG ((LM_DEBUG, "Starting server\n"));
72 try
74 CORBA::ORB_var orb =
75 CORBA::ORB_init (argc, argv);
77 CORBA::Object_var poa_object =
78 orb->resolve_initial_references ("RootPOA");
80 if (CORBA::is_nil (poa_object.in ()))
81 ACE_ERROR_RETURN ((LM_ERROR,
82 " (%P|%t) Unable to initialize the POA.\n"),
83 1);
85 PortableServer::POA_var root_poa =
86 PortableServer::POA::_narrow (poa_object.in ());
88 PortableServer::POAManager_var poa_manager =
89 root_poa->the_POAManager ();
92 if (parse_args (argc, argv) != 0)
93 return 1;
95 Big_Reply_i *big_reply_gen = 0;
97 ACE_NEW_RETURN (big_reply_gen,
98 Big_Reply_i (orb.in (),
99 data_size),
103 PortableServer::ServantBase_var big_reply_owner_transfer(big_reply_gen);
105 PortableServer::ObjectId_var id =
106 root_poa->activate_object (big_reply_gen);
108 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
110 Test::Big_Reply_var big_reply =
111 Test::Big_Reply::_narrow (object.in ());
113 CORBA::String_var ior =
114 orb->object_to_string (big_reply.in ());
116 // If the ior_output_file exists, output the ior to it
117 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
118 if (output_file == 0)
119 ACE_ERROR_RETURN ((LM_ERROR,
120 "Cannot open output file for writing IOR: %s\n",
121 ior_output_file),
123 ACE_OS::fprintf (output_file, "%s", ior.in ());
124 ACE_OS::fclose (output_file);
126 poa_manager->activate ();
128 OrbTask task(orb.in());
130 if (task.activate (THR_NEW_LWP | THR_JOINABLE,
131 n_threads) != 0)
132 ACE_ERROR_RETURN ((LM_ERROR,
133 "Cannot activate threads\n"),
135 task.wait();
137 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
139 root_poa->destroy (true, true);
141 catch (const CORBA::Exception& ex)
143 ex._tao_print_exception ("Caught exception:");
144 return 1;
147 ACE_DEBUG ((LM_DEBUG, "Ending server\n"));
149 return 0;