summaryrefslogtreecommitdiffstats
path: root/src/lib/hooks/callout_handle_associate.h
blob: c222590f31d1c3c7f53e542fe273a5fc2d40b7a9 (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
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef CALLOUT_HANDLE_ASSOCIATE_H
#define CALLOUT_HANDLE_ASSOCIATE_H

#include <hooks/callout_handle.h>

namespace isc {
namespace hooks {

/// @brief Base class for classes which need to be associated with
/// a @c CalloutHandle object.
///
/// The @c CalloutHandle is an object used to pass various parameters
/// between Kea and the callouts. The Kea servers usually invoke
/// multiple different callouts for a single packet such as DHCP
/// packet, control command etc. Therefore, it is required to
/// associate this packet with an instance of the callout handle, so
/// this instance can be used for all callouts invoked for this
/// packet.
///
/// Previously this association was made by the @c CalloutHandleStore
/// class. However, with the introduction of parallel processing
/// of packets (DHCP packets parking) it became awkward to use.
/// Attempts to extend this class to hold a map of associations
/// failed because of no easy way to garbage collect unused handles.
///
/// The easiest way to deal with this is to provide ownership of the
/// @c CalloutHandle to the object with which it is associated. The
/// class of this object needs to derive from this class. When the
/// object (e.g. DHCP packet) goes out of scope and is destroyed
/// this instance is destroyed as well.
class CalloutHandleAssociate {
public:

    /// @brief Constructor.
    CalloutHandleAssociate();

    /// @brief Returns callout handle.
    ///
    /// The callout handle is created if it doesn't exist. Subsequent
    /// calls to this method always return the same handle.
    ///
    /// @return Pointer to the callout handle.
    CalloutHandlePtr getCalloutHandle();

    /// @brief Reset callout handle.
    void resetCalloutHandle();

protected:

    /// @brief Callout handle stored.
    CalloutHandlePtr callout_handle_;
};

} // end of isc::hooks
} // end of isc

#endif