From 8b5f5a76aa52f43f70583a89f5b012b8352b8d06 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 2 May 2013 23:05:58 -0700 Subject: [PATCH] NSM: Command all unneeded 'switch' capable clients to exit when switching sessions. Closes #60. --- session-manager/src/nsmd.C | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/session-manager/src/nsmd.C b/session-manager/src/nsmd.C index c2fd780..1d4347c 100644 --- a/session-manager/src/nsmd.C +++ b/session-manager/src/nsmd.C @@ -49,6 +49,10 @@ /* for locking */ #include "file.h" +#include +#include +#include + #pragma GCC diagnostic ignored "-Wunused-parameter" static OSC::Endpoint *osc_server; @@ -929,7 +933,6 @@ client_by_name ( const char *name, return NULL; } - bool dumb_clients_are_alive ( ) { @@ -1221,17 +1224,39 @@ load_session_file ( const char * path ) } MESSAGE( "Commanding unneeded and dumb clients to quit" ); + + std::map client_map; + + /* count how many instances of each client are needed in the new session */ + for ( std::list::iterator i = new_clients.begin(); + i != new_clients.end(); + ++i ) + { + if ( client_map.find( (*i)->name) != client_map.end() ) + client_map[(*i)->name]++; + else + client_map[(*i)->name] = 1; + } for ( std::list::iterator i = client.begin(); i != client.end(); ++i ) { - if ( ! (*i)->is_capable_of( ":switch:" ) - || - ! client_by_name( (*i)->name, &new_clients ) ) + if ( ! (*i)->is_capable_of( ":switch:" ) ) { command_client_to_quit( *i ); } + else + { + if ( client_map.find((*i)->name ) != client_map.end() ) + { + /* client is switch capable and may be wanted in the new session */ + if ( client_map[ (*i)->name ]-- <= 0 ) + /* nope,, we already have as many as we need, stop this one */ + command_client_to_quit( *i ); + } + } + } // wait_for_replies();