summaryrefslogtreecommitdiff
path: root/ACE/ace/Service_Manager.h
blob: 6573c8588e699c634369b44bd13c936b8764421d (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Service_Manager.h
 *
 *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
 */
//=============================================================================

#ifndef ACE_SERVICE_MANAGER_H
#define ACE_SERVICE_MANAGER_H
#include /**/ "ace/pre.h"

#include "ace/SOCK_Stream.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/SOCK_Acceptor.h"
#include "ace/INET_Addr.h"
#include "ace/Service_Object.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Service_Manager
 *
 * @brief Provide a standard ACE service for managing all the services
 * configured in an ACE_Service_Repository.
 *
 * This implementation is simple and just handles each client
 * request one at a time.  There are currently 3 types of requests:
 * - List services: If the string "help" is sent, return a list of all
 *   the services supported by the Service Configurator.
 * - Reconfigure: If the string "reconfigure" is sent trigger a
 *   reconfiguration, which will re-read the local <svc.conf> file.
 * - Process directive: If neither "help" nor "reconfigure" is sent,
 *   simply treat the incoming string as a process directive and pass
 *   it along to <ACE_Service_Config::process_directive>.  This allows
 *   remote configuration via command-line instructions like
 *   % echo suspend My_Remote_Service | telnet hostname 3911
 *
 * Each request is associated with a new connection, which is closed
 * when the request is processed.  In addition, you must be using the
 * singleton <ACE_Reactor::instance> in order to trigger
 * reconfigurations.
 */
class ACE_Export ACE_Service_Manager : public ACE_Service_Object
{
public:
  // = Initialization and termination hooks.
  /// Constructor.
  ACE_Service_Manager (void);

  /// Destructor.
  virtual ~ACE_Service_Manager (void);

protected:
  // = Perform the various meta-services.

  /// Trigger a reconfiguration of the Service Configurator by
  /// re-reading its local <svc.conf> file.
  virtual int reconfigure_services (void);

  /// Determine all the services offered by this daemon and return the
  /// information back to the client.
  virtual int list_services (void);

  // = Dynamic linking hooks.
  virtual int init (int argc, ACE_TCHAR *argv[]);
  virtual int info (ACE_TCHAR **info_string, size_t length) const;
  virtual int fini (void);

  // = Scheduling hooks.
  virtual int suspend (void);
  virtual int resume (void);

  /// Dump the state of an object.
  void dump (void) const;

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

protected:
  int open (const ACE_INET_Addr &sia);

  // = Demultiplexing hooks.
  virtual ACE_HANDLE get_handle (void) const;
  virtual int handle_input (ACE_HANDLE fd);
  virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask);
  virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);

  /// Handle one request.
  virtual void process_request (ACE_TCHAR *request);

  /// Connection to the client (we only support one client connection
  /// at a time).
  ACE_SOCK_Stream client_stream_;

  /// Acceptor instance.
  ACE_SOCK_Acceptor acceptor_;

  /// Keep track whether we debug or not.
  bool debug_;

  /// The signal used to trigger reconfiguration.
  int signum_;

  /// Default port for the Acceptor to listen on.
  static u_short DEFAULT_PORT_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"
#endif /* _SERVICE_MANAGER_H */