summaryrefslogtreecommitdiff
path: root/TAO/examples/POA/Generic_Servant/MyFooServant.cpp
blob: d236da4f6f66e3e269647e8131b36cf4ff01169f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// $Id$

// ================================================================
//
//
// = FILENAME
//     MyFooServant.cpp
//
// = DESCRIPTION
//     This is a simple foo servant implementation
//
// = AUTHOR
//     Irfan Pyarali
//
// ================================================================
#define ACE_BUILD_SVC_EXPORT

#include "MyFooServant.h"

ACE_RCSID(Generic_Servant, MyFooServant, "$Id$")

// Constructor
MyFooServant::MyFooServant (CORBA::ORB_ptr orb,
			    PortableServer::POA_ptr poa,
                            CORBA::Long value)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    poa_ (PortableServer::POA::_duplicate (poa)),
    value_ (value)
{
}

// Destructor
MyFooServant::~MyFooServant (void)
{
}

// Return the Default POA of this Servant
PortableServer::POA_ptr
MyFooServant::_default_POA (CORBA::Environment &/*env*/)
{
  return PortableServer::POA::_duplicate (this->poa_.in ());
}

CORBA::Long
MyFooServant::doit (CORBA::Environment &/*env*/)
{
  return this->value_;
}

void
MyFooServant::simply_doit (CORBA::Environment &/*env*/)
{
}

void
MyFooServant::shutdown (CORBA::Environment &)
{
  this->orb_->shutdown ();
}


// This is the point of entry into this library.

extern "C" GENERIC_SERVANT_Export PortableServer::Servant create_MyFoo (CORBA::ORB_ptr orb,
                                                                        PortableServer::POA_ptr poa,
                                                                        CORBA::Long value);

// The servant pointer is returned which will be of Base class
// type. The binding to the MyFoo servant will happen at run-time.

PortableServer::Servant
create_MyFoo (CORBA::ORB_ptr orb,
              PortableServer::POA_ptr poa,
              CORBA::Long value)
{
  PortableServer::Servant servant;

  ACE_NEW_RETURN (servant,
                  MyFooServant (orb,
                                poa,
                                value),
                  0);
  return servant;
}


extern "C" GENERIC_SERVANT_Export PortableServer::Servant supply_servant (const PortableServer::ObjectId &oid,
                                                                          PortableServer::POA_ptr poa,
                                                                          CORBA::ORB_ptr orb);

// The servant pointer is returned which will be of Base class
// type. The binding to the servant will happen at run-time.

PortableServer::Servant
supply_servant (const PortableServer::ObjectId &oid,
                PortableServer::POA_ptr poa,
                CORBA::ORB_ptr orb)
{
  PortableServer::Servant servant = 0;

  // Convert ObjectId to String.
  CORBA::String_var s = PortableServer::ObjectId_to_string (oid);

  if (ACE_OS::strstr (s.in (), "Foo") != 0)
    ACE_NEW_RETURN (servant,
                    MyFooServant (orb,
                                  poa,
                                  0),
                    0);
  return servant;
}

extern "C" GENERIC_SERVANT_Export void destroy_servant (const PortableServer::ObjectId &oid,
                                                        PortableServer::POA_ptr poa,
                                                        PortableServer::Servant servant);

// This function will take care of the destruction of the servant.

void
destroy_servant (const PortableServer::ObjectId & /* oid */,
                PortableServer::POA_ptr /* poa */,
                 PortableServer::Servant servant)
{
  delete servant;
}