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 <string>
6 #include <functional>
7
8 #include <nx/sdk/i_utility_provider.h>
9 #include <nx/sdk/analytics/i_plugin.h>
10 #include <nx/sdk/helpers/ref_countable.h>
11 #include <nx/sdk/ptr.h>
12
13 #include "engine.h"
14
15 namespace nx {
16 namespace sdk {
17 namespace analytics {
18
23 class Plugin: public RefCountable<IPlugin>
24 {
25 public:
26 using CreateEngine = std::function<IEngine*(Plugin* plugin)>;
27
37 Plugin(std::string pluginManifest, CreateEngine createEngine);
38
39 virtual ~Plugin() override;
40
41 Ptr<IUtilityProvider> utilityProvider() const { return m_utilityProvider; }
42
46 virtual std::string instanceId() const { return ""; }
47
48 protected:
49 Plugin();
50
54 virtual Result<IEngine*> doObtainEngine();
55
56 virtual std::string manifestString() const;
57
58 //-------------------------------------------------------------------------------------------------
59 // Not intended to be used by a descendant.
60
61 public:
62 virtual void setUtilityProvider(IUtilityProvider* utilityProvider) override;
63
64 protected:
65 virtual void getManifest(Result<const IString*>* outResult) const override;
66 virtual void doCreateEngine(Result<IEngine*>* outResult) override;
67
68 private:
69 void logLifeCycleEvent(const std::string& event) const;
70
71 void logCreation() const { logLifeCycleEvent("Created"); }
72 void logDestruction() const { logLifeCycleEvent("Destroyed"); }
73
74 void logError(const std::string& message) const;
75
76 private:
77 const std::string m_jsonManifest;
78
79 CreateEngine m_createEngineFunc;
80 Ptr<IUtilityProvider> m_utilityProvider;
81 };
82
83 } // namespace analytics
84 } // namespace sdk
85 } // namespace nx
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::Plugin::setUtilityProvider
virtual void setUtilityProvider(IUtilityProvider *utilityProvider) override
Definition: plugin.cpp:49
nx::sdk::analytics::Plugin::instanceId
virtual std::string instanceId() const
Definition: plugin.h:46
nx::sdk::analytics::Plugin::doObtainEngine
virtual Result< IEngine * > doObtainEngine()
Definition: plugin.cpp:41
nx::sdk::Result
Definition: result.h:47
nx::sdk::IUtilityProvider
Definition: i_utility_provider.h:61
nx
Definition: apple_utils.h:6
nx::sdk::RefCountable
Definition: ref_countable.h:84
nx::sdk::analytics::Plugin
Definition: plugin.h:23