Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring DataStorm demos to ice-demos #227

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ server
locator
publisher
subscriber
reader
writer
talk
chatserver
chatgl2client
Expand All @@ -17,6 +19,8 @@ chatpollclient
!**/msbuild/locator
!**/msbuild/publisher
!**/msbuild/subscriber
!**/msbuild/reader
!**/msbuild/writer

!**/Sources/client
!**/Sources/server
Expand Down
152 changes: 152 additions & 0 deletions cpp/C++ demos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,44 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mtalk", "mtalk", "{B1F08922
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "Ice\mtalk\msbuild\client\client.vcxproj", "{7A216D2F-18DC-415A-96E7-A417B1DC7FB4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStorm", "DataStorm", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clock", "clock", "{9F79C5E8-103C-4C38-8CBD-56F80EA85B09}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\clock\msbuild\reader\reader.vcxproj", "{E9146C23-516D-4D87-A217-EDF5A08DBF04}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\clock\msbuild\writer\writer.vcxproj", "{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "keyFilter", "keyFilter", "{FE2D0F22-6A55-427B-BFF2-1B93F166757C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\keyFilter\msbuild\reader\reader.vcxproj", "{0FA27393-6D89-4612-8170-81122C6B8936}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\keyFilter\msbuild\writer\writer.vcxproj", "{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "minimal", "minimal", "{765BF359-660D-4050-9F74-E9BE9212005A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\minimal\msbuild\reader\reader.vcxproj", "{7464DBD0-F9B8-4DCE-948E-ED4A12215689}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\minimal\msbuild\writer\writer.vcxproj", "{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "node", "node", "{C769473B-134B-4FD5-8F37-F22012C08C50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sampleFilter", "sampleFilter", "{639F8A00-F592-4CB3-BC92-0AFB9388D03F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\node\msbuild\reader\reader.vcxproj", "{07A7881F-0E97-4855-BA2A-8253F30A5FA0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\node\msbuild\writer\writer.vcxproj", "{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\sampleFilter\msbuild\reader\reader.vcxproj", "{9834D6A0-4696-4525-9BB6-D51AAF557EC1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\sampleFilter\msbuild\writer\writer.vcxproj", "{864A92F2-D094-45AF-8277-50F43824C4EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "stock", "stock", "{64DF5504-2D9E-409C-A998-0881AB01FC09}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reader", "DataStorm\stock\msbuild\reader\reader.vcxproj", "{5550D94C-D162-4367-BF79-00243E79D3D1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "DataStorm\stock\msbuild\writer\writer.vcxproj", "{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -1075,6 +1113,102 @@ Global
{7A216D2F-18DC-415A-96E7-A417B1DC7FB4}.Release|Win32.Build.0 = Release|Win32
{7A216D2F-18DC-415A-96E7-A417B1DC7FB4}.Release|x64.ActiveCfg = Release|x64
{7A216D2F-18DC-415A-96E7-A417B1DC7FB4}.Release|x64.Build.0 = Release|x64
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Debug|Win32.ActiveCfg = Debug|Win32
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Debug|Win32.Build.0 = Debug|Win32
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Debug|x64.ActiveCfg = Debug|x64
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Debug|x64.Build.0 = Debug|x64
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Release|Win32.ActiveCfg = Release|Win32
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Release|Win32.Build.0 = Release|Win32
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Release|x64.ActiveCfg = Release|x64
{E9146C23-516D-4D87-A217-EDF5A08DBF04}.Release|x64.Build.0 = Release|x64
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Debug|Win32.ActiveCfg = Debug|Win32
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Debug|Win32.Build.0 = Debug|Win32
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Debug|x64.ActiveCfg = Debug|x64
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Debug|x64.Build.0 = Debug|x64
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Release|Win32.ActiveCfg = Release|Win32
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Release|Win32.Build.0 = Release|Win32
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Release|x64.ActiveCfg = Release|x64
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03}.Release|x64.Build.0 = Release|x64
{0FA27393-6D89-4612-8170-81122C6B8936}.Debug|Win32.ActiveCfg = Debug|Win32
{0FA27393-6D89-4612-8170-81122C6B8936}.Debug|Win32.Build.0 = Debug|Win32
{0FA27393-6D89-4612-8170-81122C6B8936}.Debug|x64.ActiveCfg = Debug|x64
{0FA27393-6D89-4612-8170-81122C6B8936}.Debug|x64.Build.0 = Debug|x64
{0FA27393-6D89-4612-8170-81122C6B8936}.Release|Win32.ActiveCfg = Release|Win32
{0FA27393-6D89-4612-8170-81122C6B8936}.Release|Win32.Build.0 = Release|Win32
{0FA27393-6D89-4612-8170-81122C6B8936}.Release|x64.ActiveCfg = Release|x64
{0FA27393-6D89-4612-8170-81122C6B8936}.Release|x64.Build.0 = Release|x64
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Debug|Win32.ActiveCfg = Debug|Win32
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Debug|Win32.Build.0 = Debug|Win32
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Debug|x64.ActiveCfg = Debug|x64
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Debug|x64.Build.0 = Debug|x64
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Release|Win32.ActiveCfg = Release|Win32
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Release|Win32.Build.0 = Release|Win32
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Release|x64.ActiveCfg = Release|x64
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C}.Release|x64.Build.0 = Release|x64
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Debug|Win32.ActiveCfg = Debug|Win32
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Debug|Win32.Build.0 = Debug|Win32
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Debug|x64.ActiveCfg = Debug|x64
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Debug|x64.Build.0 = Debug|x64
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Release|Win32.ActiveCfg = Release|Win32
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Release|Win32.Build.0 = Release|Win32
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Release|x64.ActiveCfg = Release|x64
{7464DBD0-F9B8-4DCE-948E-ED4A12215689}.Release|x64.Build.0 = Release|x64
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Debug|Win32.ActiveCfg = Debug|Win32
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Debug|Win32.Build.0 = Debug|Win32
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Debug|x64.ActiveCfg = Debug|x64
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Debug|x64.Build.0 = Debug|x64
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Release|Win32.ActiveCfg = Release|Win32
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Release|Win32.Build.0 = Release|Win32
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Release|x64.ActiveCfg = Release|x64
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6}.Release|x64.Build.0 = Release|x64
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Debug|Win32.ActiveCfg = Debug|Win32
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Debug|Win32.Build.0 = Debug|Win32
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Debug|x64.ActiveCfg = Debug|x64
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Debug|x64.Build.0 = Debug|x64
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Release|Win32.ActiveCfg = Release|Win32
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Release|Win32.Build.0 = Release|Win32
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Release|x64.ActiveCfg = Release|x64
{07A7881F-0E97-4855-BA2A-8253F30A5FA0}.Release|x64.Build.0 = Release|x64
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Debug|Win32.ActiveCfg = Debug|Win32
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Debug|Win32.Build.0 = Debug|Win32
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Debug|x64.ActiveCfg = Debug|x64
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Debug|x64.Build.0 = Debug|x64
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Release|Win32.ActiveCfg = Release|Win32
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Release|Win32.Build.0 = Release|Win32
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Release|x64.ActiveCfg = Release|x64
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7}.Release|x64.Build.0 = Release|x64
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Debug|Win32.ActiveCfg = Debug|Win32
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Debug|Win32.Build.0 = Debug|Win32
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Debug|x64.ActiveCfg = Debug|x64
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Debug|x64.Build.0 = Debug|x64
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Release|Win32.ActiveCfg = Release|Win32
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Release|Win32.Build.0 = Release|Win32
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Release|x64.ActiveCfg = Release|x64
{9834D6A0-4696-4525-9BB6-D51AAF557EC1}.Release|x64.Build.0 = Release|x64
{864A92F2-D094-45AF-8277-50F43824C4EE}.Debug|Win32.ActiveCfg = Debug|Win32
{864A92F2-D094-45AF-8277-50F43824C4EE}.Debug|Win32.Build.0 = Debug|Win32
{864A92F2-D094-45AF-8277-50F43824C4EE}.Debug|x64.ActiveCfg = Debug|x64
{864A92F2-D094-45AF-8277-50F43824C4EE}.Debug|x64.Build.0 = Debug|x64
{864A92F2-D094-45AF-8277-50F43824C4EE}.Release|Win32.ActiveCfg = Release|Win32
{864A92F2-D094-45AF-8277-50F43824C4EE}.Release|Win32.Build.0 = Release|Win32
{864A92F2-D094-45AF-8277-50F43824C4EE}.Release|x64.ActiveCfg = Release|x64
{864A92F2-D094-45AF-8277-50F43824C4EE}.Release|x64.Build.0 = Release|x64
{5550D94C-D162-4367-BF79-00243E79D3D1}.Debug|Win32.ActiveCfg = Debug|Win32
{5550D94C-D162-4367-BF79-00243E79D3D1}.Debug|Win32.Build.0 = Debug|Win32
{5550D94C-D162-4367-BF79-00243E79D3D1}.Debug|x64.ActiveCfg = Debug|x64
{5550D94C-D162-4367-BF79-00243E79D3D1}.Debug|x64.Build.0 = Debug|x64
{5550D94C-D162-4367-BF79-00243E79D3D1}.Release|Win32.ActiveCfg = Release|Win32
{5550D94C-D162-4367-BF79-00243E79D3D1}.Release|Win32.Build.0 = Release|Win32
{5550D94C-D162-4367-BF79-00243E79D3D1}.Release|x64.ActiveCfg = Release|x64
{5550D94C-D162-4367-BF79-00243E79D3D1}.Release|x64.Build.0 = Release|x64
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Debug|Win32.ActiveCfg = Debug|Win32
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Debug|Win32.Build.0 = Debug|Win32
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Debug|x64.ActiveCfg = Debug|x64
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Debug|x64.Build.0 = Debug|x64
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Release|Win32.ActiveCfg = Release|Win32
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Release|Win32.Build.0 = Release|Win32
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Release|x64.ActiveCfg = Release|x64
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1203,6 +1337,24 @@ Global
{E0D028F5-7111-465F-B7AB-3E1F60BC29D7} = {44504257-9751-4CA1-AF97-86995FE49C45}
{B1F08922-D984-49AD-ADC3-4A77D13A7E1F} = {60A225B4-F05B-412D-82B6-50B9A1539B6A}
{7A216D2F-18DC-415A-96E7-A417B1DC7FB4} = {B1F08922-D984-49AD-ADC3-4A77D13A7E1F}
{9F79C5E8-103C-4C38-8CBD-56F80EA85B09} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{E9146C23-516D-4D87-A217-EDF5A08DBF04} = {9F79C5E8-103C-4C38-8CBD-56F80EA85B09}
{D5FFCE1A-7264-42D7-AE3F-60AF35D71B03} = {9F79C5E8-103C-4C38-8CBD-56F80EA85B09}
{FE2D0F22-6A55-427B-BFF2-1B93F166757C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{0FA27393-6D89-4612-8170-81122C6B8936} = {FE2D0F22-6A55-427B-BFF2-1B93F166757C}
{E7270286-71D1-4C31-A2A4-A9DBA0D28E6C} = {FE2D0F22-6A55-427B-BFF2-1B93F166757C}
{765BF359-660D-4050-9F74-E9BE9212005A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{7464DBD0-F9B8-4DCE-948E-ED4A12215689} = {765BF359-660D-4050-9F74-E9BE9212005A}
{5362D3A2-6280-4C76-9C98-B2B30F6A7EC6} = {765BF359-660D-4050-9F74-E9BE9212005A}
{C769473B-134B-4FD5-8F37-F22012C08C50} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{639F8A00-F592-4CB3-BC92-0AFB9388D03F} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{07A7881F-0E97-4855-BA2A-8253F30A5FA0} = {C769473B-134B-4FD5-8F37-F22012C08C50}
{558F8E62-C7E5-4DB1-9175-925A0DCE55B7} = {C769473B-134B-4FD5-8F37-F22012C08C50}
{9834D6A0-4696-4525-9BB6-D51AAF557EC1} = {639F8A00-F592-4CB3-BC92-0AFB9388D03F}
{864A92F2-D094-45AF-8277-50F43824C4EE} = {639F8A00-F592-4CB3-BC92-0AFB9388D03F}
{64DF5504-2D9E-409C-A998-0881AB01FC09} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{5550D94C-D162-4367-BF79-00243E79D3D1} = {64DF5504-2D9E-409C-A998-0881AB01FC09}
{4362D2DF-3F07-4248-9CB4-9682B29EE0D3} = {64DF5504-2D9E-409C-A998-0881AB01FC09}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {637833EA-7321-4124-9416-0A38CE37CA31}
Expand Down
5 changes: 5 additions & 0 deletions cpp/DataStorm/clock/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) ZeroC, Inc. All rights reserved.

$(demo)_dependencies = DataStorm Ice

demos += $(demo)
16 changes: 16 additions & 0 deletions cpp/DataStorm/clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This demo illustrates how to implement a custom encoder and decoder for the topic value type
`chrono::system_clock::time_point`.

To run the demo, start the writer and specify the name of a city:

```shell
writer
```

In a separate window, start the reader:

```shell
reader
```

The reader will print the time sent by the writer. You can start multiple writers and readers.
86 changes: 86 additions & 0 deletions cpp/DataStorm/clock/Reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#include <DataStorm/DataStorm.h>
#include <Ice/Ice.h>

#include <chrono>
#include <iostream>

using namespace std;

namespace DataStorm
{
template<> struct Encoder<chrono::system_clock::time_point>
{
static Ice::ByteSeq encode(const chrono::system_clock::time_point&)
{
assert(false); // Not used by the reader but it still needs to be declared.
return Ice::ByteSeq{};
}
};

template<> struct Decoder<chrono::system_clock::time_point>
{
static chrono::system_clock::time_point decode(const Ice::ByteSeq& data)
{
// Decode the number of seconds since epoch. The value is encoded in a way which doesn't depend on the
// platform endianess (little endian with variable number of bytes).
long long int value = 0;
for (auto p = data.rbegin(); p != data.rend(); ++p)
{
value = value * 256 + static_cast<long long int>(*p);
}
return chrono::time_point<chrono::system_clock>(chrono::seconds(value));
}
};
};

int
main(int argc, char* argv[])
{
try
{
// CtrlCHandler must be called before the node is created or any other threads are started.
Ice::CtrlCHandler ctrlCHandler;

// Instantiates node.
DataStorm::Node node(argc, argv, "config.reader");

// Shutdown the node on Ctrl-C.
ctrlCHandler.setCallback([&node](int) { node.shutdown(); });

// Instantiates the "time" topic.
DataStorm::Topic<string, chrono::system_clock::time_point> topic(node, "time");

// Instantiate a reader to read the time from all the topic cities.
auto reader = DataStorm::makeAnyKeyReader(topic);

// Wait for at least on writer to connect.
reader.waitForWriters();

// Prints out the received samples.
reader.onSamples(
nullptr,
[](const DataStorm::Sample<string, chrono::system_clock::time_point>& sample)
{
auto time = chrono::system_clock::to_time_t(sample.getValue());
char timeString[100];
if (strftime(timeString, sizeof(timeString), "%x %X", localtime(&time)) == 0)
{
timeString[0] = '\0';
}
cout << "received time for `" << sample.getKey() << "': " << timeString << endl;
});

// Exit once the user hits Ctrl-C to shutdown the node.
node.waitForShutdown();
}
catch (const std::exception& ex)
{
cerr << ex.what() << endl;
return 1;
}
return 0;
}
78 changes: 78 additions & 0 deletions cpp/DataStorm/clock/Writer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) ZeroC, Inc. All rights reserved.

#include <DataStorm/DataStorm.h>
#include <Ice/Ice.h>

#include <iostream>
#include <string>
#include <thread>

using namespace std;

namespace DataStorm
{
template<> struct Encoder<chrono::system_clock::time_point>
{
static Ice::ByteSeq encode(const chrono::system_clock::time_point& time)
{
// Encode the number of seconds since epoch. The value is encoded in a way which doesn't depend on the
// platform endianess (little endian with variable number of bytes).
Ice::ByteSeq data;
auto value = chrono::time_point_cast<chrono::seconds>(time).time_since_epoch().count();
while (value)
{
data.push_back(static_cast<std::byte>(value % 256));
value = value / 256;
}
return data;
}
};

template<> struct Decoder<chrono::system_clock::time_point>
{
static chrono::system_clock::time_point decode(const Ice::ByteSeq&)
{
assert(false); // Not used by the reader but it still needs to be declared.
return chrono::system_clock::time_point();
}
};
};

int
main(int argc, char* argv[])
{
try
{
// CtrlCHandler must be called before the node is created or any other threads are started.
Ice::CtrlCHandler ctrlCHandler;

// Instantiates node.
DataStorm::Node node(argc, argv, "config.writer");

// Shutdown the node on Ctrl-C.
ctrlCHandler.setCallback([&node](int) { node.shutdown(); });

// Asks for city name to publish updates
string city;
cout << "Please enter city name: ";
getline(cin, city);

// Instantiates the "time" topic.
DataStorm::Topic<string, chrono::system_clock::time_point> topic(node, "time");

// Instantiate a writer to write the time from the given city.
auto writer = DataStorm::makeSingleKeyWriter(topic, city);

while (!node.isShutdown())
{
writer.update(chrono::system_clock::now());
this_thread::sleep_for(chrono::seconds(1));
}
}
catch (const std::exception& ex)
{
cerr << ex.what() << endl;
return 1;
}
return 0;
}
Loading
Loading