Repository navigation
Expand file tree
/
Copy pathIDobbyRdkPlugin.h
More file actions
175 lines (155 loc) · 6.49 KB
/
Copy pathIDobbyRdkPlugin.h
File metadata and controls
175 lines (155 loc) · 6.49 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 Sky UK
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* File: IDobbyRdkPlugin.h
*
*/
#ifndef IDobbyRdkPlugin_H
#define IDobbyRdkPlugin_H
#include "DobbyRdkPluginUtils.h"
#include "rt_dobby_schema.h"
#if defined(DOBBY_BUILD)
#include <Logging.h>
#else
#include <Dobby/Logging.h>
#endif
#include <sys/types.h>
#include <memory>
#include <string>
#include <vector>
// -----------------------------------------------------------------------------
/**
* @class IDobbyRdkPlugin
* @brief Interface that plugin libraries have to implement.
*
*
*/
class IDobbyRdkPlugin
{
public:
virtual ~IDobbyRdkPlugin() = default;
public:
// -------------------------------------------------------------------------
/**
* @brief Should return the name of the plugin
*
* @return string with the name of the hook.
*/
virtual std::string name() const = 0;
public:
// -------------------------------------------------------------------------
/**
* @brief Bit flags that should be returned by hookHints.
*
* The flags are fairly self explanatory.
*/
enum HintFlags : unsigned
{
PostInstallationFlag = (1 << 0),
PreCreationFlag = (1 << 1),
CreateRuntimeFlag = (1 << 2),
CreateContainerFlag = (1 << 3),
#ifdef USE_STARTCONTAINER_HOOK
StartContainerFlag = (1 << 4),
#endif
PostStartFlag = (1 << 5),
PostHaltFlag = (1 << 6),
PostStopFlag = (1 << 7),
Unknown = 0
};
// -------------------------------------------------------------------------
/**
* @brief Should return a bitfield of the hook points implemented by the
* plugin.
*
* Only bits that are set will be called as hooks. This is to optimise
* the implementation of the hook code to ensure we don't waste time
* trying to run hooks that don't do anything
*
* The value returned should be constant for the lifetime of the class
*
* @return bitmask of the HintFlags bits.
*/
virtual unsigned hookHints() const = 0;
public:
// Dobby hook
virtual bool postInstallation() = 0;
// Dobby hook
virtual bool preCreation() = 0;
// OCI Hook
virtual bool createRuntime() = 0;
// OCI Hook
virtual bool createContainer() = 0;
#ifdef USE_STARTCONTAINER_HOOK
// OCI Hook
virtual bool startContainer() = 0;
#endif
// OCI Hook
virtual bool postStart() = 0;
// Dobby hook
virtual bool postHalt() = 0;
// OCI Hook (called after delete)
virtual bool postStop() = 0;
public:
/**
* @brief Should return the names of the plugins this plugin depends on.
*
* This can be used to determine the order in which the plugins should be
* processed when running hooks.
*
* @return Names of the plugins this plugin depends on.
*/
virtual std::vector<std::string> getDependencies() const = 0;
};
// -----------------------------------------------------------------------------
/**
* @define PUBLIC_FN
* @brief Macro for setting the visibility on the symbols
*
* See https://gcc.gnu.org/wiki/Visibility for details on why this is a good
* idea.
*
*/
#if __GNUC__ >= 4
#define PUBLIC_FN __attribute__((visibility("default")))
#else
#define PUBLIC_FN
#endif
// -----------------------------------------------------------------------------
/**
* @define REGISTER_RDK_PLUGIN
* @brief Macro for plugins to use to register themselves
*
* Plugin manager searches for libraries that implement these C methods
* so without calling this macro the plugin will not be loaded. Need to be
* C methods to work around c++ name-mangling
*
*/
#define REGISTER_RDK_PLUGIN(_class) \
extern "C" PUBLIC_FN IDobbyRdkPlugin *createIDobbyRdkPlugin(std::shared_ptr<rt_dobby_schema>& containerConfig, const std::shared_ptr<DobbyRdkPluginUtils> &utils, const std::string& rootfsPath); \
extern "C" PUBLIC_FN IDobbyRdkPlugin *createIDobbyRdkPlugin(std::shared_ptr<rt_dobby_schema>& containerConfig, const std::shared_ptr<DobbyRdkPluginUtils> &utils, const std::string& rootfsPath) \
{ \
return new _class(containerConfig, utils, rootfsPath); \
} \
extern "C" PUBLIC_FN void destroyIDobbyRdkPlugin(_class const *_plugin); \
extern "C" PUBLIC_FN void destroyIDobbyRdkPlugin(_class const *_plugin) \
{ \
return delete _plugin; \
}
#endif // !defined(IDobbyRdkPlugin_H)