nx_metadata_sdk 1.0 Metadata SDK

plugin.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <functional>
6 #include <string>
7
8 #include <nx/sdk/analytics/i_plugin.h>
9 #include <nx/sdk/helpers/ref_countable.h>
10 #include <nx/sdk/i_utility_provider.h>
11 #include <nx/sdk/ptr.h>
12
13 #include "engine.h"
14
15 namespace nx::sdk::analytics {
16
21 class Plugin: public RefCountable<IPlugin>
22 {
23 public:
24 using CreateEngine = std::function<IEngine*(Plugin* plugin)>;
25
35 Plugin(std::string pluginManifest, CreateEngine createEngine);
36
37 virtual ~Plugin() override;
38
39 Ptr<IUtilityProvider> utilityProvider() const { return m_utilityProvider; }
40
44 virtual std::string instanceId() const { return ""; }
45
46 protected:
47 Plugin();
48
52 virtual Result<IEngine*> doObtainEngine();
53
54 virtual std::string manifestString() const;
55
56 //-------------------------------------------------------------------------------------------------
57 // Not intended to be used by a descendant.
58
59 public:
60 virtual void setUtilityProvider(IUtilityProvider* utilityProvider) override;
61
62 protected:
63 virtual void getManifest(Result<const IString*>* outResult) const override;
64 virtual void doCreateEngine(Result<IEngine*>* outResult) override;
65
66 private:
67 void logLifeCycleEvent(const std::string& event) const;
68
69 void logCreation() const { logLifeCycleEvent("Created"); }
70 void logDestruction() const { logLifeCycleEvent("Destroyed"); }
71
72 void logError(const std::string& message) const;
73
74 private:
75 const std::string m_jsonManifest;
76
77 CreateEngine m_createEngineFunc;
78 Ptr<IUtilityProvider> m_utilityProvider;
79 };
80
81 } // namespace nx::sdk::analytics
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::Plugin::setUtilityProvider
virtual void setUtilityProvider(IUtilityProvider *utilityProvider) override
Definition: plugin.cpp:47
nx::sdk::analytics::Plugin::instanceId
virtual std::string instanceId() const
Definition: plugin.h:44
nx::sdk::analytics
Definition: consuming_device_agent.cpp:24
nx::sdk::analytics::Plugin::doObtainEngine
virtual Result< IEngine * > doObtainEngine()
Definition: plugin.cpp:39
nx::sdk::Result
Definition: result.h:48
nx::sdk::IUtilityProvider
Definition: i_utility_provider.h:78
nx::sdk::RefCountable
Definition: ref_countable.h:83
nx::sdk::analytics::Plugin
Definition: plugin.h:21