2 * valerie_status.c -- Unit Status Handling
3 * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* System header files */
26 /* Application header files */
27 #include "valerie_status.h"
28 #include "valerie_tokeniser.h"
29 #include "valerie_util.h"
31 /** Parse a unit status string.
34 void valerie_status_parse( valerie_status status
, char *text
)
36 valerie_tokeniser tokeniser
= valerie_tokeniser_init( );
37 if ( valerie_tokeniser_parse_new( tokeniser
, text
, " " ) == 17 )
39 status
->unit
= atoi( valerie_tokeniser_get_string( tokeniser
, 0 ) );
40 strncpy( status
->clip
, valerie_util_strip( valerie_tokeniser_get_string( tokeniser
, 2 ), '\"' ), sizeof( status
->clip
) );
41 status
->position
= atol( valerie_tokeniser_get_string( tokeniser
, 3 ) );
42 status
->speed
= atoi( valerie_tokeniser_get_string( tokeniser
, 4 ) );
43 status
->fps
= atof( valerie_tokeniser_get_string( tokeniser
, 5 ) );
44 status
->in
= atol( valerie_tokeniser_get_string( tokeniser
, 6 ) );
45 status
->out
= atol( valerie_tokeniser_get_string( tokeniser
, 7 ) );
46 status
->length
= atol( valerie_tokeniser_get_string( tokeniser
, 8 ) );
48 strncpy( status
->tail_clip
, valerie_util_strip( valerie_tokeniser_get_string( tokeniser
, 9 ), '\"' ), sizeof( status
->tail_clip
) );
49 status
->tail_position
= atol( valerie_tokeniser_get_string( tokeniser
, 10 ) );
50 status
->tail_in
= atol( valerie_tokeniser_get_string( tokeniser
, 11 ) );
51 status
->tail_out
= atol( valerie_tokeniser_get_string( tokeniser
, 12 ) );
52 status
->tail_length
= atol( valerie_tokeniser_get_string( tokeniser
, 13 ) );
53 status
->seek_flag
= atoi( valerie_tokeniser_get_string( tokeniser
, 14 ) );
54 status
->generation
= atoi( valerie_tokeniser_get_string( tokeniser
, 15 ) );
55 status
->clip_index
= atoi( valerie_tokeniser_get_string( tokeniser
, 16 ) );
57 if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "unknown" ) )
58 status
->status
= unit_unknown
;
59 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "undefined" ) )
60 status
->status
= unit_undefined
;
61 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "offline" ) )
62 status
->status
= unit_offline
;
63 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "not_loaded" ) )
64 status
->status
= unit_not_loaded
;
65 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "stopped" ) )
66 status
->status
= unit_stopped
;
67 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "paused" ) )
68 status
->status
= unit_paused
;
69 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "playing" ) )
70 status
->status
= unit_playing
;
71 else if ( !strcmp( valerie_tokeniser_get_string( tokeniser
, 1 ), "disconnected" ) )
72 status
->status
= unit_disconnected
;
76 memset( status
, 0, sizeof( valerie_status_t
) );
77 fprintf( stderr
, "Status thread changed?\n" );
79 valerie_tokeniser_close( tokeniser
);
82 /** Serialise a status into a string.
85 char *valerie_status_serialise( valerie_status status
, char *text
, int length
)
87 char *status_string
= NULL
;
89 switch( status
->status
)
92 status_string
= "undefined";
96 status_string
= "offline";
100 status_string
= "not_loaded";
104 status_string
= "stopped";
108 status_string
= "playing";
112 status_string
= "unknown";
116 status_string
= "paused";
119 case unit_disconnected
:
120 status_string
= "disconnected";
124 snprintf( text
, length
, "%d %s \"%s\" %d %d %.2f %d %d %d \"%s\" %d %d %d %d %d %d %d\r\n",
135 status
->tail_position
,
141 status
->clip_index
);
146 /** Compare two status codes for changes.
149 int valerie_status_compare( valerie_status status1
, valerie_status status2
)
151 return memcmp( status1
, status2
, sizeof( valerie_status_t
) );
154 /** Copy status code info from dest to src.
157 valerie_status
valerie_status_copy( valerie_status dest
, valerie_status src
)
159 return memcpy( dest
, src
, sizeof( valerie_status_t
) );