Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Threads / Message_Receiver.h
blob395a94d3a609673365cc51fd77897615f7b3ce41
1 /**
2 * Sample code from The ACE Programmer's Guide,
3 * copyright 2003 Addison-Wesley. All Rights Reserved.
4 */
6 #ifndef __MESSAGE_RECEIVER_H_
7 #define __MESSAGE_RECEIVER_H_
9 #include "ace/Log_Msg.h"
10 #include "ace/Message_Block.h"
11 #include "ace/SOCK_Stream.h"
12 #include "ace/Svc_Handler.h"
13 #include "ace/Synch.h"
14 #include "ace/Task.h"
16 // Listing 1 code/ch12
17 struct DeviceCommandHeader
19 int length_;
20 int deviceId_;
22 // Listing 1
24 class HA_Device_Repository
26 public:
27 HA_Device_Repository ();
29 int update_device (int device_id, char *commands);
31 private:
32 ACE_Task_Base *owner_;
35 HA_Device_Repository::HA_Device_Repository ()
36 { }
38 int
39 HA_Device_Repository::update_device (int, char *)
41 return 0;
44 class HA_CommandHandler : public ACE_Task<ACE_MT_SYNCH>
46 public:
47 HA_CommandHandler (HA_Device_Repository &rep) : rep_(rep)
48 { }
50 virtual int svc();
52 private:
53 HA_Device_Repository &rep_;
56 class Message_Receiver :
57 public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
59 public:
60 Message_Receiver () : handler_(0)
62 ACE_ASSERT(0);
65 Message_Receiver (HA_CommandHandler *ch) : handler_(ch)
66 { }
68 ACE_Message_Block *shut_down_message ();
70 virtual int handle_input (ACE_HANDLE fd);
72 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
73 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK)
75 this->peer ().close ();
76 delete this;
77 return 0;
80 private:
81 int read_header (DeviceCommandHeader *dch);
82 int copy_payload (ACE_Message_Block *mb, int payload_length);
84 private:
85 HA_CommandHandler *handler_;
88 #endif /* __MESSAGE_RECEIVER_H */