Unified · Split
| @@ -417,8 +417,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") · 416 unmodified lines | |||
| 417 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") | 417 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 418 | endif() | 418 | endif() |
| 419 | 419 | ||
| 420 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") | ||
| 421 | |||
| 420 | # Build gsf library | 422 | # Build gsf library |
| 421 | add_library (gsf STATIC ${GSF_SOURCE_FILES}) | 423 | add_library (gsf ${GSF_SOURCE_FILES}) |
| 422 | target_link_libraries (gsf pthread m z bz2 boost_system boost_thread boost_date_time boost_iostreams) | 424 | target_link_libraries (gsf pthread m z bz2 boost_system boost_thread boost_date_time boost_iostreams) |
| 423 | 425 | ||
| 424 | # Install headers and library | 426 | # Install headers and library |
| @@ -80,6 +80,34 @@ bool StringComparer::operator()(const std::string& left, const std::string& righ · 79 unmodified lines | |||
| 80 | return Compare(left, right) < 0; | 80 | return Compare(left, right) < 0; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | uint32_t GSF::WriteBytes(vector<uint8_t>& buffer, const uint8_t* source, const uint32_t offset, const uint32_t length) | ||
| 84 | { | ||
| 85 | for (uint32_t i = 0; i < length; i++) | ||
| 86 | buffer.push_back(source[offset + i]); | ||
| 87 | |||
| 88 | return length; | ||
| 89 | } | ||
| 90 | |||
| 91 | uint32_t GSF::WriteBytes(vector<uint8_t>& buffer, const vector<uint8_t>& source) | ||
| 92 | { | ||
| 93 | const uint32_t length = source.size(); | ||
| 94 | |||
| 95 | for (uint32_t i = 0; i < length; i++) | ||
| 96 | buffer.push_back(source[i]); | ||
| 97 | |||
| 98 | return length; | ||
| 99 | } | ||
| 100 | |||
| 101 | uint32_t GSF::WriteBytes(vector<uint8_t>& buffer, const Guid& value) | ||
| 102 | { | ||
| 103 | const uint8_t* bytes = value.data; | ||
| 104 | |||
| 105 | for (uint32_t i = 0; i < 16; i++) | ||
| 106 | buffer.push_back(bytes[i]); | ||
| 107 | |||
| 108 | return 16; | ||
| 109 | } | ||
| 110 | |||
| 83 | Guid GSF::NewGuid() | 111 | Guid GSF::NewGuid() |
| 84 | { | 112 | { |
| 85 | return RandomGuidGen(); | 113 | return RandomGuidGen(); |
| @@ -333,33 +333,9 @@ namespace GSF · 332 unmodified lines | |||
| 333 | return length; | 333 | return length; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | static uint32_t WriteBytes(std::vector<uint8_t>& buffer, const uint8_t* source, const uint32_t offset, const uint32_t length) | 336 | uint32_t WriteBytes(std::vector<uint8_t>& buffer, const uint8_t* source, const uint32_t offset, const uint32_t length); |
| 337 | { | 337 | uint32_t WriteBytes(std::vector<uint8_t>& buffer, const std::vector<uint8_t>& source); |
| 338 | for (uint32_t i = 0; i < length; i++) | 338 | uint32_t WriteBytes(std::vector<uint8_t>& buffer, const Guid& value); |
| 339 | buffer.push_back(source[offset + i]); | ||
| 340 | |||
| 341 | return length; | ||
| 342 | } | ||
| 343 | |||
| 344 | static uint32_t WriteBytes(std::vector<uint8_t>& buffer, const std::vector<uint8_t>& source) | ||
| 345 | { | ||
| 346 | const uint32_t length = source.size(); | ||
| 347 | |||
| 348 | for (uint32_t i = 0; i < length; i++) | ||
| 349 | buffer.push_back(source[i]); | ||
| 350 | |||
| 351 | return length; | ||
| 352 | } | ||
| 353 | |||
| 354 | static uint32_t WriteBytes(std::vector<uint8_t>& buffer, const Guid& value) | ||
| 355 | { | ||
| 356 | const uint8_t* bytes = value.data; | ||
| 357 | |||
| 358 | for (uint32_t i = 0; i < 16; i++) | ||
| 359 | buffer.push_back(bytes[i]); | ||
| 360 | |||
| 361 | return 16; | ||
| 362 | } | ||
| 363 | 339 | ||
| 364 | Guid NewGuid(); | 340 | Guid NewGuid(); |
| 365 | 341 | ||
| @@ -25,7 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include <iomanip> | 25 | #include <iomanip> |
| 26 | #include <sstream> | 26 | #include <sstream> |
| 27 | #include <locale> | 27 | #include <locale> |
| 28 | #include <codecvt> | 28 | #include <boost/locale.hpp> |
| 29 | #include <boost/uuid/uuid_io.hpp> | 29 | #include <boost/uuid/uuid_io.hpp> |
| 30 | #include <boost/uuid/string_generator.hpp> | 30 | #include <boost/uuid/string_generator.hpp> |
| 31 | #include <boost/date_time/posix_time/posix_time.hpp> | 31 | #include <boost/date_time/posix_time/posix_time.hpp> |
| @@ -36,6 +36,7 @@ · 4 unmodified lines | |||
| 36 | using namespace std; | 36 | using namespace std; |
| 37 | using namespace std::chrono; | 37 | using namespace std::chrono; |
| 38 | using namespace boost::uuids; | 38 | using namespace boost::uuids; |
| 39 | using namespace boost::locale::conv; | ||
| 39 | using namespace boost::posix_time; | 40 | using namespace boost::posix_time; |
| 40 | using namespace boost::gregorian; | 41 | using namespace boost::gregorian; |
| 41 | using namespace GSF; | 42 | using namespace GSF; |
| @@ -270,14 +271,12 @@ std::string GSF::ToString(const TimeSpan& value) · 228 unmodified lines | |||
| 270 | 271 | ||
| 271 | wstring GSF::ToUTF16(const string& value) | 272 | wstring GSF::ToUTF16(const string& value) |
| 272 | { | 273 | { |
| 273 | wstring_convert<codecvt_utf8<wchar_t>, wchar_t> converter; | 274 | return utf_to_utf<wchar_t>(value); |
| 274 | return converter.from_bytes(value); | ||
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | string GSF::ToUTF8(const wstring& value) | 277 | string GSF::ToUTF8(const wstring& value) |
| 278 | { | 278 | { |
| 279 | wstring_convert<codecvt_utf8<wchar_t>, wchar_t> converter; | 279 | return utf_to_utf<char>(value); |
| 280 | return converter.to_bytes(value); | ||
| 281 | } | 280 | } |
| 282 | 281 | ||
| 283 | bool GSF::ParseBoolean(const string& value) | 282 | bool GSF::ParseBoolean(const string& value) |
| @@ -61,6 +61,7 @@ namespace GSF · 60 unmodified lines | |||
| 61 | std::string ToString(const TimeSpan& value); | 61 | std::string ToString(const TimeSpan& value); |
| 62 | 62 | ||
| 63 | std::wstring ToUTF16(const std::string& value); | 63 | std::wstring ToUTF16(const std::string& value); |
| 64 | |||
| 64 | std::string ToUTF8(const std::wstring& value); | 65 | std::string ToUTF8(const std::wstring& value); |
| 65 | 66 | ||
| 66 | // Converts an integer value to a hex representation | 67 | // Converts an integer value to a hex representation |
| @@ -24,6 +24,7 @@ · 23 unmodified lines | |||
| 24 | #ifndef _TIMER_H | 24 | #ifndef _TIMER_H |
| 25 | #define _TIMER_H | 25 | #define _TIMER_H |
| 26 | 26 | ||
| 27 | #include <utility> | ||
| 27 | #include "CommonTypes.h" | 28 | #include "CommonTypes.h" |
| 28 | 29 | ||
| 29 | namespace GSF | 30 | namespace GSF |
| @@ -34,7 +35,7 @@ namespace GSF · 4 unmodified lines | |||
| 34 | class Timer // NOLINT | 35 | class Timer // NOLINT |
| 35 | { | 36 | { |
| 36 | private: | 37 | private: |
| 37 | GSF::Thread* m_timerThread; | 38 | SharedPtr<GSF::Thread> m_timerThread; |
| 38 | GSF::IOContext m_timerContext; | 39 | GSF::IOContext m_timerContext; |
| 39 | boost::asio::deadline_timer m_timer; | 40 | boost::asio::deadline_timer m_timer; |
| 40 | int32_t m_interval; | 41 | int32_t m_interval; |
| @@ -59,7 +60,7 @@ namespace GSF · 18 unmodified lines | |||
| 59 | return; | 60 | return; |
| 60 | 61 | ||
| 61 | // Reset timer thread when context has nothing left to run | 62 | // Reset timer thread when context has nothing left to run |
| 62 | delete m_timerThread; | 63 | m_timerThread.reset(); |
| 63 | m_timerThread = nullptr; | 64 | m_timerThread = nullptr; |
| 64 | 65 | ||
| 65 | // Restart context in preparation for next run | 66 | // Restart context in preparation for next run |
| @@ -82,11 +83,11 @@ namespace GSF · 16 unmodified lines | |||
| 82 | { | 83 | { |
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | Timer(const int32_t interval, const TimerElapsedCallback& callback, const bool autoReset = false) : | 86 | Timer(const int32_t interval, TimerElapsedCallback callback, const bool autoReset = false) : |
| 86 | m_timerThread(nullptr), | 87 | m_timerThread(nullptr), |
| 87 | m_timer(m_timerContext), | 88 | m_timer(m_timerContext), |
| 88 | m_interval(interval), | 89 | m_interval(interval), |
| 89 | m_callback(callback), | 90 | m_callback(std::move(callback)), |
| 90 | m_userData(nullptr), | 91 | m_userData(nullptr), |
| 91 | m_autoReset(autoReset), | 92 | m_autoReset(autoReset), |
| 92 | m_disposing(false) | 93 | m_disposing(false) |
| @@ -96,8 +97,6 @@ namespace GSF · 3 unmodified lines | |||
| 96 | ~Timer() | 97 | ~Timer() |
| 97 | { | 98 | { |
| 98 | m_disposing = true; | 99 | m_disposing = true; |
| 99 | delete m_timerThread; | ||
| 100 | m_timerThread = nullptr; | ||
| 101 | Stop(); | 100 | Stop(); |
| 102 | } | 101 | } |
| 103 | 102 | ||
| @@ -150,7 +149,7 @@ namespace GSF · 46 unmodified lines | |||
| 150 | m_timer.async_wait(boost::bind(&Timer::TimerElaspsed, this, boost::asio::placeholders::error)); | 149 | m_timer.async_wait(boost::bind(&Timer::TimerElaspsed, this, boost::asio::placeholders::error)); |
| 151 | 150 | ||
| 152 | if (m_timerThread == nullptr) | 151 | if (m_timerThread == nullptr) |
| 153 | m_timerThread = new GSF::Thread(boost::bind(&Timer::TimerThread, this)); | 152 | m_timerThread = NewSharedPtr<GSF::Thread>(boost::bind(&Timer::TimerThread, this)); |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | void Stop() | 155 | void Stop() |
| @@ -22,9 +22,9 @@ GSF Library files: · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | Boost Library files: | 23 | Boost Library files: |
| 24 | C:\Projects\boost | 24 | C:\Projects\boost |
| 25 | \boost | 25 | \boost |
| 26 | \libs | 26 | \libs |
| 27 | etc... | 27 | etc... |
| 28 | 28 | ||
| 29 | If you have an existing Boost installation you can simply create a symbolic | 29 | If you have an existing Boost installation you can simply create a symbolic |
| 30 | link to the folder, e.g., mklink /D C:\Projects\boost C:\boost_1_66_0 | 30 | link to the folder, e.g., mklink /D C:\Projects\boost C:\boost_1_66_0 |
| @@ -69,7 +69,7 @@ GNU Make (http://www.gnu.org/software/make/) · 38 unmodified lines | |||
| 69 | 69 | ||
| 70 | zlib Library, e.g.: sudo apt install zlib1g-dev | 70 | zlib Library, e.g.: sudo apt install zlib1g-dev |
| 71 | 71 | ||
| 72 | bzip2 library, e.g.: sudo apt install libbz2-dev | 72 | bzip2 Library, e.g.: sudo apt install libbz2-dev |
| 73 | 73 | ||
| 74 | Boost C++ Libraries v1.66.0 (http://www.boost.org/) | 74 | Boost C++ Libraries v1.66.0 (http://www.boost.org/) |
| 75 | - Boost.Asio | 75 | - Boost.Asio |
| @@ -98,6 +98,9 @@ and type the following command. · 22 unmodified lines | |||
| 98 | Using the CMake GUI, you can modify configuration options, such as | 98 | Using the CMake GUI, you can modify configuration options, such as |
| 99 | building as a shared library or changing the installation directory. | 99 | building as a shared library or changing the installation directory. |
| 100 | 100 | ||
| 101 | To make a debug build, use the following: | ||
| 102 | |||
| 103 | cmake -DCMAKE_BUILD_TYPE=Debug | ||
| 101 | 104 | ||
| 102 | 3. Build | 105 | 3. Build |
| 103 | -------- | 106 | -------- |
| @@ -44,7 +44,7 @@ void DisplayClientDisconnected(DataPublisher* source, const SubscriberConnection · 43 unmodified lines | |||
| 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); | 46 | void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 47 | void HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | 47 | void HandleProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 48 | 48 | ||
| 49 | void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<MeasurementMetadataPtr>& measurementMetadata, vector<PhasorMetadataPtr>& phasorMetadata) | 49 | void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<MeasurementMetadataPtr>& measurementMetadata, vector<PhasorMetadataPtr>& phasorMetadata) |
| 50 | { | 50 | { |
| @@ -57,7 +57,7 @@ void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<Mea · 6 unmodified lines | |||
| 57 | device1Metadata->UniqueID = NewGuid(); | 57 | device1Metadata->UniqueID = NewGuid(); |
| 58 | device1Metadata->Longitude = 300; | 58 | device1Metadata->Longitude = 300; |
| 59 | device1Metadata->Latitude = 200; | 59 | device1Metadata->Latitude = 200; |
| 60 | device1Metadata->FramesPerSecond = 1; | 60 | device1Metadata->FramesPerSecond = 30; |
| 61 | device1Metadata->ProtocolName = "GEP"; | 61 | device1Metadata->ProtocolName = "GEP"; |
| 62 | device1Metadata->UpdatedOn = timestamp; | 62 | device1Metadata->UpdatedOn = timestamp; |
| 63 | 63 | ||
| @@ -136,8 +136,8 @@ void LoadMetadataToPublish(vector<DeviceMetadataPtr>& deviceMetadata, vector<Mea · 72 unmodified lines | |||
| 136 | // | 136 | // |
| 137 | // This application accepts the port of the publisher via command line argument, | 137 | // This application accepts the port of the publisher via command line argument, |
| 138 | // starts listening for subscriber connections, the displays summary information | 138 | // starts listening for subscriber connections, the displays summary information |
| 139 | // about the measurements it publishes. It provides fourteen measurements, i.e., | 139 | // about the measurements it publishes. It provides four manually defined |
| 140 | // PPA:1 through PPA:14 | 140 | // measurements, i.e., PPA:1 through PPA:4 |
| 141 | // | 141 | // |
| 142 | // Measurements are transmitted via the TCP command channel. | 142 | // Measurements are transmitted via the TCP command channel. |
| 143 | int main(int argc, char* argv[]) | 143 | int main(int argc, char* argv[]) |
| @@ -213,9 +213,9 @@ bool RunPublisher(uint16_t port) · 69 unmodified lines | |||
| 213 | Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); | 213 | Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); |
| 214 | Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); | 214 | Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 215 | Publisher->RegisterTemporalSubscriptionRequestedCallback(&HandleTemporalSubscriptionRequested); | 215 | Publisher->RegisterTemporalSubscriptionRequestedCallback(&HandleTemporalSubscriptionRequested); |
| 216 | Publisher->RegisterTemporalProcessingIntervalChangeRequestedCallback(&HandleTemporalProcessingIntervalChangeRequested); | 216 | Publisher->RegisterProcessingIntervalChangeRequestedCallback(&HandleProcessingIntervalChangeRequested); |
| 217 | 217 | ||
| 218 | // Enable temporal subscription support | 218 | // Enable temporal subscription support - this allows historical data requests as well as real-time |
| 219 | Publisher->SetSupportsTemporalSubscriptions(true); | 219 | Publisher->SetSupportsTemporalSubscriptions(true); |
| 220 | 220 | ||
| 221 | // Load metadata to be used for publication | 221 | // Load metadata to be used for publication |
| @@ -235,7 +235,7 @@ bool RunPublisher(uint16_t port) · 13 unmodified lines | |||
| 235 | { | 235 | { |
| 236 | static uint32_t count = MeasurementsToPublish.size(); | 236 | static uint32_t count = MeasurementsToPublish.size(); |
| 237 | const int64_t timestamp = ToTicks(UtcNow()); | 237 | const int64_t timestamp = ToTicks(UtcNow()); |
| 238 | vector<Measurement> measurements; | 238 | vector<MeasurementPtr> measurements; |
| 239 | 239 | ||
| 240 | measurements.reserve(count); | 240 | measurements.reserve(count); |
| 241 | 241 | ||
| @@ -243,10 +243,10 @@ bool RunPublisher(uint16_t port) · 1 unmodified line | |||
| 243 | for (size_t i = 0; i < count; i++) | 243 | for (size_t i = 0; i < count; i++) |
| 244 | { | 244 | { |
| 245 | const MeasurementMetadataPtr metadata = MeasurementsToPublish[i]; | 245 | const MeasurementMetadataPtr metadata = MeasurementsToPublish[i]; |
| 246 | Measurement measurement; | 246 | MeasurementPtr measurement = NewSharedPtr<Measurement>(); |
| 247 | 247 | ||
| 248 | measurement.SignalID = metadata->SignalID; | 248 | measurement->SignalID = metadata->SignalID; |
| 249 | measurement.Timestamp = timestamp; | 249 | measurement->Timestamp = timestamp; |
| 250 | 250 | ||
| 251 | const float64_t randFraction = rand() / randMax; | 251 | const float64_t randFraction = rand() / randMax; |
| 252 | const float64_t sign = randFraction > 0.5 ? 1.0 : -1.0; | 252 | const float64_t sign = randFraction > 0.5 ? 1.0 : -1.0; |
| @@ -271,7 +271,7 @@ bool RunPublisher(uint16_t port) · 18 unmodified lines | |||
| 271 | break; | 271 | break; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | measurement.Value = value; | 274 | measurement->Value = value; |
| 275 | 275 | ||
| 276 | measurements.push_back(measurement); | 276 | measurements.push_back(measurement); |
| 277 | } | 277 | } |
| @@ -330,7 +330,7 @@ void HandleTemporalSubscriptionRequested(DataPublisher* source, const Subscriber · 52 unmodified lines | |||
| 330 | CompletionTimer->Start(); | 330 | CompletionTimer->Start(); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | void HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) | 333 | void HandleProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 334 | { | 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; | 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 | } | 336 | } |
| @@ -135,7 +135,7 @@ bool RunPublisher(uint16_t port) · 134 unmodified lines | |||
| 135 | { | 135 | { |
| 136 | static uint32_t count = MeasurementsToPublish.size(); | 136 | static uint32_t count = MeasurementsToPublish.size(); |
| 137 | const int64_t timestamp = ToTicks(UtcNow()); | 137 | const int64_t timestamp = ToTicks(UtcNow()); |
| 138 | vector<Measurement> measurements; | 138 | vector<MeasurementPtr> measurements; |
| 139 | 139 | ||
| 140 | measurements.reserve(count); | 140 | measurements.reserve(count); |
| 141 | 141 | ||
| @@ -143,11 +143,11 @@ bool RunPublisher(uint16_t port) · 1 unmodified line | |||
| 143 | for (size_t i = 0; i < count; i++) | 143 | for (size_t i = 0; i < count; i++) |
| 144 | { | 144 | { |
| 145 | const MeasurementMetadataPtr metadata = MeasurementsToPublish[i]; | 145 | const MeasurementMetadataPtr metadata = MeasurementsToPublish[i]; |
| 146 | Measurement measurement; | 146 | MeasurementPtr measurement = NewSharedPtr<Measurement>(); |
| 147 | 147 | ||
| 148 | measurement.SignalID = metadata->SignalID; | 148 | measurement->SignalID = metadata->SignalID; |
| 149 | measurement.Timestamp = timestamp; | 149 | measurement->Timestamp = timestamp; |
| 150 | measurement.Value = float64_t(rand()); | 150 | measurement->Value = float64_t(rand()); |
| 151 | 151 | ||
| 152 | measurements.push_back(measurement); | 152 | measurements.push_back(measurement); |
| 153 | } | 153 | } |
| @@ -178,10 +178,10 @@ void DataPublisher::DispatchTemporalSubscriptionRequested(const SubscriberConnec · 177 unmodified lines | |||
| 178 | Dispatch(&TemporalSubscriptionRequestedDispatcher, reinterpret_cast<uint8_t*>(&connectionReference), 0, sizeof(SubscriberConnection**)); | 178 | Dispatch(&TemporalSubscriptionRequestedDispatcher, reinterpret_cast<uint8_t*>(&connectionReference), 0, sizeof(SubscriberConnection**)); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | void DataPublisher::DispatchTemporalProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection) | 181 | void DataPublisher::DispatchProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection) |
| 182 | { | 182 | { |
| 183 | SubscriberConnection* connectionReference = &*connection; | 183 | SubscriberConnection* connectionReference = &*connection; |
| 184 | Dispatch(&TemporalProcessingIntervalChangeRequestedDispatcher, reinterpret_cast<uint8_t*>(&connectionReference), 0, sizeof(SubscriberConnection**)); | 184 | Dispatch(&ProcessingIntervalChangeRequestedDispatcher, reinterpret_cast<uint8_t*>(&connectionReference), 0, sizeof(SubscriberConnection**)); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | // Dispatcher function for status messages. Decodes the message and provides it to the user via the status message callback. | 187 | // Dispatcher function for status messages. Decodes the message and provides it to the user via the status message callback. |
| @@ -249,13 +249,13 @@ void DataPublisher::TemporalSubscriptionRequestedDispatcher(DataPublisher* sourc · 61 unmodified lines | |||
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | void DataPublisher::TemporalProcessingIntervalChangeRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer) | 252 | void DataPublisher::ProcessingIntervalChangeRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer) |
| 253 | { | 253 | { |
| 254 | SubscriberConnection* connection = *reinterpret_cast<SubscriberConnection**>(const_cast<uint8_t*>(&buffer[0])); | 254 | SubscriberConnection* connection = *reinterpret_cast<SubscriberConnection**>(const_cast<uint8_t*>(&buffer[0])); |
| 255 | 255 | ||
| 256 | if (source != nullptr) | 256 | if (source != nullptr) |
| 257 | { | 257 | { |
| 258 | const SubscriberConnectionCallback temporalProcessingIntervalChangeRequestedCallback = source->m_temporalProcessingIntervalChangeRequestedCallback; | 258 | const SubscriberConnectionCallback temporalProcessingIntervalChangeRequestedCallback = source->m_processingIntervalChangeRequestedCallback; |
| 259 | 259 | ||
| 260 | if (temporalProcessingIntervalChangeRequestedCallback != nullptr) | 260 | if (temporalProcessingIntervalChangeRequestedCallback != nullptr) |
| 261 | temporalProcessingIntervalChangeRequestedCallback(source, connection->GetReference()); | 261 | temporalProcessingIntervalChangeRequestedCallback(source, connection->GetReference()); |
| @@ -880,7 +880,7 @@ void DataPublisher::RegisterTemporalSubscriptionRequestedCallback(const Subscrib · 618 unmodified lines | |||
| 880 | m_temporalSubscriptionRequestedCallback = temporalSubscriptionRequestedCallback; | 880 | m_temporalSubscriptionRequestedCallback = temporalSubscriptionRequestedCallback; |
| 881 | } | 881 | } |
| 882 | 882 | ||
| 883 | void DataPublisher::RegisterTemporalProcessingIntervalChangeRequestedCallback(const SubscriberConnectionCallback& temporalProcessingIntervalChangeRequestedCallback) | 883 | void DataPublisher::RegisterProcessingIntervalChangeRequestedCallback(const SubscriberConnectionCallback& processingIntervalChangeRequestedCallback) |
| 884 | { | 884 | { |
| 885 | m_temporalProcessingIntervalChangeRequestedCallback = temporalProcessingIntervalChangeRequestedCallback; | 885 | m_processingIntervalChangeRequestedCallback = processingIntervalChangeRequestedCallback; |
| 886 | } | 886 | } |
| @@ -104,7 +104,7 @@ namespace Transport · 103 unmodified lines | |||
| 104 | SubscriberConnectionCallback m_clientConnectedCallback; | 104 | SubscriberConnectionCallback m_clientConnectedCallback; |
| 105 | SubscriberConnectionCallback m_clientDisconnectedCallback; | 105 | SubscriberConnectionCallback m_clientDisconnectedCallback; |
| 106 | SubscriberConnectionCallback m_temporalSubscriptionRequestedCallback; | 106 | SubscriberConnectionCallback m_temporalSubscriptionRequestedCallback; |
| 107 | SubscriberConnectionCallback m_temporalProcessingIntervalChangeRequestedCallback; | 107 | SubscriberConnectionCallback m_processingIntervalChangeRequestedCallback; |
| 108 | 108 | ||
| 109 | // Dispatchers | 109 | // Dispatchers |
| 110 | void Dispatch(const DispatcherFunction& function); | 110 | void Dispatch(const DispatcherFunction& function); |
| @@ -114,14 +114,14 @@ namespace Transport · 3 unmodified lines | |||
| 114 | void DispatchClientConnected(const SubscriberConnectionPtr& connection); | 114 | void DispatchClientConnected(const SubscriberConnectionPtr& connection); |
| 115 | void DispatchClientDisconnected(const SubscriberConnectionPtr& connection); | 115 | void DispatchClientDisconnected(const SubscriberConnectionPtr& connection); |
| 116 | void DispatchTemporalSubscriptionRequested(const SubscriberConnectionPtr& connection); | 116 | void DispatchTemporalSubscriptionRequested(const SubscriberConnectionPtr& connection); |
| 117 | void DispatchTemporalProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection); | 117 | void DispatchProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection); |
| 118 | 118 | ||
| 119 | static void StatusMessageDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 119 | static void StatusMessageDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 120 | static void ErrorMessageDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 120 | static void ErrorMessageDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 121 | static void ClientConnectedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 121 | static void ClientConnectedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 122 | static void ClientDisconnectedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 122 | static void ClientDisconnectedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 123 | static void TemporalSubscriptionRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 123 | static void TemporalSubscriptionRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 124 | static void TemporalProcessingIntervalChangeRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); | 124 | static void ProcessingIntervalChangeRequestedDispatcher(DataPublisher* source, const std::vector<uint8_t>& buffer); |
| 125 | static int32_t GetColumnIndex(const GSF::Data::DataTablePtr& table, const std::string& columnName); | 125 | static int32_t GetColumnIndex(const GSF::Data::DataTablePtr& table, const std::string& columnName); |
| 126 | public: | 126 | public: |
| 127 | // Creates a new instance of the data publisher. | 127 | // Creates a new instance of the data publisher. |
| @@ -189,18 +189,18 @@ namespace Transport · 61 unmodified lines | |||
| 189 | // Callback registration | 189 | // Callback registration |
| 190 | // | 190 | // |
| 191 | // Callback functions are defined with the following signatures: | 191 | // Callback functions are defined with the following signatures: |
| 192 | // void ProcessStatusMessage(DataPublisher* source, const string& message) | 192 | // void HandleStatusMessage(DataPublisher* source, const string& message) |
| 193 | // void ProcessErrorMessage(DataPublisher* source, const string& message) | 193 | // void HandleErrorMessage(DataPublisher* source, const string& message) |
| 194 | // void ProcessClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); | 194 | // void HandleClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 195 | // void ProcessClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); | 195 | // void HandleClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 196 | // void ProcessTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | 196 | // void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 197 | // void ProcessTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | 197 | // void HandleProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 198 | void RegisterStatusMessageCallback(const MessageCallback& statusMessageCallback); | 198 | void RegisterStatusMessageCallback(const MessageCallback& statusMessageCallback); |
| 199 | void RegisterErrorMessageCallback(const MessageCallback& errorMessageCallback); | 199 | void RegisterErrorMessageCallback(const MessageCallback& errorMessageCallback); |
| 200 | void RegisterClientConnectedCallback(const SubscriberConnectionCallback& clientConnectedCallback); | 200 | void RegisterClientConnectedCallback(const SubscriberConnectionCallback& clientConnectedCallback); |
| 201 | void RegisterClientDisconnectedCallback(const SubscriberConnectionCallback& clientDisconnectedCallback); | 201 | void RegisterClientDisconnectedCallback(const SubscriberConnectionCallback& clientDisconnectedCallback); |
| 202 | void RegisterTemporalSubscriptionRequestedCallback(const SubscriberConnectionCallback& temporalSubscriptionRequestedCallback); | 202 | void RegisterTemporalSubscriptionRequestedCallback(const SubscriberConnectionCallback& temporalSubscriptionRequestedCallback); |
| 203 | void RegisterTemporalProcessingIntervalChangeRequestedCallback(const SubscriberConnectionCallback& temporalProcessingIntervalChangeRequestedCallback); | 203 | void RegisterProcessingIntervalChangeRequestedCallback(const SubscriberConnectionCallback& processingIntervalChangeRequestedCallback); |
| 204 | 204 | ||
| 205 | friend class SubscriberConnection; | 205 | friend class SubscriberConnection; |
| 206 | }; | 206 | }; |
| @@ -264,14 +264,14 @@ namespace Transport · 263 unmodified lines | |||
| 264 | // Callback registration | 264 | // Callback registration |
| 265 | // | 265 | // |
| 266 | // Callback functions are defined with the following signatures: | 266 | // Callback functions are defined with the following signatures: |
| 267 | // void ProcessStatusMessage(DataSubscriber* source, const string& message) | 267 | // void HandleStatusMessage(DataSubscriber* source, const string& message) |
| 268 | // void ProcessErrorMessage(DataSubscriber* source, const string& message) | 268 | // void HandleErrorMessage(DataSubscriber* source, const string& message) |
| 269 | // void ProcessDataStartTime(DataSubscriber* source, int64_t startTime) | 269 | // void HandleDataStartTime(DataSubscriber* source, int64_t startTime) |
| 270 | // void ProcessMetadata(DataSubscriber* source, const vector<uint8_t>& metadata) | 270 | // void HandleMetadata(DataSubscriber* source, const vector<uint8_t>& metadata) |
| 271 | // void ProcessNewMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements) | 271 | // void HandleNewMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements) |
| 272 | // void ProcessProcessingComplete(DataSubscriber* source, const string& message) | 272 | // void HandleProcessingComplete(DataSubscriber* source, const string& message) |
| 273 | // void ProcessConfigurationChanged(DataSubscriber* source) | 273 | // void HandleConfigurationChanged(DataSubscriber* source) |
| 274 | // void ProcessConnectionTerminated(DataSubscriber* source) | 274 | // void HandleConnectionTerminated(DataSubscriber* source) |
| 275 | // | 275 | // |
| 276 | // Metadata is provided to the user as zlib-compressed XML, | 276 | // Metadata is provided to the user as zlib-compressed XML, |
| 277 | // and must be decompressed and interpreted before it can be used. | 277 | // and must be decompressed and interpreted before it can be used. |
| @@ -75,10 +75,10 @@ void PublisherInstance::HandleTemporalSubscriptionRequested(DataPublisher* sourc · 74 unmodified lines | |||
| 75 | instance->TemporalSubscriptionRequested(connection); | 75 | instance->TemporalSubscriptionRequested(connection); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | void PublisherInstance::HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) | 78 | void PublisherInstance::HandleProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection) |
| 79 | { | 79 | { |
| 80 | PublisherInstance* instance = static_cast<PublisherInstance*>(source->GetUserData()); | 80 | PublisherInstance* instance = static_cast<PublisherInstance*>(source->GetUserData()); |
| 81 | instance->TemporalProcessingIntervalChangeRequested(connection); | 81 | instance->ProcessingIntervalChangeRequested(connection); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | void PublisherInstance::StatusMessage(const string& message) | 84 | void PublisherInstance::StatusMessage(const string& message) |
| @@ -106,7 +106,7 @@ void PublisherInstance::TemporalSubscriptionRequested(const SubscriberConnection · 21 unmodified lines | |||
| 106 | cout << "Client \"" << connection->GetConnectionID() << "\" with subscriber ID " << ToString(connection->GetSubscriberID()) << " has requested a temporal subscription starting at " << ToString(connection->GetStartTimeConstraint()) << endl << endl; | 106 | cout << "Client \"" << connection->GetConnectionID() << "\" with subscriber ID " << ToString(connection->GetSubscriberID()) << " has requested a temporal subscription starting at " << ToString(connection->GetStartTimeConstraint()) << endl << endl; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void PublisherInstance::TemporalProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection) | 109 | void PublisherInstance::ProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection) |
| 110 | { | 110 | { |
| 111 | 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; | 111 | 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; |
| 112 | } | 112 | } |
| @@ -119,7 +119,7 @@ void PublisherInstance::Initialize() · 6 unmodified lines | |||
| 119 | m_publisher.RegisterClientConnectedCallback(&HandleClientConnected); | 119 | m_publisher.RegisterClientConnectedCallback(&HandleClientConnected); |
| 120 | m_publisher.RegisterClientDisconnectedCallback(&HandleClientDisconnected); | 120 | m_publisher.RegisterClientDisconnectedCallback(&HandleClientDisconnected); |
| 121 | m_publisher.RegisterTemporalSubscriptionRequestedCallback(&HandleTemporalSubscriptionRequested); | 121 | m_publisher.RegisterTemporalSubscriptionRequestedCallback(&HandleTemporalSubscriptionRequested); |
| 122 | m_publisher.RegisterTemporalProcessingIntervalChangeRequestedCallback(&HandleTemporalProcessingIntervalChangeRequested); | 122 | m_publisher.RegisterProcessingIntervalChangeRequestedCallback(&HandleProcessingIntervalChangeRequested); |
| 123 | 123 | ||
| 124 | m_initialized = true; | 124 | m_initialized = true; |
| 125 | } | 125 | } |
| @@ -134,6 +134,21 @@ void PublisherInstance::DefineMetadata(const DataSetPtr& metadata) · 8 unmodified lines | |||
| 134 | m_publisher.DefineMetadata(metadata); | 134 | m_publisher.DefineMetadata(metadata); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | const DataSetPtr& PublisherInstance::GetMetadata() const | ||
| 138 | { | ||
| 139 | return m_publisher.GetMetadata(); | ||
| 140 | } | ||
| 141 | |||
| 142 | const DataSetPtr& PublisherInstance::GetFilteringMetadata() const | ||
| 143 | { | ||
| 144 | return m_publisher.GetFilteringMetadata(); | ||
| 145 | } | ||
| 146 | |||
| 147 | vector<MeasurementMetadataPtr> PublisherInstance::FilterMetadata(const string& filterExpression) const | ||
| 148 | { | ||
| 149 | return m_publisher.FilterMetadata(filterExpression); | ||
| 150 | } | ||
| 151 | |||
| 137 | void PublisherInstance::PublishMeasurements(const vector<Measurement>& measurements) | 152 | void PublisherInstance::PublishMeasurements(const vector<Measurement>& measurements) |
| 138 | { | 153 | { |
| 139 | if (!m_initialized) | 154 | if (!m_initialized) |
| @@ -150,6 +165,26 @@ void PublisherInstance::PublishMeasurements(const vector<MeasurementPtr>& measur · 10 unmodified lines | |||
| 150 | m_publisher.PublishMeasurements(measurements); | 165 | m_publisher.PublishMeasurements(measurements); |
| 151 | } | 166 | } |
| 152 | 167 | ||
| 168 | const GSF::Guid& PublisherInstance::GetNodeID() const | ||
| 169 | { | ||
| 170 | return m_publisher.GetNodeID(); | ||
| 171 | } | ||
| 172 | |||
| 173 | void PublisherInstance::SetNodeID(const GSF::Guid& nodeID) | ||
| 174 | { | ||
| 175 | m_publisher.SetNodeID(nodeID); | ||
| 176 | } | ||
| 177 | |||
| 178 | SecurityMode PublisherInstance::GetSecurityMode() const | ||
| 179 | { | ||
| 180 | return m_publisher.GetSecurityMode(); | ||
| 181 | } | ||
| 182 | |||
| 183 | void PublisherInstance::SetSecurityMode(SecurityMode securityMode) | ||
| 184 | { | ||
| 185 | m_publisher.SetSecurityMode(securityMode); | ||
| 186 | } | ||
| 187 | |||
| 153 | bool PublisherInstance::IsMetadataRefreshAllowed() const | 188 | bool PublisherInstance::IsMetadataRefreshAllowed() const |
| 154 | { | 189 | { |
| 155 | return m_publisher.IsMetadataRefreshAllowed(); | 190 | return m_publisher.IsMetadataRefreshAllowed(); |
| @@ -30,7 +30,7 @@ namespace GSF { · 29 unmodified lines | |||
| 30 | namespace TimeSeries { | 30 | namespace TimeSeries { |
| 31 | namespace Transport | 31 | namespace Transport |
| 32 | { | 32 | { |
| 33 | class PublisherInstance | 33 | class PublisherInstance // NOLINT |
| 34 | { | 34 | { |
| 35 | private: | 35 | private: |
| 36 | // Publication members | 36 | // Publication members |
| @@ -46,7 +46,7 @@ namespace Transport · 9 unmodified lines | |||
| 46 | static void HandleClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); | 46 | static void HandleClientConnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 47 | static void HandleClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); | 47 | static void HandleClientDisconnected(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 48 | static void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | 48 | static void HandleTemporalSubscriptionRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 49 | static void HandleTemporalProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); | 49 | static void HandleProcessingIntervalChangeRequested(DataPublisher* source, const SubscriberConnectionPtr& connection); |
| 50 | 50 | ||
| 51 | protected: | 51 | protected: |
| 52 | virtual void StatusMessage(const std::string& message); // Defaults output to cout | 52 | virtual void StatusMessage(const std::string& message); // Defaults output to cout |
| @@ -54,7 +54,7 @@ namespace Transport · 1 unmodified line | |||
| 54 | virtual void ClientConnected(const SubscriberConnectionPtr& connection); | 54 | virtual void ClientConnected(const SubscriberConnectionPtr& connection); |
| 55 | virtual void ClientDisconnected(const SubscriberConnectionPtr& connection); | 55 | virtual void ClientDisconnected(const SubscriberConnectionPtr& connection); |
| 56 | virtual void TemporalSubscriptionRequested(const SubscriberConnectionPtr& connection); | 56 | virtual void TemporalSubscriptionRequested(const SubscriberConnectionPtr& connection); |
| 57 | virtual void TemporalProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection); | 57 | virtual void ProcessingIntervalChangeRequested(const SubscriberConnectionPtr& connection); |
| 58 | 58 | ||
| 59 | public: | 59 | public: |
| 60 | PublisherInstance(uint16_t port, bool ipV6); | 60 | PublisherInstance(uint16_t port, bool ipV6); |
| @@ -71,9 +71,30 @@ namespace Transport · 10 unmodified lines | |||
| 71 | // Define metadata from existing dataset | 71 | // Define metadata from existing dataset |
| 72 | void DefineMetadata(const GSF::Data::DataSetPtr& metadata); | 72 | void DefineMetadata(const GSF::Data::DataSetPtr& metadata); |
| 73 | 73 | ||
| 74 | // Gets primary metadata. This dataset contains all the normalized metadata tables that define | ||
| 75 | // the available detail about the data points that can be subscribed to by clients. | ||
| 76 | const GSF::Data::DataSetPtr& GetMetadata() const; | ||
| 77 | |||
| 78 | // Gets filtering metadata. This dataset, derived from primary metadata, contains a flattened | ||
| 79 | // table used to subscribe to a filtered set of points with an expression, e.g.: | ||
| 80 | // FILTER ActiveMeasurements WHERE SignalType LIKE '%PHA' | ||
| 81 | const GSF::Data::DataSetPtr& GetFilteringMetadata() const; | ||
| 82 | |||
| 83 | // Filters primary MeasurementDetail metadata returning values as measurement metadata records | ||
| 84 | std::vector<MeasurementMetadataPtr> FilterMetadata(const std::string& filterExpression) const; | ||
| 85 | |||
| 74 | void PublishMeasurements(const std::vector<Measurement>& measurements); | 86 | void PublishMeasurements(const std::vector<Measurement>& measurements); |
| 75 | void PublishMeasurements(const std::vector<MeasurementPtr>& measurements); | 87 | void PublishMeasurements(const std::vector<MeasurementPtr>& measurements); |
| 76 | 88 | ||
| 89 | // Node ID defines a unique identification for the DataPublisher | ||
| 90 | // instance that gets included in published metadata so that clients | ||
| 91 | // can easily distinguish the source of the measurements | ||
| 92 | const GSF::Guid& GetNodeID() const; | ||
| 93 | void SetNodeID(const GSF::Guid& nodeID); | ||
| 94 | |||
| 95 | SecurityMode GetSecurityMode() const; | ||
| 96 | void SetSecurityMode(SecurityMode securityMode); | ||
| 97 | |||
| 77 | bool IsMetadataRefreshAllowed() const; | 98 | bool IsMetadataRefreshAllowed() const; |
| 78 | void SetMetadataRefreshAllowed(bool allowed); | 99 | void SetMetadataRefreshAllowed(bool allowed); |
| 79 | 100 | ||
| @@ -154,12 +154,12 @@ uint32_t SignalIndexCache::GetBinaryLength() const · 153 unmodified lines | |||
| 154 | return m_binaryLength; | 154 | return m_binaryLength; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | void SignalIndexCache::RecalculateBinaryLength(const SubscriberConnectionPtr& connection) | 157 | void SignalIndexCache::RecalculateBinaryLength(const SubscriberConnection& connection) |
| 158 | { | 158 | { |
| 159 | uint32_t binaryLength = 28; | 159 | uint32_t binaryLength = 28; |
| 160 | 160 | ||
| 161 | for (size_t i = 0; i < m_signalIDList.size(); i++) | 161 | for (size_t i = 0; i < m_signalIDList.size(); i++) |
| 162 | binaryLength += 26 + connection->EncodeString(m_sourceList[i]).size(); | 162 | binaryLength += 26 + connection.EncodeString(m_sourceList[i]).size(); |
| 163 | 163 | ||
| 164 | m_binaryLength = binaryLength; | 164 | m_binaryLength = binaryLength; |
| 165 | } | 165 | } |
| @@ -214,7 +214,7 @@ void SignalIndexCache::Parse(const vector<uint8_t>& buffer, Guid& subscriberID) · 48 unmodified lines | |||
| 214 | // IDs that may need to be parsed in the future... | 214 | // IDs that may need to be parsed in the future... |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | void SignalIndexCache::Serialize(const SubscriberConnectionPtr& connection, vector<uint8_t>& buffer) | 217 | void SignalIndexCache::Serialize(const SubscriberConnection& connection, vector<uint8_t>& buffer) |
| 218 | { | 218 | { |
| 219 | const uint32_t binaryLengthLocation = buffer.size(); | 219 | const uint32_t binaryLengthLocation = buffer.size(); |
| 220 | uint32_t binaryLength = 28; | 220 | uint32_t binaryLength = 28; |
| @@ -223,7 +223,7 @@ void SignalIndexCache::Serialize(const SubscriberConnectionPtr& connection, vect · 2 unmodified lines | |||
| 223 | WriteBytes(buffer, uint32_t(0)); | 223 | WriteBytes(buffer, uint32_t(0)); |
| 224 | 224 | ||
| 225 | // Encode subscriber ID | 225 | // Encode subscriber ID |
| 226 | Guid subscriberID = connection->GetSubscriberID(); | 226 | Guid subscriberID = connection.GetSubscriberID(); |
| 227 | SwapGuidEndianness(subscriberID, true); | 227 | SwapGuidEndianness(subscriberID, true); |
| 228 | WriteBytes(buffer, subscriberID); | 228 | WriteBytes(buffer, subscriberID); |
| 229 | 229 | ||
| @@ -242,7 +242,7 @@ void SignalIndexCache::Serialize(const SubscriberConnectionPtr& connection, vect · 12 unmodified lines | |||
| 242 | WriteBytes(buffer, signalID); | 242 | WriteBytes(buffer, signalID); |
| 243 | 243 | ||
| 244 | // Encode source | 244 | // Encode source |
| 245 | vector<uint8_t> sourceBytes = connection->EncodeString(m_sourceList[i]); | 245 | vector<uint8_t> sourceBytes = connection.EncodeString(m_sourceList[i]); |
| 246 | EndianConverter::WriteBigEndianBytes(buffer, int32_t(sourceBytes.size())); | 246 | EndianConverter::WriteBigEndianBytes(buffer, int32_t(sourceBytes.size())); |
| 247 | WriteBytes(buffer, sourceBytes); | 247 | WriteBytes(buffer, sourceBytes); |
| 248 | 248 | ||
| @@ -85,11 +85,11 @@ namespace Transport · 84 unmodified lines | |||
| 85 | // a vector size, for an exact size call RecalculateBinaryLength first | 85 | // a vector size, for an exact size call RecalculateBinaryLength first |
| 86 | uint32_t GetBinaryLength() const; | 86 | uint32_t GetBinaryLength() const; |
| 87 | 87 | ||
| 88 | void RecalculateBinaryLength(const SubscriberConnectionPtr& connection); | 88 | void RecalculateBinaryLength(const SubscriberConnection& connection); |
| 89 | 89 | ||
| 90 | void Parse(const std::vector<uint8_t>& buffer, Guid& subscriberID); | 90 | void Parse(const std::vector<uint8_t>& buffer, Guid& subscriberID); |
| 91 | 91 | ||
| 92 | void Serialize(const SubscriberConnectionPtr& connection, std::vector<uint8_t>& buffer); | 92 | void Serialize(const SubscriberConnection& connection, std::vector<uint8_t>& buffer); |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | typedef SharedPtr<SignalIndexCache> SignalIndexCachePtr; | 95 | typedef SharedPtr<SignalIndexCache> SignalIndexCachePtr; |
| @@ -167,7 +167,7 @@ int32_t SubscriberConnection::GetProcessingInterval() const · 166 unmodified lines | |||
| 167 | void SubscriberConnection::SetProcessingInterval(int32_t value) | 167 | void SubscriberConnection::SetProcessingInterval(int32_t value) |
| 168 | { | 168 | { |
| 169 | m_processingInterval = value; | 169 | m_processingInterval = value; |
| 170 | m_parent->DispatchTemporalProcessingIntervalChangeRequested(shared_from_this()); | 170 | m_parent->DispatchProcessingIntervalChangeRequested(shared_from_this()); |
| 171 | m_parent->DispatchStatusMessage(m_connectionID + " was assigned a new processing interval of " + ToString(value) + "."); | 171 | m_parent->DispatchStatusMessage(m_connectionID + " was assigned a new processing interval of " + ToString(value) + "."); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| @@ -363,7 +363,7 @@ void SubscriberConnection::Stop() · 189 unmodified lines | |||
| 363 | 363 | ||
| 364 | void SubscriberConnection::PublishMeasurements(const vector<MeasurementPtr>& measurements) | 364 | void SubscriberConnection::PublishMeasurements(const vector<MeasurementPtr>& measurements) |
| 365 | { | 365 | { |
| 366 | if (measurements.empty() || !m_isSubscribed) | 366 | if (measurements.empty() || !m_isSubscribed || m_signalIndexCache == nullptr) |
| 367 | return; | 367 | return; |
| 368 | 368 | ||
| 369 | if (!m_startTimeSent) | 369 | if (!m_startTimeSent) |
| @@ -435,7 +435,13 @@ void SubscriberConnection::HandleSubscribe(uint8_t* data, uint32_t length) · 65 unmodified lines | |||
| 435 | { | 435 | { |
| 436 | const bool usePayloadCompression = (GetOperationalModes() & OperationalModes::CompressPayloadData) > 0; | 436 | const bool usePayloadCompression = (GetOperationalModes() & OperationalModes::CompressPayloadData) > 0; |
| 437 | const bool useCompactMeasurementFormat = (flags & DataPacketFlags::Compact) > 0; | 437 | const bool useCompactMeasurementFormat = (flags & DataPacketFlags::Compact) > 0; |
| 438 | |||
| 439 | m_parent->DispatchStatusMessage("About to decode connection string with " + ToString(byteLength) + " bytes..."); | ||
| 440 | |||
| 438 | const string connectionString = DecodeString(data, index, byteLength); | 441 | const string connectionString = DecodeString(data, index, byteLength); |
| 442 | |||
| 443 | m_parent->DispatchStatusMessage("Successfully decoded connection string: " + connectionString); | ||
| 444 | |||
| 439 | const StringMap<string> settings = ParseKeyValuePairs(connectionString); | 445 | const StringMap<string> settings = ParseKeyValuePairs(connectionString); |
| 440 | string setting; | 446 | string setting; |
| 441 | 447 | ||
| @@ -474,7 +480,11 @@ void SubscriberConnection::HandleSubscribe(uint8_t* data, uint32_t length) · 32 unmodified lines | |||
| 474 | // Apply subscriber filter expression and build signal index cache | 480 | // Apply subscriber filter expression and build signal index cache |
| 475 | if (TryGetValue(settings, "inputMeasurementKeys", setting)) | 481 | if (TryGetValue(settings, "inputMeasurementKeys", setting)) |
| 476 | { | 482 | { |
| 477 | if (!ParseSubscriptionRequest(setting, signalIndexCache)) | 483 | bool success; |
| 484 | |||
| 485 | signalIndexCache = ParseSubscriptionRequest(setting, success); | ||
| 486 | |||
| 487 | if (!success) | ||
| 478 | return; | 488 | return; |
| 479 | } | 489 | } |
| 480 | 490 | ||
| @@ -533,7 +543,7 @@ void SubscriberConnection::HandleSubscribe(uint8_t* data, uint32_t length) · 52 unmodified lines | |||
| 533 | signalCount = signalIndexCache->Count(); | 543 | signalCount = signalIndexCache->Count(); |
| 534 | 544 | ||
| 535 | // Send updated signal index cache to client with validated rights of the selected input measurement keys | 545 | // Send updated signal index cache to client with validated rights of the selected input measurement keys |
| 536 | SendResponse(ServerResponse::UpdateSignalIndexCache, ServerCommand::Subscribe, SerializeSignalIndexCache(signalIndexCache)); | 546 | SendResponse(ServerResponse::UpdateSignalIndexCache, ServerCommand::Subscribe, SerializeSignalIndexCache(*signalIndexCache)); |
| 537 | } | 547 | } |
| 538 | 548 | ||
| 539 | SetSignalIndexCache(signalIndexCache); | 549 | SetSignalIndexCache(signalIndexCache); |
| @@ -706,7 +716,7 @@ void SubscriberConnection::HandleUserCommand(uint8_t command, uint8_t* data, uin · 166 unmodified lines | |||
| 706 | { | 716 | { |
| 707 | } | 717 | } |
| 708 | 718 | ||
| 709 | bool SubscriberConnection::ParseSubscriptionRequest(const std::string& filterExpression, SignalIndexCachePtr& signalIndexCache) | 719 | SignalIndexCachePtr SubscriberConnection::ParseSubscriptionRequest(const string& filterExpression, bool& success) |
| 710 | { | 720 | { |
| 711 | string exceptionMessage, parsingException; | 721 | string exceptionMessage, parsingException; |
| 712 | FilterExpressionParserPtr parser = NewSharedPtr<FilterExpressionParser>(filterExpression); | 722 | FilterExpressionParserPtr parser = NewSharedPtr<FilterExpressionParser>(filterExpression); |
| @@ -749,7 +759,9 @@ bool SubscriberConnection::ParseSubscriptionRequest(const std::string& filterExp · 36 unmodified lines | |||
| 749 | 759 | ||
| 750 | SendResponse(ServerResponse::Failed, ServerCommand::Subscribe, exceptionMessage); | 760 | SendResponse(ServerResponse::Failed, ServerCommand::Subscribe, exceptionMessage); |
| 751 | m_parent->DispatchErrorMessage(exceptionMessage); | 761 | m_parent->DispatchErrorMessage(exceptionMessage); |
| 752 | return false; | 762 | |
| 763 | success = false; | ||
| 764 | return nullptr; | ||
| 753 | } | 765 | } |
| 754 | 766 | ||
| 755 | uint32_t charSizeEstimate; | 767 | uint32_t charSizeEstimate; |
| @@ -772,7 +784,7 @@ bool SubscriberConnection::ParseSubscriptionRequest(const std::string& filterExp · 16 unmodified lines | |||
| 772 | const int32_t signalIDColumn = DataPublisher::GetColumnIndex(activeMeasurements, "SignalID"); | 784 | const int32_t signalIDColumn = DataPublisher::GetColumnIndex(activeMeasurements, "SignalID"); |
| 773 | 785 | ||
| 774 | // Create a new signal index cache for filtered measurements | 786 | // Create a new signal index cache for filtered measurements |
| 775 | signalIndexCache = NewSharedPtr<SignalIndexCache>(); | 787 | SignalIndexCachePtr signalIndexCache = NewSharedPtr<SignalIndexCache>(); |
| 776 | 788 | ||
| 777 | for (size_t i = 0; i < rows.size(); i++) | 789 | for (size_t i = 0; i < rows.size(); i++) |
| 778 | { | 790 | { |
| @@ -785,7 +797,8 @@ bool SubscriberConnection::ParseSubscriptionRequest(const std::string& filterExp · 6 unmodified lines | |||
| 785 | signalIndexCache->AddMeasurementKey(uint16_t(i), signalID, source, id, charSizeEstimate); | 797 | signalIndexCache->AddMeasurementKey(uint16_t(i), signalID, source, id, charSizeEstimate); |
| 786 | } | 798 | } |
| 787 | 799 | ||
| 788 | return true; | 800 | success = true; |
| 801 | return signalIndexCache; | ||
| 789 | } | 802 | } |
| 790 | 803 | ||
| 791 | void SubscriberConnection::PublishDataPacket(const vector<uint8_t>& packet, const int32_t count) | 804 | void SubscriberConnection::PublishDataPacket(const vector<uint8_t>& packet, const int32_t count) |
| @@ -970,7 +983,7 @@ void SubscriberConnection::ParseCommand(const ErrorCode& error, uint32_t bytesTr · 178 unmodified lines | |||
| 970 | ReadCommandChannel(); | 983 | ReadCommandChannel(); |
| 971 | } | 984 | } |
| 972 | 985 | ||
| 973 | std::vector<uint8_t> SubscriberConnection::SerializeSignalIndexCache(const SignalIndexCachePtr& signalIndexCache) | 986 | std::vector<uint8_t> SubscriberConnection::SerializeSignalIndexCache(SignalIndexCache& signalIndexCache) const |
| 974 | { | 987 | { |
| 975 | vector<uint8_t> serializationBuffer; | 988 | vector<uint8_t> serializationBuffer; |
| 976 | 989 | ||
| @@ -982,8 +995,8 @@ std::vector<uint8_t> SubscriberConnection::SerializeSignalIndexCache(const Signa · 5 unmodified lines | |||
| 982 | if (!useCommonSerializationFormat) | 995 | if (!useCommonSerializationFormat) |
| 983 | throw PublisherException("DataPublisher only supports common serialization format"); | 996 | throw PublisherException("DataPublisher only supports common serialization format"); |
| 984 | 997 | ||
| 985 | serializationBuffer.reserve(uint32_t(signalIndexCache->GetBinaryLength() * 0.02)); | 998 | serializationBuffer.reserve(uint32_t(signalIndexCache.GetBinaryLength() * 0.02)); |
| 986 | signalIndexCache->Serialize(shared_from_this(), serializationBuffer); | 999 | signalIndexCache.Serialize(*this, serializationBuffer); |
| 987 | 1000 | ||
| 988 | if (compressSignalIndexCache && useGZipCompression) | 1001 | if (compressSignalIndexCache && useGZipCompression) |
| 989 | { | 1002 | { |
| @@ -1232,7 +1245,15 @@ string SubscriberConnection::DecodeString(const uint8_t* data, uint32_t offset, · 242 unmodified lines | |||
| 1232 | switch (m_encoding) | 1245 | switch (m_encoding) |
| 1233 | { | 1246 | { |
| 1234 | case OperationalEncoding::UTF8: | 1247 | case OperationalEncoding::UTF8: |
| 1235 | return string(reinterpret_cast<const char*>(data + offset), length / sizeof(char)); | 1248 | { |
| 1249 | string value {}; | ||
| 1250 | value.reserve(length / sizeof(char)); | ||
| 1251 | |||
| 1252 | for (size_t i = 0; i < length; i += sizeof(char)) | ||
| 1253 | value.append(1, static_cast<char>(data[offset + i])); | ||
| 1254 | |||
| 1255 | return value; | ||
| 1256 | } | ||
| 1236 | case OperationalEncoding::Unicode: | 1257 | case OperationalEncoding::Unicode: |
| 1237 | case OperationalEncoding::ANSI: | 1258 | case OperationalEncoding::ANSI: |
| 1238 | swapBytes = !swapBytes; | 1259 | swapBytes = !swapBytes; |
| @@ -1246,7 +1267,7 @@ string SubscriberConnection::DecodeString(const uint8_t* data, uint32_t offset, · 7 unmodified lines | |||
| 1246 | if (swapBytes) | 1267 | if (swapBytes) |
| 1247 | value.append(1, EndianConverter::ToLittleEndian<wchar_t>(data, offset + i)); | 1268 | value.append(1, EndianConverter::ToLittleEndian<wchar_t>(data, offset + i)); |
| 1248 | else | 1269 | else |
| 1249 | value.append(1, *reinterpret_cast<const wchar_t*>(data + offset + i)); | 1270 | value.append(1, static_cast<wchar_t>(data[offset + i])); |
| 1250 | } | 1271 | } |
| 1251 | 1272 | ||
| 1252 | return ToUTF8(value); | 1273 | return ToUTF8(value); |
| @@ -103,13 +103,13 @@ namespace Transport · 102 unmodified lines | |||
| 103 | void HandlePublishCommandMeasurements(uint8_t* data, uint32_t length); | 103 | void HandlePublishCommandMeasurements(uint8_t* data, uint32_t length); |
| 104 | void HandleUserCommand(uint8_t command, uint8_t* data, uint32_t length); | 104 | void HandleUserCommand(uint8_t command, uint8_t* data, uint32_t length); |
| 105 | 105 | ||
| 106 | bool ParseSubscriptionRequest(const std::string& filterExpression, SignalIndexCachePtr& signalIndexCache); | 106 | SignalIndexCachePtr ParseSubscriptionRequest(const std::string& filterExpression, bool& success); |
| 107 | void PublishDataPacket(const std::vector<uint8_t>& packet, int32_t count); | 107 | void PublishDataPacket(const std::vector<uint8_t>& packet, int32_t count); |
| 108 | bool SendDataStartTime(uint64_t timestamp); | 108 | bool SendDataStartTime(uint64_t timestamp); |
| 109 | void ReadCommandChannel(); | 109 | void ReadCommandChannel(); |
| 110 | void ReadPayloadHeader(const ErrorCode& error, uint32_t bytesTransferred); | 110 | void ReadPayloadHeader(const ErrorCode& error, uint32_t bytesTransferred); |
| 111 | void ParseCommand(const ErrorCode& error, uint32_t bytesTransferred); | 111 | void ParseCommand(const ErrorCode& error, uint32_t bytesTransferred); |
| 112 | std::vector<uint8_t> SerializeSignalIndexCache(const SignalIndexCachePtr& signalIndexCache); | 112 | std::vector<uint8_t> SerializeSignalIndexCache(SignalIndexCache& signalIndexCache) const; |
| 113 | std::vector<uint8_t> SerializeMetadata(const GSF::Data::DataSetPtr& metadata) const; | 113 | std::vector<uint8_t> SerializeMetadata(const GSF::Data::DataSetPtr& metadata) const; |
| 114 | GSF::Data::DataSetPtr FilterClientMetadata(const StringMap<GSF::FilterExpressions::ExpressionTreePtr>& filterExpressions) const; | 114 | GSF::Data::DataSetPtr FilterClientMetadata(const StringMap<GSF::FilterExpressions::ExpressionTreePtr>& filterExpressions) const; |
| 115 | 115 | ||