Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
IDobbyPlugin.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: IDobbyPlugins.h
21 *
22 */
23#ifndef IDOBBYPLUGIN_H
24#define IDOBBYPLUGIN_H
25
26#include "ContainerId.h"
27#include "IDobbyEnv.h"
28#include "IDobbyUtils.h"
29#include "IDobbyStartState.h"
30
31#if defined(RDK)
32# include <json/json.h>
33#else
34# include <jsoncpp/json.h>
35#endif
36
37#include <sys/types.h>
38
39#include <string>
40#include <memory>
41
42
43// -----------------------------------------------------------------------------
51{
52public:
53 virtual ~IDobbyPlugin() = default;
54
55public:
56 // -------------------------------------------------------------------------
66 virtual std::string name() const = 0;
67
68public:
69
70 // -------------------------------------------------------------------------
76 enum HintFlags : unsigned
77 {
78 PostConstructionSync = (1 << 0),
79 PreStartSync = (1 << 1),
80 PostStartSync = (1 << 2),
81 PostStopSync = (1 << 3),
82 PreDestructionSync = (1 << 4),
83
84 PostConstructionAsync = (1 << 16),
85 PreStartAsync = (1 << 17),
86 PostStartAsync = (1 << 18),
87 PostStopAsync = (1 << 19),
88 PreDestructionAsync = (1 << 20)
89 };
90
91 // -------------------------------------------------------------------------
105 virtual unsigned hookHints() const = 0;
106
107public:
108
109 // -------------------------------------------------------------------------
134 virtual bool postConstruction(const ContainerId& id,
135 const std::shared_ptr<IDobbyStartState>& startupState,
136 const std::string& rootfsPath,
137 const Json::Value& jsonData) = 0;
138
139 // -------------------------------------------------------------------------
157 virtual bool preStart(const ContainerId& id,
158 pid_t pid,
159 const std::string& rootfsPath,
160 const Json::Value& jsonData) = 0;
161
162 // -------------------------------------------------------------------------
178 virtual bool postStart(const ContainerId& id,
179 pid_t pid,
180 const std::string& rootfsPath,
181 const Json::Value& jsonData) = 0;
182
183 // -------------------------------------------------------------------------
196 virtual bool postStop(const ContainerId& id,
197 const std::string& rootfsPath,
198 const Json::Value& jsonData) = 0;
199
200 // -------------------------------------------------------------------------
216 virtual bool preDestruction(const ContainerId& id,
217 const std::string& rootfsPath,
218 const Json::Value& jsonData) = 0;
219
220};
221
222
223// -----------------------------------------------------------------------------
232#if __GNUC__ >= 4
233# define PUBLIC_FN __attribute__ ((visibility ("default")))
234#else
235# define PUBLIC_FN
236#endif
237
238
239// -----------------------------------------------------------------------------
247#define REGISTER_DOBBY_PLUGIN(_class, _args...) \
248 int PUBLIC_FN __attribute__((weak)) __ai_debug_log_level = 0; \
249 void PUBLIC_FN __attribute__((weak)) \
250 __ai_debug_log_printf(int level, const char *file, const char *func, \
251 int line, const char *fmt, ...) \
252 { } \
253 void PUBLIC_FN __attribute__((weak)) \
254 __ai_debug_log_sys_printf(int err, int level, const char *file, \
255 const char *func, int line, const char *fmt, ...) \
256 { } \
257 \
258 extern "C" PUBLIC_FN IDobbyPlugin* createIDobbyPlugin(const std::shared_ptr<IDobbyEnv>& env, \
259 const std::shared_ptr<IDobbyUtils>& utils); \
260 extern "C" PUBLIC_FN IDobbyPlugin* createIDobbyPlugin(const std::shared_ptr<IDobbyEnv>& env, \
261 const std::shared_ptr<IDobbyUtils>& utils) \
262 { \
263 return new _class(std::dynamic_pointer_cast<IDobbyEnv>(env), \
264 std::dynamic_pointer_cast<IDobbyUtils>(utils), \
265 ##_args); \
266 } \
267 extern "C" PUBLIC_FN void destroyIDobbyPlugin(_class const* _plugin); \
268 extern "C" PUBLIC_FN void destroyIDobbyPlugin(_class const* _plugin) \
269 { \
270 return delete _plugin; \
271 }
272
273
274
275#endif // !defined(IDOBBYPLUGIN_H)
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition ContainerId.h:41
Interface that plugin libraries have to implement.
Definition IDobbyPlugin.h:51
virtual bool preStart(const ContainerId &id, pid_t pid, const std::string &rootfsPath, const Json::Value &jsonData)=0
Hook function called after the container is setup, but before the init process is executed.
virtual bool postStart(const ContainerId &id, pid_t pid, const std::string &rootfsPath, const Json::Value &jsonData)=0
Hook function called after the container is started and the init process is now running.
virtual bool preDestruction(const ContainerId &id, const std::string &rootfsPath, const Json::Value &jsonData)=0
Hook function called just before the rootfs is deleted, this is called even if there was an error sta...
virtual bool postConstruction(const ContainerId &id, const std::shared_ptr< IDobbyStartState > &startupState, const std::string &rootfsPath, const Json::Value &jsonData)=0
Hook function called after the rootfs has been created, but before the container is launched.
HintFlags
Bit flags that should be returned by hookHints.
Definition IDobbyPlugin.h:77
virtual bool postStop(const ContainerId &id, const std::string &rootfsPath, const Json::Value &jsonData)=0
Hook function called after the container has stopped.
virtual unsigned hookHints() const =0
Should return a bitfield of the hook points implemented by the plugin.
virtual std::string name() const =0
Should return the name of the plugin, this is used to match against the json spec file used to create...