summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Common/OrbTask.cpp
blob: ff6ad717898d7f4f65520485b5d39479e32d96c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// This may look like C, but it's really -*- C++ -*-

//=============================================================================
/**
 *  @file    OrbTask.cpp
 *
 *  $Id$
 *
 *  @author  Tim Bradley <bradley_t@ociweb.com>
 */
//=============================================================================

#include "OrbTask.h"
#include "ace/CORBA_macros.h"

namespace { enum { MAX_ORB_TASK_WORKER_THREADS = 20 }; }


OrbTask::OrbTask(CORBA::ORB_ptr orb, unsigned num_threads)
  : orb_(CORBA::ORB::_duplicate(orb)),
    num_threads_(num_threads)
{
}


OrbTask::~OrbTask()
{
}


int
OrbTask::open(void*)
{
  if (this->num_threads_ < 1)
    {
      ACE_ERROR_RETURN((LM_ERROR,
                        "(%P|%t) OrbTask failed to open.  "
                        "num_threads_ (%d) is less-than 1.\n",
                        this->num_threads_),
                       -1);
    }

  if (this->num_threads_ > MAX_ORB_TASK_WORKER_THREADS)
    {
      ACE_ERROR_RETURN((LM_ERROR,
                        "(%P|%t) OrbTask failed to open.  "
                        "num_threads_ (%d) is too large.  Max is %d.\n",
                        this->num_threads_, MAX_ORB_TASK_WORKER_THREADS),
                       -1);
    }

  if (CORBA::is_nil(this->orb_.in()))
    {
      ACE_ERROR_RETURN((LM_ERROR,
                        "(%P|%t) OrbTask failed to open.  "
                        "ORB object reference is nil.\n"),
                        -1);
    }

  if (this->activate(THR_NEW_LWP | THR_JOINABLE, this->num_threads_) != 0)
    {
      // Assumes that when activate returns non-zero return code that
      // no threads were activated.
      ACE_ERROR_RETURN((LM_ERROR,
                        "(%P|%t) OrbTask failed to activate "
                        "(%d) worker threads.\n",
                        this->num_threads_),
                       -1);
    }

  return 0;
}


int
OrbTask::svc()
{
  ACE_TRY_NEW_ENV
  {
    this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_TRY_CHECK;
  }
  ACE_CATCHALL
  {
    ACE_ERROR((LM_ERROR,
      "(%P|%t) Exception raised by ORB::run() method. "
      "OrbTask is stopping.\n"));
  }
  ACE_ENDTRY;

  return 0;
}


int
OrbTask::close(u_long)
{
  return 0;
}