Commit 70e77275 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCMediaDiscoverer: Code cleanup and use Objective-C 2.0...

MacOSX/Framework/VLCMediaDiscoverer: Code cleanup and use Objective-C 2.0 @property. (Patch by Enrique Osuna).
parent 1fb4f986
......@@ -27,20 +27,44 @@
@class VLCMediaList;
/**
* TODO: Documentation VLCMediaDiscoverer
*/
@interface VLCMediaDiscoverer : NSObject
{
NSString *localizedName;
VLCMediaList * discoveredMedia;
void * mdis;
BOOL running;
NSString * localizedName; //< TODO: Documentation VLCMediaDiscoverer.localizedName
VLCMediaList * discoveredMedia; //< TODO: Documentation VLCMediaDiscoverer.discoveredMedia
void * mdis; //< TODO: Documentation VLCMediaDiscoverer.mdis
BOOL running; //< TODO: Documentation VLCMediaDiscoverer.running
}
/**
* Maintains a list of available media discoverers. This list is populated as new media
* discoverers are created.
* \return A list of available media discoverers.
*/
+ (NSArray *)availableMediaDiscoverer;
/* Initializers */
/**
* Initializes new object with specified name.
* \param aSerchName Name of the service for this VLCMediaDiscoverer object.
* \returns Newly created media discoverer.
*/
- (id)initWithName:(NSString *)aServiceName;
- (VLCMediaList *)discoveredMedia;
/**
* TODO: Documentation VLCMediaDiscoverer.discoveredMedia
*/
@property (readonly) VLCMediaList * discoveredMedia;
- (NSString *)localizedName;
/**
* TODO: Documentation VLCMediaDiscoverer.localizedName
*/
@property (readonly) NSString * localizedName;
- (BOOL)isRunning;
/**
* TODO: Documentation VLCMediaDiscoverer.isRunning
*/
@property (readonly) BOOL isRunning;
@end
......@@ -30,15 +30,25 @@
#include <vlc/libvlc.h>
static NSArray * availableMediaDiscoverer = nil;
static NSMutableArray * availableMediaDiscoverer = nil; // Global list of media discoverers
/**
* Declares call back functions to be used with libvlc event callbacks.
*/
@interface VLCMediaDiscoverer (Private)
/**
* TODO: Documention
*/
- (void)mediaDiscovererStarted;
/**
* TODO: Documention
*/
- (void)mediaDiscovererEnded;
@end
/* libvlc event callback */
static void HandleMediaDiscovererStarted(const libvlc_event_t *event, void *user_data)
static void HandleMediaDiscovererStarted(const libvlc_event_t * event, void * user_data)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id self = user_data;
......@@ -83,12 +93,12 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance],
[aServiceName UTF8String],
&ex );
quit_on_exception( &ex );
libvlc_event_manager_t * p_em = libvlc_media_discoverer_event_manager(mdis);
libvlc_event_attach(p_em, libvlc_MediaDiscovererStarted, HandleMediaDiscovererStarted, self, NULL);
libvlc_event_attach(p_em, libvlc_MediaDiscovererEnded, HandleMediaDiscovererEnded, self, NULL);
running = libvlc_media_discoverer_is_running(mdis);
quit_on_exception( &ex );
}
return self;
}
......@@ -112,9 +122,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
- (void)dealloc
{
if( localizedName )
[localizedName release];
if( discoveredMedia )
[discoveredMedia release];
libvlc_media_discoverer_release( mdis );
[super dealloc];
......@@ -126,33 +134,24 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
return discoveredMedia;
libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis );
VLCMediaList * ret = [VLCMediaList mediaListWithLibVLCMediaList: p_mlist];
VLCMediaList * ret = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
libvlc_media_list_release( p_mlist );
if( ret )
{
discoveredMedia = [ret retain];
}
return discoveredMedia;
}
- (NSString *)localizedName
{
NSString * aString = nil;
char * name = libvlc_media_discoverer_localized_name( mdis );
if( localizedName )
if ( localizedName )
return localizedName;
char * name = libvlc_media_discoverer_localized_name( mdis );
if (name)
{
aString = [NSString stringWithUTF8String:name];
localizedName = [[NSString stringWithUTF8String:name] retain];
free( name );
}
if( aString )
{
localizedName = [aString retain];
}
return localizedName;
}
......@@ -169,6 +168,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
running = YES;
[self didChangeValueForKey:@"running"];
}
- (void)mediaDiscovererEnded
{
[self willChangeValueForKey:@"running"];
......
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