summaryrefslogtreecommitdiff
path: root/examples/Connection/non_blocking/CPP-connector.h
blob: 81be8b6ba717615cf5f7ac955779f0cf17a71699 (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
/* -*- C++ -*- */
// $Id$

#if !defined (CPP_CONNECTOR_H)
#define CPP_CONNECTOR_H

#include "ace/Service_Config.h"
#include "ace/Connector.h"

template <ACE_PEER_STREAM_1>
class Peer_Handler : public ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_SYNCH>
{
public:
  Peer_Handler (ACE_Reactor *r);

  virtual int open (void * = 0);
  // Activate the handler when connection is established.

  // = Demultiplexing hooks.
  virtual int handle_output (ACE_HANDLE);
  virtual int handle_input (ACE_HANDLE);
  virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask mask);

  virtual ACE_HANDLE get_handle (void) const;

protected:
  // = These methods implement the State pattern.
  int idle (void);
  int connected (void);
  int disconnecting (void);
  int stdio (void);

  int (Peer_Handler<ACE_PEER_STREAM_2>::*action_) (void);
  // Keeps track of which state we are in.

private:
};

template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1>
class IPC_Client : public ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>
{
public:
  // = Initialization and termination methods.
  IPC_Client (void);
  ~IPC_Client (void);

  // = Dynamic linking hooks.
  virtual int init (int argc, char *argv[]);
  // Initialize the IPC client.

  virtual int fini (void);
  // Destroy the IPC client.

  virtual int svc (void);
  // Run the svc.
  
  virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
  // Report connection errors.

private:
  typedef ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2> inherited;

  ACE_Synch_Options options_;
  // Options for the active connection factory.

  ACE_Sig_Adapter done_handler_;
  // Keeps track of when we shut down due to receipt of the SIGINT
  // signal.
};

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "CPP-connector.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#endif /* CPP_CONNECTOR_H */