summaryrefslogtreecommitdiff
path: root/ACE/ace/PIP_IO_Handler.h
blob: 563a95303c284cb8c2ad3c3a602f86d464b0687b (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
 /**
  * @file PIP_IO_Handler.h
  *
  * // $Id$
  *
  * @author John Moore <ljohn7@gmail.com>
  *
  * This file contains the specification for a class
  * that manages network I/O
*/

#ifndef _PIP_IO_HANDLER_H_
#define _PIP_IO_HANDLER_H_

#include "ace/Message_Queue.h"
#include "ace/Mutex.h"
#include "ace/PIP_Messages.h"
#include "ace/Svc_Handler.h"
#include "ace/Thread_Mutex.h"

// Typedefs
typedef ACE_Message_Queue_Ex<ACE_PIP_Protocol_Message, ACE_NULL_SYNCH>
   PROTO_MESSAGE_QUEUE_TYPE;

/**
 * @class ACE_PIP_IO_Handler
 *
 * @brief Performs network I/O 
 *
 * @author John Moore <ljohn7@gmail.com>
 */
class ACE_Export ACE_PIP_IO_Handler : 
   public ACE_Svc_Handler<ACE_SOCK_Stream, ACE_MT_SYNCH>
{
  public:
  
   /// Constructor
   ACE_PIP_IO_Handler ();
   
   /// Destructor
   virtual ~ACE_PIP_IO_Handler();

   /// Enqueue a message to be sent
   virtual int put_message (ACE_PIP_Protocol_Message* message) = 0;

   /// Initialize the priority of the handler, and inform the other end
   /// of the priority
   virtual void init(ACE_UINT32 site_id,
                     ACE_UINT32 destination_site_id,
                     ACE_UINT32 priority);
   
   /// Handles read event on socket.
   virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);

   /// Handles read event on socket.
   virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);

   /// Set the site_id
   void site_id(ACE_UINT32 site_id);

   /// Get the site id
   ACE_UINT32 site_id() const;

   /// Get the other end's site id
   ACE_UINT32 destination_site_id() const;
   
   /// Get the handler id
   void handler_id(ACE_UINT32 handler_id);

   /// Set the handler id
   ACE_UINT32 handler_id() const;

   /// Get the address of the remote site
   ACE_INET_Addr remote_address() const;

 protected:
   
   /// Reads priority from socket
   void extract_priority();
   
   // variables to track the state of the handler
   bool read_closed_;
   bool write_closed_;
   bool priority_set_;

   ACE_UINT32 site_id_;
   ACE_UINT32 handler_id_;
   ACE_UINT32 destination_site_id_;

   const ACE_Time_Value millisecond_;

   PROTO_MESSAGE_QUEUE_TYPE outgoing_message_queue_;
   ACE_Thread_Mutex big_lock_;
};

#if defined (__ACE_INLINE__)
#include "PIP_IO_Handler.inl"
#endif /* __ACE_INLINE__ */


#endif /* _PIP_IO_Handler_H_ */