fix eof getting per unit
[rugen] / src / page_status.c
index d561c72..295217d 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * page_status.c -- Status Page Handling
  * Copyright (C) 2002-2003 Charles Yates <charles.yates@pandora.be>
+ * Copyright (C) 2010 Dan Dennedy <dan@dennedy.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,7 +30,6 @@
 #include "interface.h"
 #include "support.h"
 #include "dv1394app.h"
-#include "util.h"
 #include "page.h"
 
 typedef struct 
@@ -37,12 +37,13 @@ typedef struct
        struct page_t parent;
        dv1394app app;
        GtkWidget *widget;
-       valerie status;
+       mvcp status;
        int terminated;
        pthread_t status_thread;
        guint context;
        int unit;
        int count;
+       struct page_t *parent_page;
 }
 *page_status, page_status_t;
 
@@ -51,45 +52,45 @@ static GtkWidget *this_page_get_widget( page );
 /** Show the status associated to a unit.
 */
 
-static int show_status( page_status this, valerie_status status )
+static char* status_to_text( mvcp_status status )
+{
+       switch( status->status )
+       {
+               case unit_offline:      return "offline";       break;
+               case unit_undefined:    return "undefined";     break;
+               case unit_not_loaded:   return "unloaded";      break;
+               case unit_stopped:      return "stopped";       break;
+               case unit_playing:      return "playing";       break;
+               case unit_paused:       return "paused";        break;
+               case unit_disconnected: return "disconnect";    break;
+               case unit_unknown:      return "unknown";       break;
+       }
+       return "unknown";
+}
+
+static void format_status_string(char* buf, int size, mvcp_status status , char* sep)
+{
+       char tc1[12], tc2[12], tc3[12];
+
+       snprintf( buf, size,
+               "[%s]%sIN:%s%sPOS:%s%sOUT:%s%s%s%s",
+               status_to_text( status ), sep,
+               frames2tc(status->in,       status->fps, tc1), sep,
+               frames2tc(status->position, status->fps, tc2), sep,
+               frames2tc(status->out,      status->fps, tc3), sep,
+               status->clip, sep
+       );
+
+}
+
+static int show_status( page_status this, mvcp_status status )
 {
        GtkWidget *widget = this_page_get_widget( ( page )this );
        char temp[ 1024 ] = "";
        char temp2[ 1024 ];
        char label_name[ 256 ];
 
-       sprintf( temp, "%05d %05d %05d %s [", status->in, status->position, status->out, status->clip );
-       
-       switch( status->status )
-       {
-               case unit_offline:
-                       strcat( temp, "offline" );
-                       break;
-               case unit_undefined:
-                       strcat( temp, "undefined" );
-                       break;
-               case unit_not_loaded:
-                       strcat( temp, "unloaded" );
-                       break;
-               case unit_stopped:
-                       strcat( temp, "stopped" );
-                       break;
-               case unit_playing:
-                       strcat( temp, "playing" );
-                       break;
-               case unit_paused:
-                       strcat( temp, "paused" );
-                       break;
-               case unit_disconnected:
-                       strcat( temp, "disconnect" );
-                       break;
-               default:
-                       strcat( temp, "unknown" );
-                       break;
-       }
-
-       strcat( temp, "]" );
-       
+       format_status_string(temp, sizeof(temp), status , "\n");
        sprintf( label_name, "label_unit_%d", status->unit );
 
        gdk_threads_enter();
@@ -97,6 +98,7 @@ static int show_status( page_status this, valerie_status status )
        gtk_label_set_text( GTK_LABEL( widget ), temp );
        if ( status->unit == dv1394app_get_selected_unit( this->app ) )
        {
+               format_status_string(temp, sizeof(temp), status , " ");
                sprintf( temp2, "U%d - %s", status->unit, temp );
                widget = lookup_widget( dv1394app_get_widget( this->app ), "statusbar" );
                gtk_statusbar_pop( GTK_STATUSBAR( widget ), this->context );
@@ -118,20 +120,20 @@ static void show_units( page_status this, gboolean active )
        char temp[ 1024 ] = "";
        char button_name[ 256 ];
        
-       valerie_units units = NULL;
-       valerie_unit_entry_t unit;
+       mvcp_units units = NULL;
+       mvcp_unit_entry_t unit;
        int unit_count = 0;
        
-       valerie_nodes nodes = NULL;
-       valerie_node_entry_t node;
+       mvcp_nodes nodes = NULL;
+       mvcp_node_entry_t node;
        int node_count = 0;
 
        if ( active )
        {
-               units = valerie_units_init( this->status );
-               unit_count = valerie_units_count( units );
-               nodes = valerie_nodes_init( this->status );
-               node_count = valerie_nodes_count( nodes );
+               units = mvcp_units_init( this->status );
+               unit_count = mvcp_units_count( units );
+               nodes = mvcp_nodes_init( this->status );
+               node_count = mvcp_nodes_count( nodes );
                this->count = unit_count;
        }
        
@@ -141,11 +143,11 @@ static void show_units( page_status this, gboolean active )
        {
                if ( index < unit_count )
                {
-                       valerie_units_get( units, index, &unit );
+                       mvcp_units_get( units, index, &unit );
                        
                        for ( index2 = 0; index2 < node_count; index2 ++ )
                        {
-                               valerie_nodes_get( nodes, index2, &node );
+                               mvcp_nodes_get( nodes, index2, &node );
                                if ( !strcmp( node.guid, unit.guid ) )
                                        break;
                        }
@@ -176,8 +178,8 @@ static void show_units( page_status this, gboolean active )
        gdk_flush();
        gdk_threads_leave();                    
 
-       valerie_notifier notifier = valerie_get_notifier( this->status );
-       valerie_status_t status;
+       mvcp_notifier notifier = mvcp_get_notifier( this->status );
+       mvcp_status_t status;
 
        for ( index = 0; index < MAX_UNITS; index ++ )
        {
@@ -185,14 +187,14 @@ static void show_units( page_status this, gboolean active )
                if ( !active )
                        status.status = unit_disconnected;
                else
-                       valerie_notifier_get( notifier, &status, index );
+                       mvcp_notifier_get( notifier, &status, index );
                show_status( this, &status );           
        }
                
        if ( active )
        {
-               valerie_nodes_close( nodes );
-               valerie_units_close( units );
+               mvcp_nodes_close( nodes );
+               mvcp_units_close( units );
        }
 }
 
@@ -202,17 +204,27 @@ static void show_units( page_status this, gboolean active )
 static void *status_thread( void *arg )
 {
        page_status this = arg;
-       valerie_notifier notifier = valerie_get_notifier( this->status );
-       valerie_status_t status;
+       mvcp_notifier notifier = mvcp_get_notifier( this->status );
+       mvcp_status_t status;
 
        show_units( this, TRUE );
        
        while ( !this->terminated )
        {
-               if ( valerie_notifier_wait( notifier, &status ) != -1 )
+               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];
+
+               if ( mvcp_notifier_wait( notifier, &status ) != -1 )
                {
                        if ( status.status == unit_disconnected )
+                       {
+                               this->app->eof[this->app->selected_unit] = 0;
                                break;
+                       }
                        if ( show_status( this, &status ) )
                                show_units( this, TRUE );
                }
@@ -246,10 +258,10 @@ void on_radiobutton_toggled( GtkToggleButton *togglebutton, gpointer user_data )
        }
        if ( index < MAX_UNITS )
        {
-               valerie_status_t status;
-               valerie_notifier notifier = valerie_get_notifier( this->status );
+               mvcp_status_t status;
+               mvcp_notifier notifier = mvcp_get_notifier( this->status );
                dv1394app_on_unit_change( app, index );
-               valerie_notifier_get( notifier, &status, index );
+               mvcp_notifier_get( notifier, &status, index );
                gdk_threads_leave( );
                show_status( this, &status );
                gdk_threads_enter( );
@@ -260,14 +272,14 @@ static GtkWidget *this_page_get_widget( page super )
 {
        page_status this = ( page_status )super;
        if ( this->widget == NULL )
-               this->widget = create_page_status( );
+               this->widget = this->parent_page->get_widget(this->parent_page);
        return this->widget;
 }
 
 static void this_page_get_toolbar_info( page super, GtkIconSize size, GtkWidget **icon, char **label )
 {
-       *icon = gtk_image_new_from_stock( "gtk-execute",  size );
-       *label = "_Units";
+       *icon = gtk_image_new_from_stock( "gtk-home",  size );
+       *label = _("_Units");
 }
 
 static void this_page_on_connect( page super )
@@ -276,7 +288,7 @@ static void this_page_on_connect( page super )
        if ( this->terminated )
        {
                this->terminated = 0;
-               this->status = valerie_init( dv1394app_get_parser( this->app ) );
+               this->status = mvcp_init( dv1394app_get_parser( this->app ) );
                pthread_create( &this->status_thread, NULL, status_thread, this );
        }
 }
@@ -291,7 +303,7 @@ static void this_page_on_disconnect( page super )
                gdk_threads_leave();
                pthread_join( this->status_thread, NULL );
                gdk_threads_enter();
-               valerie_close( this->status );
+               mvcp_close( this->status );
                widget = lookup_widget( dv1394app_get_widget( this->app ), "statusbar" );
                gtk_statusbar_push( GTK_STATUSBAR( widget ), this->context, "Disconnected." );
        }
@@ -304,12 +316,13 @@ static void this_page_close( page super )
                free( this );
 }
 
-page page_status_init( dv1394app app )
+page page_status_init( dv1394app app, struct page_t *parent_page )
 {
        page_status this = calloc( 1, sizeof( page_status_t ) );
        int index = 0;
        GtkWidget *widget;
-       
+
+       this->parent_page = parent_page;
        this->parent.get_widget = this_page_get_widget;
        this->parent.get_toolbar_info = this_page_get_toolbar_info;
        this->parent.on_connect = this_page_on_connect;