forked from eclipse-uprotocol/up-tck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SocketUTransport for mock testing. (eclipse-uprotocol#64)
This PR implements a socket transport to the python dispacther script, and necessary data structures for listener callbacks and callback removal. The high level code is a private implementation in SocketUTransport.cpp. The unordered_map supporting callbacks is in SafeTupleMap.h. The details of this is std::hash extensions to hash tuples of optionals for filtering with wildcards.
- Loading branch information
Showing
11 changed files
with
834 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Local build steps for SocketUTransport | ||
*From the up_client_socket/cpp directory, run the following commands* | ||
1. conan install --build=missing . | ||
2. cmake --preset conan-release | ||
3. (cd build/Release; cmake --build . -- -j) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
[requires] | ||
up-core-api/1.6.0 | ||
protobuf/3.21.12 | ||
up-cpp/0.1.2-dev | ||
rapidjson/cci.20230929 | ||
up-cpp/1.0.1-rc1 | ||
spdlog/1.13.0 | ||
fmt/10.2.1 | ||
openssl/1.1.1w | ||
|
||
[generators] | ||
CMakeDeps | ||
CMakeToolchain | ||
|
||
[layout] | ||
cmake_layout | ||
cmake_layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License Version 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cxxabi.h> | ||
|
||
#include <string> | ||
|
||
template <typename T> | ||
std::string demangle(const T& t) { | ||
auto info = typeid(t).name(); | ||
int status; | ||
auto realname = abi::__cxa_demangle(info, NULL, NULL, &status); | ||
return std::string(realname); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License Version 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <mutex> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "TupleOfOptionals.h" | ||
|
||
template <typename KEY, typename VALUE> | ||
class SafeTupleMap { | ||
std::unordered_map<KEY, std::shared_ptr<VALUE>, | ||
tuple_of_optionals::hash<KEY>> | ||
map_; | ||
std::mutex mtx; | ||
|
||
public: | ||
using Key = KEY; | ||
|
||
SafeTupleMap() = default; | ||
|
||
std::shared_ptr<VALUE> find(const KEY& key, bool create = false) { | ||
std::unique_lock<std::mutex> lock(mtx); | ||
auto it = map_.find(key); | ||
if (!create) { | ||
return (it != map_.end()) ? it->second : nullptr; | ||
} else { | ||
if (it != map_.end()) | ||
return it->second; | ||
auto ptr = std::make_shared<VALUE>(); | ||
map_.emplace(key, ptr); | ||
return ptr; | ||
} | ||
} | ||
|
||
void erase(std::function<void(std::shared_ptr<VALUE>)> fn) { | ||
std::unique_lock<std::mutex> lock(mtx); | ||
for (auto [key, ptr] : map_) { | ||
fn(ptr); | ||
} | ||
} | ||
}; |
Oops, something went wrong.