History

TimeSeriesPlatformLibrary: Added initial implementation of TSSC

J. Ritchie Carroll committed 8 years ago

Commit 782ffc41 parent 0cd889922 files · +1449 −169Browse files

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

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/AdvancedSubscribe.cpp+20−19
@@ -183,37 +183,38 @@ void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, u · 182 unmodified lines
183183
184184 // Callback which is called when the subscriber has
185185 // received a new packet of measurements from the publisher.
186−void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements)
186+void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements)
187187 {
188188 const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
189189 const size_t MaxTimestampSize = 80;
190190
191− static int processCount = 0;
192− size_t i;
191+ static long processCount = 0;
192+ static char timestamp[MaxTimestampSize];
193+ static const long interval = 5 * 60;
194+ const long measurementCount = measurements.size();
195+ const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);
193196
194− char timestamp[MaxTimestampSize];
197+ processCount += measurementCount;
195198
196− // Only display messages every five
197− // seconds (assuming 30 calls per second).
198− if (processCount % 150 == 0)
199+ // Only display messages every few seconds
200+ if (showMessage)
199201 {
200− cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
202+ stringstream message;
201203
202− if (!newMeasurements.empty())
203− {
204− if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp))
205− cout << "Timestamp: " << string(timestamp) << endl;
204+ message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
206205
207− cout << "Point\tValue" << endl;
206+ if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))
207+ message << "Timestamp: " << string(timestamp) << endl;
208208
209− for (i = 0; i < newMeasurements.size(); ++i)
210− cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl;
209+ message << "Point\tValue" << endl;
211210
212− cout << endl;
213− }
214− }
211+ for (const auto& measurement : measurements)
212+ message << measurement->ID << '\t' << measurement->Value << endl;
213+
214+ message << endl;
215215
216− ++processCount;
216+ cout << message.str();
217+ }
217218 }
218219
219220 // Callback that is called when the subscriber auto-reconnects.

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