From 8df5e84b24ee6af0633a47521cd252eb7270b4e9 Mon Sep 17 00:00:00 2001 From: Maksym Veremeyenko Date: Tue, 14 Jun 2011 19:23:37 +0300 Subject: [PATCH] fix status getting then second unit always overwrite last status --- src/page_status.c | 40 ++++++++++++++++++++++++++++++---------- 1 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/page_status.c b/src/page_status.c index 295217d..555a766 100644 --- a/src/page_status.c +++ b/src/page_status.c @@ -203,33 +203,53 @@ static void show_units( page_status this, gboolean active ) static void *status_thread( void *arg ) { + int i; page_status this = arg; mvcp_notifier notifier = mvcp_get_notifier( this->status ); mvcp_status_t status; + mvcp_status_t *statuses; show_units( this, TRUE ); - + + statuses = malloc(sizeof(mvcp_status_t) * this->count); + memset(statuses, 0, sizeof(mvcp_status_t) * this->count); + while ( !this->terminated ) { char buf[32]; - if ( !this->app->eof[this->app->selected_unit] && - mvcp_unit_get( this->app->command, this->app->selected_unit, - "eof", buf, sizeof(buf) ) != -1) - this->app->eof[this->app->selected_unit] = buf[0]; + /* wait for any event from notifier */ + mvcp_notifier_wait( notifier, &status ); - if ( mvcp_notifier_wait( notifier, &status ) != -1 ) + /* get status for all units */ + for(i = 0; i < this->count; i++) { + mvcp_notifier_get( notifier, &status, i); + if ( status.status == unit_disconnected ) + goto break_unit_disconnected; + + if( memcmp(&status, &statuses[i], sizeof(mvcp_status_t)) || !this->app->eof[i]) { - this->app->eof[this->app->selected_unit] = 0; - break; + /* save status */ + statuses[i] = status; + + /* save eof status */ + if ( !this->app->eof[i] && mvcp_unit_get( this->app->command, i, + "eof", buf, sizeof(buf) ) != -1) + this->app->eof[i] = buf[0]; + + /* send status update */ + if ( show_status( this, &status ) ) + show_units( this, TRUE ); } - if ( show_status( this, &status ) ) - show_units( this, TRUE ); } } +break_unit_disconnected: + + free(statuses); + show_units( this, FALSE ); if ( !this->terminated ) -- 1.7.4.4