nx_server_plugin_sdk 1.0 Server Plugin SDK

axis_relayio_manager.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 <list>
6 #include <map>
7 #include <set>
8
9 #include <QtCore/QAtomicInt>
10 #include <QtCore/QMutex>
11 #include <QtCore/QObject>
12 #include <QtCore/QWaitCondition>
13 #include <QtNetwork/QNetworkReply>
14
15 #include <camera/camera_plugin.h>
16 #include <plugins/plugin_tools.h>
17
18 class AxisCameraManager;
19
21
25 class AxisRelayIOManager
26 :
27 public QObject,
28 public nxcip::CameraRelayIOManager
29 {
30 Q_OBJECT
31
32 public:
36 AxisRelayIOManager(
37 AxisCameraManager* cameraManager,
38 unsigned int inputPortCount,
39 unsigned int outputPortCount );
40 virtual ~AxisRelayIOManager();
41
43 virtual void* queryInterface( const nxpl::NX_GUID& interfaceID ) override;
45 virtual int addRef() const override;
47 virtual int releaseRef() const override;
48
50 virtual int getRelayOutputList( char** idList, int* idNum ) const override;
52 virtual int getInputPortList( char** idList, int* idNum ) const override;
54 virtual int setRelayOutputState(
55 const char* outputID,
56 int activate,
57 unsigned int autoResetTimeoutMS ) override;
59 virtual int startInputPortMonitoring() override;
61 virtual void stopInputPortMonitoring() override;
63 virtual void registerEventHandler( nxcip::CameraInputEventHandler* handler ) override;
65 virtual void unregisterEventHandler( nxcip::CameraInputEventHandler* handler ) override;
67 virtual void getLastErrorString( char* errorString ) const override;
68
69 private:
70 using PortMonitoringSlotPtr = void(AxisRelayIOManager::*)(int);
71
72 struct AsyncCallContext
73 {
74 AsyncCallContext()
75 :
76 done( false ),
77 resultCode( 0 )
78 {
79 }
80
81 bool done;
82 int resultCode;
83 };
84
85 enum MultipartedParsingState
86 {
87 waitingDelimiter,
88 readingHeaders,
89 readingData
90 };
91
92 nxpt::CommonRefManager m_refManager;
93 AxisCameraManager* m_cameraManager;
94 unsigned int m_inputPortCount;
95 unsigned int m_outputPortCount;
96 std::map<QString, unsigned int> m_inputPortNameToIndex;
97 std::map<QString, unsigned int> m_outputPortNameToIndex;
98 std::list<nxcip::CameraInputEventHandler*> m_eventHandlers;
100 mutable QMutex m_mutex;
101 std::map<unsigned int, QNetworkReply*> m_inputPortHttpMonitor;
102 QWaitCondition m_cond;
103 QAtomicInt m_asyncCallCounter;
105 std::map<int, AsyncCallContext> m_awaitedAsyncCallIDs;
106 MultipartedParsingState m_multipartedParsingState;
107
108 void copyPortList(
109 char** idList,
110 int* idNum,
111 const std::map<QString, unsigned int>& portNameToIndex ) const;
112 void callSlotFromOwningThread( PortMonitoringSlotPtr slotPtr, int* const resultCode = NULL );
113 void readAxisRelayPortNotification( const QByteArray& line );
114
115 private:
116 void startInputPortMonitoringPriv( int asyncCallID );
117 void stopInputPortMonitoringPriv( int asyncCallID );
118 void onMonitorDataAvailable();
119 void onConnectionFinished( QNetworkReply* reply );
120 };
AxisRelayIOManager::AxisRelayIOManager
AxisRelayIOManager(AxisCameraManager *cameraManager, unsigned int inputPortCount, unsigned int outputPortCount)
Definition: axis_relayio_manager.cpp:17
AxisRelayIOManager::queryInterface
virtual void * queryInterface(const nxpl::NX_GUID &interfaceID) override
Implementation of nxcip::CameraRelayIOManager::queryInterface.
Definition: axis_relayio_manager.cpp:69
AxisRelayIOManager::releaseRef
virtual int releaseRef() const override
Implementation of nxpl::PluginInterface::releaseRef.
Definition: axis_relayio_manager.cpp:89
AxisRelayIOManager::setRelayOutputState
virtual int setRelayOutputState(const char *outputID, int activate, unsigned int autoResetTimeoutMS) override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:106
AxisRelayIOManager::getRelayOutputList
virtual int getRelayOutputList(char **idList, int *idNum) const override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:94
AxisRelayIOManager::getInputPortList
virtual int getInputPortList(char **idList, int *idNum) const override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:100
AxisRelayIOManager::startInputPortMonitoring
virtual int startInputPortMonitoring() override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:135
nxcip::CameraInputEventHandler
Receives events on input port state change.
Definition: camera_plugin.h:1488
AxisRelayIOManager
Provides access to camera&#39;s relay input/output port (implements nxcip::CameraRelayIOManager) ...
Definition: axis_relayio_manager.h:25
nxpl::NX_GUID
GUID of plugin interface.
Definition: plugin_api.h:26
AxisCameraManager
Provides access to camera&#39;s properties and instantiates other managers (implements nxcip::BaseCameraM...
Definition: axis_camera_manager.h:21
AxisRelayIOManager::getLastErrorString
virtual void getLastErrorString(char *errorString) const override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:168
AxisRelayIOManager::unregisterEventHandler
virtual void unregisterEventHandler(nxcip::CameraInputEventHandler *handler) override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:160
nxcip::CameraRelayIOManager
Relay input/output management.
Definition: camera_plugin.h:1407
nxpt::CommonRefManager
Definition: plugin_tools.h:67
plugin_tools.h
AxisRelayIOManager::addRef
virtual int addRef() const override
Implementation of nxpl::PluginInterface::addRef.
Definition: axis_relayio_manager.cpp:84
AxisRelayIOManager::registerEventHandler
virtual void registerEventHandler(nxcip::CameraInputEventHandler *handler) override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:152
AxisRelayIOManager::stopInputPortMonitoring
virtual void stopInputPortMonitoring() override
Implementation of nxcip::CameraRelayIOManager::getRelayOutputList.
Definition: axis_relayio_manager.cpp:146