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 | 184 | // Callback which is called when the subscriber has |
| 185 | 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 | 188 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; |
| 189 | 189 | const size_t MaxTimestampSize = 80; |
| 190 | 190 | |
| 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); | |
| 193 | 196 | |
| 194 | − char timestamp[MaxTimestampSize]; | |
| 197 | + processCount += measurementCount; | |
| 195 | 198 | |
| 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) | |
| 199 | 201 | { |
| 200 | − cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | |
| 202 | + stringstream message; | |
| 201 | 203 | |
| 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; | |
| 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) | |
| 210 | − cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl; | |
| 209 | + message << "Point\tValue" << endl; | |
| 211 | 210 | |
| 212 | − cout << endl; | |
| 213 | − } | |
| 214 | − } | |
| 211 | + for (const auto& measurement : measurements) | |
| 212 | + message << measurement->ID << '\t' << measurement->Value << endl; | |
| 213 | + | |
| 214 | + message << endl; | |
| 215 | 215 | |
| 216 | − ++processCount; | |
| 216 | + cout << message.str(); | |
| 217 | + } | |
| 217 | 218 | } |
| 218 | 219 | |
| 219 | 220 | // Callback that is called when the subscriber auto-reconnects. |