summaryrefslogtreecommitdiff
path: root/CIAO/tests/Collocation/Receiver/Receiver_exec.cpp
blob: 34e98f1c14f90403d9a135a5fe8d586c35a30af8 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// -*- C++ -*-
// $Id$

/**
 * Code generated by the The ACE ORB (TAO) IDL Compiler v2.0.2
 * TAO and the TAO IDL Compiler have been developed by:
 *       Center for Distributed Object Computing
 *       Washington University
 *       St. Louis, MO
 *       USA
 *       http://www.cs.wustl.edu/~schmidt/doc-center.html
 * and
 *       Distributed Object Computing Laboratory
 *       University of California at Irvine
 *       Irvine, CA
 *       USA
 * and
 *       Institute for Software Integrated Systems
 *       Vanderbilt University
 *       Nashville, TN
 *       USA
 *       http://www.isis.vanderbilt.edu/
 *
 * Information about TAO is available at:
 *     http://www.cs.wustl.edu/~schmidt/TAO.html
 **/

#include "Receiver_exec.h"
#include "tao/ORB_Core.h"
#include "ace/Reactor.h"

namespace CIAO_Receiver_Impl
{

  /**
     * HelloGenerator
     */

  HelloGenerator::HelloGenerator (Receiver_exec_i &generator)
    : generator_ (generator)
  {
  }

  int
  HelloGenerator::handle_timeout (const ACE_Time_Value &, const void *)
  {
    // Notify the subscribers
    this->generator_.tick ();
    return 0;
  }

  /**
  * Component Executor Implementation Class: Receiver_exec_i
  */

  Receiver_exec_i::Receiver_exec_i (void)
  : interval_ (2, 1)
  {
    ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::Receiver_exec_i \n "));
    ACE_NEW_THROW_EX (this->hello_generator_,
                       HelloGenerator (*this),
                       ::CORBA::NO_MEMORY ());
  }

  Receiver_exec_i::~Receiver_exec_i (void)
  {
  }

  // Supported operations and attributes.
  ACE_Reactor*
  Receiver_exec_i::reactor (void)
   {
     ACE_Reactor* reactor = 0;
     ::CORBA::Object_var ccm_object =
       this->ciao_context_->get_CCM_object();
     if (! ::CORBA::is_nil (ccm_object.in ()))
       {
         ::CORBA::ORB_var orb = ccm_object->_get_orb ();
         if (! ::CORBA::is_nil (orb.in ()))
           {
             reactor = orb->orb_core ()->reactor ();
           }
       }
     if (reactor == 0)
       {
         throw ::CORBA::INTERNAL ();
       }
     return reactor;
   }

   void
   Receiver_exec_i::tick (void)
   {
     ACE_DEBUG ((LM_DEBUG, "$$$$$$$$$$$$$$  Start interface method in Receiver_exec_i::tick - "
                                     "set point  for  sender.\n"));
     try
       {
         /// Retrieve the connection to the sender.
         Hello_var hello_to_rec =
           this->ciao_context_->get_connection_hello_to_rec ();
         if (! ::CORBA::is_nil (hello_to_rec.in ()))
           {
 /*            CORBA::String_var message = hello_to_rec->say_hello ();
             ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::tick - "
                                           "got hello-message from sender  <%C>.\n",
                                           message.in()));
*/           pointer_id::_var_type p = new pointer_id;
             p->point = (long)p.ptr ();
             hello_to_rec->set_point(p.in());

              ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::tick - "
                                            "set_hello-point with pointer %@\n",
                                            (void *)p.ptr ()));

           }
         else
           {
             ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::tick - "
                                            "no connection hello_to_rec with sender.\n"));
           }
        }
     catch (const CORBA::Exception &e)
       {
         /// Always catch CORBA exceptions. There might be somthing wrong with
         /// the CIAO framework (i.e. connection lost).
         e._tao_print_exception("Receiverr_exec_i::tick - "
                                "Error: Unexpected exception");
       }
     catch (...)
       {
         /// Just for all security
         ACE_ERROR ((LM_ERROR, "Receiver_exec_i::tick - "
                     "Error: Unexpected and unknown exception caught\n"));
       }
     ACE_DEBUG ((LM_DEBUG, "$$$$$$$$$$$$$$  End interface method in Receiver_exec_i::tick - "
                                      "set point  for  sender.\n"));

   }
  // Component attributes and port operations.

   // Operations from Components::SessionComponent.

  void
  Receiver_exec_i::set_session_context (
    ::Components::SessionContext_ptr ctx)
  {
    this->ciao_context_ =
      ::CCM_Receiver_Context::_narrow (ctx);

    if ( ::CORBA::is_nil (this->ciao_context_.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }
  }

  void
  Receiver_exec_i::configuration_complete (void)
  {
    ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::configuration_complete \n "));
    /// No need to implement anything
  }

  void
  Receiver_exec_i::ccm_activate (void)
  {
    ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_activate \n "));
    /// No need to implement anything
    /// Start the timer .
     if (this->reactor ()->schedule_timer(
                 this->hello_generator_,  // The callback object
                 0,                       // No arguments for this callback
                 ACE_Time_Value (1, 0),   // Initial delay
                 this->interval_) == -1)  // Time interval
       {
         ACE_ERROR ((LM_ERROR, "Receiver_exec_i::ccm_activate - "
                               "Error scheduling timer\n"));
       }
     else
       {
         ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_activate - "
                               "Hello generator is running\n"));
       }
   }

  void
  Receiver_exec_i::ccm_passivate (void)
  {
    /// No need to implement anything
    ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_passivate \n "));
  }

  void
  Receiver_exec_i::ccm_remove (void)
  {
    /// No need to implement anything
    ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_remove \n "));
  }

  extern "C" RECEIVER_EXEC_Export ::Components::EnterpriseComponent_ptr
  create_Receiver_Impl (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();

    ACE_NEW_NORETURN (
      retval,
      Receiver_exec_i);

    return retval;
  }
}