Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / DevGuideExamples / LocalObjects / ServantLocator / MessengerLocator_i.cpp
blob4e0d4f301ffe9ade648ef71acf7446c41c4d77f0
1 #include "MessengerLocator_i.h"
2 #include "Messenger_i.h"
4 #include "ace/SString.h"
5 #include <iostream>
7 Messenger_Locator_i::Messenger_Locator_i()
11 PortableServer::Servant
12 Messenger_Locator_i::preinvoke (const PortableServer::ObjectId &oid,
13 PortableServer::POA_ptr,
14 const char *,
15 void * & cookie )
17 // Get the ObjectId in string format.
18 CORBA::String_var oid_str = PortableServer::ObjectId_to_string (oid);
20 std::cout << "preinvoke called..." << oid_str << std::endl;
22 // Check if the ObjectId is valid.
23 ACE_CString cstr(oid_str.in());
24 if (cstr == "Messenger") {
25 // Create the required servant
26 PortableServer::ServantBase_var servant = new Messenger_i ();
28 // Set a flag so that we know to delete it in postinvoke().
29 cookie = (void *)1;
31 return servant._retn();
33 else {
34 throw CORBA::OBJECT_NOT_EXIST ();
38 void
39 Messenger_Locator_i::postinvoke (const PortableServer::ObjectId &,
40 PortableServer::POA_ptr,
41 const char *,
42 void * cookie,
43 PortableServer::Servant servant)
45 std::cout << "postinvoke called..." << std::endl;
47 // Delete the servant as it is no longer needed.
48 if (cookie != 0) {
49 delete servant;