summaryrefslogtreecommitdiff
path: root/TAO/tests/POA/Generic_Servant/test_i.cpp
blob: e8c87b99e13388d4b574d817e0f8edc2897cd74a (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
#include "test_i.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_string.h"

// Constructor
test_i::test_i (CORBA::ORB_ptr orb,
                PortableServer::POA_ptr poa)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    poa_ (PortableServer::POA::_duplicate (poa))
{
}

PortableServer::POA_ptr
test_i::_default_POA (void)
{
  return PortableServer::POA::_duplicate (this->poa_.in ());
}

void
test_i::method (void)
{
}

void
test_i::oneway_method (void)
{
}

void
test_i::sleep (CORBA::ULong timeout,
               const char *method)
{
  ACE_DEBUG ((LM_DEBUG,
              "Thread %t starting %s with timeout %d\n",
              method,
              timeout));

  ACE_OS::sleep (timeout);

  ACE_DEBUG ((LM_DEBUG,
              "Thread %t completes %s\n",
              method));
}

void
test_i::timed_method (CORBA::ULong timeout)
{
  this->sleep (timeout,
               "test_i::timed_method");
}

void
test_i::timed_oneway_method (CORBA::ULong timeout)
{
  this->sleep (timeout,
               "test_i::timed_oneway_method");
}

void
test_i::shutdown (void)
{
  this->orb_->shutdown (0);
}


// This is the point of entry into this library.
extern "C" GENERIC_SERVANT_Export PortableServer::Servant create_test_i (CORBA::ORB_ptr orb,
                                                                         PortableServer::POA_ptr poa);

PortableServer::Servant
create_test_i (CORBA::ORB_ptr orb,
               PortableServer::POA_ptr poa)
{
  PortableServer::Servant servant;

  ACE_NEW_RETURN (servant,
                  test_i (orb,
                          poa),
                  0);
  return servant;
}


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

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 (), "test") != 0)
    ACE_NEW_RETURN (servant,
                    test_i (orb,
                            poa),
                    0);
  return servant;
}

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

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