Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AdvancedSubscribe.cpp (1 of 22 files). Show all
Unified · Split
| @@ -183,37 +183,38 @@ void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, u · 182 unmodified lines | |||
| 183 | 183 | ||
| 184 | // Callback which is called when the subscriber has | 184 | // Callback which is called when the subscriber has |
| 185 | // received a new packet of measurements from the publisher. | 185 | // 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) |
| 187 | { | 187 | { |
| 188 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | 188 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; |
| 189 | const size_t MaxTimestampSize = 80; | 189 | const size_t MaxTimestampSize = 80; |
| 190 | 190 | ||
| 191 | static int processCount = 0; | 191 | static long processCount = 0; |
| 192 | size_t i; | 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); | ||
| 193 | 196 | ||
| 194 | char timestamp[MaxTimestampSize]; | 197 | processCount += measurementCount; |
| 195 | 198 | ||
| 196 | // Only display messages every five | 199 | // Only display messages every few seconds |
| 197 | // seconds (assuming 30 calls per second). | 200 | if (showMessage) |
| 198 | if (processCount % 150 == 0) | ||
| 199 | { | 201 | { |
| 200 | cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | 202 | stringstream message; |
| 201 | 203 | ||
| 202 | if (!newMeasurements.empty()) | 204 | message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; |
| 203 | { | ||
| 204 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp)) | ||
| 205 | cout << "Timestamp: " << string(timestamp) << endl; | ||
| 206 | 205 | ||
| 207 | cout << "Point\tValue" << endl; | 206 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) |
| 207 | message << "Timestamp: " << string(timestamp) << endl; | ||
| 208 | 208 | ||
| 209 | for (i = 0; i < newMeasurements.size(); ++i) | 209 | message << "Point\tValue" << endl; |
| 210 | cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl; | ||
| 211 | 210 | ||
| 212 | cout << endl; | 211 | for (const auto& measurement : measurements) |
| 213 | } | 212 | message << measurement->ID << '\t' << measurement->Value << endl; |
| 214 | } | 213 | |
| 214 | message << endl; | ||
| 215 | 215 | ||
| 216 | ++processCount; | 216 | cout << message.str(); |
| 217 | } | ||
| 217 | } | 218 | } |
| 218 | 219 | ||
| 219 | // Callback that is called when the subscriber auto-reconnects. | 220 | // Callback that is called when the subscriber auto-reconnects. |