Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / OrbTask.cpp
blob097c6c1f49454d9b4cafca41d92f1bc88cd745c1
1 //=============================================================================
2 /**
3 * @file OrbTask.cpp
5 * @author Tim Bradley <bradley_t@ociweb.com>
6 */
7 //=============================================================================
9 #include "OrbTask.h"
10 #include "ace/CORBA_macros.h"
12 namespace { enum { MAX_ORB_TASK_WORKER_THREADS = 20 }; }
14 OrbTask::OrbTask(CORBA::ORB_ptr orb, unsigned num_threads)
15 : orb_(CORBA::ORB::_duplicate(orb)),
16 num_threads_(num_threads)
20 int
21 OrbTask::open(void*)
23 if (this->num_threads_ < 1)
25 ACE_ERROR_RETURN((LM_ERROR,
26 "(%P|%t) OrbTask failed to open. "
27 "num_threads_ (%d) is less-than 1.\n",
28 this->num_threads_),
29 -1);
32 if (this->num_threads_ > MAX_ORB_TASK_WORKER_THREADS)
34 ACE_ERROR_RETURN((LM_ERROR,
35 "(%P|%t) OrbTask failed to open. "
36 "num_threads_ (%d) is too large. Max is %d.\n",
37 this->num_threads_, MAX_ORB_TASK_WORKER_THREADS),
38 -1);
41 if (CORBA::is_nil(this->orb_.in()))
43 ACE_ERROR_RETURN((LM_ERROR,
44 "(%P|%t) OrbTask failed to open. "
45 "ORB object reference is nil.\n"),
46 -1);
49 if (this->activate(THR_NEW_LWP | THR_JOINABLE, this->num_threads_) != 0)
51 // Assumes that when activate returns non-zero return code that
52 // no threads were activated.
53 ACE_ERROR_RETURN((LM_ERROR,
54 "(%P|%t) OrbTask failed to activate "
55 "(%d) worker threads.\n",
56 this->num_threads_),
57 -1);
60 return 0;
64 int
65 OrbTask::svc()
67 try
69 this->orb_->run();
71 catch (...)
73 ACE_ERROR((LM_ERROR,
74 "(%P|%t) Exception raised by ORB::run() method. "
75 "OrbTask is stopping.\n"));
78 return 0;
81 int
82 OrbTask::close(u_long)
84 return 0;