summaryrefslogtreecommitdiff
path: root/TAO/DevGuideExamples/LocalObjects/ServantLocator/MessengerLocator_i.cpp
blob: a3bb99603c0ff243b634df90c428ccab63fd3dd7 (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
#include "MessengerLocator_i.h"
#include "Messenger_i.h"

#include "ace/SString.h"
#include <iostream>

Messenger_Locator_i::Messenger_Locator_i()
{
}

PortableServer::Servant
Messenger_Locator_i::preinvoke (const PortableServer::ObjectId &oid,
                                           PortableServer::POA_ptr,
                                           const char *,
                                           void * & cookie )
{
  // Get the ObjectId in string format.
  CORBA::String_var oid_str = PortableServer::ObjectId_to_string (oid);

  std::cout << "preinvoke called..." << oid_str << std::endl;

  // Check if the ObjectId is valid.
  ACE_CString cstr(oid_str.in());
  if (cstr == "Messenger") {
    // Create the required servant
    PortableServer::ServantBase_var servant = new Messenger_i ();

    // Set a flag so that we know to delete it in postinvoke().
    cookie = (void *)1;

    return servant._retn();
  }
  else {
    throw CORBA::OBJECT_NOT_EXIST ();
  }
}

void
Messenger_Locator_i::postinvoke (const PortableServer::ObjectId &,
                                 PortableServer::POA_ptr,
                                 const char *,
                                 void * cookie,
                                 PortableServer::Servant servant)
{

  std::cout << "postinvoke called..." << std::endl;

  // Delete the servant as it is no longer needed.
  if (cookie != 0) {
    delete servant;
  }
}