MacOSX/Framework/VLCMediaDiscoverer: Code cleanup and use Objective-C 2.0 @property...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 2 Jan 2008 02:42:44 +0000 (02:42 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 2 Jan 2008 02:42:44 +0000 (02:42 +0000)
extras/MacOSX/Framework/Headers/Public/VLCMediaDiscoverer.h
extras/MacOSX/Framework/Sources/VLCMediaDiscoverer.m

index 729bb12..2967b83 100644 (file)
 
 @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
index c030ee1..0bd3bed 100644 (file)
 
 #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;
@@ -62,14 +72,14 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
 @implementation VLCMediaDiscoverer
 + (NSArray *)availableMediaDiscoverer
 {
-        if( !availableMediaDiscoverer )
-        {
-            availableMediaDiscoverer = [[NSArray arrayWithObjects:
-                                    [[[VLCMediaDiscoverer alloc] initWithName:@"sap"] autorelease],
-                                    [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcast"] autorelease],
-                                    [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcasttv"] autorelease], nil] retain];
-        }
-        return availableMediaDiscoverer;
+    if( !availableMediaDiscoverer )
+    {
+        availableMediaDiscoverer = [[NSArray arrayWithObjects:
+                                [[[VLCMediaDiscoverer alloc] initWithName:@"sap"] autorelease],
+                                [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcast"] autorelease],
+                                [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcasttv"] autorelease], nil] retain];
+    }
+    return availableMediaDiscoverer;
 }
 
 - (id)initWithName:(NSString *)aServiceName
@@ -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,10 +122,8 @@ static void HandleMediaDiscovererEnded( const libvlc_event_t * event, void * use
 
 - (void)dealloc
 {
-    if( localizedName )
-        [localizedName release];
-    if( discoveredMedia )
-        [discoveredMedia release];
+    [localizedName release];
+    [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];
-    }
+    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"];