2 * mvcp_status.c -- Unit Status Handling
3 * Copyright (C) 2002-2009 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 "mvcp_status.h"
28 #include "mvcp_tokeniser.h"
29 #include "mvcp_util.h"
31 /** Parse a unit status string.
34 void mvcp_status_parse( mvcp_status status
, char *text
)
36 mvcp_tokeniser tokeniser
= mvcp_tokeniser_init( );
37 int r
= mvcp_tokeniser_parse_new( tokeniser
, text
, " " );
38 if ( 19 == r
|| 17 == r
)
40 status
->unit
= atoi( mvcp_tokeniser_get_string( tokeniser
, 0 ) );
41 strncpy( status
->clip
, mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser
, 2 ), '\"' ), sizeof( status
->clip
) );
42 status
->position
= atol( mvcp_tokeniser_get_string( tokeniser
, 3 ) );
43 status
->speed
= atoi( mvcp_tokeniser_get_string( tokeniser
, 4 ) );
44 status
->fps
= atof( mvcp_tokeniser_get_string( tokeniser
, 5 ) );
45 status
->in
= atol( mvcp_tokeniser_get_string( tokeniser
, 6 ) );
46 status
->out
= atol( mvcp_tokeniser_get_string( tokeniser
, 7 ) );
47 status
->length
= atol( mvcp_tokeniser_get_string( tokeniser
, 8 ) );
49 strncpy( status
->tail_clip
, mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser
, 9 ), '\"' ), sizeof( status
->tail_clip
) );
50 status
->tail_position
= atol( mvcp_tokeniser_get_string( tokeniser
, 10 ) );
51 status
->tail_in
= atol( mvcp_tokeniser_get_string( tokeniser
, 11 ) );
52 status
->tail_out
= atol( mvcp_tokeniser_get_string( tokeniser
, 12 ) );
53 status
->tail_length
= atol( mvcp_tokeniser_get_string( tokeniser
, 13 ) );
54 status
->seek_flag
= atoi( mvcp_tokeniser_get_string( tokeniser
, 14 ) );
55 status
->generation
= atoi( mvcp_tokeniser_get_string( tokeniser
, 15 ) );
56 status
->clip_index
= atoi( mvcp_tokeniser_get_string( tokeniser
, 16 ) );
59 status
->start
= atoi( mvcp_tokeniser_get_string( tokeniser
, 17 ) );
60 status
->dur
= atoi( mvcp_tokeniser_get_string( tokeniser
, 18 ) );
63 if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "unknown" ) )
64 status
->status
= unit_unknown
;
65 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "undefined" ) )
66 status
->status
= unit_undefined
;
67 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "offline" ) )
68 status
->status
= unit_offline
;
69 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "not_loaded" ) )
70 status
->status
= unit_not_loaded
;
71 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "stopped" ) )
72 status
->status
= unit_stopped
;
73 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "paused" ) )
74 status
->status
= unit_paused
;
75 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "playing" ) )
76 status
->status
= unit_playing
;
77 else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser
, 1 ), "disconnected" ) )
78 status
->status
= unit_disconnected
;
82 memset( status
, 0, sizeof( mvcp_status_t
) );
83 fprintf( stderr
, "Status thread changed?\n" );
85 mvcp_tokeniser_close( tokeniser
);
88 /** Serialise a status into a string.
91 char *mvcp_status_serialise( mvcp_status status
, char *text
, int length
)
93 const char *status_string
= NULL
;
95 switch( status
->status
)
98 status_string
= "undefined";
102 status_string
= "offline";
105 case unit_not_loaded
:
106 status_string
= "not_loaded";
110 status_string
= "stopped";
114 status_string
= "playing";
118 status_string
= "unknown";
122 status_string
= "paused";
125 case unit_disconnected
:
126 status_string
= "disconnected";
130 snprintf( text
, length
, "%d %s \"%s\" %d %d %.2f %d %d %d \"%s\" %d %d %d %d %d %d %d %d %d\r\n",
141 status
->tail_position
,
154 /** Compare two status codes for changes.
157 int mvcp_status_compare( mvcp_status status1
, mvcp_status status2
)
159 return memcmp( status1
, status2
, sizeof( mvcp_status_t
) );
162 /** Copy status code info from dest to src.
165 mvcp_status
mvcp_status_copy( mvcp_status dest
, mvcp_status src
)
167 return memcpy( dest
, src
, sizeof( mvcp_status_t
) );