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 @@ ...@@ -27,20 +27,44 @@
@class VLCMediaList; @class VLCMediaList;
/**
* TODO: Documentation VLCMediaDiscoverer
*/
@interface VLCMediaDiscoverer : NSObject @interface VLCMediaDiscoverer : NSObject
{ {
NSString *localizedName; NSString * localizedName; //< TODO: Documentation VLCMediaDiscoverer.localizedName
VLCMediaList * discoveredMedia; VLCMediaList * discoveredMedia; //< TODO: Documentation VLCMediaDiscoverer.discoveredMedia
void * mdis; void * mdis; //< TODO: Documentation VLCMediaDiscoverer.mdis
BOOL running; 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; + (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; - (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 @end
...@@ -30,15 +30,25 @@ ...@@ -30,15 +30,25 @@
#include <vlc/libvlc.h> #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) @interface VLCMediaDiscoverer (Private)
/**
* TODO: Documention
*/
- (void)mediaDiscovererStarted; - (void)mediaDiscovererStarted;
/**
* TODO: Documention
*/
- (void)mediaDiscovererEnded; - (void)mediaDiscovererEnded;
@end @end
/* libvlc event callback */ /* 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]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id self = user_data; id self = user_data;
...@@ -83,12 +93,12 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use ...@@ -83,12 +93,12 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance], mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance],
[aServiceName UTF8String], [aServiceName UTF8String],
&ex ); &ex );
quit_on_exception( &ex );
libvlc_event_manager_t * p_em = libvlc_media_discoverer_event_manager(mdis); 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_MediaDiscovererStarted, HandleMediaDiscovererStarted, self, NULL);
libvlc_event_attach(p_em, libvlc_MediaDiscovererEnded, HandleMediaDiscovererEnded, self, NULL); libvlc_event_attach(p_em, libvlc_MediaDiscovererEnded, HandleMediaDiscovererEnded, self, NULL);
running = libvlc_media_discoverer_is_running(mdis); running = libvlc_media_discoverer_is_running(mdis);
quit_on_exception( &ex );
} }
return self; return self;
} }
...@@ -112,9 +122,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use ...@@ -112,9 +122,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
- (void)dealloc - (void)dealloc
{ {
if( localizedName )
[localizedName release]; [localizedName release];
if( discoveredMedia )
[discoveredMedia release]; [discoveredMedia release];
libvlc_media_discoverer_release( mdis ); libvlc_media_discoverer_release( mdis );
[super dealloc]; [super dealloc];
...@@ -126,33 +134,24 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use ...@@ -126,33 +134,24 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
return discoveredMedia; return discoveredMedia;
libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis ); 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 ); libvlc_media_list_release( p_mlist );
if( ret )
{
discoveredMedia = [ret retain]; discoveredMedia = [ret retain];
}
return discoveredMedia; return discoveredMedia;
} }
- (NSString *)localizedName - (NSString *)localizedName
{ {
NSString * aString = nil; if ( localizedName )
char * name = libvlc_media_discoverer_localized_name( mdis );
if( localizedName )
return localizedName; return localizedName;
char * name = libvlc_media_discoverer_localized_name( mdis );
if (name) if (name)
{ {
aString = [NSString stringWithUTF8String:name]; localizedName = [[NSString stringWithUTF8String:name] retain];
free( name ); free( name );
} }
if( aString )
{
localizedName = [aString retain];
}
return localizedName; return localizedName;
} }
...@@ -169,6 +168,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use ...@@ -169,6 +168,7 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
running = YES; running = YES;
[self didChangeValueForKey:@"running"]; [self didChangeValueForKey:@"running"];
} }
- (void)mediaDiscovererEnded - (void)mediaDiscovererEnded
{ {
[self willChangeValueForKey:@"running"]; [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