Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / PICurrent / ClientInterceptor.cpp
blobc46cca7caf895de2bc0f1603c8bbd3d2a4fd691f
1 #include "ClientInterceptor.h"
2 #include "tao/OctetSeqC.h"
3 #include "tao/PI/ClientRequestInfo.h"
4 #include "MessengerC.h"
5 #include "ace/OS_NS_string.h"
6 #include <iostream>
8 const CORBA::ULong service_ctx_id = 0xdeed;
10 ClientInterceptor::
11 ClientInterceptor (Messenger_var theMessenger,
12 PortableInterceptor::Current_ptr thePic,
13 PortableInterceptor::SlotId theSlot)
14 : myname_ ("Client_Authentication_Interceptor")
16 std::cout << "Calling ClientInterceptor constructor." << std::endl;
17 this->messenger = theMessenger;
18 this->pic = thePic;
19 this->slot = theSlot;
22 ClientInterceptor::~ClientInterceptor (void)
26 char *
27 ClientInterceptor::name ()
29 std::cout << "Calling ClientInterceptor name() method" << std::endl;
30 return CORBA::string_dup (this->myname_);
33 void
34 ClientInterceptor::destroy ()
38 void
39 ClientInterceptor::send_poll (PortableInterceptor::ClientRequestInfo_ptr ri)
41 ACE_UNUSED_ARG(ri);
42 std::cout << "Calling send_poll()." << std::endl;
46 void
47 ClientInterceptor::send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
49 std::cout << "Calling send_request()." << std::endl;
51 IOP::ServiceContext sc;
52 sc.context_id = service_ctx_id;
54 const char user_name[] = "Ron Klein";
55 std::cout << "User's Name: " << user_name << std::endl;
56 CORBA::ULong string_len = sizeof (user_name) + 1;
57 CORBA::Octet *buf = 0;
58 buf = new CORBA::Octet [string_len];
60 ACE_OS::strcpy (reinterpret_cast<char*> (buf), user_name);
62 sc.context_data.replace (string_len, string_len, buf, true);
64 // recursive call setup
65 CORBA::Any *recurse = ri->get_slot(slot);
66 CORBA::Boolean x;
67 CORBA::Any flag;
68 if (*recurse >>= CORBA::Any::to_boolean(x)) {
69 if (x == false)
71 x = true;
72 flag <<= CORBA::Any::from_boolean(x);
74 pic->set_slot(slot, flag);
76 // get server time
77 std::cout << "Server Time = " << messenger->get_time() << std::endl;
79 } else {
80 std::cerr << "Could not extract a boolean value from any" << std::endl;
83 // Add this context to the service context list.
84 ri->add_request_service_context (sc, false);
86 // reset recursion test
87 x = false;
88 flag <<= CORBA::Any::from_boolean(x);
89 pic->set_slot(slot,flag);
93 void
94 ClientInterceptor::receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
96 ACE_UNUSED_ARG(ri);
97 std::cout << "Calling receive_reply()." << std::endl;
100 void
101 ClientInterceptor::receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
103 ACE_UNUSED_ARG(ri);
104 std::cout << "Calling receive_other()." << std::endl;
107 void
108 ClientInterceptor::receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri)
110 ACE_UNUSED_ARG(ri);
111 std::cout << "Calling receive_exception()." << std::endl;