...
This commit is contained in:
@@ -8,10 +8,10 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#if __has_include(<unistd.h>) // POSIX
|
||||
#define FORK_EXISTS 1
|
||||
@@ -139,28 +139,46 @@ protected:
|
||||
|
||||
// started sessions weak pointers
|
||||
template <interfaces::adc_netsession_c SessionT>
|
||||
static std::unordered_map<const AdcNetSessionManager*, std::unordered_set<std::weak_ptr<SessionT>>> _serverSessions;
|
||||
// static std::unordered_map<const AdcNetSessionManager*, std::unordered_set<std::weak_ptr<SessionT>>>
|
||||
// _serverSessions;
|
||||
static inline std::unordered_map<const AdcNetSessionManager*, std::list<std::weak_ptr<SessionT>>> _serverSessions{};
|
||||
std::vector<std::function<bool()>> _stopSessionFunc;
|
||||
std::vector<std::function<void(const AdcNetSessionManager*)>> _moveCtorFunc;
|
||||
|
||||
template <interfaces::adc_netsession_c SessionT>
|
||||
void startSession(std::shared_ptr<SessionT>& sess_ptr)
|
||||
{
|
||||
auto res = _serverSessions<SessionT>[this].emplace(sess_ptr);
|
||||
if (res.second) {
|
||||
sess_ptr->start();
|
||||
auto it = _serverSessions<SessionT>[this].end();
|
||||
it = _serverSessions<SessionT>[this].emplace(it, sess_ptr);
|
||||
sess_ptr->start();
|
||||
|
||||
_stopSessionFunc.emplace_back([res, this]() {
|
||||
if (!res.first->expired()) { // session is still existing
|
||||
auto sess = res.first->lock();
|
||||
sess->stop();
|
||||
_serverSessions<SessionT>[this].erase(res.first);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
_stopSessionFunc.emplace_back([it, this]() {
|
||||
if (!it->expired()) { // session is still existing
|
||||
auto sess = it->lock();
|
||||
sess->stop();
|
||||
_serverSessions<SessionT>[this].erase(it);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// auto res = _serverSessions<SessionT>[this].emplace(sess_ptr);
|
||||
// if (res.second) {
|
||||
// sess_ptr->start();
|
||||
|
||||
// _stopSessionFunc.emplace_back([res, this]() {
|
||||
// if (!res.first->expired()) { // session is still existing
|
||||
// auto sess = res.first->lock();
|
||||
// sess->stop();
|
||||
// _serverSessions<SessionT>[this].erase(res.first);
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// define move-function only once per SessionT!
|
||||
if (_serverSessions<SessionT>[this].size() == 1) {
|
||||
|
||||
Reference in New Issue
Block a user