Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / ASX / UPIPE_Event_Server / Peer_Router.h
blobf24577307da5a39e53dd7ac7ccd56c1495cedbf9
1 /* -*- C++ -*- */
2 // The interface between one or more peers and a stream. A peer
3 // typically runs remotely on another machine.
5 #ifndef _PEER_ROUTER_H
6 #define _PEER_ROUTER_H
8 #include "ace/Acceptor.h"
10 #if !defined (ACE_LACKS_PRAGMA_ONCE)
11 # pragma once
12 #endif /* ACE_LACKS_PRAGMA_ONCE */
14 #include "ace/Svc_Handler.h"
15 #include "ace/UPIPE_Acceptor.h"
16 #include "ace/UPIPE_Addr.h"
17 #include "ace/Thread_Manager.h"
18 #include "ace/Map_Manager.h"
20 #if defined (ACE_HAS_THREADS)
21 #include "ace/RW_Mutex.h"
23 // Forward declaration.
24 template <class PEER_HANDLER, class KEY>
25 class Peer_Router;
27 template <class PEER_HANDLER, class KEY>
28 class Acceptor_Factory : public ACE_Acceptor<PEER_HANDLER, ACE_UPIPE_ACCEPTOR>
30 public:
31 Acceptor_Factory (Peer_Router<PEER_HANDLER, KEY> *pr);
32 Peer_Router<PEER_HANDLER, KEY> *router ();
34 int init (int argc, ACE_TCHAR *argv[]);
35 // Initialize the acceptor when it's linked dynamically.
37 private:
38 Peer_Router<PEER_HANDLER, KEY> *pr_;
41 // Receive input from a Peer..
42 template <class ROUTER, class KEY>
43 class Peer_Handler : public ACE_Svc_Handler<ACE_UPIPE_STREAM, ACE_MT_SYNCH>
45 public:
46 Peer_Handler (ACE_Thread_Manager * = 0);
48 virtual int open (void * = 0);
49 // Called by the ACE_Acceptor::handle_input() to activate this object.
51 virtual int handle_input (ACE_HANDLE);
52 // Receive input from the peer..
54 virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0);
55 // Send output to a peer.
57 protected:
58 ROUTER *router_task_;
59 // Pointer to write task..
61 private:
62 // Don't need this method here...
63 virtual int svc ();
66 // This abstract base class provides mechanisms for routing messages
67 // to/from a ACE_Stream from/to one or more peers (which are typically
68 // running on remote hosts). A subclass of Peer_Router overrides the
69 // open(), close(), and put() methods in order to specialize the
70 // behavior of the router to meet application-specific requirements.
72 template <class PEER_HANDLER, class PEER_KEY>
73 class Peer_Router : public ACE_Task<ACE_MT_SYNCH>
75 public:
76 Peer_Router (ACE_Thread_Manager * = 0);
77 ~Peer_Router ();
79 typedef Peer_Handler<Peer_Router<PEER_HANDLER, PEER_KEY>, PEER_KEY> HANDLER;
81 // Remove a PEER_HANDLER from the PEER_MAP.
82 virtual int unbind_peer (PEER_KEY);
84 // Add a PEER_HANDLER to the PEER_MAP.
85 virtual int bind_peer (PEER_KEY, HANDLER *);
87 // Send the message block to the peer(s)..
88 int send_peers (ACE_Message_Block *mb);
90 protected:
91 // Handle control messages arriving from adjacent Modules.
92 virtual int control (ACE_Message_Block *);
94 // Map used to keep track of active peers.
95 ACE_Map_Manager <PEER_KEY, PEER_HANDLER *, ACE_RW_Mutex> peer_map_;
97 // Dynamic linking initialization hooks inherited from ACE_Task.
98 virtual int init (int argc, ACE_TCHAR *argv[]);
99 virtual int fini ();
101 // Factory for accepting new PEER_HANDLERs.
102 Acceptor_Factory<PEER_HANDLER, PEER_KEY> *acceptor_;
104 private:
105 Peer_Router (const Peer_Router<PEER_HANDLER, PEER_KEY> &) = delete;
106 void operator= (const Peer_Router<PEER_HANDLER, PEER_KEY> &) = delete;
109 #if defined (__ACE_INLINE__)
110 #define ACE_INLINE inline
111 #else
112 #define ACE_INLINE
113 #endif /* __ACE_INLINE__ */
115 #include "Peer_Router.cpp"
117 #endif /* ACE_HAS_THREADS */
118 #endif /* _PEER_ROUTER_H */