Kea  1.9.9-git
server_hooks.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef SERVER_HOOKS_H
8 #define SERVER_HOOKS_H
9 
10 #include <exceptions/exceptions.h>
11 #include <hooks/parking_lots.h>
12 
13 #include <boost/noncopyable.hpp>
14 #include <boost/shared_ptr.hpp>
15 
16 #include <map>
17 #include <string>
18 #include <vector>
19 
20 namespace isc {
21 namespace hooks {
22 
27 class DuplicateHook : public Exception {
28 public:
29  DuplicateHook(const char* file, size_t line, const char* what) :
30  isc::Exception(file, line, what) {}
31 };
32 
36 class NoSuchHook : public Exception {
37 public:
38  NoSuchHook(const char* file, size_t line, const char* what) :
39  isc::Exception(file, line, what) {}
40 };
41 
43 typedef boost::shared_ptr<ServerHooks> ServerHooksPtr;
44 
61 
62 class ServerHooks : public boost::noncopyable {
63 public:
64 
66  static const int CONTEXT_CREATE = 0;
67  static const int CONTEXT_DESTROY = 1;
68 
78  void reset();
79 
92  int registerHook(const std::string& name);
93 
104  std::string getName(int index) const;
105 
115  int getIndex(const std::string& name) const;
116 
126  int findIndex(const std::string& name) const;
127 
133  int getCount() const {
134  return (hooks_.size());
135  }
136 
142  std::vector<std::string> getHookNames() const;
143 
149  static ServerHooks& getServerHooks();
150 
154  static ServerHooksPtr getServerHooksPtr();
155 
160 
166  ParkingLotPtr getParkingLotPtr(const int hook_index);
167 
173  ParkingLotPtr getParkingLotPtr(const std::string& hook_name);
174 
193  static std::string commandToHookName(const std::string& command_name);
194 
203  static std::string hookToCommandName(const std::string& hook_name);
204 
205 private:
219  ServerHooks();
220 
229  void initialize();
230 
232  typedef std::map<std::string, int> HookCollection;
233  typedef std::map<int, std::string> InverseHookCollection;
234 
237  HookCollection hooks_;
238  InverseHookCollection inverse_hooks_;
239 
240  ParkingLotsPtr parking_lots_;
241 };
242 
243 } // namespace util
244 } // namespace isc
245 
246 #endif // SERVER_HOOKS_H
void reset()
Reset to Initial State.
static const int CONTEXT_CREATE
Index numbers for pre-defined hooks.
Definition: server_hooks.h:66
Duplicate hook.
Definition: server_hooks.h:27
ParkingLotPtr getParkingLotPtr(const int hook_index)
Returns pointer to the ParkingLot for the specified hook index.
boost::shared_ptr< ParkingLot > ParkingLotPtr
Type of the pointer to the parking lot.
Definition: parking_lots.h:288
static ServerHooks & getServerHooks()
Return ServerHooks object.
int getCount() const
Return number of hooks.
Definition: server_hooks.h:133
int getIndex(const std::string &name) const
Get hook index.
boost::shared_ptr< ServerHooks > ServerHooksPtr
Definition: server_hooks.h:42
DuplicateHook(const char *file, size_t line, const char *what)
Definition: server_hooks.h:29
std::string getName(int index) const
Get hook name.
static ServerHooksPtr getServerHooksPtr()
Returns pointer to ServerHooks object.
static const int CONTEXT_DESTROY
Definition: server_hooks.h:67
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
boost::shared_ptr< ParkingLots > ParkingLotsPtr
Type of the pointer to the parking lots.
Definition: parking_lots.h:415
Defines the logger used by the top-level component of kea-dhcp-ddns.
Invalid hook.
Definition: server_hooks.h:36
static std::string commandToHookName(const std::string &command_name)
Generates hook point name for the given control command name.
ParkingLotsPtr getParkingLotsPtr() const
Returns pointer to all parking lots.
NoSuchHook(const char *file, size_t line, const char *what)
Definition: server_hooks.h:38
int findIndex(const std::string &name) const
Find hook index.
static std::string hookToCommandName(const std::string &hook_name)
Returns command name for a specified hook name.
Server hook collection.
Definition: server_hooks.h:62
int registerHook(const std::string &name)
Register a hook.
Definition: server_hooks.cc:44
std::vector< std::string > getHookNames() const
Get hook names.