Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / AVStreams / Component_Switching / distributer.h
blob6eca9f6a293392eb8d227465f3b33996e3be650e
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file distributer.h
7 * Process to receive data from the sender and send it to the
8 * receiver.
10 * @author Yamuna Krishnamurthy <yamuna@cs.wustl.edu>
12 //=============================================================================
15 #include "Connection_Manager.h"
16 #include "orbsvcs/AV/AVStreams_i.h"
17 #include "orbsvcs/AV/Endpoint_Strategy.h"
18 #include "orbsvcs/AV/Policy.h"
20 /**
21 * @class Signal_Handler
22 TITLE
23 * This class Handles the SIGINT signal through the Reactor.
24 * Useful to gracefully release the process
26 class Signal_Handler : public ACE_Event_Handler
29 public:
31 Signal_Handler (void);
33 /// Override this method to implement graceful shutdown.
34 int handle_signal(int signum, siginfo_t*,ucontext_t*);
39 /**
40 * @class Distributer_Receiver_Callback
42 * @brief Application defined callback object.
44 * AVStreams calls this class when data shows up from a sender.
46 class Distributer_Receiver_Callback : public TAO_AV_Callback
48 public:
50 //// Constructor.
51 Distributer_Receiver_Callback (void);
53 /// Method that is called when there is data to be received from a
54 /// sender.
55 int receive_frame (ACE_Message_Block *frame,
56 TAO_AV_frame_info *frame_info,
57 const ACE_Addr &peer_address);
59 /// Called when the sender is done sending data and wants to close
60 /// down the connection.
61 int handle_destroy (void);
63 /// Accessor methods for the flowname of the callback.
64 ACE_CString &flowname (void);
65 void flowname (const ACE_CString &flowname);
67 private:
68 //// Count of the frames passing through us.
69 int frame_count_;
71 //// Flowname of the flow.
72 ACE_CString flowname_;
75 /**
76 * @class Distributer_Sender_Callback
78 * @brief Defines a class for the distributer application callback
79 * for receiving data.
81 * This class overrides the methods of the TAO_AV_Callback so the
82 * AVStreams can make upcalls to the application.
84 class Distributer_Sender_Callback : public TAO_AV_Callback
87 public:
89 //// Called when the sender has finished reading the file and wants
90 //// to close down the connection.
91 int handle_destroy (void);
93 /// Accessor methods for the flowname of the callback.
94 ACE_CString &flowname (void);
95 void flowname (const ACE_CString &flowname);
97 private:
99 ACE_CString flowname_;
104 * @class Distributer_Receiver_StreamEndPoint
106 * @brief Application defined stream endpoint object.
108 * AVStreams calls this class during connection setup.
110 class Distributer_Receiver_StreamEndPoint : public TAO_Server_StreamEndPoint
112 public:
113 /// Create a receiver application callback.
114 int get_callback (const char *flowname,
115 TAO_AV_Callback *&callback);
117 //// Store the reference to the protocol object corresponding
118 //// to the transport
119 int set_protocol_object (const char *,
120 TAO_AV_Protocol_Object *object);
122 //// Called when a sender makes a connection request.
123 virtual CORBA::Boolean handle_connection_requested (AVStreams::flowSpec &the_spec);
125 private:
126 //// Receiver application callback.
127 Distributer_Receiver_Callback callback_;
131 * @class Distributer_Sender_StreamEndPoint
133 * @brief / Defines a sender stream endpoint.
135 class Distributer_Sender_StreamEndPoint : public TAO_Client_StreamEndPoint
137 public:
138 //// Create the application callback and return its handle to
139 //// AVStreams for further application callbacks.
140 int get_callback (const char *flowname,
141 TAO_AV_Callback *&callback);
143 //// Set protocol object corresponding to the transport protocol
144 //// chosen.
145 int set_protocol_object (const char *flowname,
146 TAO_AV_Protocol_Object *object);
148 protected:
149 //// Application callback.
150 Distributer_Sender_Callback callback_;
153 typedef TAO_AV_Endpoint_Reactive_Strategy_A
154 <Distributer_Sender_StreamEndPoint,
155 TAO_VDev,
156 AV_Null_MediaCtrl>
157 SENDER_ENDPOINT_STRATEGY;
159 typedef TAO_AV_Endpoint_Reactive_Strategy_B
160 <Distributer_Receiver_StreamEndPoint,
161 TAO_VDev,
162 AV_Null_MediaCtrl>
163 RECEIVER_ENDPOINT_STRATEGY;
166 * @class Distributer
168 * @brief Distributer Application.
170 * The distributer is the intermediate receiver that receives
171 * data from the sender and forwards to a receiver.
173 class Distributer
175 public:
176 //// Constructor
177 Distributer (void);
179 //// Destructor.
180 ~Distributer (void);
182 //// Initialize data components.
183 int init (int argc,
184 ACE_TCHAR **argv);
186 //// Parse args.
187 int parse_args (int argc,
188 ACE_TCHAR **argv);
190 /// Flag to know when we are done.
191 bool done (void) const;
192 void done (bool);
194 //// Accessor to connection manager.
195 Connection_Manager &connection_manager (void);
197 //// Called when stream created
198 void stream_created (void);
200 //// Called when stream destroyed
201 void stream_destroyed (void);
203 ////Unbind the sender and receiver from the Naming Service
204 void shut_down (void);
206 protected:
207 //// Connection manager.
208 Connection_Manager connection_manager_;
210 //// The sender endpoint strategy.
211 SENDER_ENDPOINT_STRATEGY sender_endpoint_strategy_;
213 //// The receiver endpoint strategy.
214 RECEIVER_ENDPOINT_STRATEGY receiver_endpoint_strategy_;
216 //// The distributer receiver multimedia device
217 TAO_MMDevice* distributer_receiver_mmdevice_;
219 //// The distributer receiver multimedia device
220 TAO_MMDevice* distributer_sender_mmdevice_;
222 //// The name of the sender to connect to.
223 ACE_CString sender_name_;
225 //// Our name.
226 ACE_CString distributer_name_;
228 //// Flag to know when we are done.
229 bool done_;
231 //// Number of active streams. When a stream is disconnected this
232 //// count is decremented.
233 int stream_count_;
235 //// Reference to the signal handler.
236 Signal_Handler signal_handler_;