Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples (1 of 7 files). Show all
Unified · Split
| @@ -23,9 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | #include <iostream> |
| 25 | 25 | #include <string> |
| 26 | −#include <vector> | |
| 27 | 26 | |
| 28 | −#include "../Common/Convert.h" | |
| 29 | 27 | #include "../Transport/DataPublisher.h" |
| 30 | 28 | |
| 31 | 29 | using namespace std; |
| @@ -33,7 +31,7 @@ using namespace GSF; · 1 unmodified line | ||
| 33 | 31 | using namespace GSF::TimeSeries; |
| 34 | 32 | using namespace GSF::TimeSeries::Transport; |
| 35 | 33 | |
| 36 | −DataPublisher Subscriber; | |
| 34 | +DataPublisherPtr Publisher; | |
| 37 | 35 | |
| 38 | 36 | bool RunPublisher(uint16_t port); |
| 39 | 37 | //void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements); |
| @@ -86,27 +84,15 @@ int main(int argc, char* argv[]) · 46 unmodified lines | ||
| 86 | 84 | // - Publish |
| 87 | 85 | bool RunPublisher(uint16_t port) |
| 88 | 86 | { |
| 89 | − // SubscriptionInfo is a helper object which allows the user | |
| 90 | − // to set up their subscription and reuse subscription settings. | |
| 91 | − //SubscriptionInfo info; | |
| 92 | − //info.FilterExpression = "PPA:1;PPA:2;PPA:3;PPA:4;PPA:5;PPA:6;PPA:7;PPA:8;PPA:9;PPA:10;PPA:11;PPA:12;PPA:13;PPA:14"; | |
| 93 | − | |
| 94 | − // Register callbacks | |
| 95 | − Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage); | |
| 96 | − Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage); | |
| 97 | − //Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements); | |
| 98 | − | |
| 99 | − cout << endl << "Listening on port: " << port << "..." << endl << endl; | |
| 100 | − | |
| 101 | 87 | string errorMessage; |
| 102 | 88 | bool connected = false; |
| 103 | 89 | |
| 104 | 90 | try |
| 105 | 91 | { |
| 106 | − //Subscriber.Connect(hostname, port); | |
| 92 | + Publisher = NewSharedPtr<DataPublisher>(port); | |
| 107 | 93 | connected = true; |
| 108 | 94 | } |
| 109 | − catch (SubscriberException& ex) | |
| 95 | + catch (PublisherException& ex) | |
| 110 | 96 | { |
| 111 | 97 | errorMessage = ex.what(); |
| 112 | 98 | } |
| @@ -116,57 +102,60 @@ bool RunPublisher(uint16_t port) · 3 unmodified lines | ||
| 116 | 102 | } |
| 117 | 103 | catch (...) |
| 118 | 104 | { |
| 119 | − errorMessage = current_exception_diagnostic_information(true); | |
| 105 | + errorMessage = boost::current_exception_diagnostic_information(true); | |
| 120 | 106 | } |
| 121 | 107 | |
| 122 | 108 | if (connected) |
| 123 | 109 | { |
| 124 | − cout << "Connected! Subscribing to data..." << endl << endl; | |
| 125 | − Subscriber.Subscribe(info); | |
| 110 | + cout << endl << "Listening on port: " << port << "..." << endl << endl; | |
| 111 | + | |
| 112 | + // Register callbacks | |
| 113 | + Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); | |
| 114 | + Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); | |
| 126 | 115 | } |
| 127 | 116 | else |
| 128 | 117 | { |
| 129 | − cerr << "Failed to connect to \"" << hostname << ":" << port << "\": " << errorMessage; | |
| 118 | + cerr << "Failed to listen on port: " << port << ": " << errorMessage; | |
| 130 | 119 | } |
| 131 | 120 | |
| 132 | 121 | return connected; |
| 133 | 122 | } |
| 134 | 123 | |
| 135 | −// Callback which is called when the subscriber has | |
| 136 | −// received a new packet of measurements from the publisher. | |
| 137 | −void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements) | |
| 138 | −{ | |
| 139 | − const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | |
| 140 | − const uint32_t MaxTimestampSize = 80; | |
| 141 | − | |
| 142 | − static long processCount = 0; | |
| 143 | − static char timestamp[MaxTimestampSize]; | |
| 144 | − static const long interval = 5 * 60; | |
| 145 | − const long measurementCount = measurements.size(); | |
| 146 | − const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval); | |
| 147 | − | |
| 148 | − processCount += measurementCount; | |
| 149 | − | |
| 150 | − // Only display messages every few seconds | |
| 151 | − if (showMessage) | |
| 152 | − { | |
| 153 | − stringstream message; | |
| 154 | − | |
| 155 | − message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | |
| 156 | − | |
| 157 | − if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) | |
| 158 | − message << "Timestamp: " << string(timestamp) << endl; | |
| 159 | − | |
| 160 | − message << "Point\tValue" << endl; | |
| 161 | − | |
| 162 | − for (const auto& measurement : measurements) | |
| 163 | − message << measurement->ID << '\t' << measurement->Value << endl; | |
| 164 | − | |
| 165 | − message << endl; | |
| 166 | − | |
| 167 | − cout << message.str(); | |
| 168 | − } | |
| 169 | −} | |
| 124 | +//// Callback which is called when the subscriber has | |
| 125 | +//// received a new packet of measurements from the publisher. | |
| 126 | +//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements) | |
| 127 | +//{ | |
| 128 | +// const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | |
| 129 | +// const uint32_t MaxTimestampSize = 80; | |
| 130 | +// | |
| 131 | +// static long processCount = 0; | |
| 132 | +// static char timestamp[MaxTimestampSize]; | |
| 133 | +// static const long interval = 5 * 60; | |
| 134 | +// const long measurementCount = measurements.size(); | |
| 135 | +// const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval); | |
| 136 | +// | |
| 137 | +// processCount += measurementCount; | |
| 138 | +// | |
| 139 | +// // Only display messages every few seconds | |
| 140 | +// if (showMessage) | |
| 141 | +// { | |
| 142 | +// stringstream message; | |
| 143 | +// | |
| 144 | +// message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | |
| 145 | +// | |
| 146 | +// if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) | |
| 147 | +// message << "Timestamp: " << string(timestamp) << endl; | |
| 148 | +// | |
| 149 | +// message << "Point\tValue" << endl; | |
| 150 | +// | |
| 151 | +// for (const auto& measurement : measurements) | |
| 152 | +// message << measurement->ID << '\t' << measurement->Value << endl; | |
| 153 | +// | |
| 154 | +// message << endl; | |
| 155 | +// | |
| 156 | +// cout << message.str(); | |
| 157 | +// } | |
| 158 | +//} | |
| 170 | 159 | |
| 171 | 160 | // Callback which is called to display status messages from the subscriber. |
| 172 | 161 | void DisplayStatusMessage(DataPublisher* source, const string& message) |