Scenario:
1) Client1 call rpc-method "Login" with parameters: login = "user", password = "123".
2) RcfServer create "RcfSession1" with parameters: login = "user".
3) RcfServer create TokenId and send this to Client1.
4) Client2 call rpc-method "Login" with parameters: login = "user", password = "123".
5) RcfServer create "RcfSession2" with parameters: login = "user".
6) RcfServer determines that this user is already running (login same). RcfServer call method "dissconnect" for session "RcfSession1".
7) RcfServer create TokenId and send this to Client2.
How to implement paragraph 6 ?
[RCF::Session] How call disconnect on other session?
Re: [RCF::Session] How call disconnect on other session?
You can maintain a global map of RCF sessions, indexed by a client ID. Something like this:
In your login function, you add a weak pointer to the current RCF session into the map:
Then later on you can check whether a session is present for a given client ID, and take appropriate action:
You will need to implement some thread synchronization for accessing the session map, as there may be multiple threads accessing it concurrently.
Code: Select all
std::map<std::string, RCF::RcfSessionWeakPtr> g_sessionMap;
Code: Select all
RCF::RcfSession & session = RCF::getCurrentRcfSession();
g_sessionMap[clientId] = session.shared_from_this();
Code: Select all
RCF::RcfSessionPtr sessionPtr = g_sessionMap[clientId].lock();
if (sessionPtr)
{
// This client already has a session.
// Disconnect it.
sessionPtr->disconnect();
}
Re: [RCF::Session] How call disconnect on other session?
How to ensure that the "RcfSession1" at the current time does not perform the request? (suddenly at a given time is already running disconnection)jarl wrote:Then later on you can check whether a session is present for a given client ID, and take appropriate action:
Code: Select all
RCF::RcfSessionPtr sessionPtr = g_sessionMap[clientId].lock(); if (sessionPtr) { // This client already has a session. // Disconnect it. sessionPtr->disconnect(); // RcfSession1 }
After "sessionPtr->disconnect();" need call "g_sessionMap.erase(clientId)" ?