| 159 | | } |
|---|
| 160 | | |
|---|
| 161 | | static void AddDvd( services_discovery_t *p_sd, char *psz_device ) |
|---|
| 162 | | { |
|---|
| 163 | | char *psz_name; |
|---|
| 164 | | char *psz_uri; |
|---|
| 165 | | char *psz_blockdevice; |
|---|
| 166 | | input_item_t *p_input; |
|---|
| 167 | | #ifdef HAVE_HAL_1 |
|---|
| 168 | | psz_name = libhal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| 169 | | psz_device, "volume.label", NULL ); |
|---|
| 170 | | psz_blockdevice = libhal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| 171 | | psz_device, "block.device", NULL ); |
|---|
| 172 | | #else |
|---|
| 173 | | psz_name = hal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| 174 | | psz_device, "volume.label" ); |
|---|
| 175 | | psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| 176 | | psz_device, "block.device" ); |
|---|
| 177 | | #endif |
|---|
| 178 | | asprintf( &psz_uri, "dvd://%s", psz_blockdevice ); |
|---|
| 179 | | /* Create the playlist item here */ |
|---|
| 180 | | p_input = input_ItemNew( p_sd, psz_uri, psz_name ); |
|---|
| 181 | | free( psz_uri ); |
|---|
| 182 | | #ifdef HAVE_HAL_1 |
|---|
| 183 | | libhal_free_string( psz_device ); |
|---|
| 184 | | #else |
|---|
| 185 | | hal_free_string( psz_device ); |
|---|
| 186 | | #endif |
|---|
| 187 | | if( !p_input ) |
|---|
| 188 | | { |
|---|
| 189 | | return; |
|---|
| 190 | | } |
|---|
| 191 | | AddItem( p_sd, p_input ); |
|---|
| 192 | | } |
|---|
| 193 | | |
|---|
| 194 | | static void AddItem( services_discovery_t *p_sd, input_item_t * p_input ) |
|---|
| | 196 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 197 | while( p_sys->i_devices_number > 0 ); |
|---|
| | 198 | { |
|---|
| | 199 | struct udi_input_id_t *p_udi_entry = p_sys->pp_devices[0]; |
|---|
| | 200 | if( p_udi_entry->psz_udi ) free( p_udi_entry->psz_udi ); |
|---|
| | 201 | TAB_REMOVE( p_sys->i_devices_number, p_sys->pp_devices, 0 ); |
|---|
| | 202 | if( p_udi_entry ) free( p_udi_entry ); |
|---|
| | 203 | } |
|---|
| | 204 | p_sys->pp_devices = NULL; |
|---|
| | 205 | #endif |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | static void AddItem( services_discovery_t *p_sd, input_item_t * p_input |
|---|
| | 209 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 210 | ,char* psz_device |
|---|
| | 211 | #endif |
|---|
| | 212 | ) |
|---|
| 212 | | } |
|---|
| | 231 | |
|---|
| | 232 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 233 | struct udi_input_id_t *p_udi_entry; |
|---|
| | 234 | p_udi_entry = malloc( sizeof( struct udi_input_id_t ) ); |
|---|
| | 235 | if( !p_udi_entry ) |
|---|
| | 236 | { |
|---|
| | 237 | return; |
|---|
| | 238 | } |
|---|
| | 239 | p_udi_entry->i_id = p_item->i_id; |
|---|
| | 240 | p_udi_entry->psz_udi = strdup( psz_device ); |
|---|
| | 241 | TAB_APPEND( p_sys->i_devices_number, p_sys->pp_devices, p_udi_entry ); |
|---|
| | 242 | #endif |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | static void AddDvd( services_discovery_t *p_sd, char *psz_device ) |
|---|
| | 246 | { |
|---|
| | 247 | char *psz_name; |
|---|
| | 248 | char *psz_uri; |
|---|
| | 249 | char *psz_blockdevice; |
|---|
| | 250 | input_item_t *p_input; |
|---|
| | 251 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 252 | psz_name = libhal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| | 253 | psz_device, "volume.label", NULL ); |
|---|
| | 254 | psz_blockdevice = libhal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| | 255 | psz_device, "block.device", NULL ); |
|---|
| | 256 | #else |
|---|
| | 257 | psz_name = hal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| | 258 | psz_device, "volume.label" ); |
|---|
| | 259 | psz_blockdevice = hal_device_get_property_string( p_sd->p_sys->p_ctx, |
|---|
| | 260 | psz_device, "block.device" ); |
|---|
| | 261 | #endif |
|---|
| | 262 | asprintf( &psz_uri, "dvd://%s", psz_blockdevice ); |
|---|
| | 263 | /* Create the playlist item here */ |
|---|
| | 264 | p_input = input_ItemNew( p_sd, psz_uri, psz_name ); |
|---|
| | 265 | free( psz_uri ); |
|---|
| | 266 | if( !p_input ) |
|---|
| | 267 | { |
|---|
| | 268 | return; |
|---|
| | 269 | } |
|---|
| | 270 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 271 | AddItem( p_sd, p_input, psz_device ); |
|---|
| | 272 | #else |
|---|
| | 273 | AddItem( p_sd, p_input ); |
|---|
| | 274 | #endif |
|---|
| | 275 | } |
|---|
| | 276 | |
|---|
| | 277 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 278 | static void DelItem( services_discovery_t *p_sd, char* psz_udi ) |
|---|
| | 279 | { |
|---|
| | 280 | services_discovery_sys_t *p_sys = p_sd->p_sys; |
|---|
| | 281 | int i; |
|---|
| | 282 | |
|---|
| | 283 | playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_sd, |
|---|
| | 284 | VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); |
|---|
| | 285 | if( !p_playlist ) |
|---|
| | 286 | { |
|---|
| | 287 | msg_Err( p_sd, "playlist not found" ); |
|---|
| | 288 | return; |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | for( i = 0; i < p_sys->i_devices_number; i++ ) |
|---|
| | 292 | { |
|---|
| | 293 | if( strcmp( psz_udi, p_sys->pp_devices[i]->psz_udi ) == 0 ) |
|---|
| | 294 | { |
|---|
| | 295 | playlist_DeleteFromItemId( p_playlist, p_sys->pp_devices[i]->i_id ); |
|---|
| | 296 | } |
|---|
| | 297 | } |
|---|
| | 298 | |
|---|
| | 299 | vlc_object_release( p_playlist ); |
|---|
| | 300 | } |
|---|
| | 301 | #endif |
|---|
| 313 | | #ifdef HAVE_DBUS_2 |
|---|
| 314 | | /* We'll use D-Bus to listen for devices evenements */ |
|---|
| 315 | | /* TODO: Manage hot removal of devices */ |
|---|
| 316 | | DBusMessage* dbus_message; |
|---|
| 317 | | DBusMessageIter dbus_args; |
|---|
| 318 | | const char** psz_dbus_value; |
|---|
| 319 | | char* psz_dbus_device; |
|---|
| 320 | | DBusError dbus_error; |
|---|
| 321 | | DBusConnection* p_connection; |
|---|
| 322 | | |
|---|
| 323 | | dbus_error_init( &dbus_error ); |
|---|
| 324 | | |
|---|
| 325 | | /* connect to the system bus */ |
|---|
| 326 | | p_connection = dbus_bus_get( DBUS_BUS_SYSTEM, &dbus_error ); |
|---|
| 327 | | if ( dbus_error_is_set( &dbus_error ) ) |
|---|
| 328 | | { |
|---|
| 329 | | msg_Err( p_sd, "D-Bus Connection Error (%s)\n", dbus_error.message); |
|---|
| 330 | | dbus_error_free( &dbus_error ); |
|---|
| 331 | | return; |
|---|
| 332 | | } |
|---|
| 333 | | |
|---|
| 334 | | /* check for hal signals */ |
|---|
| 335 | | dbus_bus_add_match( p_connection, |
|---|
| 336 | | "type='signal',interface='org.freedesktop.Hal.Manager'", &dbus_error ); |
|---|
| 337 | | dbus_connection_flush( p_connection ); |
|---|
| 338 | | |
|---|
| 339 | | /* an error ? oooh too bad :) */ |
|---|
| 340 | | if ( dbus_error_is_set( &dbus_error ) ) |
|---|
| 341 | | { |
|---|
| 342 | | msg_Err( p_sd, "D-Bus signal match Error (%s)\n", dbus_error.message); |
|---|
| 343 | | return; |
|---|
| 344 | | } |
|---|
| 345 | | |
|---|
| | 401 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| 348 | | /* read next available message */ |
|---|
| 349 | | dbus_connection_read_write( p_connection, 0 ); |
|---|
| 350 | | dbus_message = dbus_connection_pop_message( p_connection ); |
|---|
| 351 | | |
|---|
| 352 | | if( dbus_message == NULL ) |
|---|
| 353 | | { |
|---|
| 354 | | /* we've worked really hard, now it's time to sleep */ |
|---|
| 355 | | msleep( 100000 ); |
|---|
| 356 | | continue; |
|---|
| 357 | | } |
|---|
| 358 | | /* check if the message is a signal from the correct interface */ |
|---|
| 359 | | if( dbus_message_is_signal( dbus_message, "org.freedesktop.Hal.Manager", |
|---|
| 360 | | "DeviceAdded" ) ) |
|---|
| 361 | | { |
|---|
| 362 | | /* read the parameter (it must be an udi string) */ |
|---|
| 363 | | if( dbus_message_iter_init( dbus_message, &dbus_args ) && |
|---|
| 364 | | ( dbus_message_iter_get_arg_type( &dbus_args ) == |
|---|
| 365 | | DBUS_TYPE_STRING ) |
|---|
| 366 | | ) |
|---|
| 367 | | { |
|---|
| 368 | | dbus_message_iter_get_basic( &dbus_args, &psz_dbus_value ); |
|---|
| 369 | | /* psz_bus_value musn't be freed, but AddCdda will do it |
|---|
| 370 | | * so we allocate some memory, and copy it into psz_dbus_device |
|---|
| 371 | | */ |
|---|
| 372 | | psz_dbus_device = strdup( psz_dbus_value ); |
|---|
| 373 | | ParseDevice( p_sd, psz_dbus_device ); |
|---|
| 374 | | } |
|---|
| 375 | | } |
|---|
| 376 | | dbus_message_unref( dbus_message ); |
|---|
| 377 | | } |
|---|
| 378 | | #endif |
|---|
| 379 | | } |
|---|
| | 404 | /* look for events on the bus, blocking 1 second */ |
|---|
| | 405 | dbus_connection_read_write_dispatch( |
|---|
| | 406 | libhal_ctx_get_dbus_connection(p_sys->p_ctx), 1000 ); |
|---|
| | 407 | } |
|---|
| | 408 | #endif |
|---|
| | 409 | |
|---|
| | 410 | } |
|---|
| | 411 | |
|---|
| | 412 | #if defined( HAVE_HAL_1 ) && defined( HAVE_DBUS_2 ) |
|---|
| | 413 | void DeviceAdded( LibHalContext *p_ctx, const char *psz_udi ) |
|---|
| | 414 | { |
|---|
| | 415 | ParseDevice( p_sd_global, (char*) psz_udi ); |
|---|
| | 416 | } |
|---|
| | 417 | void DeviceRemoved( LibHalContext *p_ctx, const char *psz_udi ) |
|---|
| | 418 | { |
|---|
| | 419 | DelItem( p_sd_global, (char*) psz_udi ); |
|---|
| | 420 | } |
|---|
| | 421 | #endif |
|---|
| | 422 | |
|---|