Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyLegacyPluginManager.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: DobbyLegacyPluginManager.h
21 *
22 */
23#ifndef DOBBYLEGACYPLUGINMANAGER_H
24#define DOBBYLEGACYPLUGINMANAGER_H
25
26#include "IDobbyUtils.h"
27#include "ContainerId.h"
28
29#if defined(RDK)
30# include <json/json.h>
31#else
32# include <jsoncpp/json.h>
33#endif
34
35#include <pthread.h>
36#include <sys/types.h>
37
38#include <map>
39#include <string>
40#include <memory>
41#include <future>
42
43#if defined(RDK)
44# define DEFAULT_PLUGIN_PATH "/usr/lib/plugins/dobby"
45#else
46# define DEFAULT_PLUGIN_PATH "/opt/libexec"
47#endif
48
49class IDobbyPlugin;
51class IDobbyEnv;
52
53// -----------------------------------------------------------------------------
65{
66public:
67 DobbyLegacyPluginManager(const std::shared_ptr<IDobbyEnv>& env,
68 const std::shared_ptr<IDobbyUtils>& utils,
69 const std::string& path = std::string(DEFAULT_PLUGIN_PATH));
71
72public:
73 void refreshPlugins(const std::string& path = std::string(DEFAULT_PLUGIN_PATH));
74
75public:
76 bool executePostConstructionHooks(const std::map<std::string, Json::Value>& plugins,
77 const ContainerId& id,
78 const std::shared_ptr<IDobbyStartState>& startupState,
79 const std::string& rootfsPath) const;
80
81 bool executePreStartHooks(const std::map<std::string, Json::Value>& plugins,
82 const ContainerId& id,
83 pid_t pid,
84 const std::string& rootfsPath) const;
85
86 bool executePostStartHooks(const std::map<std::string, Json::Value>& plugins,
87 const ContainerId& id,
88 pid_t pid,
89 const std::string& rootfsPath) const;
90
91 bool executePostStopHooks(const std::map<std::string, Json::Value>& plugins,
92 const ContainerId& id,
93 const std::string& rootfsPath) const;
94
95 bool executePreDestructionHooks(const std::map<std::string, Json::Value>& plugins,
96 const ContainerId& id,
97 const std::string& rootfsPath) const;
98
99private:
100 typedef std::function<bool (IDobbyPlugin*, const Json::Value&)> HookFn;
101
102 bool executeHooks(const std::map<std::string, Json::Value>& plugins,
103 const HookFn& hookFn,
104 unsigned asyncFlag,
105 unsigned syncFlag) const;
106
107
108private:
109 inline std::shared_ptr<IDobbyPlugin> getPlugin(const std::string& name) const;
110 void loadPlugins(const std::string& path);
111
112private:
113 mutable pthread_rwlock_t mRwLock;
114 const std::shared_ptr<IDobbyEnv> mEnvironment;
115 const std::shared_ptr<IDobbyUtils> mUtilities;
116 std::map<std::string, std::pair<void*, std::shared_ptr<IDobbyPlugin>>> mPlugins;
117
118};
119
120
121#endif // !defined(DOBBYLEGACYPLUGINMANAGER_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
Class that manages all the plugin hook libraries.
Definition DobbyLegacyPluginManager.h:65
bool executePreStartHooks(const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const
Calls the preStart method for the given plugins.
Definition DobbyLegacyPluginManager.cpp:424
bool executePreDestructionHooks(const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const
Calls the preDestruction method for the given plugins.
Definition DobbyLegacyPluginManager.cpp:529
bool executeHooks(const std::map< std::string, Json::Value > &plugins, const HookFn &hookFn, unsigned asyncFlag, unsigned syncFlag) const
Calls the supplied hook function for the plugins in the list.
Definition DobbyLegacyPluginManager.cpp:296
bool executePostConstructionHooks(const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::shared_ptr< IDobbyStartState > &startupState, const std::string &rootfsPath) const
Calls the postConstruction method for the given plugins.
Definition DobbyLegacyPluginManager.cpp:388
void refreshPlugins(const std::string &path=std::string(DEFAULT_PLUGIN_PATH))
(re)loads all the plugin libraries found at the given path
Definition DobbyLegacyPluginManager.cpp:234
bool executePostStartHooks(const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const
Calls the postStart method for the given plugins.
Definition DobbyLegacyPluginManager.cpp:460
void loadPlugins(const std::string &path)
Scans the given path for any shared objects that implement the plugin entry points.
Definition DobbyLegacyPluginManager.cpp:101
bool executePostStopHooks(const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const
Calls the postStop method for the given plugins.
Definition DobbyLegacyPluginManager.cpp:495
std::shared_ptr< IDobbyPlugin > getPlugin(const std::string &name) const
Get the plugin with the name, or nullptr if no plugin.
Definition DobbyLegacyPluginManager.cpp:251
Interface that exports the environment of the daemon to plugins.
Definition IDobbyEnv.h:46
Interface that plugin libraries have to implement.
Definition IDobbyPlugin.h:51
Utility interface passed in at the post-construction phase, to allow some final tweaking of the conta...
Definition IDobbyStartState.h:40