Cleanup Solaris support
[ACE_TAO.git] / TAO / examples / AMI / FL_Callback / peer.cpp
blobac19e3863ce5bd4d6fc3fd4ba99658f290fec35f
1 #include "Peer_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/OS_NS_errno.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://progress.ior");
8 int nthreads = 4;
9 int interval = 0; // microseconds
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:t:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case 'n':
25 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
26 break;
28 case 't':
29 interval = ACE_OS::atoi (get_opts.opt_arg ());
30 break;
32 case '?':
33 default:
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "usage: %s "
36 "-k <iorfile>"
37 "-n <threads>"
38 "-t <microseconds>"
39 "\n",
40 argv [0]),
41 -1);
43 // Indicates successful parsing of the command line
44 return 0;
47 /**
48 * Run a server thread
50 * Use the ACE_Task_Base class to run server threads
52 class Worker : public ACE_Task_Base
54 public:
55 /// ctor
56 Worker (CORBA::ORB_ptr orb);
58 /// The thread entry point.
59 virtual int svc ();
61 private:
62 /// The orb
63 CORBA::ORB_var orb_;
66 int
67 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
69 int priority =
70 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
71 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
73 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
74 priority);
76 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
77 priority);
79 // Enable FIFO scheduling
80 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
81 priority,
82 ACE_SCOPE_PROCESS)) != 0)
84 if (ACE_OS::last_error () == EPERM)
86 ACE_DEBUG ((LM_DEBUG,
87 "server (%P|%t): user is not superuser, "
88 "test runs in time-shared class\n"));
90 else
91 ACE_ERROR ((LM_ERROR,
92 "server (%P|%t): sched_params failed\n"));
95 try
97 CORBA::ORB_var orb =
98 CORBA::ORB_init (argc, argv);
100 CORBA::Object_var poa_object =
101 orb->resolve_initial_references("RootPOA");
103 if (CORBA::is_nil (poa_object.in ()))
104 ACE_ERROR_RETURN ((LM_ERROR,
105 " (%P|%t) Unable to initialize the POA.\n"),
108 PortableServer::POA_var root_poa =
109 PortableServer::POA::_narrow (poa_object.in ());
111 PortableServer::POAManager_var poa_manager =
112 root_poa->the_POAManager ();
114 poa_manager->activate ();
116 if (parse_args (argc, argv) != 0)
117 return 1;
119 CORBA::Object_var progress_object =
120 orb->string_to_object (ior);
122 Progress_var progress =
123 Progress::_narrow (progress_object.in ());
125 ACE_Time_Value delay (0, interval);
127 Peer_i peer;
128 peer.init (orb.in (),
129 progress.in (),
130 delay);
132 Worker worker (orb.in ());
133 if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
134 nthreads) != 0)
135 ACE_ERROR_RETURN ((LM_ERROR,
136 "Cannot activate client threads\n"),
139 worker.thr_mgr ()->wait ();
141 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
143 catch (const CORBA::Exception& ex)
145 ex._tao_print_exception ("Caught exception:");
146 return 1;
149 return 0;
152 // ****************************************************************
154 Worker::Worker (CORBA::ORB_ptr orb)
155 : orb_ (CORBA::ORB::_duplicate (orb))
160 Worker::svc ()
162 ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting event loop\n"));
163 this->orb_->run ();
164 return 0;