Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Fix for subscription notifications
Browse files Browse the repository at this point in the history
Value of connection id was truncated, so no response was sent on wire

Signed-off-by: Miladinovic Bojan <fixed-term.bojan.miladinovic@se.bosch.com>
  • Loading branch information
Miladinovic Bojan committed Nov 1, 2019
1 parent 19c6949 commit 495babc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 0 additions & 2 deletions w3c-visserver-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ target_include_directories(w3c-unit-test INTERFACE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(w3c-unit-test INTERFACE ${OPENSSL_LIBRARIES})
endif(UNIT_TEST)



if(BUILD_TEST_CLIENT)
add_executable(testclient ${CMAKE_CURRENT_SOURCE_DIR}/test/testclient.cpp)
target_link_libraries(testclient simple-websocket-server)
Expand Down
6 changes: 4 additions & 2 deletions w3c-visserver-api/include/SubscriptionHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class WsChannel;
class WsServer;
class ILogger;

using SubConnId = uint64_t;

// Subscription ID: Client ID
typedef std::unordered_map<uint32_t, uint64_t> subscriptions_t;
typedef std::unordered_map<uint32_t, SubConnId> subscriptions_t;

// Subscription UUID
typedef std::string uuid_t;
Expand All @@ -52,7 +54,7 @@ class SubscriptionHandler : public ISubscriptionHandler {
std::mutex subMutex;
std::thread subThread;
bool threadRun;
std::queue<std::pair<uint32_t, jsoncons::json>> buffer;
std::queue<std::pair<SubConnId, jsoncons::json>> buffer;

public:
SubscriptionHandler(std::shared_ptr<ILogger> loggerUtil,
Expand Down
3 changes: 2 additions & 1 deletion w3c-visserver-api/src/SubscriptionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int SubscriptionHandler::updateByUUID(const string &signalUUID,

for (auto subID : handle->second) {
std::lock_guard<std::mutex> lock(subMutex);
pair<uint32_t, json> newSub;
pair<SubConnId, json> newSub;
newSub = std::make_pair(subID.second, value);
buffer.push(newSub);
}
Expand Down Expand Up @@ -159,6 +159,7 @@ void* SubscriptionHandler::subThreadRunner() {
buffer.pop();

auto connId = newSub.first;

jsoncons::json value = newSub.second;

jsoncons::json answer;
Expand Down
4 changes: 0 additions & 4 deletions w3c-visserver-api/src/VssDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,8 @@ void VssDatabase::setSignal(WsChannel& channel,
for (size_t i = 0; i < setValues.size(); i++) {
jsoncons::json item = setValues[i];
string jPath = item["path"].as<string>();
#ifdef DEBUG
logger->Log(LogLevel::VERBOSE, "vssdatabase::setSignal: path found = " + jPath);
logger->Log(LogLevel::VERBOSE, "value to set asstring = " + item["value"].as<string>());
#endif
rwMutex.lock();
jsoncons::json resArray = json_query(data_tree, jPath);
rwMutex.unlock();
Expand All @@ -551,9 +549,7 @@ void VssDatabase::setSignal(WsChannel& channel,
rwMutex.lock();
json_replace(data_tree, jPath, resJson);
rwMutex.unlock();
#ifdef DEBUG
logger->Log(LogLevel::VERBOSE, "vssdatabase::setSignal: new value set at path " + jPath);
#endif

string uuid = resJson["uuid"].as<string>();

Expand Down
4 changes: 2 additions & 2 deletions w3c-visserver-api/src/WebSockHttpFlexServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <vector>
#include <unordered_map>
#include <utility>
#include <limits>
#include <regex>
#include <stdexcept>

Expand Down Expand Up @@ -95,7 +96,6 @@ namespace {
newChannel->setConnID(reinterpret_cast<uint64_t>(session));
newChannel->setType(WsChannel::Type::WEBSOCKET_PLAIN);
connPlainWebSock_[session] = newChannel;

return *newChannel;
}

Expand Down Expand Up @@ -199,7 +199,7 @@ namespace {
std::shared_ptr<ILogger> logger;
std::shared_ptr<IRestHandler> restHandler;

const unsigned DEFAULT_TIMEOUT_VALUE = 60u; // in seconds
const unsigned DEFAULT_TIMEOUT_VALUE = std::numeric_limits<unsigned int>::max(); // in seconds
const unsigned WEBSOCKET_TIMEOUT_VALUE = DEFAULT_TIMEOUT_VALUE;
const unsigned HTTP_TIMEOUT_VALUE = DEFAULT_TIMEOUT_VALUE;

Expand Down

0 comments on commit 495babc

Please sign in to comment.