-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathAbstractPlugin.h
More file actions
94 lines (76 loc) · 2.31 KB
/
AbstractPlugin.h
File metadata and controls
94 lines (76 loc) · 2.31 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
#include <Corrade/PluginManager/AbstractPlugin.h>
#include <exception>
#include <nlohmann/json.hpp>
#include <string>
#include <unordered_map>
namespace visor {
using json = nlohmann::json;
class CoreRegistry;
class HttpServer;
namespace geo {
class MaxmindDB;
}
class SchemaException : public std::runtime_error
{
public:
explicit SchemaException(const std::string &msg)
: std::runtime_error(msg)
{
}
};
/**
* These are loadable plugins (static or dynamic libraries)
* Their job is to enable life cycle maintenance of AbstractModule instances
* This means they provide an interface to do so over the Admin API and through Policies
*/
class AbstractPlugin : public Corrade::PluginManager::AbstractPlugin
{
public:
typedef const std::unordered_map<std::string, std::string> SchemaMap;
private:
CoreRegistry *_registry;
/**
* Utility functions for checking json schema
*/
void check_schema(json obj, SchemaMap &required, SchemaMap &optional);
/**
* Configure Admin API routes for life cycle maintenance of AbstractModule instances
* @param svr
*/
virtual void setup_routes(HttpServer *svr) = 0;
virtual void on_init_plugin([[maybe_unused]] geo::MaxmindDB *city_db, [[maybe_unused]] geo::MaxmindDB *asn_db)
{
}
const CoreRegistry *registry() const
{
return _registry;
}
CoreRegistry *registry()
{
return _registry;
}
public:
static Corrade::Containers::Array<Corrade::Containers::String> pluginSearchPaths()
{
return {Corrade::Containers::InPlaceInit, {""}};
}
explicit AbstractPlugin(Corrade::PluginManager::AbstractManager &manager, const Corrade::Containers::StringView plugin)
: Corrade::PluginManager::AbstractPlugin{manager, plugin}
{
}
void init_plugin(CoreRegistry *mgrs, HttpServer *svr, geo::MaxmindDB *city_db, geo::MaxmindDB *asn_db)
{
_registry = mgrs;
if (svr) {
setup_routes(svr);
}
on_init_plugin(city_db, asn_db);
}
};
}