-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket_streaming_server_impl.cpp
More file actions
115 lines (94 loc) · 4.04 KB
/
websocket_streaming_server_impl.cpp
File metadata and controls
115 lines (94 loc) · 4.04 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <websocket_streaming_server_module/websocket_streaming_server_impl.h>
#include <coretypes/impl.h>
#include <coreobjects/property_object_factory.h>
#include <coreobjects/property_factory.h>
#include <opendaq/server_type_factory.h>
#include <opendaq/custom_log.h>
BEGIN_NAMESPACE_OPENDAQ_WEBSOCKET_STREAMING_SERVER_MODULE
using namespace daq;
WebsocketStreamingServerImpl::WebsocketStreamingServerImpl(const DevicePtr& rootDevice,
const PropertyObjectPtr& config,
const ContextPtr& context)
: Server("OpenDAQLTStreaming", config, rootDevice, context)
, websocketStreamingServer(rootDevice, context)
{
const uint16_t streamingPort = config.getPropertyValue("WebsocketStreamingPort");
const uint16_t controlPort = config.getPropertyValue("WebsocketControlPort");
websocketStreamingServer.setStreamingPort(streamingPort);
websocketStreamingServer.setControlPort(controlPort);
websocketStreamingServer.start();
}
WebsocketStreamingServerImpl::~WebsocketStreamingServerImpl()
{
websocketStreamingServer.stop();
}
void WebsocketStreamingServerImpl::populateDefaultConfigFromProvider(const ContextPtr& context, const PropertyObjectPtr& config)
{
if (!context.assigned())
return;
if (!config.assigned())
return;
auto options = context.getModuleOptions("StreamingLtServer");
for (const auto& [key, value] : options)
{
if (config.hasProperty(key))
{
config->setPropertyValue(key, value);
}
}
}
PropertyObjectPtr WebsocketStreamingServerImpl::createDefaultConfig(const ContextPtr& context)
{
constexpr Int minPortValue = 0;
constexpr Int maxPortValue = 65535;
auto defaultConfig = PropertyObject();
const auto websocketPortProp =
IntPropertyBuilder("WebsocketStreamingPort", 7414).setMinValue(minPortValue).setMaxValue(maxPortValue).build();
defaultConfig.addProperty(websocketPortProp);
const auto websocketControlPortProp =
IntPropertyBuilder("WebsocketControlPort", 7438).setMinValue(minPortValue).setMaxValue(maxPortValue).build();
defaultConfig.addProperty(websocketControlPortProp);
defaultConfig.addProperty(StringProperty("Path", "/"));
populateDefaultConfigFromProvider(context, defaultConfig);
return defaultConfig;
}
PropertyObjectPtr WebsocketStreamingServerImpl::getDiscoveryConfig()
{
auto discoveryConfig = PropertyObject();
discoveryConfig.addProperty(StringProperty("ServiceName", "_streaming-lt._tcp.local."));
discoveryConfig.addProperty(StringProperty("ServiceCap", "LT"));
discoveryConfig.addProperty(StringProperty("Path", config.getPropertyValue("Path")));
discoveryConfig.addProperty(IntProperty("Port", config.getPropertyValue("WebsocketStreamingPort")));
discoveryConfig.addProperty(StringProperty("ProtocolVersion", ""));
return discoveryConfig;
}
ServerTypePtr WebsocketStreamingServerImpl::createType(const ContextPtr& context)
{
return ServerType(
"OpenDAQLTStreaming",
"openDAQ LT Streaming server",
"Publishes device signals as a flat list and streams data over WebsocketTcp protocol",
WebsocketStreamingServerImpl::createDefaultConfig(context));
}
void WebsocketStreamingServerImpl::onStopServer()
{
websocketStreamingServer.stop();
}
PropertyObjectPtr WebsocketStreamingServerImpl::populateDefaultConfig(const PropertyObjectPtr& config, const ContextPtr& context)
{
const auto defConfig = createDefaultConfig(context);
for (const auto& prop : defConfig.getAllProperties())
{
const auto name = prop.getName();
if (config.hasProperty(name))
defConfig.setPropertyValue(name, config.getPropertyValue(name));
}
return defConfig;
}
OPENDAQ_DEFINE_CLASS_FACTORY_WITH_INTERFACE(
INTERNAL_FACTORY, WebsocketStreamingServer, daq::IServer,
daq::DevicePtr, rootDevice,
PropertyObjectPtr, config,
const ContextPtr&, context
)
END_NAMESPACE_OPENDAQ_WEBSOCKET_STREAMING_SERVER_MODULE