Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DobbyRdkPluginManager.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: DobbyRdkPluginManager.h
21  *
22  */
23 #ifndef DOBBYRDKPLUGINMANAGER_H
24 #define DOBBYRDKPLUGINMANAGER_H
25 
26 #include "IDobbyRdkPlugin.h"
27 #include "IDobbyRdkLoggingPlugin.h"
28 
29 #include <sys/types.h>
30 #include <map>
31 #include <string>
32 #include <memory>
33 #include <set>
34 #include <vector>
35 #include <algorithm>
36 
38 
39 // -----------------------------------------------------------------------------
48 {
49 public:
50  DobbyRdkPluginManager(std::shared_ptr<rt_dobby_schema> containerConfig,
51  const std::string &rootfsPath,
52  const std::string &pluginPath,
53  const std::shared_ptr<DobbyRdkPluginUtils> &utils);
55 
56 public:
57  const std::vector<std::string> listLoadedPlugins() const;
58  const std::vector<std::string> listLoadedLoggers() const;
59  bool runPlugins(const IDobbyRdkPlugin::HintFlags &hookPoint,
60  const uint timeoutMs = 0) const;
61 
62  // This is public as RDKPluginManager isn't responsible for handling logging
63  std::shared_ptr<IDobbyRdkLoggingPlugin> getContainerLogger() const;
64  void setExitStatus(int status) const;
65 
66  std::shared_ptr<rt_dobby_schema> getContainerConfig() const
67  {
68  return mContainerConfig;
69  };
70 
71 private:
72  bool loadPlugins();
73  bool preprocessPlugins();
74  bool executeHook(const std::string &pluginName,
75  const IDobbyRdkPlugin::HintFlags hook) const;
76  bool executeHookTimeout(const std::string &pluginName,
77  const IDobbyRdkPlugin::HintFlags hook,
78  const uint timeoutMs) const;
79  std::string HookPointToString(const IDobbyRdkPlugin::HintFlags &hookPoint) const;
80 
81  bool implementsHook(const std::string &pluginName,
82  const IDobbyRdkPlugin::HintFlags hook) const;
83  bool isLoaded(const std::string &pluginName) const;
84  bool isRequired(const std::string &pluginName) const;
85  inline std::shared_ptr<IDobbyRdkPlugin> getPlugin(const std::string &name) const;
86  inline std::shared_ptr<IDobbyRdkLoggingPlugin> getLogger(const std::string &name) const;
87 
88 private:
89  bool mValid;
90  std::map<std::string, std::pair<void *, std::shared_ptr<IDobbyRdkLoggingPlugin>>> mLoggers;
91  std::map<std::string, std::pair<void *, std::shared_ptr<IDobbyRdkPlugin>>> mPlugins;
92  std::set<std::string> mRequiredPlugins;
93  std::shared_ptr<rt_dobby_schema> mContainerConfig;
94  const std::string mRootfsPath;
95  const std::string mPluginPath;
96  const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
97  std::unique_ptr<DobbyRdkPluginDependencySolver> mDependencySolver;
98 };
99 
100 #endif // !defined(DOBBYRDKPLUGINMANAGER_H)
Class that tracks dependencies between plugins.
Definition: DobbyRdkPluginDependencySolver.h:40
Class that manages all the RDK plugin hook libraries.
Definition: DobbyRdkPluginManager.h:48
bool executeHookTimeout(const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook, const uint timeoutMs) const
Definition: DobbyRdkPluginManager.cpp:687
std::shared_ptr< IDobbyRdkPlugin > getPlugin(const std::string &name) const
Get the plugin with the name, or nullptr if no plugin.
Definition: DobbyRdkPluginManager.cpp:521
~DobbyRdkPluginManager()
Definition: DobbyRdkPluginManager.cpp:74
bool runPlugins(const IDobbyRdkPlugin::HintFlags &hookPoint, const uint timeoutMs=0) const
Run the plugins specified in the container config at the given hook point. Returns true if all requir...
Definition: DobbyRdkPluginManager.cpp:853
std::string HookPointToString(const IDobbyRdkPlugin::HintFlags &hookPoint) const
Definition: DobbyRdkPluginManager.cpp:802
bool implementsHook(const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook) const
Check if a plugin implements the specified hook.
Definition: DobbyRdkPluginManager.cpp:605
std::shared_ptr< IDobbyRdkLoggingPlugin > getContainerLogger() const
Get the logging plugin specified in the container config. Each container can only have a single plugi...
Definition: DobbyRdkPluginManager.cpp:458
bool isLoaded(const std::string &pluginName) const
Check if a plugin is loaded.
Definition: DobbyRdkPluginManager.cpp:579
DobbyRdkPluginManager(std::shared_ptr< rt_dobby_schema > containerConfig, const std::string &rootfsPath, const std::string &pluginPath, const std::shared_ptr< DobbyRdkPluginUtils > &utils)
Create instance of DobbyRdkPlugin Manager and load all plugins that can be found in pluginPath.
Definition: DobbyRdkPluginManager.cpp:53
bool preprocessPlugins()
Prepares the dependency solver and required plugins data structures.
Definition: DobbyRdkPluginManager.cpp:358
const std::vector< std::string > listLoadedPlugins() const
Just return a list of all loaded plugin names.
Definition: DobbyRdkPluginManager.cpp:561
bool executeHook(const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook) const
Definition: DobbyRdkPluginManager.cpp:633
bool isRequired(const std::string &pluginName) const
Check if a plugin is required.
Definition: DobbyRdkPluginManager.cpp:591
std::shared_ptr< IDobbyRdkLoggingPlugin > getLogger(const std::string &name) const
Get the logger with the name, or nullptr if no plugin.
Definition: DobbyRdkPluginManager.cpp:429
void setExitStatus(int status) const
Set the exit status of the container.
Definition: DobbyRdkPluginManager.cpp:508
bool loadPlugins()
Scans the given path for any shared objects that implement the plugin entry points.
Definition: DobbyRdkPluginManager.cpp:152
const std::vector< std::string > listLoadedLoggers() const
Just return a list of all loaded logging plugin names.
Definition: DobbyRdkPluginManager.cpp:544
HintFlags
Bit flags that should be returned by hookHints.
Definition: IDobbyRdkPlugin.h:70