summaryrefslogtreecommitdiff
path: root/CIAO/ciao/Servants/Port_Activator_T.cpp
blob: 4aef5bb4a5db3a92682cbc571d14f892b4af05ac (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
// $Id$

#ifndef CIAO_PORT_ACTIVATOR_T_CPP
#define CIAO_PORT_ACTIVATOR_T_CPP

#include "Port_Activator_T.h"
#include "tao/CORBA_String.h"

#include "ace/OS_NS_string.h"

namespace CIAO
{
  template <typename SERV,
            typename EXEC,
            typename CONTEXT,
            typename COMP_SERV>
  Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::Port_Activator_T (
      const char *oid,
      const char *name,
      Port_Activator_Types::Type t,
      typename EXEC::_ptr_type e,
      typename CONTEXT::_ptr_type c,
      COMP_SERV *cc)
    : Port_Activator_i (oid, name, t)
    , executor_ (EXEC::_duplicate (e))
    , context_ (CONTEXT::_duplicate (c))
    , comp_serv_ (cc)
  {
  }

  template <typename SERV,
            typename EXEC,
            typename CONTEXT,
            typename COMP_SERV>
  void
  Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::deactivate (
      PortableServer::Servant servant, CORBA::Boolean)
  {
    SERVANT *s = dynamic_cast<SERVANT *> (servant);
    if (s)
      {
        s->_remove_ref ();
      }
  }

  template <typename SERV,
            typename EXEC,
            typename CONTEXT,
            typename COMP_SERV>
  PortableServer::Servant
  Port_Activator_T<SERV, EXEC, CONTEXT, COMP_SERV>::activate (
      const PortableServer::ObjectId &oid)
  {
    CORBA::String_var str = PortableServer::ObjectId_to_string (oid);

    // An additional check, may not be necessary. Being on the safe
    // side.
    if (ACE_OS::strcmp (this->oid_.in (), str.in ()) == 0)
      {
        if (this->t_ == Port_Activator_Types::FACET && ::CORBA::is_nil (this->executor_.in ()))
          {
            ::CORBA::Object_var tmp =
              this->comp_serv_->get_facet_executor (this->name_.in ());

            this->executor_ = EXEC::_narrow (tmp.in ());
          }

        SERVANT *s = 0;

        ACE_NEW_THROW_EX (s,
                          SERVANT (this->executor_.in (),
                                   this->context_.in ()),
                          ::CORBA::NO_MEMORY ());

        return s;
      }

    throw ::CORBA::OBJECT_NOT_EXIST ();
  }
}

#endif /*SERVANT_ACTIVATOR_T_CPP*/