Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
IDobbyRdkPlugin.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 2020 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: IDobbyRdkPlugin.h
21  *
22  */
23 #ifndef IDobbyRdkPlugin_H
24 #define IDobbyRdkPlugin_H
25 
26 #include "DobbyRdkPluginUtils.h"
27 #include "rt_dobby_schema.h"
28 
29 #if defined(DOBBY_BUILD)
30 #include <Logging.h>
31 #else
32 #include <Dobby/Logging.h>
33 #endif
34 
35 #include <sys/types.h>
36 
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 // -----------------------------------------------------------------------------
49 {
50 public:
51  virtual ~IDobbyRdkPlugin() = default;
52 
53 public:
54  // -------------------------------------------------------------------------
60  virtual std::string name() const = 0;
61 
62 public:
63  // -------------------------------------------------------------------------
69  enum HintFlags : unsigned
70  {
71  PostInstallationFlag = (1 << 0),
72  PreCreationFlag = (1 << 1),
73  CreateRuntimeFlag = (1 << 2),
74  CreateContainerFlag = (1 << 3),
75 #ifdef USE_STARTCONTAINER_HOOK
76  StartContainerFlag = (1 << 4),
77 #endif
78  PostStartFlag = (1 << 5),
79  PostHaltFlag = (1 << 6),
80  PostStopFlag = (1 << 7),
81  Unknown = 0
82  };
83 
84  // -------------------------------------------------------------------------
97  virtual unsigned hookHints() const = 0;
98 
99 public:
100  // Dobby hook
101  virtual bool postInstallation() = 0;
102 
103  // Dobby hook
104  virtual bool preCreation() = 0;
105 
106  // OCI Hook
107  virtual bool createRuntime() = 0;
108 
109  // OCI Hook
110  virtual bool createContainer() = 0;
111 
112 #ifdef USE_STARTCONTAINER_HOOK
113  // OCI Hook
114  virtual bool startContainer() = 0;
115 #endif
116 
117  // OCI Hook
118  virtual bool postStart() = 0;
119 
120  // Dobby hook
121  virtual bool postHalt() = 0;
122 
123  // OCI Hook (called after delete)
124  virtual bool postStop() = 0;
125 
126 public:
135  virtual std::vector<std::string> getDependencies() const = 0;
136 };
137 
138 // -----------------------------------------------------------------------------
147 #if __GNUC__ >= 4
148 #define PUBLIC_FN __attribute__((visibility("default")))
149 #else
150 #define PUBLIC_FN
151 #endif
152 
153 // -----------------------------------------------------------------------------
163 #define REGISTER_RDK_PLUGIN(_class) \
164  extern "C" PUBLIC_FN IDobbyRdkPlugin *createIDobbyRdkPlugin(std::shared_ptr<rt_dobby_schema>& containerConfig, const std::shared_ptr<DobbyRdkPluginUtils> &utils, const std::string& rootfsPath); \
165  extern "C" PUBLIC_FN IDobbyRdkPlugin *createIDobbyRdkPlugin(std::shared_ptr<rt_dobby_schema>& containerConfig, const std::shared_ptr<DobbyRdkPluginUtils> &utils, const std::string& rootfsPath) \
166 { \
167  return new _class(containerConfig, utils, rootfsPath); \
168  } \
169  extern "C" PUBLIC_FN void destroyIDobbyRdkPlugin(_class const *_plugin); \
170  extern "C" PUBLIC_FN void destroyIDobbyRdkPlugin(_class const *_plugin) \
171  { \
172  return delete _plugin; \
173  }
174 
175 #endif // !defined(IDobbyRdkPlugin_H)
Interface that plugin libraries have to implement.
Definition: IDobbyRdkPlugin.h:49
HintFlags
Bit flags that should be returned by hookHints.
Definition: IDobbyRdkPlugin.h:70
virtual std::string name() const =0
Should return the name of the plugin.
virtual std::vector< std::string > getDependencies() const =0
Should return the names of the plugins this plugin depends on.
virtual unsigned hookHints() const =0
Should return a bitfield of the hook points implemented by the plugin.