History

TimeSeriesPlatformLibrary: Updated SimplePublish sample to properly run.

J. Ritchie Carroll committed 7 years ago

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

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp (1 of 7 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp+45−56
@@ -23,9 +23,7 @@ · 22 unmodified lines
2323
2424 #include <iostream>
2525 #include <string>
26−#include <vector>
2726
28−#include "../Common/Convert.h"
2927 #include "../Transport/DataPublisher.h"
3028
3129 using namespace std;
@@ -33,7 +31,7 @@ using namespace GSF; · 1 unmodified line
3331 using namespace GSF::TimeSeries;
3432 using namespace GSF::TimeSeries::Transport;
3533
36−DataPublisher Subscriber;
34+DataPublisherPtr Publisher;
3735
3836 bool RunPublisher(uint16_t port);
3937 //void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements);
@@ -86,27 +84,15 @@ int main(int argc, char* argv[]) · 46 unmodified lines
8684 // - Publish
8785 bool RunPublisher(uint16_t port)
8886 {
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−
10187 string errorMessage;
10288 bool connected = false;
10389
10490 try
10591 {
106− //Subscriber.Connect(hostname, port);
92+ Publisher = NewSharedPtr<DataPublisher>(port);
10793 connected = true;
10894 }
109− catch (SubscriberException& ex)
95+ catch (PublisherException& ex)
11096 {
11197 errorMessage = ex.what();
11298 }
@@ -116,57 +102,60 @@ bool RunPublisher(uint16_t port) · 3 unmodified lines
116102 }
117103 catch (...)
118104 {
119− errorMessage = current_exception_diagnostic_information(true);
105+ errorMessage = boost::current_exception_diagnostic_information(true);
120106 }
121107
122108 if (connected)
123109 {
124− cout << "Connected! Subscribing to data..." << endl << endl;
125− Subscriber.Subscribe(info);
110+ cout << endl << "Listening on port: " << port << "..." << endl << endl;
111+
112+ // Register callbacks
113+ Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage);
114+ Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage);
126115 }
127116 else
128117 {
129− cerr << "Failed to connect to \"" << hostname << ":" << port << "\": " << errorMessage;
118+ cerr << "Failed to listen on port: " << port << ": " << errorMessage;
130119 }
131120
132121 return connected;
133122 }
134123
135−// Callback which is called when the subscriber has
136−// received a new packet of measurements from the publisher.
137−void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)
138−{
139− const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
140− const uint32_t MaxTimestampSize = 80;
141−
142− static long processCount = 0;
143− static char timestamp[MaxTimestampSize];
144− static const long interval = 5 * 60;
145− const long measurementCount = measurements.size();
146− const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);
147−
148− processCount += measurementCount;
149−
150− // Only display messages every few seconds
151− if (showMessage)
152− {
153− stringstream message;
154−
155− message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
156−
157− if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))
158− message << "Timestamp: " << string(timestamp) << endl;
159−
160− message << "Point\tValue" << endl;
161−
162− for (const auto& measurement : measurements)
163− message << measurement->ID << '\t' << measurement->Value << endl;
164−
165− message << endl;
166−
167− cout << message.str();
168− }
169−}
124+//// Callback which is called when the subscriber has
125+//// received a new packet of measurements from the publisher.
126+//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)
127+//{
128+// const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
129+// const uint32_t MaxTimestampSize = 80;
130+//
131+// static long processCount = 0;
132+// static char timestamp[MaxTimestampSize];
133+// static const long interval = 5 * 60;
134+// const long measurementCount = measurements.size();
135+// const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);
136+//
137+// processCount += measurementCount;
138+//
139+// // Only display messages every few seconds
140+// if (showMessage)
141+// {
142+// stringstream message;
143+//
144+// message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
145+//
146+// if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))
147+// message << "Timestamp: " << string(timestamp) << endl;
148+//
149+// message << "Point\tValue" << endl;
150+//
151+// for (const auto& measurement : measurements)
152+// message << measurement->ID << '\t' << measurement->Value << endl;
153+//
154+// message << endl;
155+//
156+// cout << message.str();
157+// }
158+//}
170159
171160 // Callback which is called to display status messages from the subscriber.
172161 void DisplayStatusMessage(DataPublisher* source, const string& message)

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