Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AdvancedPublish.cpp (1 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 | } | ||