nx_server_plugin_sdk 1.0 Server Plugin SDK

integration.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_integration.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 Integration: public RefCountable<IIntegration>
22 {
23 public:
24 using CreateEngine = std::function<IEngine*(Integration* integration)>;
25
35 Integration(std::string integrationManifest, CreateEngine createEngine);
36
37 virtual ~Integration() override;
38
39 Ptr<IUtilityProvider> utilityProvider() const { return m_utilityProvider; }
40
44 virtual std::string instanceId() const { return ""; }
45
46 protected:
47 Integration();
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
Definition: consuming_device_agent.cpp:25
nx::sdk::analytics::Integration::instanceId
virtual std::string instanceId() const
Definition: integration.h:44
nx::sdk::analytics::Integration::doObtainEngine
virtual Result< IEngine * > doObtainEngine()
Definition: integration.cpp:39
nx::sdk::Result
Definition: result.h:52
nx::sdk::IUtilityProvider
Definition: i_utility_provider.h:189
nx::sdk::analytics::Integration::setUtilityProvider
virtual void setUtilityProvider(IUtilityProvider *utilityProvider) override
Definition: integration.cpp:47
nx::sdk::RefCountable
Definition: ref_countable.h:83
nx::sdk::analytics::Integration
Definition: integration.h:21