History

TimeSeriesPlatformLibrary: Updated SimplePublish sample to properly run.

J. Ritchie Carroll committed 7 years ago

Commit 4d190cd1 parent 285fcea7 files · +108 −99Browse files

Unified · Split

7 files
  1. Source/Applications/TimeSeries Platform Library Samples/SimplePublish/SimplePublish.vcxproj +2 −2
  2. Source/Libraries/TimeSeriesPlatformLibrary/Common/CommonTypes.h +1 −0
  3. Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.cpp +7 −0
  4. Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.h +2 −0
  5. Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp +45 −56
  6. Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.cpp +48 −41
  7. Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.h +3 −0
Source/Applications/TimeSeries Platform Library Samples/SimplePublish/SimplePublish.vcxproj+2−2
@@ -61,7 +61,7 @@ · 60 unmodified lines
61 </PrecompiledHeader>61 </PrecompiledHeader>
62 <WarningLevel>Level3</WarningLevel>62 <WarningLevel>Level3</WarningLevel>
63 <Optimization>Disabled</Optimization>63 <Optimization>Disabled</Optimization>
64 <PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>64 <PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
65 <SDLCheck>true</SDLCheck>65 <SDLCheck>true</SDLCheck>
66 <AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>66 <AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
67 </ClCompile>67 </ClCompile>
@@ -79,7 +79,7 @@ · 11 unmodified lines
79 <Optimization>MaxSpeed</Optimization>79 <Optimization>MaxSpeed</Optimization>
80 <FunctionLevelLinking>true</FunctionLevelLinking>80 <FunctionLevelLinking>true</FunctionLevelLinking>
81 <IntrinsicFunctions>true</IntrinsicFunctions>81 <IntrinsicFunctions>true</IntrinsicFunctions>
82 <PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>82 <PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
83 <SDLCheck>true</SDLCheck>83 <SDLCheck>true</SDLCheck>
84 <AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>84 <AdditionalIncludeDirectories>$(SolutionDir)\..\..\boost</AdditionalIncludeDirectories>
85 </ClCompile>85 </ClCompile>
Source/Libraries/TimeSeriesPlatformLibrary/Common/CommonTypes.h+1−0
@@ -206,6 +206,7 @@ namespace GSF · 205 unmodified lines
206 typedef boost::any Object;206 typedef boost::any Object;
207 typedef boost::uuids::uuid Guid;207 typedef boost::uuids::uuid Guid;
208 typedef boost::posix_time::ptime DateTime;208 typedef boost::posix_time::ptime DateTime;
209 typedef boost::posix_time::time_duration TimeSpan;
209 typedef boost::system::error_code ErrorCode;210 typedef boost::system::error_code ErrorCode;
210 typedef boost::system::system_error SystemError;211 typedef boost::system::system_error SystemError;
211 typedef boost::exception Exception;212 typedef boost::exception Exception;
Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.cpp+7−0
@@ -254,6 +254,13 @@ std::string GSF::ToString(const DateTime& value, const char* format) · 253 unmodified lines
254 return stream.str();254 return stream.str();
255}255}
256 256
257std::string GSF::ToString(const TimeSpan& value)
258{
259 // TODO: Consider improving elapsed time string with hours, minutes, etc.
260 const float64_t seconds = value.total_milliseconds() / 1000.0;
261 return ToString(seconds) + " seconds";
262}
263
257wstring GSF::ToUTF16(const string& value)264wstring GSF::ToUTF16(const string& value)
258{265{
259 wstring_convert<codecvt_utf8<wchar_t>, wchar_t> converter;266 wstring_convert<codecvt_utf8<wchar_t>, wchar_t> converter;
Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.h+2−0
@@ -55,6 +55,8 @@ namespace GSF · 54 unmodified lines
55 55
56 std::string ToString(const DateTime& value, const char* format = "%Y-%m-%d %H:%M:%S%F");56 std::string ToString(const DateTime& value, const char* format = "%Y-%m-%d %H:%M:%S%F");
57 57
58 std::string ToString(const TimeSpan& value);
59
58 std::wstring ToUTF16(const std::string& value);60 std::wstring ToUTF16(const std::string& value);
59 std::string ToUTF8(const std::wstring& value);61 std::string ToUTF8(const std::wstring& value);
60 62
Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp+45−56
@@ -23,9 +23,7 @@ · 22 unmodified lines
23 23
24#include <iostream>24#include <iostream>
25#include <string>25#include <string>
26#include <vector>
27 26
28#include "../Common/Convert.h"
29#include "../Transport/DataPublisher.h"27#include "../Transport/DataPublisher.h"
30 28
31using namespace std;29using namespace std;
@@ -33,7 +31,7 @@ using namespace GSF; · 1 unmodified line
33using namespace GSF::TimeSeries;31using namespace GSF::TimeSeries;
34using namespace GSF::TimeSeries::Transport;32using namespace GSF::TimeSeries::Transport;
35 33
36DataPublisher Subscriber;34DataPublisherPtr Publisher;
37 35
38bool RunPublisher(uint16_t port);36bool RunPublisher(uint16_t port);
39//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements);37//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements);
@@ -86,27 +84,15 @@ int main(int argc, char* argv[]) · 46 unmodified lines
86// - Publish84// - Publish
87bool RunPublisher(uint16_t port)85bool RunPublisher(uint16_t port)
88{86{
89 // SubscriptionInfo is a helper object which allows the user
90 // to set up their subscription and reuse subscription settings.
91 //SubscriptionInfo info;
92 //info.FilterExpression = "PPA:1;PPA:2;PPA:3;PPA:4;PPA:5;PPA:6;PPA:7;PPA:8;PPA:9;PPA:10;PPA:11;PPA:12;PPA:13;PPA:14";
93
94 // Register callbacks
95 Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
96 Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
97 //Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);
98
99 cout << endl << "Listening on port: " << port << "..." << endl << endl;
100
101 string errorMessage;87 string errorMessage;
102 bool connected = false;88 bool connected = false;
103 89
104 try90 try
105 {91 {
106 //Subscriber.Connect(hostname, port);92 Publisher = NewSharedPtr<DataPublisher>(port);
107 connected = true;93 connected = true;
108 }94 }
109 catch (SubscriberException& ex)95 catch (PublisherException& ex)
110 {96 {
111 errorMessage = ex.what();97 errorMessage = ex.what();
112 }98 }
@@ -116,57 +102,60 @@ bool RunPublisher(uint16_t port) · 3 unmodified lines
116 }102 }
117 catch (...)103 catch (...)
118 {104 {
119 errorMessage = current_exception_diagnostic_information(true);105 errorMessage = boost::current_exception_diagnostic_information(true);
120 }106 }
121 107
122 if (connected)108 if (connected)
123 {109 {
124 cout << "Connected! Subscribing to data..." << endl << endl;110 cout << endl << "Listening on port: " << port << "..." << endl << endl;
125 Subscriber.Subscribe(info);111
112 // Register callbacks
113 Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage);
114 Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage);
126 }115 }
127 else116 else
128 {117 {
129 cerr << "Failed to connect to \"" << hostname << ":" << port << "\": " << errorMessage;118 cerr << "Failed to listen on port: " << port << ": " << errorMessage;
130 }119 }
131 120
132 return connected;121 return connected;
133}122}
134 123
135// Callback which is called when the subscriber has124//// Callback which is called when the subscriber has
136// received a new packet of measurements from the publisher.125//// received a new packet of measurements from the publisher.
137void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)126//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)
138{127//{
139 const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";128// const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
140 const uint32_t MaxTimestampSize = 80;129// const uint32_t MaxTimestampSize = 80;
141 130//
142 static long processCount = 0;131// static long processCount = 0;
143 static char timestamp[MaxTimestampSize];132// static char timestamp[MaxTimestampSize];
144 static const long interval = 5 * 60;133// static const long interval = 5 * 60;
145 const long measurementCount = measurements.size();134// const long measurementCount = measurements.size();
146 const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);135// const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);
147 136//
148 processCount += measurementCount;137// processCount += measurementCount;
149 138//
150 // Only display messages every few seconds139// // Only display messages every few seconds
151 if (showMessage)140// if (showMessage)
152 {141// {
153 stringstream message;142// stringstream message;
154 143//
155 message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;144// message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
156 145//
157 if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))146// if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))
158 message << "Timestamp: " << string(timestamp) << endl;147// message << "Timestamp: " << string(timestamp) << endl;
159 148//
160 message << "Point\tValue" << endl;149// message << "Point\tValue" << endl;
161 150//
162 for (const auto& measurement : measurements)151// for (const auto& measurement : measurements)
163 message << measurement->ID << '\t' << measurement->Value << endl;152// message << measurement->ID << '\t' << measurement->Value << endl;
164 153//
165 message << endl;154// message << endl;
166 155//
167 cout << message.str();156// cout << message.str();
168 }157// }
169}158//}
170 159
171// Callback which is called to display status messages from the subscriber.160// Callback which is called to display status messages from the subscriber.
172void DisplayStatusMessage(DataPublisher* source, const string& message)161void DisplayStatusMessage(DataPublisher* source, const string& message)
Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.cpp+48−41
@@ -67,10 +67,11 @@ struct ClientConnectedInfo · 66 unmodified lines
67 67
68ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandChannelService, IOContext& dataChannelService) :68ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandChannelService, IOContext& dataChannelService) :
69 m_parent(std::move(parent)),69 m_parent(std::move(parent)),
70 m_commandChannelService(commandChannelService),
70 m_subscriberID(NewGuid()),71 m_subscriberID(NewGuid()),
71 m_operationalModes(OperationalModes::NoFlags),72 m_operationalModes(OperationalModes::NoFlags),
72 m_encoding(OperationalEncoding::UTF8),73 m_encoding(OperationalEncoding::UTF8),
73 m_commandChannelSocket(commandChannelService),74 m_commandChannelSocket(m_commandChannelService),
74 m_udpPort(0),75 m_udpPort(0),
75 m_dataChannelSocket(dataChannelService),76 m_dataChannelSocket(dataChannelService),
76 m_timeIndex(0),77 m_timeIndex(0),
@@ -81,42 +82,6 @@ ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandCh · 4 unmodified lines
81 m_pingTimer.SetAutoReset(true);82 m_pingTimer.SetAutoReset(true);
82 m_pingTimer.SetCallback(&ClientConnection::PingTimerElapsed);83 m_pingTimer.SetCallback(&ClientConnection::PingTimerElapsed);
83 m_pingTimer.SetUserData(this);84 m_pingTimer.SetUserData(this);
84
85 // Attempt to lookup remote connection identification for logging purposes
86 auto remoteEndPoint = m_commandChannelSocket.remote_endpoint();
87 m_ipAddress = remoteEndPoint.address();
88
89 if (remoteEndPoint.protocol() == tcp::v6())
90 m_connectionID = "[" + m_ipAddress.to_string() + "]:" + ToString(remoteEndPoint.port());
91 else
92 m_connectionID = m_ipAddress.to_string() + ":" + ToString(remoteEndPoint.port());
93
94 try
95 {
96 DnsResolver resolver(commandChannelService);
97 const DnsResolver::query query(m_ipAddress.to_string(), ToString(remoteEndPoint.port()));
98 DnsResolver::iterator iterator = resolver.resolve(query);
99 const DnsResolver::iterator end;
100
101 while (iterator != end)
102 {
103 auto endPoint = *iterator++;
104
105 if (!endPoint.host_name().empty())
106 {
107 m_hostName = endPoint.host_name();
108 m_connectionID = m_hostName + " (" + m_connectionID + ")";
109 break;
110 }
111 }
112 }
113 catch (...)
114 { //-V565
115 // DNS lookup failure is not a catastrophe
116 }
117
118 if (m_hostName.empty())
119 m_hostName = m_ipAddress.to_string();
120}85}
121 86
122ClientConnection::~ClientConnection() = default;87ClientConnection::~ClientConnection() = default;
@@ -190,7 +155,43 @@ std::vector<uint8_t> ClientConnection::IVs(int cipherIndex) · 67 unmodified lines
190 155
191void ClientConnection::Start()156void ClientConnection::Start()
192{157{
193 158 // Attempt to lookup remote connection identification for logging purposes
159 auto remoteEndPoint = m_commandChannelSocket.remote_endpoint();
160 m_ipAddress = remoteEndPoint.address();
161
162 if (remoteEndPoint.protocol() == tcp::v6())
163 m_connectionID = "[" + m_ipAddress.to_string() + "]:" + ToString(remoteEndPoint.port());
164 else
165 m_connectionID = m_ipAddress.to_string() + ":" + ToString(remoteEndPoint.port());
166
167 try
168 {
169 DnsResolver resolver(m_commandChannelService);
170 const DnsResolver::query query(m_ipAddress.to_string(), ToString(remoteEndPoint.port()));
171 DnsResolver::iterator iterator = resolver.resolve(query);
172 const DnsResolver::iterator end;
173
174 while (iterator != end)
175 {
176 auto endPoint = *iterator++;
177
178 if (!endPoint.host_name().empty())
179 {
180 m_hostName = endPoint.host_name();
181 m_connectionID = m_hostName + " (" + m_connectionID + ")";
182 break;
183 }
184 }
185 }
186 catch (...)
187 { //-V565
188 // DNS lookup failure is not a catastrophe
189 }
190
191 if (m_hostName.empty())
192 m_hostName = m_ipAddress.to_string();
193
194 m_pingTimer.Start();
194}195}
195 196
196void ClientConnection::CommandChannelSendAsync(uint8_t* data, uint32_t offset, uint32_t length)197void ClientConnection::CommandChannelSendAsync(uint8_t* data, uint32_t offset, uint32_t length)
@@ -241,7 +242,6 @@ DataPublisher::DataPublisher(const TcpEndPoint& endpoint) : · 44 unmodified lines
241 m_errorMessageCallback(nullptr),242 m_errorMessageCallback(nullptr),
242 m_clientConnectedCallback(nullptr)243 m_clientConnectedCallback(nullptr)
243{244{
244 m_commandChannelService.restart();
245 m_callbackThread = Thread(bind(&DataPublisher::RunCallbackThread, this));245 m_callbackThread = Thread(bind(&DataPublisher::RunCallbackThread, this));
246 m_commandChannelAcceptThread = Thread(bind(&DataPublisher::RunCommandChannelAcceptThread, this));246 m_commandChannelAcceptThread = Thread(bind(&DataPublisher::RunCommandChannelAcceptThread, this));
247}247}
@@ -253,6 +253,13 @@ DataPublisher::DataPublisher(uint16_t port, bool ipV6) : · 5 unmodified lines
253 253
254DataPublisher::~DataPublisher() = default;254DataPublisher::~DataPublisher() = default;
255 255
256DataPublisher::CallbackDispatcher::CallbackDispatcher() :
257 Source(nullptr),
258 Data(nullptr),
259 Function(nullptr)
260{
261}
262
256void DataPublisher::RunCallbackThread()263void DataPublisher::RunCallbackThread()
257{264{
258 while (true)265 while (true)
@@ -346,8 +353,8 @@ void DataPublisher::HandleMetadataRefresh(const ClientConnectionPtr& connection, · 87 unmodified lines
346 353
347 if (rowCount > 0)354 if (rowCount > 0)
348 {355 {
349 const auto elapsedTime = (UtcNow() - startTime).total_seconds();356 const TimeSpan elapsedTime = UtcNow() - startTime;
350 DispatchStatusMessage(ToString(rowCount) + " records spanning " + ToString(tables.size()) + " tables of meta-data prepared in " + ToString(elapsedTime) + " seconds, sending response to " + connection->GetConnectionID() + "...");357 DispatchStatusMessage(ToString(rowCount) + " records spanning " + ToString(tables.size()) + " tables of meta-data prepared in " + ToString(elapsedTime) + ", sending response to " + connection->GetConnectionID() + "...");
351 }358 }
352 else359 else
353 {360 {
Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.h+3−0
@@ -65,6 +65,7 @@ namespace Transport · 64 unmodified lines
65 {65 {
66 private:66 private:
67 const DataPublisherPtr m_parent;67 const DataPublisherPtr m_parent;
68 GSF::IOContext& m_commandChannelService;
68 GSF::Guid m_subscriberID;69 GSF::Guid m_subscriberID;
69 std::string m_connectionID;70 std::string m_connectionID;
70 uint32_t m_operationalModes;71 uint32_t m_operationalModes;
@@ -273,6 +274,8 @@ namespace Transport · 202 unmodified lines
273 274
274 friend class ClientConnection;275 friend class ClientConnection;
275 };276 };
277
278 typedef SharedPtr<DataPublisher> DataPublisherPtr;
276}}}279}}}
277 280
278#endif281#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t