Commit 7158665d authored by Yoann Peronneau's avatar Yoann Peronneau

* src/misc/vlm.c: start exporting some VLM control functions

parent fd474910
...@@ -390,11 +390,14 @@ typedef struct vod_media_t vod_media_t; ...@@ -390,11 +390,14 @@ typedef struct vod_media_t vod_media_t;
typedef struct opengl_t opengl_t; typedef struct opengl_t opengl_t;
typedef struct opengl_sys_t opengl_sys_t; typedef struct opengl_sys_t opengl_sys_t;
/* divers */ /* VLM */
typedef struct vlc_meta_t vlc_meta_t;
typedef struct vlm_t vlm_t; typedef struct vlm_t vlm_t;
typedef struct vlm_message_t vlm_message_t; typedef struct vlm_message_t vlm_message_t;
typedef struct vlm_media_t vlm_media_t;
typedef struct vlm_schedule_t vlm_schedule_t;
/* divers */
typedef struct vlc_meta_t vlc_meta_t;
/***************************************************************************** /*****************************************************************************
......
...@@ -46,7 +46,7 @@ typedef struct ...@@ -46,7 +46,7 @@ typedef struct
} vlm_media_instance_t; } vlm_media_instance_t;
typedef struct struct vlm_media_t
{ {
vlc_bool_t b_enabled; vlc_bool_t b_enabled;
int i_type; int i_type;
...@@ -76,10 +76,10 @@ typedef struct ...@@ -76,10 +76,10 @@ typedef struct
int i_instance; int i_instance;
vlm_media_instance_t **instance; vlm_media_instance_t **instance;
} vlm_media_t; };
typedef struct struct vlm_schedule_t
{ {
/* names "schedule" is reserved */ /* names "schedule" is reserved */
char *psz_name; char *psz_name;
...@@ -97,7 +97,7 @@ typedef struct ...@@ -97,7 +97,7 @@ typedef struct
i_repeat < 0 : endless repeat */ i_repeat < 0 : endless repeat */
int i_repeat; int i_repeat;
} vlm_schedule_t; };
/* ok, here is the structure of a vlm_message: /* ok, here is the structure of a vlm_message:
The parent node is ( name_of_the_command , NULL ), or The parent node is ( name_of_the_command , NULL ), or
...@@ -134,6 +134,16 @@ struct vlm_t ...@@ -134,6 +134,16 @@ struct vlm_t
VLC_EXPORT( vlm_t *, __vlm_New, ( vlc_object_t * ) ); VLC_EXPORT( vlm_t *, __vlm_New, ( vlc_object_t * ) );
VLC_EXPORT( void, vlm_Delete, ( vlm_t * ) ); VLC_EXPORT( void, vlm_Delete, ( vlm_t * ) );
VLC_EXPORT( int, vlm_ExecuteCommand, ( vlm_t *, char *, vlm_message_t ** ) ); VLC_EXPORT( int, vlm_ExecuteCommand, ( vlm_t *, char *, vlm_message_t ** ) );
VLC_EXPORT( void, vlm_MessageDelete, ( vlm_message_t* ) ); VLC_EXPORT( void, vlm_MessageDelete, ( vlm_message_t * ) );
VLC_EXPORT( vlm_media_t *, vlm_MediaNew, ( vlm_t *, char *, int ) );
VLC_EXPORT( void, vlm_MediaDelete, ( vlm_t *, vlm_media_t *, char * ) );
VLC_EXPORT( int, vlm_MediaSetup, ( vlm_t *, vlm_media_t *, char *, char * ) );
VLC_EXPORT( int, vlm_MediaControl, ( vlm_t *, vlm_media_t *, char *, char *, char * ) );
VLC_EXPORT( vlm_schedule_t *, vlm_ScheduleNew, ( vlm_t *, char * ) );
VLC_EXPORT( void, vlm_ScheduleDelete, ( vlm_t *, vlm_schedule_t *, char * ) );
VLC_EXPORT( int, vlm_ScheduleSetup, ( vlm_schedule_t *, char *, char * ) );
VLC_EXPORT( int, vlm_MediaVodControl, ( void *, vod_media_t *, char *, int, va_list ) );
VLC_EXPORT( int, vlm_Save, ( vlm_t *, char * ) );
VLC_EXPORT( int, vlm_Load, ( vlm_t *, char * ) );
#endif #endif
...@@ -49,30 +49,21 @@ ...@@ -49,30 +49,21 @@
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
*****************************************************************************/ *****************************************************************************/
static char *vlm_Save( vlm_t * );
static int vlm_Load( vlm_t *, char *);
static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * ); static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * );
static vlm_message_t *vlm_Help( vlm_t *, char * ); static vlm_message_t *vlm_Help( vlm_t *, char * );
static vlm_media_t *vlm_MediaNew ( vlm_t *, char *, int );
static void vlm_MediaDelete ( vlm_t *, vlm_media_t *, char * );
static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * ); static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * );
static int vlm_MediaSetup ( vlm_t *, vlm_media_t *, char *, char * );
static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char *, char * );
static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, char * ); static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, char * );
static vlm_message_t *vlm_MessageNew( char *, const char *, ... ); static vlm_message_t *vlm_MessageNew( char *, const char *, ... );
static vlm_message_t *vlm_MessageAdd( vlm_message_t*, vlm_message_t* ); static vlm_message_t *vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char * );
static void vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *);
static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *);
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *);
static int vlm_MediaVodControl( void *, vod_media_t *, char *, int, va_list ); static char *Save( vlm_t * );
static int Load( vlm_t *, char * );
static int ExecuteCommand( vlm_t *, char *, vlm_message_t **); static int ExecuteCommand( vlm_t *, char *, vlm_message_t ** );
static int Manage( vlc_object_t* ); static int Manage( vlc_object_t * );
/***************************************************************************** /*****************************************************************************
* vlm_New: * vlm_New:
...@@ -192,6 +183,70 @@ int vlm_ExecuteCommand( vlm_t *p_vlm, char *psz_command, ...@@ -192,6 +183,70 @@ int vlm_ExecuteCommand( vlm_t *p_vlm, char *psz_command,
return i_result; return i_result;
} }
/*****************************************************************************
* vlm_Save:
*****************************************************************************/
int vlm_Save( vlm_t *p_vlm, char *psz_file )
{
FILE *file;
char *psz_save;
if( !p_vlm || !psz_file ) return 1;
file = fopen( psz_file, "w" );
if( file == NULL ) return 1;
psz_save = Save( p_vlm );
if( psz_save == NULL )
{
fclose( file );
return 1;
}
fwrite( psz_save, strlen( psz_save ), 1, file );
fclose( file );
free( psz_save );
return 0;
}
/*****************************************************************************
* vlm_Load:
*****************************************************************************/
int vlm_Load( vlm_t *p_vlm, char *psz_file )
{
FILE *file;
int64_t i_size;
char *psz_buffer;
if( !p_vlm || !psz_file ) return 1;
file = fopen( psz_file, "r" );
if( file == NULL ) return 1;
if( fseek( file, 0, SEEK_END) != 0 ) return 2;
i_size = ftell( file );
fseek( file, 0, SEEK_SET);
psz_buffer = malloc( i_size + 1 );
if( !psz_buffer )
{
fclose( file );
return 2;
}
fread( psz_buffer, 1, i_size, file);
psz_buffer[ i_size ] = '\0';
if( Load( p_vlm, psz_buffer ) )
{
free( psz_buffer );
return 3;
}
free( psz_buffer );
fclose( file );
return 0;
}
/***************************************************************************** /*****************************************************************************
* FindEndCommand * FindEndCommand
*****************************************************************************/ *****************************************************************************/
...@@ -539,27 +594,15 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command, ...@@ -539,27 +594,15 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
else if( !strcmp(ppsz_command[0], "save") ) else if( !strcmp(ppsz_command[0], "save") )
{ {
FILE *file;
if( i_command != 2 ) goto syntax_error; if( i_command != 2 ) goto syntax_error;
file = fopen( ppsz_command[1], "w" ); if( vlm_Save( p_vlm, ppsz_command[1] ) )
if( file == NULL )
{ {
p_message = vlm_MessageNew( "save", "Unable to save to file" ); p_message = vlm_MessageNew( "save", "Unable to save to file" );
goto error; goto error;
} }
else else
{ {
char *psz_save = vlm_Save( p_vlm );
if( psz_save == NULL )
{
fclose( file );
goto error;
}
fwrite( psz_save, strlen( psz_save ), 1, file );
fclose( file );
free( psz_save );
p_message = vlm_MessageNew( "save", NULL ); p_message = vlm_MessageNew( "save", NULL );
goto success; goto success;
} }
...@@ -567,53 +610,25 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command, ...@@ -567,53 +610,25 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
else if( !strcmp(ppsz_command[0], "load") ) else if( !strcmp(ppsz_command[0], "load") )
{ {
FILE *file;
if( i_command != 2 ) goto syntax_error; if( i_command != 2 ) goto syntax_error;
file = fopen( ppsz_command[1], "r" ); switch( vlm_Load( p_vlm, ppsz_command[1] ) )
if( file == NULL )
{
p_message = vlm_MessageNew( "load", "Unable to load from file" );
goto error;
}
else
{
int64_t i_size;
char *psz_buffer;
if( fseek( file, 0, SEEK_END) == 0 )
{
i_size = ftell( file );
fseek( file, 0, SEEK_SET);
psz_buffer = malloc( i_size + 1 );
if( !psz_buffer )
{ {
fclose( file ); case 0:
p_message = vlm_MessageNew( "load", NULL );
goto success;
case 2:
p_message = vlm_MessageNew( "load", "read file error" );
goto error; goto error;
} case 3:
fread( psz_buffer, 1, i_size, file); p_message =
psz_buffer[ i_size ] = '\0'; vlm_MessageNew( "load", "error while loading file" );
if( vlm_Load( p_vlm, psz_buffer ) )
{
free( psz_buffer );
p_message = vlm_MessageNew( "load", "error while loading "
"file" );
goto error; goto error;
} default:
free( psz_buffer ); p_message =
} vlm_MessageNew( "load", "Unable to load from file" );
else
{
p_message = vlm_MessageNew( "load", "read file error" );
goto error; goto error;
} }
fclose( file );
p_message = vlm_MessageNew( "load", NULL );
goto success;
}
} }
else else
...@@ -817,7 +832,7 @@ vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media, char *psz_name ) ...@@ -817,7 +832,7 @@ vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media, char *psz_name )
return NULL; return NULL;
} }
static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
{ {
vlm_media_t *media = malloc( sizeof( vlm_media_t ) ); vlm_media_t *media = malloc( sizeof( vlm_media_t ) );
...@@ -873,7 +888,7 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) ...@@ -873,7 +888,7 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
} }
/* for now, simple delete. After, del with options (last arg) */ /* for now, simple delete. After, del with options (last arg) */
static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name ) void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
{ {
if( media == NULL ) return; if( media == NULL ) return;
...@@ -918,7 +933,7 @@ static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name ) ...@@ -918,7 +933,7 @@ static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
free( media ); free( media );
} }
static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
char *psz_value ) char *psz_value )
{ {
if( !psz_cmd) return VLC_EGENERIC; if( !psz_cmd) return VLC_EGENERIC;
...@@ -1063,7 +1078,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, ...@@ -1063,7 +1078,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id, int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
char *psz_command, char *psz_args ) char *psz_command, char *psz_args )
{ {
vlm_media_instance_t *p_instance; vlm_media_instance_t *p_instance;
...@@ -1189,7 +1204,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id, ...@@ -1189,7 +1204,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
/***************************************************************************** /*****************************************************************************
* Schedule handling * Schedule handling
*****************************************************************************/ *****************************************************************************/
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name ) vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
{ {
vlm_schedule_t *p_sched = malloc( sizeof( vlm_schedule_t ) ); vlm_schedule_t *p_sched = malloc( sizeof( vlm_schedule_t ) );
...@@ -1217,7 +1232,7 @@ static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name ) ...@@ -1217,7 +1232,7 @@ static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
} }
/* for now, simple delete. After, del with options (last arg) */ /* for now, simple delete. After, del with options (last arg) */
static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched, void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
char *psz_name ) char *psz_name )
{ {
if( sched == NULL ) return; if( sched == NULL ) return;
...@@ -1246,7 +1261,7 @@ static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name ) ...@@ -1246,7 +1261,7 @@ static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name )
} }
/* Ok, setup schedule command will be able to support only one (argument value) at a time */ /* Ok, setup schedule command will be able to support only one (argument value) at a time */
static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
char *psz_value ) char *psz_value )
{ {
if( !strcmp( psz_cmd, "enabled" ) ) if( !strcmp( psz_cmd, "enabled" ) )
...@@ -1852,7 +1867,7 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter ) ...@@ -1852,7 +1867,7 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
/***************************************************************************** /*****************************************************************************
* Config handling functions * Config handling functions
*****************************************************************************/ *****************************************************************************/
static int vlm_Load( vlm_t *vlm, char *file ) static int Load( vlm_t *vlm, char *file )
{ {
char *pf = file; char *pf = file;
...@@ -1890,7 +1905,7 @@ static int vlm_Load( vlm_t *vlm, char *file ) ...@@ -1890,7 +1905,7 @@ static int vlm_Load( vlm_t *vlm, char *file )
return 0; return 0;
} }
static char *vlm_Save( vlm_t *vlm ) static char *Save( vlm_t *vlm )
{ {
char *save = NULL; char *save = NULL;
char *p; char *p;
...@@ -2127,7 +2142,7 @@ static char *vlm_Save( vlm_t *vlm ) ...@@ -2127,7 +2142,7 @@ static char *vlm_Save( vlm_t *vlm )
/***************************************************************************** /*****************************************************************************
* Manage: * Manage:
*****************************************************************************/ *****************************************************************************/
static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media, int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
char *psz_id, int i_query, va_list args ) char *psz_id, int i_query, va_list args )
{ {
vlm_t *vlm = (vlm_t *)p_private; vlm_t *vlm = (vlm_t *)p_private;
...@@ -2306,5 +2321,17 @@ vlm_t *__vlm_New( vlc_object_t *a ) ...@@ -2306,5 +2321,17 @@ vlm_t *__vlm_New( vlc_object_t *a )
void vlm_Delete( vlm_t *a ){} void vlm_Delete( vlm_t *a ){}
int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c ){ return -1; } int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c ){ return -1; }
void vlm_MessageDelete( vlm_message_t *a ){} void vlm_MessageDelete( vlm_message_t *a ){}
vlm_media_t *vlm_MediaNew( vlm_t *a, char *b, int c ){ return NULL }
void vlm_MediaDelete( vlm_t *a, vlm_media_t *b, char *c ){}
int vlm_MediaSetup( vlm_t *a, vlm_media_t *b, char *c, char *d ){ return -1; }
int vlm_MediaControl( vlm_t *a, vlm_media_t *b, char *c, char *d, char *e )
{ return -1; }
vlm_schedule_t * vlm_ScheduleNew( vlm_t *a, char *b ){ return NULL; }
void vlm_ScheduleDelete( vlm_t *a, vlm_schedule_t *b, char *c ){}
int vlm_ScheduleSetup( vlm_schedule_t *a, char *b, char *c ){ return -1; }
int vlm_MediaVodControl( void *a, vod_media_t *b, char *c, int, va_list d )
{ return -1; }
int vlm_Save( vlm_t *a, char *b ){ return -1; }
int vlm_Load( vlm_t *a, char *b ){ return -1; }
#endif /* ENABLE_VLM */ #endif /* ENABLE_VLM */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment