Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples (3 of 8 files). Show all
Unified · Split
| @@ -22,15 +22,15 @@ · 21 unmodified lines | ||
| 22 | 22 | //****************************************************************************************************** |
| 23 | 23 | |
| 24 | 24 | #include <iostream> |
| 25 | − | |
| 26 | −#include "../Common/Convert.h" | |
| 27 | 25 | #include "SubscriberHandler.h" |
| 26 | +#include "../Common/Convert.h" | |
| 28 | 27 | |
| 29 | 28 | using namespace std; |
| 30 | 29 | using namespace GSF; |
| 30 | +using namespace GSF::TimeSeries; | |
| 31 | +using namespace GSF::TimeSeries::Transport; | |
| 31 | 32 | |
| 32 | 33 | #define TotalInstances 3 |
| 33 | − | |
| 34 | 34 | SubscriberHandler* Subscriber[TotalInstances]; |
| 35 | 35 | |
| 36 | 36 | int main(int argc, char* argv[]) |
| @@ -55,7 +55,6 @@ int main(int argc, char* argv[]) · 18 unmodified lines | ||
| 55 | 55 | for (uint32_t i = 0; i < TotalInstances; i++) |
| 56 | 56 | { |
| 57 | 57 | SubscriberHandler* subscriber = new SubscriberHandler("Subscriber " + ToString(i + 1)); |
| 58 | − | |
| 59 | 58 | subscriber->Initialize(hostname, port); |
| 60 | 59 | |
| 61 | 60 | switch (i) |
| @@ -87,13 +86,14 @@ int main(int argc, char* argv[]) · 25 unmodified lines | ||
| 87 | 86 | |
| 88 | 87 | // Shutdown subscriber instances |
| 89 | 88 | for (uint32_t i = 0; i < TotalInstances; i++) |
| 90 | − { | |
| 91 | 89 | Subscriber[i]->Disconnect(); |
| 92 | − delete Subscriber[i]; | |
| 93 | − } | |
| 94 | 90 | |
| 95 | 91 | // Disconnect the subscriber to stop background threads. |
| 96 | 92 | cout << "Disconnected." << endl; |
| 97 | 93 | |
| 94 | + // Delete subscriber instances | |
| 95 | + for (uint32_t i = 0; i < TotalInstances; i++) | |
| 96 | + delete Subscriber[i]; | |
| 97 | + | |
| 98 | 98 | return 0; |
| 99 | 99 | } |
| @@ -31,12 +31,18 @@ · 30 unmodified lines | ||
| 31 | 31 | using namespace std; |
| 32 | 32 | using namespace GSF; |
| 33 | 33 | using namespace GSF::TimeSeries; |
| 34 | +using namespace GSF::TimeSeries::Transport; | |
| 34 | 35 | |
| 35 | −SubscriberHandler::SubscriberHandler(const string& name) : | |
| 36 | − m_name(name) | |
| 36 | +SubscriberHandler::SubscriberHandler(string name) : | |
| 37 | + m_name(std::move(name)) | |
| 37 | 38 | { |
| 38 | 39 | } |
| 39 | 40 | |
| 41 | +SubscriberHandler::~SubscriberHandler() | |
| 42 | +{ | |
| 43 | + cout << "Calling " << m_name << " destructor..."; | |
| 44 | +} | |
| 45 | + | |
| 40 | 46 | SubscriptionInfo SubscriberHandler::CreateSubscriptionInfo() |
| 41 | 47 | { |
| 42 | 48 | SubscriptionInfo info = SubscriberInstance::CreateSubscriptionInfo(); |
| @@ -63,6 +69,12 @@ SubscriptionInfo SubscriberHandler::CreateSubscriptionInfo() · 20 unmodified lines | ||
| 63 | 69 | return info; |
| 64 | 70 | } |
| 65 | 71 | |
| 72 | +void SubscriberHandler::SetupSubscriberConnector(SubscriberConnector& connector) | |
| 73 | +{ | |
| 74 | + // TODO: Modify connector properties as desired... | |
| 75 | + //connector.SetMaxRetries(-1); | |
| 76 | +} | |
| 77 | + | |
| 66 | 78 | void SubscriberHandler::StatusMessage(const string& message) |
| 67 | 79 | { |
| 68 | 80 | // TODO: Make sure these messages get logged to an appropriate location |
| @@ -71,7 +83,9 @@ void SubscriberHandler::StatusMessage(const string& message) · 2 unmodified lines | ||
| 71 | 83 | |
| 72 | 84 | status << "[" << m_name << "] " << message; |
| 73 | 85 | |
| 86 | + m_coutLock.lock(); | |
| 74 | 87 | SubscriberInstance::StatusMessage(status.str()); |
| 88 | + m_coutLock.unlock(); | |
| 75 | 89 | } |
| 76 | 90 | |
| 77 | 91 | void SubscriberHandler::ErrorMessage(const string& message) |
| @@ -82,12 +96,19 @@ void SubscriberHandler::ErrorMessage(const string& message) · 4 unmodified lines | ||
| 82 | 96 | |
| 83 | 97 | status << "[" << m_name << "] " << message; |
| 84 | 98 | |
| 99 | + m_coutLock.lock(); | |
| 85 | 100 | SubscriberInstance::ErrorMessage(status.str()); |
| 101 | + m_coutLock.unlock(); | |
| 86 | 102 | } |
| 87 | 103 | |
| 88 | 104 | void SubscriberHandler::DataStartTime(time_t unixSOC, uint16_t milliseconds) |
| 89 | 105 | { |
| 90 | − // TODO: This reports timestamp of very first received measurement (if useful) | |
| 106 | + // TODO: This reports timestamp, time_t format, of very first received measurement (if useful) | |
| 107 | +} | |
| 108 | + | |
| 109 | +void SubscriberHandler::DataStartTime(DateTime startTime) | |
| 110 | +{ | |
| 111 | + // TODO: This reports timestamp, ptime format, of very first received measurement (if useful) | |
| 91 | 112 | } |
| 92 | 113 | |
| 93 | 114 | void SubscriberHandler::ReceivedMetadata(const vector<uint8_t>& payload) |
| @@ -167,16 +188,16 @@ void SubscriberHandler::ReceivedNewMeasurements(const vector<MeasurementPtr>& me · 73 unmodified lines | ||
| 167 | 188 | message << GetTotalMeasurementsReceived() << " measurements received so far..." << endl; |
| 168 | 189 | |
| 169 | 190 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) |
| 170 | − message << string(timestamp); | |
| 191 | + message << string(timestamp) << endl; | |
| 171 | 192 | |
| 172 | 193 | message << "Signal ID: " << boost::lexical_cast<string>(measurements[0]->SignalID) << endl; |
| 173 | 194 | |
| 174 | − message << "Point\tValue" << endl; | |
| 195 | + message << "\tPoint\tValue" << endl; | |
| 175 | 196 | |
| 176 | 197 | for (const auto& measurement : measurements) |
| 177 | − message << '\t' << measurement->ID << '\t' << measurement->Value; | |
| 198 | + message << '\t' << measurement->ID << '\t' << measurement->Value << endl; | |
| 178 | 199 | |
| 179 | − message << '\t' << GetTotalMeasurementsReceived() << endl; | |
| 200 | + message << "Total measurements: " << GetTotalMeasurementsReceived() << endl; | |
| 180 | 201 | |
| 181 | 202 | StatusMessage(message.str()); |
| 182 | 203 | } |
| @@ -200,4 +221,4 @@ void SubscriberHandler::ConnectionEstablished() · 17 unmodified lines | ||
| 200 | 221 | void SubscriberHandler::ConnectionTerminated() |
| 201 | 222 | { |
| 202 | 223 | StatusMessage("Connection terminated."); |
| 203 | −} | |
| 224 | +} | |
| @@ -24,24 +24,24 @@ · 23 unmodified lines | ||
| 24 | 24 | #ifndef __SUBSCRIBER_HANDLER_H |
| 25 | 25 | #define __SUBSCRIBER_HANDLER_H |
| 26 | 26 | |
| 27 | +#include "../Common/CommonTypes.h" | |
| 27 | 28 | #include "../Transport/SubscriberInstance.h" |
| 28 | 29 | |
| 29 | −using namespace std; | |
| 30 | −using namespace GSF::TimeSeries; | |
| 31 | −using namespace GSF::TimeSeries::Transport; | |
| 32 | − | |
| 33 | −class SubscriberHandler : public SubscriberInstance | |
| 30 | +class SubscriberHandler : public GSF::TimeSeries::Transport::SubscriberInstance | |
| 34 | 31 | { |
| 35 | 32 | private: |
| 36 | − string m_name; | |
| 33 | + std::string m_name; | |
| 34 | + GSF::Mutex m_coutLock; | |
| 37 | 35 | |
| 38 | 36 | protected: |
| 39 | − SubscriptionInfo CreateSubscriptionInfo() override; | |
| 40 | − void StatusMessage(const string& message) override; | |
| 41 | − void ErrorMessage(const string& message) override; | |
| 37 | + GSF::TimeSeries::Transport::SubscriptionInfo CreateSubscriptionInfo() override; | |
| 38 | + void SetupSubscriberConnector(GSF::TimeSeries::Transport::SubscriberConnector& connector) override; | |
| 39 | + void StatusMessage(const std::string& message) override; | |
| 40 | + void ErrorMessage(const std::string& message) override; | |
| 42 | 41 | void DataStartTime(time_t unixSOC, uint16_t milliseconds) override; |
| 43 | − void ReceivedMetadata(const vector<uint8_t>& payload) override; | |
| 44 | − void ReceivedNewMeasurements(const vector<MeasurementPtr>& measurements) override; | |
| 42 | + void DataStartTime(GSF::DateTime startTime) override; | |
| 43 | + void ReceivedMetadata(const std::vector<uint8_t>& payload) override; | |
| 44 | + void ReceivedNewMeasurements(const std::vector<GSF::TimeSeries::MeasurementPtr>& measurements) override; | |
| 45 | 45 | void ParsedMetadata() override; |
| 46 | 46 | void ConfigurationChanged() override; |
| 47 | 47 | void HistoricalReadComplete() override; |
| @@ -49,7 +49,10 @@ protected: · 1 unmodified line | ||
| 49 | 49 | void ConnectionTerminated() override; |
| 50 | 50 | |
| 51 | 51 | public: |
| 52 | − SubscriberHandler(const string& name); | |
| 52 | + SubscriberHandler(std::string name); | |
| 53 | + ~SubscriberHandler(); | |
| 53 | 54 | }; |
| 54 | 55 | |
| 56 | +typedef GSF::SharedPtr<SubscriberHandler> SubscriberHandlerPtr; | |
| 57 | + | |
| 55 | 58 | #endif |