]> git.sesse.net Git - mlt/blob - src/valerie/valerie_status.c
Merge ../mlt++
[mlt] / src / valerie / valerie_status.c
1 /*
2  * valerie_status.c -- Unit Status Handling
3  * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /* System header files */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* Application header files */
27 #include "valerie_status.h"
28 #include "valerie_tokeniser.h"
29 #include "valerie_util.h"
30
31 /** Parse a unit status string.
32 */
33
34 void valerie_status_parse( valerie_status status, char *text )
35 {
36         valerie_tokeniser tokeniser = valerie_tokeniser_init( );
37         if ( valerie_tokeniser_parse_new( tokeniser, text, " " ) == 17 )
38         {
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 ) );
47
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 ) );
56
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;
73         }
74         else
75         {
76                 memset( status, 0, sizeof( valerie_status_t ) );
77                 fprintf( stderr, "Status thread changed?\n" );
78         }
79         valerie_tokeniser_close( tokeniser );
80 }
81
82 /** Serialise a status into a string.
83 */
84
85 char *valerie_status_serialise( valerie_status status, char *text, int length )
86 {
87         const char *status_string = NULL;
88
89         switch( status->status )
90         {
91                 case unit_undefined:
92                         status_string = "undefined";
93                         break;
94
95                 case unit_offline:
96                         status_string = "offline";
97                         break;
98
99                 case unit_not_loaded:
100                         status_string = "not_loaded";
101                         break;
102
103                 case unit_stopped:
104                         status_string = "stopped";
105                         break;
106
107                 case unit_playing:
108                         status_string = "playing";
109                         break;
110
111                 case unit_unknown:
112                         status_string = "unknown";
113                         break;
114
115                 case unit_paused:
116                         status_string = "paused";
117                         break;
118
119                 case unit_disconnected:
120                         status_string = "disconnected";
121                         break;
122         }
123
124         snprintf( text, length, "%d %s \"%s\" %d %d %.2f %d %d %d \"%s\" %d %d %d %d %d %d %d\r\n",
125                                                         status->unit,
126                                                         status_string,
127                                                         status->clip,
128                                                         status->position, 
129                                                         status->speed,
130                                                         status->fps,
131                                                         status->in,
132                                                         status->out,
133                                                         status->length,
134                                                         status->tail_clip,
135                                                         status->tail_position, 
136                                                         status->tail_in,
137                                                         status->tail_out,
138                                                         status->tail_length,
139                                                         status->seek_flag,
140                                                         status->generation,
141                                                         status->clip_index );
142
143         return text;
144 }
145
146 /** Compare two status codes for changes.
147 */
148
149 int valerie_status_compare( valerie_status status1, valerie_status status2 )
150 {
151         return memcmp( status1, status2, sizeof( valerie_status_t ) );
152 }
153
154 /** Copy status code info from dest to src.
155 */
156
157 valerie_status valerie_status_copy( valerie_status dest, valerie_status src )
158 {
159         return memcpy( dest, src, sizeof( valerie_status_t ) );
160 }