Page 1 of 1

[RCF::Session] How call disconnect on other session?

Posted: Thu Jan 09, 2014 5:52 am
by acDev
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 ?

Re: [RCF::Session] How call disconnect on other session?

Posted: Fri Jan 10, 2014 12:56 am
by jarl
You can maintain a global map of RCF sessions, indexed by a client ID. Something like this:

Code: Select all

std::map<std::string, RCF::RcfSessionWeakPtr> g_sessionMap;
In your login function, you add a weak pointer to the current RCF session into the map:

Code: Select all

RCF::RcfSession & session = RCF::getCurrentRcfSession();
g_sessionMap[clientId] = session.shared_from_this();
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();
}
You will need to implement some thread synchronization for accessing the session map, as there may be multiple threads accessing it concurrently.

Re: [RCF::Session] How call disconnect on other session?

Posted: Fri Jan 10, 2014 9:17 am
by acDev
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
}
How to ensure that the "RcfSession1" at the current time does not perform the request? (suddenly at a given time is already running disconnection)

After "sessionPtr->disconnect();" need call "g_sessionMap.erase(clientId)" ?