Commit 756605b7 authored by Laurent Aimar's avatar Laurent Aimar

* vlm.*: move vlm to the core (now, vlm_New create only one instance)

 * http.c: begin support of vlm interraction (not yet documented).
parent c56ae63c
...@@ -313,6 +313,9 @@ typedef struct httpd_stream_t httpd_stream_t; ...@@ -313,6 +313,9 @@ typedef struct httpd_stream_t httpd_stream_t;
/* divers */ /* divers */
typedef struct vlc_meta_t vlc_meta_t; typedef struct vlc_meta_t vlc_meta_t;
typedef struct vlm_t vlm_t;
typedef struct vlm_message_t vlm_message_t;
/***************************************************************************** /*****************************************************************************
* Variable callbacks * Variable callbacks
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vlc_objects.h: vlc_object_t definition. * vlc_objects.h: vlc_object_t definition.
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: vlc_objects.h,v 1.22 2004/01/25 18:17:08 zorglub Exp $ * $Id$
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#define VLC_OBJECT_PACKETIZER (-13) #define VLC_OBJECT_PACKETIZER (-13)
#define VLC_OBJECT_ENCODER (-14) #define VLC_OBJECT_ENCODER (-14)
#define VLC_OBJECT_DIALOGS (-15) #define VLC_OBJECT_DIALOGS (-15)
#define VLC_OBJECT_VLM (-16)
#define VLC_OBJECT_GENERIC (-666) #define VLC_OBJECT_GENERIC (-666)
......
/***************************************************************************** /*****************************************************************************
* .c: VLM interface plugin * vlc_vlm.h: VLM interface plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN * Copyright (C) 2000, 2001 VideoLAN
* $Id$ * $Id$
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef _VLC_VLM_H
#define _VLC_VLM_H 1
/* VLM specific - structures and functions */ /* VLM specific - structures and functions */
enum enum
{ {
...@@ -83,19 +86,17 @@ typedef struct ...@@ -83,19 +86,17 @@ typedef struct
The parent node is ( name_of_the_command , NULL ), or The parent node is ( name_of_the_command , NULL ), or
( name_of_the_command , message_error ) on error. ( name_of_the_command , message_error ) on error.
If a node has children, it should not have a value (=NULL).*/ If a node has children, it should not have a value (=NULL).*/
typedef struct vlm_message struct vlm_message_t
{ {
char *psz_name; char *psz_name;
char *psz_value; char *psz_value;
int i_child; int i_child;
vlm_message_t **child;
struct vlm_message **child; };
} vlm_message_t;
typedef struct struct vlm_t
{ {
VLC_COMMON_MEMBERS VLC_COMMON_MEMBERS
...@@ -114,12 +115,15 @@ typedef struct ...@@ -114,12 +115,15 @@ typedef struct
int i_schedule; int i_schedule;
vlm_schedule_t **schedule; vlm_schedule_t **schedule;
} vlm_t; };
#define vlm_New( a ) __vlm_New( VLC_OBJECT(a) ) #define vlm_New( a ) __vlm_New( VLC_OBJECT(a) )
vlm_t *__vlm_New ( vlc_object_t * );
void vlm_Delete( vlm_t * );
int vlm_ExecuteCommand( vlm_t *, char *, vlm_message_t **); VLC_EXPORT( vlm_t *, __vlm_New, ( vlc_object_t * ) );
void vlm_MessageDelete( vlm_message_t* ); VLC_EXPORT( void, vlm_Delete, ( vlm_t * ) );
VLC_EXPORT( int, vlm_ExecuteCommand, ( vlm_t *, char *, vlm_message_t **) );
VLC_EXPORT( void, vlm_MessageDelete, ( vlm_message_t* ) );
#endif
This diff is collapsed.
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
#include "network.h" #include "network.h"
#include "vlm.h" #include "vlc_vlm.h"
#if defined( WIN32 ) || defined( UNDER_CE ) #if defined( WIN32 ) || defined( UNDER_CE )
#define SOCKET_CLOSE(a) closesocket(a) #define SOCKET_CLOSE(a) closesocket(a)
......
SOURCES_telnet = telnet.c vlm.c vlm.h
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* objects.c: vlc_object_t handling * objects.c: vlc_object_t handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2004 VideoLAN * Copyright (C) 2004 VideoLAN
* $Id: objects.c,v 1.46 2004/03/03 13:25:24 fenrir Exp $ * $Id$
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "vlc_codec.h" #include "vlc_codec.h"
#include "vlc_httpd.h" #include "vlc_httpd.h"
#include "vlc_vlm.h"
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -155,6 +156,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type ) ...@@ -155,6 +156,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
i_size = sizeof( httpd_t ); i_size = sizeof( httpd_t );
psz_type = "http daemon"; psz_type = "http daemon";
break; break;
case VLC_OBJECT_VLM:
i_size = sizeof( vlm_t );
psz_type = "vlm dameon";
break;
default: default:
i_size = i_type > 0 i_size = i_type > 0
? i_type > (int)sizeof(vlc_object_t) ? i_type > (int)sizeof(vlc_object_t)
......
...@@ -29,28 +29,28 @@ ...@@ -29,28 +29,28 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/intf.h> #include <vlc/intf.h>
#include <vlc/input.h> #include <vlc/input.h>
#ifdef HAVE_TIME_H #ifdef HAVE_TIME_H
# include <time.h> /* ctime() */ # include <time.h> /* ctime() */
#endif #endif
#include "vlm.h" #include "vlc_vlm.h"
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
*****************************************************************************/ *****************************************************************************/
static char *vlm_Save( vlm_t * ); static char *vlm_Save( vlm_t * );
static int vlm_Load( vlm_t *, char *); static int vlm_Load( vlm_t *, char *);
static vlm_media_t *vlm_MediaNew( vlm_t *, char *, int );
static int vlm_MediaDelete( vlm_t *, vlm_media_t *, char * );
static vlm_media_t *vlm_MediaSearch( vlm_t *, char * );
static int vlm_MediaSetup( vlm_media_t *, char *, char * );
static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, 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 int vlm_MediaDelete ( vlm_t *, vlm_media_t *, char * );
static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * );
static int vlm_MediaSetup ( vlm_media_t *, char *, char * );
static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char * );
static vlm_message_t* vlm_MessageNew( char * , char * ); static vlm_message_t* vlm_MessageNew( char * , 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* );
...@@ -59,10 +59,118 @@ static int vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *); ...@@ -59,10 +59,118 @@ static int vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *);
static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *); static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *);
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleSearch( 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_t *__vlm_New ( vlc_object_t *p_this )
{
vlc_value_t lockval;
vlm_t *vlm = NULL;
/* to be sure to avoid multiple creation */
var_Create( p_this->p_libvlc, "vlm_mutex", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc, "vlm_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
if( !(vlm = vlc_object_find( p_this, VLC_OBJECT_VLM, FIND_ANYWHERE )) )
{
msg_Info( p_this, "creating vlm" );
if( ( vlm = vlc_object_create( p_this, VLC_OBJECT_VLM ) ) == NULL )
{
vlc_mutex_unlock( lockval.p_address );
return NULL;
}
vlc_mutex_init( p_this->p_vlc, &vlm->lock );
vlm->i_media = 0;
vlm->media = NULL;
vlm->i_schedule = 0;
vlm->schedule = NULL;
vlc_object_yield( vlm );
vlc_object_attach( vlm, p_this->p_vlc );
}
vlc_mutex_unlock( lockval.p_address );
if( vlc_thread_create( vlm, "vlm thread",
Manage, VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
{
vlc_mutex_destroy( &vlm->lock );
vlc_object_destroy( vlm );
return NULL;
}
return vlm;
}
/*****************************************************************************
* vlm_Delete:
*****************************************************************************/
void vlm_Delete( vlm_t *vlm )
{
vlc_value_t lockval;
int i;
var_Get( vlm->p_libvlc, "vlm_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
vlc_object_release( vlm );
if( vlm->i_refcount > 0 )
{
vlc_mutex_unlock( lockval.p_address );
return;
}
vlm->b_die = VLC_TRUE;
vlc_thread_join( vlm );
vlc_mutex_destroy( &vlm->lock );
for( i = 0; i < vlm->i_media; i++ )
{
vlm_media_t *media = vlm->media[i];
vlm_MediaDelete( vlm, media, NULL );
}
if( vlm->media ) free( vlm->media );
for( i = 0; i < vlm->i_schedule; i++ )
{
vlm_ScheduleDelete( vlm, vlm->schedule[i], NULL );
}
if( vlm->schedule ) free( vlm->schedule );
vlc_object_detach( vlm );
vlc_object_destroy( vlm );
vlc_mutex_unlock( lockval.p_address );
}
/*****************************************************************************
* vlm_ExecuteCommand:
*****************************************************************************/
int vlm_ExecuteCommand( vlm_t *vlm, char *command, vlm_message_t **message)
{
int result;
vlc_mutex_lock( &vlm->lock );
result = ExecuteCommand( vlm, command, message );
vlc_mutex_unlock( &vlm->lock );
return result;
}
/*****************************************************************************
*
*****************************************************************************/
#if 1 #if 1
static char *FindEndCommand( char *psz ) static char *FindEndCommand( char *psz )
{ {
...@@ -183,19 +291,8 @@ static char *FindEndCommand( char *psz ) ...@@ -183,19 +291,8 @@ static char *FindEndCommand( char *psz )
#endif #endif
int vlm_ExecuteCommand( vlm_t *vlm, char *command, vlm_message_t **message)
{
int result;
vlc_mutex_lock( &vlm->lock );
result = ExecuteCommand( vlm, command, message );
vlc_mutex_unlock( &vlm->lock );
return result;
}
/* Execute a command which ends by '\0' (string) */ /* Execute a command which ends by '\0' (string) */
int ExecuteCommand( vlm_t *vlm, char *command , vlm_message_t **p_message) static int ExecuteCommand( vlm_t *vlm, char *command , vlm_message_t **p_message)
{ {
int i_return = 0; int i_return = 0;
int i_command = 0; int i_command = 0;
...@@ -1009,7 +1106,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, cha ...@@ -1009,7 +1106,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, cha
{ {
int i; int i;
if( media->p_input ) if( media->p_input );
{ {
input_StopThread( media->p_input ); input_StopThread( media->p_input );
input_DestroyThread( media->p_input ); input_DestroyThread( media->p_input );
...@@ -1690,61 +1787,6 @@ static char *vlm_Save( vlm_t *vlm ) ...@@ -1690,61 +1787,6 @@ static char *vlm_Save( vlm_t *vlm )
return save; return save;
} }
/*****************************************************************************
* vlm_New:
*****************************************************************************/
vlm_t *__vlm_New ( vlc_object_t *p_object )
{
vlm_t *vlm = vlc_object_create( p_object , sizeof( vlm_t ) );
vlc_mutex_init( p_object->p_vlc, &vlm->lock );
vlm->i_media = 0;
vlm->media = NULL;
vlm->i_schedule = 0;
vlm->schedule = NULL;
if( vlc_thread_create( vlm, "vlm thread",
Manage, VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
{
vlc_mutex_destroy( &vlm->lock );
vlc_object_destroy( vlm );
return NULL;
}
return vlm;
}
/*****************************************************************************
* vlm_Delete:
*****************************************************************************/
void vlm_Delete( vlm_t *vlm )
{
int i;
vlm->b_die = VLC_TRUE;
vlc_thread_join( vlm );
vlc_mutex_destroy( &vlm->lock );
for( i = 0; i < vlm->i_media; i++ )
{
vlm_media_t *media = vlm->media[i];
vlm_MediaDelete( vlm, media, NULL );
}
if( vlm->media ) free( vlm->media );
for( i = 0; i < vlm->i_schedule; i++ )
{
vlm_ScheduleDelete( vlm, vlm->schedule[i], NULL );
}
if( vlm->schedule ) free( vlm->schedule );
vlc_object_destroy( vlm );
}
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm , char *psz_name ) static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm , char *psz_name )
{ {
vlm_schedule_t *sched= malloc( sizeof( vlm_schedule_t )); vlm_schedule_t *sched= malloc( sizeof( vlm_schedule_t ));
...@@ -1891,7 +1933,9 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz ...@@ -1891,7 +1933,9 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz
{ {
struct tm time; struct tm time;
char *p; char *p;
char *psz_time = NULL, *psz_date = NULL;
time_t date; time_t date;
int i,j,k;
/* First, if date or period are modified, repeat should be equal to -1 */ /* First, if date or period are modified, repeat should be equal to -1 */
schedule->i_repeat = -1; schedule->i_repeat = -1;
...@@ -1908,16 +1952,20 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz ...@@ -1908,16 +1952,20 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz
/* date should be year/month/day-hour:minutes:seconds */ /* date should be year/month/day-hour:minutes:seconds */
p = strchr( psz_value , '-' ); p = strchr( psz_value , '-' );
if( p )
if( p == NULL && sscanf( psz_value, "%d:%d:%d" , &time.tm_hour, &time.tm_min, &time.tm_sec ) != 3 ) /* it must be a hour:minutes:seconds */
{ {
return 1; psz_date = psz_value;
psz_time = p + 1;
*p = '\0';
} }
else else
{ {
int i,j,k; psz_time = psz_value;
}
switch( sscanf( p + 1, "%d:%d:%d" , &i, &j, &k ) )
switch( sscanf( psz_time, "%d:%d:%d" , &i, &j, &k ) )
{ {
case 1: case 1:
time.tm_sec = i; time.tm_sec = i;
...@@ -1934,10 +1982,9 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz ...@@ -1934,10 +1982,9 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, char *psz
default: default:
return 1; return 1;
} }
if( psz_date )
*p = '\0'; {
switch( sscanf( psz_date, "%d/%d/%d" , &i, &j, &k ) )
switch( sscanf( psz_value, "%d/%d/%d" , &i, &j, &k ) )
{ {
case 1: case 1:
time.tm_mday = i; time.tm_mday = i;
...@@ -2086,21 +2133,6 @@ static int Manage( vlc_object_t* p_object ) ...@@ -2086,21 +2133,6 @@ static int Manage( vlc_object_t* p_object )
} }
void vlm_MessageDelete( vlm_message_t* message )
{
int i;
if( message->psz_name ) free( message->psz_name );
if( message->psz_value ) free( message->psz_value );
for( i = 0; i < message->i_child; i++)
{
vlm_MessageDelete( message->child[i] );
}
free( message );
}
static vlm_message_t* vlm_MessageNew( char *psz_name , char *psz_value ) static vlm_message_t* vlm_MessageNew( char *psz_name , char *psz_value )
{ {
vlm_message_t *message = malloc( sizeof(vlm_message_t) ); vlm_message_t *message = malloc( sizeof(vlm_message_t) );
...@@ -2129,6 +2161,21 @@ static vlm_message_t* vlm_MessageNew( char *psz_name , char *psz_value ) ...@@ -2129,6 +2161,21 @@ static vlm_message_t* vlm_MessageNew( char *psz_name , char *psz_value )
return message; return message;
} }
void vlm_MessageDelete( vlm_message_t* message )
{
int i;
if( message->psz_name ) free( message->psz_name );
if( message->psz_value ) free( message->psz_value );
for( i = 0; i < message->i_child; i++)
{
vlm_MessageDelete( message->child[i] );
}
free( message );
}
/* add a child */ /* add a child */
static vlm_message_t* vlm_MessageAdd( vlm_message_t* message , vlm_message_t* child ) static vlm_message_t* vlm_MessageAdd( vlm_message_t* message , vlm_message_t* child )
{ {
......
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