Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples (5 of 28 files). Show all
Unified · Split
| @@ -33,21 +33,23 @@ using namespace GSF::TimeSeries::Transport; · 32 unmodified lines | |||
| 33 | using namespace GSF::FilterExpressions; | 33 | using namespace GSF::FilterExpressions; |
| 34 | 34 | ||
| 35 | DataPublisherPtr Publisher; | 35 | DataPublisherPtr Publisher; |
| 36 | TimerPtr PublishTimer; | 36 | TimerPtr PublishTimer, CompletionTimer; |
| 37 | vector<DeviceMetadataPtr> DevicesToPublish; | 37 | vector<DeviceMetadataPtr> DevicesToPublish; |
| 38 | vector<MeasurementMetadataPtr> MeasurementsToPublish; | 38 | vector<MeasurementMetadataPtr> MeasurementsToPublish; |
| 39 | vector<PhasorMetadataPtr> PhasorsToPublish; | 39 | vector<PhasorMetadataPtr> PhasorsToPublish; |
| 40 | 40 | ||
| 41 | bool RunPublisher(uint16_t port); | 41 | bool RunPublisher(uint16_t port); |
| 42 | void DisplayClientConnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID); | 42 | void DisplayClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 43 | void DisplayClientDisconnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID); | 43 | void DisplayClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 44 | void DisplayStatusMessage(DataPublisher* source, const string& message); | 44 | void DisplayStatusMessage(DataPublisher* source, const string& message); |
| 45 | void DisplayErrorMessage(DataPublisher* source, const string& message); | 45 | void DisplayErrorMessage(DataPublisher* source, const string& message); |
| 46 | void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | ||
| 47 | void HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | ||
| 46 | 48 | ||
| 47 | void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<MeasurementMetadataPtr>& measurementMetadata, vector<PhasorMetadataPtr>& phasorMetadata) | 49 | void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<MeasurementMetadataPtr>& measurementMetadata, vector<PhasorMetadataPtr>& phasorMetadata) |
| 48 | { | 50 | { |
| 49 | DeviceMetadataPtr device1Metadata = NewSharedPtr<DeviceMetadata>(); | 51 | DeviceMetadataPtr device1Metadata = NewSharedPtr<DeviceMetadata>(); |
| 50 | const DateTime timestamp = UtcNow(); | 52 | const datetime_t timestamp = UtcNow(); |
| 51 | 53 | ||
| 52 | // Add a device | 54 | // Add a device |
| 53 | device1Metadata->Name = "Test PMU"; | 55 | device1Metadata->Name = "Test PMU"; |
| @@ -210,6 +212,11 @@ bool RunPublisher(uint16_t port) · 156 unmodified lines | |||
| 210 | Publisher->RegisterClientDisconnectedCallback(&DisplayClientDisconnected); | 212 | Publisher->RegisterClientDisconnectedCallback(&DisplayClientDisconnected); |
| 211 | Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); | 213 | Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); |
| 212 | Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); | 214 | Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 215 | Publisher->RegisterTemporalSubscriptionRequestedCallback(&HandleTemporalSubscriptionRequested); | ||
| 216 | Publisher->RegisterTemporalProcessingIntervalChangeRequestedCallback(&HandleTemporalProcessingIntervalChangeRequested); | ||
| 217 | |||
| 218 | // Enable temporal subscription support | ||
| 219 | Publisher->SetSupportsTemporalSubscriptions(true); | ||
| 213 | 220 | ||
| 214 | // Load metadata to be used for publication | 221 | // Load metadata to be used for publication |
| 215 | LoadMetadataToPublish(DevicesToPublish, MeasurementsToPublish, PhasorsToPublish); | 222 | LoadMetadataToPublish(DevicesToPublish, MeasurementsToPublish, PhasorsToPublish); |
| @@ -285,18 +292,18 @@ bool RunPublisher(uint16_t port) · 69 unmodified lines | |||
| 285 | return running; | 292 | return running; |
| 286 | } | 293 | } |
| 287 | 294 | ||
| 288 | void DisplayClientConnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID) | 295 | void DisplayClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 289 | { | 296 | { |
| 290 | cout << ">> New Client Connected:" << endl; | 297 | cout << ">> New Client Connected:" << endl; |
| 291 | cout << " Subscriber ID: " << ToString(subscriberID) << endl; | 298 | cout << " Subscriber ID: " << ToString(connection->GetSubscriberID()) << endl; |
| 292 | cout << " Connection ID: " << connectionID << endl << endl; | 299 | cout << " Connection ID: " << ToString(connection->GetConnectionID()) << endl << endl; |
| 293 | } | 300 | } |
| 294 | 301 | ||
| 295 | void DisplayClientDisconnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID) | 302 | void DisplayClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 296 | { | 303 | { |
| 297 | cout << ">> Client Disconnected:" << endl; | 304 | cout << ">> Client Disconnected:" << endl; |
| 298 | cout << " Subscriber ID: " << ToString(subscriberID) << endl; | 305 | cout << " Subscriber ID: " << ToString(connection->GetSubscriberID()) << endl; |
| 299 | cout << " Connection ID: " << connectionID << endl << endl; | 306 | cout << " Connection ID: " << ToString(connection->GetConnectionID()) << endl << endl; |
| 300 | } | 307 | } |
| 301 | 308 | ||
| 302 | // Callback which is called to display status messages from the subscriber. | 309 | // Callback which is called to display status messages from the subscriber. |
| @@ -309,4 +316,21 @@ void DisplayStatusMessage(DataPublisher* source, const string& message) · 6 unmodified lines | |||
| 309 | void DisplayErrorMessage(DataPublisher* source, const string& message) | 316 | void DisplayErrorMessage(DataPublisher* source, const string& message) |
| 310 | { | 317 | { |
| 311 | cerr << message << endl << endl; | 318 | cerr << message << endl << endl; |
| 312 | } | 319 | } |
| 320 | |||
| 321 | void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) | ||
| 322 | { | ||
| 323 | cout << "Client \"" << connection->GetConnectionID() << "\" with subscriber ID " << ToString(connection->GetSubscriberID()) << " has requested a temporal subscription starting at " << ToString(connection->GetStartTimeConstraint()) << endl << endl; | ||
| 324 | |||
| 325 | CompletionTimer = NewSharedPtr<Timer>(1000, [connection](Timer*, void*) | ||
| 326 | { | ||
| 327 | connection->CompleteTemporalSubscription(); | ||
| 328 | }); | ||
| 329 | |||
| 330 | CompletionTimer->Start(); | ||
| 331 | } | ||
| 332 | |||
| 333 | void HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) | ||
| 334 | { | ||
| 335 | cout << "Client \"" << connection->GetConnectionID() << "\" with subscriber ID " << ToString(connection->GetSubscriberID()) << " has requested to change its temporal processing interval to " << ToString(connection->GetProcessingInterval()) << "ms" << endl << endl; | ||
| 336 | } | ||
| @@ -1177,42 +1177,42 @@ int main(int argc, char* argv[]) · 1176 unmodified lines | |||
| 1177 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-02-04', 2, 'Month')"); | 1177 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-02-04', 2, 'Month')"); |
| 1178 | 1178 | ||
| 1179 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1179 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1180 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 4, 4))); | 1180 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 4, 4))); |
| 1181 | cout << "Test " << ++test << " succeeded..." << endl; | 1181 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1182 | 1182 | ||
| 1183 | // Test 119 | 1183 | // Test 119 |
| 1184 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#1/31/2019#, 1, 'Day')"); | 1184 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#1/31/2019#, 1, 'Day')"); |
| 1185 | 1185 | ||
| 1186 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1186 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1187 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 2, 1))); | 1187 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 2, 1))); |
| 1188 | cout << "Test " << ++test << " succeeded..." << endl; | 1188 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1189 | 1189 | ||
| 1190 | // Test 120 | 1190 | // Test 120 |
| 1191 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2019-01-31#, 2, 'Week')"); | 1191 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2019-01-31#, 2, 'Week')"); |
| 1192 | 1192 | ||
| 1193 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1193 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1194 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 2, 14))); | 1194 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 2, 14))); |
| 1195 | cout << "Test " << ++test << " succeeded..." << endl; | 1195 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1196 | 1196 | ||
| 1197 | // Test 121 | 1197 | // Test 121 |
| 1198 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2019-01-31#, 25, 'Hour')"); | 1198 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2019-01-31#, 25, 'Hour')"); |
| 1199 | 1199 | ||
| 1200 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1200 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1201 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 2, 1), time_duration(1, 0, 0))); | 1201 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 2, 1), time_duration(1, 0, 0))); |
| 1202 | cout << "Test " << ++test << " succeeded..." << endl; | 1202 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1203 | 1203 | ||
| 1204 | // Test 122 | 1204 | // Test 122 |
| 1205 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2018-12-31 23:58#, 3, 'Minute')"); | 1205 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#2018-12-31 23:58#, 3, 'Minute')"); |
| 1206 | 1206 | ||
| 1207 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1207 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1208 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 1, 1), time_duration(0, 1, 0))); | 1208 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 1, 1), time_duration(0, 1, 0))); |
| 1209 | cout << "Test " << ++test << " succeeded..." << endl; | 1209 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1210 | 1210 | ||
| 1211 | // Test 123 | 1211 | // Test 123 |
| 1212 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-01-1 00:59', 61, 'Second')"); | 1212 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-01-1 00:59', 61, 'Second')"); |
| 1213 | 1213 | ||
| 1214 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1214 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1215 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 1, 1), time_duration(1, 0, 1))); | 1215 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 1, 1), time_duration(1, 0, 1))); |
| 1216 | cout << "Test " << ++test << " succeeded..." << endl; | 1216 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1217 | 1217 | ||
| 1218 | const float64_t baseFraction = pow(10.0, time_duration::num_fractional_digits()); | 1218 | const float64_t baseFraction = pow(10.0, time_duration::num_fractional_digits()); |
| @@ -1222,14 +1222,14 @@ int main(int argc, char* argv[]) · 3 unmodified lines | |||
| 1222 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-01-1 00:00:59.999', 2, 'Millisecond')"); | 1222 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd('2019-01-1 00:00:59.999', 2, 'Millisecond')"); |
| 1223 | 1223 | ||
| 1224 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1224 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1225 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 1, 1), time_duration(0, 1, 0, fracSecond(1)))); | 1225 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 1, 1), time_duration(0, 1, 0, fracSecond(1)))); |
| 1226 | cout << "Test " << ++test << " succeeded..." << endl; | 1226 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1227 | 1227 | ||
| 1228 | // Test 125 | 1228 | // Test 125 |
| 1229 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#1/1/2019 0:0:1.029#, -FramesPerSecond, 'Millisecond')"); | 1229 | valueExpression = FilterExpressionParser::Evaluate(dataRow, "DateAdd(#1/1/2019 0:0:1.029#, -FramesPerSecond, 'Millisecond')"); |
| 1230 | 1230 | ||
| 1231 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); | 1231 | assert(valueExpression->ValueType == ExpressionValueType::DateTime); |
| 1232 | assert(valueExpression->ValueAsDateTime() == DateTime(date(2019, 1, 1), time_duration(0, 0, 0, fracSecond(999)))); | 1232 | assert(valueExpression->ValueAsDateTime() == datetime_t(date(2019, 1, 1), time_duration(0, 0, 0, fracSecond(999)))); |
| 1233 | cout << "Test " << ++test << " succeeded..." << endl; | 1233 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1234 | 1234 | ||
| 1235 | // Test 126 | 1235 | // Test 126 |
| @@ -1429,7 +1429,7 @@ int main(int argc, char* argv[]) · 193 unmodified lines | |||
| 1429 | cout << "Test " << ++test << " succeeded..." << endl; | 1429 | cout << "Test " << ++test << " succeeded..." << endl; |
| 1430 | 1430 | ||
| 1431 | // Test 150 | 1431 | // Test 150 |
| 1432 | const DateTime time = ParseTimestamp("2019-02-10T15:55:25.090477Z"); | 1432 | const datetime_t time = ParseTimestamp("2019-02-10T15:55:25.090477Z"); |
| 1433 | const int64_t ticks = ToTicks(time); | 1433 | const int64_t ticks = ToTicks(time); |
| 1434 | 1434 | ||
| 1435 | assert(ticks == 636854109250904770L); | 1435 | assert(ticks == 636854109250904770L); |
| @@ -36,8 +36,8 @@ TimerPtr PublishTimer; · 35 unmodified lines | |||
| 36 | vector<MeasurementMetadataPtr> MeasurementsToPublish; | 36 | vector<MeasurementMetadataPtr> MeasurementsToPublish; |
| 37 | 37 | ||
| 38 | bool RunPublisher(uint16_t port); | 38 | bool RunPublisher(uint16_t port); |
| 39 | void DisplayClientConnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID); | 39 | void DisplayClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 40 | void DisplayClientDisconnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID); | 40 | void DisplayClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 41 | void DisplayStatusMessage(DataPublisher* source, const string& message); | 41 | void DisplayStatusMessage(DataPublisher* source, const string& message); |
| 42 | void DisplayErrorMessage(DataPublisher* source, const string& message); | 42 | void DisplayErrorMessage(DataPublisher* source, const string& message); |
| 43 | 43 | ||
| @@ -168,18 +168,18 @@ bool RunPublisher(uint16_t port) · 124 unmodified lines | |||
| 168 | return running; | 168 | return running; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | void DisplayClientConnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID) | 171 | void DisplayClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 172 | { | 172 | { |
| 173 | cout << ">> New Client Connected:" << endl; | 173 | cout << ">> New Client Connected:" << endl; |
| 174 | cout << " Subscriber ID: " << ToString(subscriberID) << endl; | 174 | cout << " Subscriber ID: " << ToString(connection->GetSubscriberID()) << endl; |
| 175 | cout << " Connection ID: " << connectionID << endl << endl; | 175 | cout << " Connection ID: " << ToString(connection->GetConnectionID()) << endl << endl; |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | void DisplayClientDisconnected(DataPublisher* source, const Guid& subscriberID, const string& connectionID) | 178 | void DisplayClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 179 | { | 179 | { |
| 180 | cout << ">> Client Disconnected:" << endl; | 180 | cout << ">> Client Disconnected:" << endl; |
| 181 | cout << " Subscriber ID: " << ToString(subscriberID) << endl; | 181 | cout << " Subscriber ID: " << ToString(connection->GetSubscriberID()) << endl; |
| 182 | cout << " Connection ID: " << connectionID << endl << endl; | 182 | cout << " Connection ID: " << ToString(connection->GetConnectionID()) << endl << endl; |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | // Callback which is called to display status messages from the subscriber. | 185 | // Callback which is called to display status messages from the subscriber. |
| @@ -192,4 +192,4 @@ void DisplayStatusMessage(DataPublisher* source, const string& message) · 6 unmodified lines | |||
| 192 | void DisplayErrorMessage(DataPublisher* source, const string& message) | 192 | void DisplayErrorMessage(DataPublisher* source, const string& message) |
| 193 | { | 193 | { |
| 194 | cerr << message << endl << endl; | 194 | cerr << message << endl << endl; |
| 195 | } | 195 | } |
| @@ -104,7 +104,7 @@ void SubscriberHandler::DataStartTime(time_t unixSOC, uint16_t milliseconds) · 103 unmodified lines | |||
| 104 | // TODO: This reports timestamp, time_t format, of very first received measurement (if useful) | 104 | // TODO: This reports timestamp, time_t format, of very first received measurement (if useful) |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | void SubscriberHandler::DataStartTime(DateTime startTime) | 107 | void SubscriberHandler::DataStartTime(datetime_t startTime) |
| 108 | { | 108 | { |
| 109 | // TODO: This reports timestamp, ptime format, of very first received measurement (if useful) | 109 | // TODO: This reports timestamp, ptime format, of very first received measurement (if useful) |
| 110 | } | 110 | } |
| @@ -41,7 +41,7 @@ protected: · 40 unmodified lines | |||
| 41 | void StatusMessage(const std::string& message) override; | 41 | void StatusMessage(const std::string& message) override; |
| 42 | void ErrorMessage(const std::string& message) override; | 42 | void ErrorMessage(const std::string& message) override; |
| 43 | void DataStartTime(time_t unixSOC, uint16_t milliseconds) override; | 43 | void DataStartTime(time_t unixSOC, uint16_t milliseconds) override; |
| 44 | void DataStartTime(GSF::DateTime startTime) override; | 44 | void DataStartTime(GSF::datetime_t startTime) override; |
| 45 | void ReceivedMetadata(const std::vector<uint8_t>& payload) override; | 45 | void ReceivedMetadata(const std::vector<uint8_t>& payload) override; |
| 46 | void ReceivedNewMeasurements(const std::vector<GSF::TimeSeries::MeasurementPtr>& measurements) override; | 46 | void ReceivedNewMeasurements(const std::vector<GSF::TimeSeries::MeasurementPtr>& measurements) override; |
| 47 | void ParsedMetadata() override; | 47 | void ParsedMetadata() override; |