-
Notifications
You must be signed in to change notification settings - Fork 16
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.
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
9 changed files
with
426 additions
and
520 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 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
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,43 @@ | ||
#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); | ||
} | ||
} | ||
}; |
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
Oops, something went wrong.