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

RCF support and general discussion.
Post Reply
acDev
Posts: 27
Joined: Tue Oct 08, 2013 3:08 pm
Location: Moscow
Contact:

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

Post 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 ?

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

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

Post 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.
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

acDev
Posts: 27
Joined: Tue Oct 08, 2013 3:08 pm
Location: Moscow
Contact:

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

Post 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)" ?

Post Reply