Skip to content

Commit 5976a8e

Browse files
Added DynamicMetadataPublish sample that demonstrates how to dynamically update metadata
1 parent c7abb83 commit 5976a8e

7 files changed

Lines changed: 626 additions & 0 deletions

File tree

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ target_link_libraries (InstanceSubscribe sttp)
462462
add_executable (InstancePublish EXCLUDE_FROM_ALL samples/InstancePublish/InstancePublish.cpp samples/InstancePublish/PublisherHandler.cpp)
463463
target_link_libraries (InstancePublish sttp)
464464

465+
# DynamicMetadataPublish sample
466+
add_executable (DynamicMetadataPublish EXCLUDE_FROM_ALL samples/DynamicMetadataPublish/DynamicMetadataPublish.cpp samples/DynamicMetadataPublish/PublisherHandler.cpp)
467+
target_link_libraries (DynamicMetadataPublish sttp)
468+
465469
# FilterExpressionTests sample
466470
add_executable (FilterExpressionTests EXCLUDE_FROM_ALL samples/FilterExpressionTests/FilterExpressionTests.cpp)
467471
target_link_libraries (FilterExpressionTests sttp boost_filesystem)
@@ -481,6 +485,7 @@ add_custom_target (samples DEPENDS
481485
AverageFrequencyCalculator
482486
InstanceSubscribe
483487
InstancePublish
488+
DynamicMetadataPublish
484489
FilterExpressionTests
485490
SimplePublish
486491
AdvancedPublish

src/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Individual sample applications can be built as follows:
144144
make AverageFrequencyCalculator
145145
make InstanceSubscribe
146146
make InstancePublish
147+
make DynamicMetadataPublish
147148
make FilterExpressionTests
148149
make SimplePublish
149150
make AdvancedPublish
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//******************************************************************************************************
2+
// InstancePublish.cpp - Gbtc
3+
//
4+
// Copyright © 2019, Grid Protection Alliance. All Rights Reserved.
5+
//
6+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
9+
// file except in compliance with the License. You may obtain a copy of the License at:
10+
//
11+
// http://opensource.org/licenses/MIT
12+
//
13+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+
// License for the specific language governing permissions and limitations.
16+
//
17+
// Code Modification History:
18+
// ----------------------------------------------------------------------------------------------------
19+
// 03/27/2019 - J. Ritchie Carroll
20+
// Generated original version of source code.
21+
//
22+
//******************************************************************************************************
23+
24+
#include <iostream>
25+
#include "PublisherHandler.h"
26+
27+
using namespace std;
28+
using namespace sttp;
29+
using namespace sttp::transport;
30+
31+
const int32_t UpdateInterval = 10000;
32+
const int32_t MaxDeviceCount = 20;
33+
int32_t deviceCount = 1;
34+
35+
int main(int argc, char* argv[])
36+
{
37+
uint16_t port;
38+
bool autoUpdateMetadata;
39+
40+
// Ensure that the necessary
41+
// command line arguments are given.
42+
if (argc < 2)
43+
{
44+
cout << "Usage:" << endl;
45+
cout << " InstancePublish PORT [AutoUpdateMetadata?]" << endl;
46+
}
47+
else
48+
{
49+
// Get port.
50+
stringstream(argv[1]) >> port;
51+
}
52+
53+
if (argc > 2)
54+
autoUpdateMetadata = ParseBoolean(argv[2]);
55+
else
56+
autoUpdateMetadata = true;
57+
58+
PublisherHandler* publisher = new PublisherHandler("Publisher", port, false);
59+
publisher->Start();
60+
61+
if (autoUpdateMetadata)
62+
{
63+
// Setup thread to continually update meta-data
64+
Timer metadataUpdate(UpdateInterval, [publisher](Timer* timer, void*)
65+
{
66+
publisher->DefineMetadata(++deviceCount);
67+
68+
if (deviceCount >= MaxDeviceCount)
69+
{
70+
timer->Stop();
71+
publisher->StatusMessage("Metadata update timer stopped: reached configured device limit of " + ToString(MaxDeviceCount) + ".");
72+
}
73+
},
74+
true);
75+
76+
metadataUpdate.Start();
77+
78+
string line;
79+
getline(cin, line);
80+
81+
metadataUpdate.Stop();
82+
}
83+
else
84+
{
85+
int key = 0;
86+
87+
while (key != 10)
88+
{
89+
// Space bar then Enter will update metadata
90+
if (key == 32)
91+
{
92+
publisher->DefineMetadata(++deviceCount);
93+
getchar();
94+
}
95+
96+
key = getchar();
97+
}
98+
}
99+
100+
publisher->Stop();
101+
delete publisher;
102+
103+
cout << "Publishers stopped." << endl;
104+
105+
return 0;
106+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|Win32">
13+
<Configuration>Release</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{dfbe36c4-1542-428d-9ca0-de57d8a5192f}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>DynamicMetadataPublish</RootNamespace>
25+
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
26+
<ProjectName>DynamicMetadataPublish</ProjectName>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v141</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>true</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>false</UseDebugLibraries>
44+
<PlatformToolset>v141</PlatformToolset>
45+
<WholeProgramOptimization>true</WholeProgramOptimization>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<OutDir>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\samples\</OutDir>
75+
<IntDir>obj\$(Configuration)\</IntDir>
76+
<LibraryPath>$(SolutionDir)\..\..\boost\stage\lib\;$(LibraryPath)</LibraryPath>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
79+
<OutDir>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\samples\</OutDir>
80+
<IntDir>obj\$(Configuration)\</IntDir>
81+
<LibraryPath>$(SolutionDir)\..\..\boost\stage\lib\;$(LibraryPath)</LibraryPath>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
84+
<OutDir>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\samples\</OutDir>
85+
<IntDir>obj\$(Configuration)\</IntDir>
86+
<LibraryPath>$(SolutionDir)\..\..\boost\stage\lib\;$(LibraryPath)</LibraryPath>
87+
<LinkIncremental>false</LinkIncremental>
88+
</PropertyGroup>
89+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
90+
<OutDir>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\samples\</OutDir>
91+
<IntDir>obj\$(Configuration)\</IntDir>
92+
<LibraryPath>$(SolutionDir)\..\..\boost\stage\lib\;$(LibraryPath)</LibraryPath>
93+
<LinkIncremental>false</LinkIncremental>
94+
</PropertyGroup>
95+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
96+
<ClCompile>
97+
<PrecompiledHeader>
98+
</PrecompiledHeader>
99+
<WarningLevel>Level3</WarningLevel>
100+
<Optimization>Disabled</Optimization>
101+
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102+
<SDLCheck>true</SDLCheck>
103+
<AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
104+
</ClCompile>
105+
<Link>
106+
<SubSystem>Console</SubSystem>
107+
<GenerateDebugInformation>true</GenerateDebugInformation>
108+
<AdditionalDependencies>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\lib\sttp.cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
112+
<ClCompile>
113+
<PrecompiledHeader>
114+
</PrecompiledHeader>
115+
<WarningLevel>Level3</WarningLevel>
116+
<Optimization>Disabled</Optimization>
117+
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118+
<SDLCheck>true</SDLCheck>
119+
<AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
120+
</ClCompile>
121+
<Link>
122+
<SubSystem>Console</SubSystem>
123+
<GenerateDebugInformation>true</GenerateDebugInformation>
124+
<AdditionalDependencies>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\lib\sttp.cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
125+
</Link>
126+
</ItemDefinitionGroup>
127+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
128+
<ClCompile>
129+
<WarningLevel>Level3</WarningLevel>
130+
<PrecompiledHeader>
131+
</PrecompiledHeader>
132+
<Optimization>MaxSpeed</Optimization>
133+
<FunctionLevelLinking>true</FunctionLevelLinking>
134+
<IntrinsicFunctions>true</IntrinsicFunctions>
135+
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
136+
<SDLCheck>true</SDLCheck>
137+
<AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
138+
</ClCompile>
139+
<Link>
140+
<SubSystem>Console</SubSystem>
141+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
142+
<OptimizeReferences>true</OptimizeReferences>
143+
<GenerateDebugInformation>true</GenerateDebugInformation>
144+
<AdditionalDependencies>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\lib\sttp.cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
145+
</Link>
146+
</ItemDefinitionGroup>
147+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
148+
<ClCompile>
149+
<WarningLevel>Level3</WarningLevel>
150+
<PrecompiledHeader>
151+
</PrecompiledHeader>
152+
<Optimization>MaxSpeed</Optimization>
153+
<FunctionLevelLinking>true</FunctionLevelLinking>
154+
<IntrinsicFunctions>true</IntrinsicFunctions>
155+
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
156+
<SDLCheck>true</SDLCheck>
157+
<AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
158+
</ClCompile>
159+
<Link>
160+
<SubSystem>Console</SubSystem>
161+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
162+
<OptimizeReferences>true</OptimizeReferences>
163+
<GenerateDebugInformation>true</GenerateDebugInformation>
164+
<AdditionalDependencies>$(SolutionDir)..\build\output\$(PlatformTarget)\$(Configuration)\lib\sttp.cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
165+
</Link>
166+
</ItemDefinitionGroup>
167+
<ItemGroup>
168+
<ClCompile Include="PublisherHandler.cpp" />
169+
<ClCompile Include="DynamicMetadataPublish.cpp" />
170+
</ItemGroup>
171+
<ItemGroup>
172+
<ClInclude Include="PublisherHandler.h" />
173+
</ItemGroup>
174+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
175+
<ImportGroup Label="ExtensionTargets">
176+
</ImportGroup>
177+
</Project>

0 commit comments

Comments
 (0)