NSM: Time client responses.

This commit is contained in:
Jonathan Moore Liles 2012-02-27 20:28:58 -08:00
parent 250b7db644
commit 388796a1c4
1 changed files with 44 additions and 19 deletions

View File

@ -43,6 +43,7 @@
#include <ftw.h> #include <ftw.h>
#include <list> #include <list>
#include <getopt.h> #include <getopt.h>
#include <sys/time.h>
#include <OSC/Endpoint.H> #include <OSC/Endpoint.H>
/* for locking */ /* for locking */
@ -91,12 +92,14 @@ private:
int _reply_errcode; int _reply_errcode;
char *_reply_message; char *_reply_message;
int _pending_command; /* */
struct timeval _command_sent_time;
public: public:
lo_address addr; /* */ lo_address addr; /* */
char *name; /* client application name */ char *name; /* client application name */
char *executable_path; /* path to client executable */ char *executable_path; /* path to client executable */
int pending_command; /* */
int pid; /* PID of client process */ int pid; /* PID of client process */
float progress; /* */ float progress; /* */
bool active; /* client has registered via announce */ bool active; /* client has registered via announce */
@ -137,7 +140,7 @@ public:
bool reply_pending ( void ) bool reply_pending ( void )
{ {
return pending_command != COMMAND_NONE; return _pending_command != COMMAND_NONE;
} }
bool is_dumb_client ( void ) bool is_dumb_client ( void )
@ -145,6 +148,29 @@ public:
return capabilities == NULL; return capabilities == NULL;
} }
void pending_command ( int command )
{
gettimeofday( &_command_sent_time, NULL );
_pending_command = command;
}
double milliseconds_since_last_command ( void ) const
{
struct timeval now;
gettimeofday( &now, NULL );
double elapsedms = ( now.tv_sec - _command_sent_time.tv_sec ) * 1000.0;
elapsedms += ( now.tv_usec - _command_sent_time.tv_usec ) / 1000.0;
return elapsedms;
}
int pending_command ( void )
{
return _pending_command;
}
Client ( ) Client ( )
{ {
addr = 0; addr = 0;
@ -153,7 +179,7 @@ public:
dead_because_we_said = false; dead_because_we_said = false;
pid = 0; pid = 0;
progress = -0; progress = -0;
pending_command = 0; _pending_command = 0;
active = false; active = false;
client_id = 0; client_id = 0;
capabilities = 0; capabilities = 0;
@ -200,7 +226,6 @@ clients_have_errors ( )
return false; return false;
} }
Client * Client *
get_client_by_pid ( int pid ) get_client_by_pid ( int pid )
{ {
@ -238,13 +263,13 @@ handle_client_process_death ( int pid )
{ {
MESSAGE( "Client %s died.", c->name ); MESSAGE( "Client %s died.", c->name );
if ( c->pending_command == COMMAND_KILL || if ( c->pending_command() == COMMAND_KILL ||
c->pending_command == COMMAND_QUIT ) c->pending_command() == COMMAND_QUIT )
{ {
c->dead_because_we_said = true; c->dead_because_we_said = true;
} }
c->pending_command = COMMAND_NONE; c->pending_command( COMMAND_NONE );
c->active = false; c->active = false;
c->pid = 0; c->pid = 0;
@ -533,7 +558,7 @@ command_client_to_save ( Client *c )
MESSAGE( "Telling %s to save", c->name ); MESSAGE( "Telling %s to save", c->name );
osc_server->send( c->addr, "/nsm/client/save" ); osc_server->send( c->addr, "/nsm/client/save" );
c->pending_command = COMMAND_SAVE; c->pending_command( COMMAND_SAVE );
if ( gui_is_active ) if ( gui_is_active )
osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "save" ); osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "save" );
@ -564,7 +589,7 @@ void command_client_to_switch ( Client *c, const char *new_client_id )
free( full_client_id ); free( full_client_id );
free( client_project_path ); free( client_project_path );
c->pending_command = COMMAND_OPEN; c->pending_command( COMMAND_OPEN );
if ( gui_is_active ) if ( gui_is_active )
{ {
@ -743,7 +768,7 @@ OSC_HANDLER( announce )
osc_server->send( lo_message_get_source( msg ), "/nsm/client/open", client_project_path, session_name, full_client_id ); osc_server->send( lo_message_get_source( msg ), "/nsm/client/open", client_project_path, session_name, full_client_id );
c->pending_command = COMMAND_OPEN; c->pending_command( COMMAND_OPEN );
free( full_client_id ); free( full_client_id );
free( client_project_path ); free( client_project_path );
@ -849,8 +874,8 @@ killed_clients_are_alive ( )
i != cl->end(); i != cl->end();
++i ) ++i )
{ {
if ( ( (*i)->pending_command == COMMAND_QUIT || if ( ( (*i)->pending_command() == COMMAND_QUIT ||
(*i)->pending_command == COMMAND_KILL ) && (*i)->pending_command() == COMMAND_KILL ) &&
(*i)->pid > 0 ) (*i)->pid > 0 )
return true; return true;
} }
@ -924,7 +949,7 @@ command_client_to_quit ( Client *c )
if ( c->active ) if ( c->active )
{ {
c->pending_command = COMMAND_QUIT; c->pending_command( COMMAND_QUIT );
kill( c->pid, SIGTERM ); kill( c->pid, SIGTERM );
@ -939,7 +964,7 @@ command_client_to_quit ( Client *c )
osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "kill" ); osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "kill" );
/* should be kill? */ /* should be kill? */
c->pending_command = COMMAND_KILL; c->pending_command( COMMAND_KILL );
// this is a dumb client... try and kill it // this is a dumb client... try and kill it
kill( c->pid, SIGTERM ); kill( c->pid, SIGTERM );
@ -1621,8 +1646,8 @@ OSC_HANDLER( error )
c->set_reply( err_code, message ); c->set_reply( err_code, message );
MESSAGE( "Client \"%s\" replied with error: %s (%i)", c->name, message, err_code ); MESSAGE( "Client \"%s\" replied with error: %s (%i) in %fms", c->name, message, err_code, c->milliseconds_since_last_command() );
c->pending_command = COMMAND_NONE; c->pending_command( COMMAND_NONE );
if ( gui_is_active ) if ( gui_is_active )
osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "error" ); osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "error" );
@ -1642,9 +1667,9 @@ OSC_HANDLER( reply )
{ {
c->set_reply( ERR_OK, message ); c->set_reply( ERR_OK, message );
MESSAGE( "Client \"%s\" replied with: %s", c->name, message ); MESSAGE( "Client \"%s\" replied with: %s in %fms", c->name, message, c->milliseconds_since_last_command() );
c->pending_command = COMMAND_NONE; c->pending_command( COMMAND_NONE );
if ( gui_is_active ) if ( gui_is_active )
osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "ready" ); osc_server->send( gui_addr, "/nsm/gui/client/status", c->client_id, c->status = "ready" );