vlc_event_manager_t event_manager; /* Accessed through Setters for non class function */
services_discovery_sys_t *p_sys;
- void (*pf_run) ( services_discovery_t *);
};
/* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) );
VLC_EXPORT( void, services_discovery_Destroy, ( services_discovery_t * p_this ) );
-VLC_EXPORT( int, services_discovery_Start, ( services_discovery_t * p_this ) );
-VLC_EXPORT( void, services_discovery_Stop, ( services_discovery_t * p_this ) );
/* Read info from discovery object */
VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
struct services_discovery_sys_t
{
+ vlc_thread_t thread;
LibHalContext *p_ctx;
DBusConnection *p_connection;
int i_devices_number;
struct udi_input_id_t **pp_devices;
};
-static void Run ( services_discovery_t *p_intf );
-
+static void *Run ( void * );
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
p_sys->i_devices_number = 0;
p_sys->pp_devices = NULL;
- p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
dbus_error_init( &dbus_error );
if( !libhal_ctx_init( p_sys->p_ctx, &dbus_error ) )
{
msg_Err( p_sd, "hal not available : %s", dbus_error.message );
- dbus_error_free( &dbus_error );
- free( p_sys );
- return VLC_EGENERIC;
+ goto error;
}
if( !libhal_ctx_set_device_added( p_sys->p_ctx, DeviceAdded ) ||
!libhal_ctx_set_device_removed( p_sys->p_ctx, DeviceRemoved ) )
{
msg_Err( p_sd, "unable to add callback" );
- dbus_error_free( &dbus_error );
- free( p_sys );
- return VLC_EGENERIC;
+ goto error;
}
+ if( vlc_clone( &p_sys->thread, Run, p_this, VLC_THREAD_PRIORITY_LOW ) )
+ goto error;
+
services_discovery_SetLocalizedName( p_sd, _("Devices") );
return VLC_SUCCESS;
+error:
+ dbus_error_free( &dbus_error );
+ free( p_sys );
+ return VLC_EGENERIC;
}
/*****************************************************************************
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
+ /*vlc_cancel( p_sys->thread );*/
+ vlc_object_kill( p_sd );
+ vlc_join( p_sys->thread, NULL );
dbus_connection_unref( p_sys->p_connection );
struct udi_input_id_t *p_udi_entry;
/*****************************************************************************
* Run: main HAL thread
*****************************************************************************/
-static void Run( services_discovery_t *p_sd )
+static void *Run( voidt *data )
{
- int i, i_devices;
+ services_discovery_t *p_sd = data;
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
char **devices;
- services_discovery_sys_t *p_sys = p_sd->p_sys;
+ int i, i_devices;
int canc = vlc_savecancel();
/* parse existing devices first */
/* HAL 0.5.8.1 can use libhal_ctx_get_dbus_connection(p_sys->p_ctx) */
}
vlc_restorecancel (canc);
+ return NULL;
}
void DeviceAdded( LibHalContext *p_ctx, const char *psz_udi )
char **ppsz_urls;
int i_urls;
+ vlc_thread_t thread;
vlc_mutex_t lock;
vlc_cond_t wait;
bool b_update;
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static void Run( services_discovery_t *p_intf );
+static void *Run( void * );
static int UrlsChange( vlc_object_t *, char const *, vlc_value_t,
vlc_value_t, void * );
static void ParseUrls( services_discovery_t *p_sd, char *psz_urls );
vlc_cond_init( &p_sys->wait );
p_sys->b_update = true;
- p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
-
/* Give us a name */
services_discovery_SetLocalizedName( p_sd, _("Podcasts") );
var_Create( p_sd, "podcast-urls", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_AddCallback( p_sd, "podcast-urls", UrlsChange, p_sys );
+ if (vlc_clone (&p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW))
+ {
+ free (p_sys);
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
services_discovery_sys_t *p_sys = p_sd->p_sys;
int i;
+ vlc_cancel (p_sys->thread);
+ vlc_join (p_sys->thread, NULL);
+
var_DelCallback( p_sd, "podcast-urls", UrlsChange, p_sys );
vlc_cond_destroy( &p_sys->wait );
vlc_mutex_destroy( &p_sys->lock );
/*****************************************************************************
* Run: main thread
*****************************************************************************/
-static void Run( services_discovery_t *p_sd )
+static void *Run( void *data )
{
+ services_discovery_t *p_sd = data;
services_discovery_sys_t *p_sys = p_sd->p_sys;
vlc_mutex_lock( &p_sys->lock );
struct services_discovery_sys_t
{
+ vlc_thread_t thread;
+
/* Socket descriptors */
int i_fd;
int *pi_fd;
/* Main functions */
static int Demux( demux_t *p_demux );
static int Control( demux_t *, int, va_list );
- static void Run ( services_discovery_t *p_sd );
+ static void *Run ( void *p_sd );
/* Main parsing functions */
static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp );
p_sys->i_timeout = var_CreateGetInteger( p_sd, "sap-timeout" );
- p_sd->pf_run = Run;
p_sd->p_sys = p_sys;
p_sys->pi_fd = NULL;
p_sys->i_announces = 0;
p_sys->pp_announces = NULL;
+ /* TODO: create sockets here, and fix racy sockets table */
+ if (vlc_clone (&p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW))
+ {
+ free (p_sys);
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
-
int i;
+ vlc_cancel (p_sys->thread);
+ vlc_join (p_sys->thread, NULL);
+
for( i = p_sys->i_fd-1 ; i >= 0 ; i-- )
{
net_Close( p_sys->pi_fd[i] );
*****************************************************************************/
#define MAX_SAP_BUFFER 5000
-static void Run( services_discovery_t *p_sd )
+static void *Run( void *data )
{
+ services_discovery_t *p_sd = data;
char *psz_addr;
int i;
int timeout = -1;
if( p_sd->p_sys->i_fd == 0 )
{
msg_Err( p_sd, "unable to listen on any address" );
- return;
+ return NULL;
}
/* read SAP packets */
else if( timeout < 200 )
timeout = 200; /* Don't wakeup too fast. */
}
+ assert (0);
}
/**********************************************************************
* Local prototypes
*****************************************************************************/
-static void Run( services_discovery_t *p_sd );
-
+static void *Run( void * );
+struct services_discovery_sys_t
+{
+ vlc_thread_t thread;
+ enum type_e i_type;
+};
/*****************************************************************************
* Open: initialize and create stuff
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_SetLocalizedName( p_sd, _(p_items[i_type].psz_name) );
- p_sd->pf_run = Run;
- p_sd->p_sys = (void *)i_type;
+
+ p_sd->p_sys = malloc (sizeof (*(p_sd->p_sys)));
+ if (p_sd->p_sys == NULL)
+ return VLC_ENOMEM;
+
+ p_sd->p_sys->i_type = i_type;
+ if (vlc_clone (&p_sd->p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW))
+ {
+ free (p_sd->p_sys);
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
/*****************************************************************************
* Run:
*****************************************************************************/
-static void Run( services_discovery_t *p_sd )
+static void *Run( void *data )
{
- enum type_e i_type = (enum type_e)p_sd->p_sys;
+ services_discovery_t *p_sd = data;
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+ enum type_e i_type = p_sys->i_type;
int i, j;
int canc = vlc_savecancel();
if( !p_items[i_type].p_children )
{
AddSubitemsOfShoutItemURL( p_sd, &p_items[i_type], NULL );
- return;
+ vlc_restorecancel(canc);
+ return NULL;
}
for( i = 0; p_items[i_type].p_children[i].psz_name; i++ )
{
}
}
vlc_restorecancel(canc);
+ return NULL;
}
/*****************************************************************************
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
- VLC_UNUSED(p_this);
+ services_discovery_t *p_sd = (services_discovery_t *)p_this;
+ services_discovery_sys_t *p_sys = p_sd->p_sys;
+
+ vlc_join (p_sys->thread, NULL);
+ free (p_sys);
}
services_discovery_ended,
p_mdis );
- services_discovery_Start( p_mdis->p_sd );
-
/* Here we go */
return p_mdis;
__services_discovery_GetServicesNames
services_discovery_RemoveItem
services_discovery_SetLocalizedName
-services_discovery_Start
-services_discovery_Stop
sout_AccessOutControl
sout_AccessOutDelete
sout_AccessOutNew
#include "playlist_internal.h"
#include "../libvlc.h"
-static void* RunSD( vlc_object_t *p_this );
-
/*
* Services discovery
* Basically you just listen to Service discovery event through the
if( !p_sd )
return NULL;
- p_sd->pf_run = NULL;
p_sd->psz_localized_name = NULL;
vlc_event_manager_init( &p_sd->event_manager, p_sd, (vlc_object_t *)p_sd );
p_sd->b_die = false; /* FIXME */
vlc_object_attach( p_sd, p_super );
- return p_sd;
-}
-
-/***********************************************************************
- * Destroy
- ***********************************************************************/
-void services_discovery_Destroy ( services_discovery_t * p_sd )
-{
- vlc_event_manager_fini( &p_sd->event_manager );
- free( p_sd->psz_module );
- free( p_sd->psz_localized_name );
-
- vlc_object_detach( p_sd );
- vlc_object_release( p_sd );
-}
-
-/***********************************************************************
- * Start
- ***********************************************************************/
-int services_discovery_Start ( services_discovery_t * p_sd )
-{
vlc_event_t event = {
.type = vlc_ServicesDiscoveryStarted
};
vlc_event_send( &p_sd->event_manager, &event );
-
- if ((p_sd->pf_run != NULL)
- && vlc_thread_create( p_sd, "services_discovery", RunSD,
- VLC_THREAD_PRIORITY_LOW, false))
- {
- msg_Err( p_sd, "cannot create services discovery thread" );
- vlc_object_release( p_sd );
- return VLC_EGENERIC;
- }
- return VLC_SUCCESS;
+ return p_sd;
}
-/***********************************************************************
- * Stop
- ***********************************************************************/
static void ObjectKillChildrens( vlc_object_t *p_obj )
{
vlc_list_t *p_list;
vlc_list_release( p_list );
}
-void services_discovery_Stop ( services_discovery_t * p_sd )
+/***********************************************************************
+ * Destroy
+ ***********************************************************************/
+void services_discovery_Destroy ( services_discovery_t * p_sd )
{
vlc_event_t event = {
.type = vlc_ServicesDiscoveryEnded
};
ObjectKillChildrens( VLC_OBJECT(p_sd) );
- if( p_sd->pf_run ) vlc_thread_join( p_sd );
vlc_event_send( &p_sd->event_manager, &event );
module_Unneed( p_sd, p_sd->p_module );
+
+ vlc_event_manager_fini( &p_sd->event_manager );
+
+ free( p_sd->psz_module );
+ free( p_sd->psz_localized_name );
+
+ vlc_object_release( p_sd );
}
/***********************************************************************
vlc_event_send( &p_sd->event_manager, &event );
}
-/***********************************************************************
- * RunSD (Private)
- ***********************************************************************/
-static void* RunSD( vlc_object_t *p_this )
-{
- services_discovery_t *p_sd = (services_discovery_t *)p_this;
- p_sd->pf_run( p_sd );
- return NULL;
-}
-
/*
* Playlist - Services discovery bridge
*/
playlist_sd_item_removed,
p_cat );
- services_discovery_Start( p_sd );
-
/* Free in playlist_ServicesDiscoveryRemove */
p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
if( !p_sds )
return VLC_EGENERIC;
}
- services_discovery_Stop( p_sds->p_sd );
-
vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),
vlc_ServicesDiscoveryItemAdded,
playlist_sd_item_added,