summaryrefslogtreecommitdiff
path: root/TAO/examples/POA/On_Demand_Activation/Servant_Locator.cpp
blob: 52b21000087fee9b5d36bee5a984dcf5bf322f18 (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
// $Id$

// ============================================================================
//
// = LIBRARY
//     TAO/tests/POA/On_Demand_Activation/Servant_Locator
//
// = FILENAME
//     Servant_Locator.cpp
//
// = DESCRIPTION
//     Implementation of MyFooServantLocator class , used with a POA
//     having a NON_RETAIN policy.
//
// = AUTHOR
//     Irfan Pyarali
//
// ============================================================================

#include "Servant_Locator.h"
#include "MyFooServant.h"

ACE_RCSID(On_Demand_Activation, Servant_Locator, "$Id$")

MyFooServantLocator::MyFooServantLocator (CORBA::ORB_ptr orb)
  : counter_ (0),
    orb_ (CORBA::ORB::_duplicate (orb))
{
}


PortableServer::Servant
MyFooServantLocator::preinvoke (const PortableServer::ObjectId &oid,
                                PortableServer::POA_ptr poa,
                                const char * /* operation */,
                                PortableServer::ServantLocator::Cookie &cookie,
                                CORBA::Environment &env)
{
  // Convert ObjectID to String.

  CORBA::String_var s = PortableServer::ObjectId_to_string (oid);
  // If ObjectID string has a Foo Substring create and return a
  // MyFooServant.

  if (ACE_OS::strstr (s.in (), "Foo") != 0)
    {
      PortableServer::Servant servant =
        new MyFooServant (this->orb_.in (), poa, ++this->counter_);

      // Return the servant as the cookie , used as a check when
      // postinvoke is called on this MyFooServantLocator.

      cookie = servant;
      return servant;
    }
  else
    {
      CORBA::Exception *exception =
        new CORBA::OBJECT_NOT_EXIST (CORBA::COMPLETED_NO);
      env.exception (exception);
      return 0;
    }
}

void
MyFooServantLocator::postinvoke (const PortableServer::ObjectId & /* oid */,
                                 PortableServer::POA_ptr /* poa */,
                                 const char * /* operation */,
                                 PortableServer::ServantLocator::Cookie cookie,
                                 PortableServer::Servant servant,
                                 CORBA::Environment &/* env */)
{
  // Check the passed servant with the cookie.

  PortableServer::Servant my_servant = (PortableServer::Servant) cookie;
  ACE_ASSERT (servant == my_servant);
  delete servant;

  // To avoid warning about unused variable with ACE_NDEBUG.
  ACE_UNUSED_ARG (my_servant);
}