gmyth-upnp/src/gmyth_upnp.c
branchtrunk
changeset 754 cb885ee44618
parent 706 5cc97240e238
child 909 847da7267234
     1.1 --- a/gmyth-upnp/src/gmyth_upnp.c	Thu May 24 01:26:10 2007 +0100
     1.2 +++ b/gmyth-upnp/src/gmyth_upnp.c	Thu Jun 14 20:40:47 2007 +0100
     1.3 @@ -44,82 +44,91 @@
     1.4  #include <gmyth/gmyth_uri.h>
     1.5  #include <gmyth/gmyth_debug.h>
     1.6  
     1.7 -/* Maximum number of searches in the synchronized search */
     1.8 +/*
     1.9 + * Maximum number of searches in the synchronized search 
    1.10 + */
    1.11  #define GMYTH_UPNP_MAX_SEARCHS		10
    1.12  
    1.13  #define GMYTH_UPNP_GET_PRIVATE(obj) \
    1.14      (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_UPNP_TYPE, GMythUPnPPrivate))
    1.15  
    1.16  struct _GMythUPnPPrivate {
    1.17 -	GHashTable *mythtv_servers;
    1.18 -	GMythUPnPDeviceStatus last_status;
    1.19 -	gboolean upnp_dev_found;
    1.20 -	gchar *udn;
    1.21 -	GMutex *mutex;
    1.22 +    GHashTable     *mythtv_servers;
    1.23 +    GMythUPnPDeviceStatus last_status;
    1.24 +    gboolean        upnp_dev_found;
    1.25 +    gchar          *udn;
    1.26 +    GMutex         *mutex;
    1.27  };
    1.28  
    1.29 -static void gmyth_upnp_class_init          (GMythUPnPClass *klass);
    1.30 -static void gmyth_upnp_init                (GMythUPnP *object);
    1.31 +static void     gmyth_upnp_class_init(GMythUPnPClass * klass);
    1.32 +static void     gmyth_upnp_init(GMythUPnP * object);
    1.33  
    1.34 -static void gmyth_upnp_dispose  (GObject *object);
    1.35 -static void gmyth_upnp_finalize (GObject *object);
    1.36 +static void     gmyth_upnp_dispose(GObject * object);
    1.37 +static void     gmyth_upnp_finalize(GObject * object);
    1.38  
    1.39 -static void _mythtv_device_found ( GMythUPnP *gmyth_upnp, GMythUPnPDeviceStatus status, gchar *dev );
    1.40 -static void _clinkc_mythtv_device_found ( gchar *udn, GMythUPnPDeviceStatus status );
    1.41 +static void     _mythtv_device_found(GMythUPnP * gmyth_upnp,
    1.42 +                                     GMythUPnPDeviceStatus status,
    1.43 +                                     gchar * dev);
    1.44 +static void     _clinkc_mythtv_device_found(gchar * udn,
    1.45 +                                            GMythUPnPDeviceStatus status);
    1.46  
    1.47 -static gboolean gmyth_upnp_initialize ( GMythUPnP *gmyth_upnp, GMythBackendInfo *gmyth_backend_info,
    1.48 -		GMythUPnPDeviceListener listener);
    1.49 +static gboolean gmyth_upnp_initialize(GMythUPnP * gmyth_upnp,
    1.50 +                                      GMythBackendInfo *
    1.51 +                                      gmyth_backend_info,
    1.52 +                                      GMythUPnPDeviceListener listener);
    1.53  
    1.54 -static gboolean gmyth_upnp_got_mythtv_service( CgUpnpControlPoint* controlPt, gchar **udn, 
    1.55 -						GHashTable **mythtv_servers_lst );
    1.56 +static gboolean gmyth_upnp_got_mythtv_service(CgUpnpControlPoint *
    1.57 +                                              controlPt, gchar ** udn,
    1.58 +                                              GHashTable **
    1.59 +                                              mythtv_servers_lst);
    1.60  
    1.61  G_DEFINE_TYPE(GMythUPnP, gmyth_upnp, G_TYPE_OBJECT)
    1.62  
    1.63 -static GMythUPnP *gmyth_upnp_static = NULL;
    1.64 +    static GMythUPnP *gmyth_upnp_static = NULL;
    1.65  
    1.66 -static void
    1.67 -gmyth_upnp_class_init (GMythUPnPClass *klass)
    1.68 +    static void
    1.69 +                    gmyth_upnp_class_init(GMythUPnPClass * klass)
    1.70  {
    1.71 -	GObjectClass *gobject_class;
    1.72 -	GMythUPnPClass *gupnp_class;
    1.73 +    GObjectClass   *gobject_class;
    1.74 +    GMythUPnPClass *gupnp_class;
    1.75  
    1.76 -	gobject_class = (GObjectClass *) klass;
    1.77 -	gupnp_class = (GMythUPnPClass*) gobject_class;
    1.78 +    gobject_class = (GObjectClass *) klass;
    1.79 +    gupnp_class = (GMythUPnPClass *) gobject_class;
    1.80  
    1.81 -	gobject_class->dispose  = gmyth_upnp_dispose;
    1.82 -	gobject_class->finalize = gmyth_upnp_finalize;
    1.83 -	
    1.84 -	g_type_class_add_private( gobject_class, sizeof( GMythUPnPPrivate ) );
    1.85 +    gobject_class->dispose = gmyth_upnp_dispose;
    1.86 +    gobject_class->finalize = gmyth_upnp_finalize;
    1.87  
    1.88 -	gupnp_class->device_found_handler = _mythtv_device_found;
    1.89 +    g_type_class_add_private(gobject_class, sizeof(GMythUPnPPrivate));
    1.90  
    1.91 -	gupnp_class->device_found_handler_signal_id =
    1.92 -		g_signal_new ("device-found",
    1.93 -				G_TYPE_FROM_CLASS (gupnp_class),
    1.94 -				G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
    1.95 -				G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
    1.96 -				gmyth_upnp_marshal_VOID__INT_STRING, G_TYPE_NONE, 2,
    1.97 -				G_TYPE_INT, G_TYPE_STRING);
    1.98 +    gupnp_class->device_found_handler = _mythtv_device_found;
    1.99 +
   1.100 +    gupnp_class->device_found_handler_signal_id =
   1.101 +        g_signal_new("device-found",
   1.102 +                     G_TYPE_FROM_CLASS(gupnp_class),
   1.103 +                     G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
   1.104 +                     G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
   1.105 +                     gmyth_upnp_marshal_VOID__INT_STRING, G_TYPE_NONE, 2,
   1.106 +                     G_TYPE_INT, G_TYPE_STRING);
   1.107  
   1.108  }
   1.109  
   1.110  static void
   1.111 -gmyth_upnp_init ( GMythUPnP *gmyth_upnp )
   1.112 +gmyth_upnp_init(GMythUPnP * gmyth_upnp)
   1.113  {
   1.114  
   1.115 -	gmyth_upnp->backend_info = NULL;
   1.116 +    gmyth_upnp->backend_info = NULL;
   1.117  
   1.118 -	gmyth_upnp->control_point = NULL;
   1.119 +    gmyth_upnp->control_point = NULL;
   1.120  
   1.121 -	gmyth_upnp->priv = GMYTH_UPNP_GET_PRIVATE(gmyth_upnp);
   1.122 -	gmyth_upnp->priv->mutex = g_mutex_new ();
   1.123 -	gmyth_upnp->priv->upnp_dev_found = FALSE;
   1.124 +    gmyth_upnp->priv = GMYTH_UPNP_GET_PRIVATE(gmyth_upnp);
   1.125 +    gmyth_upnp->priv->mutex = g_mutex_new();
   1.126 +    gmyth_upnp->priv->upnp_dev_found = FALSE;
   1.127  
   1.128 -	g_signal_connect (G_OBJECT (gmyth_upnp), "device-found",
   1.129 -			(GCallback) (GMYTH_UPNP_GET_CLASS (gmyth_upnp)->
   1.130 -				device_found_handler), NULL);
   1.131 +    g_signal_connect(G_OBJECT(gmyth_upnp), "device-found",
   1.132 +                     (GCallback) (GMYTH_UPNP_GET_CLASS(gmyth_upnp)->
   1.133 +                                  device_found_handler), NULL);
   1.134  
   1.135 -	gmyth_upnp_static = gmyth_upnp;
   1.136 +    gmyth_upnp_static = gmyth_upnp;
   1.137  
   1.138  }
   1.139  
   1.140 @@ -127,238 +136,274 @@
   1.141   * 
   1.142   * @return a new instance of GMythUPnP. 
   1.143   */
   1.144 -GMythUPnP *
   1.145 -gmyth_upnp_new ( GMythBackendInfo *gmyth_backend_info, GMythUPnPDeviceListener handler ) 
   1.146 +GMythUPnP      *
   1.147 +gmyth_upnp_new(GMythBackendInfo * gmyth_backend_info,
   1.148 +               GMythUPnPDeviceListener handler)
   1.149  {
   1.150 -    GMythUPnP *gmyth_upnp = GMYTH_UPNP (g_object_new (GMYTH_UPNP_TYPE, NULL));
   1.151 -    
   1.152 -    g_object_ref( gmyth_backend_info );
   1.153 +    GMythUPnP      *gmyth_upnp =
   1.154 +        GMYTH_UPNP(g_object_new(GMYTH_UPNP_TYPE, NULL));
   1.155 +
   1.156 +    g_object_ref(gmyth_backend_info);
   1.157  
   1.158      gmyth_upnp->backend_info = gmyth_backend_info;
   1.159  
   1.160 -    if ( !gmyth_upnp_initialize ( gmyth_upnp, gmyth_backend_info, handler ) )
   1.161 -    {
   1.162 -    	gmyth_debug( "Error initializing the GMythUPnP!!!" );
   1.163 +    if (!gmyth_upnp_initialize(gmyth_upnp, gmyth_backend_info, handler)) {
   1.164 +        gmyth_debug("Error initializing the GMythUPnP!!!");
   1.165      }
   1.166 -    
   1.167 +
   1.168      return gmyth_upnp;
   1.169  }
   1.170  
   1.171  static void
   1.172 -gmyth_upnp_dispose  (GObject *object)
   1.173 +gmyth_upnp_dispose(GObject * object)
   1.174  {
   1.175 -	GMythUPnP *gmyth_upnp = GMYTH_UPNP(object);
   1.176 +    GMythUPnP      *gmyth_upnp = GMYTH_UPNP(object);
   1.177  
   1.178 -	if ( gmyth_upnp->control_point != NULL ) {
   1.179 -		cg_upnp_controlpoint_stop( gmyth_upnp->control_point );
   1.180 -		cg_upnp_controlpoint_delete( gmyth_upnp->control_point );
   1.181 -		gmyth_upnp->control_point = NULL;
   1.182 -	}
   1.183 -	
   1.184 -	if ( gmyth_upnp->priv->mythtv_servers != NULL )	{
   1.185 -		g_hash_table_destroy( gmyth_upnp->priv->mythtv_servers );
   1.186 -		gmyth_upnp->priv->mythtv_servers = NULL;
   1.187 -	}
   1.188 +    if (gmyth_upnp->control_point != NULL) {
   1.189 +        cg_upnp_controlpoint_stop(gmyth_upnp->control_point);
   1.190 +        cg_upnp_controlpoint_delete(gmyth_upnp->control_point);
   1.191 +        gmyth_upnp->control_point = NULL;
   1.192 +    }
   1.193  
   1.194 -	if ( gmyth_upnp->backend_info != NULL )	{
   1.195 -		g_object_unref( gmyth_upnp->backend_info );
   1.196 -		gmyth_upnp->backend_info = NULL;
   1.197 -	}
   1.198 +    if (gmyth_upnp->priv->mythtv_servers != NULL) {
   1.199 +        g_hash_table_destroy(gmyth_upnp->priv->mythtv_servers);
   1.200 +        gmyth_upnp->priv->mythtv_servers = NULL;
   1.201 +    }
   1.202  
   1.203 -	G_OBJECT_CLASS (gmyth_upnp_parent_class)->dispose (object);
   1.204 +    if (gmyth_upnp->backend_info != NULL) {
   1.205 +        g_object_unref(gmyth_upnp->backend_info);
   1.206 +        gmyth_upnp->backend_info = NULL;
   1.207 +    }
   1.208 +
   1.209 +    G_OBJECT_CLASS(gmyth_upnp_parent_class)->dispose(object);
   1.210  }
   1.211  
   1.212  static void
   1.213 -gmyth_upnp_finalize (GObject *object)
   1.214 +gmyth_upnp_finalize(GObject * object)
   1.215  {
   1.216 -	g_signal_handlers_destroy (object);
   1.217 +    g_signal_handlers_destroy(object);
   1.218  
   1.219 -	G_OBJECT_CLASS (gmyth_upnp_parent_class)->finalize (object);
   1.220 +    G_OBJECT_CLASS(gmyth_upnp_parent_class)->finalize(object);
   1.221  }
   1.222  
   1.223 -gchar *
   1.224 -gmyth_upnp_device_status_to_string( GMythUPnPDeviceStatus status )
   1.225 +gchar          *
   1.226 +gmyth_upnp_device_status_to_string(GMythUPnPDeviceStatus status)
   1.227  {
   1.228 -	if ( status == CgUpnpDeviceStatusAdded )
   1.229 -		return "Added";
   1.230 -	else if ( status == CgUpnpDeviceStatusUpdated )
   1.231 -		return "Updated";
   1.232 -	else if ( status == CgUpnpDeviceStatusInvalid )
   1.233 -		return "Invalid";
   1.234 -	else if ( status == CgUpnpDeviceStatusRemoved )
   1.235 -		return "Removed";
   1.236 -	
   1.237 -	return "";
   1.238 -}
   1.239 +    if (status == CgUpnpDeviceStatusAdded)
   1.240 +        return "Added";
   1.241 +    else if (status == CgUpnpDeviceStatusUpdated)
   1.242 +        return "Updated";
   1.243 +    else if (status == CgUpnpDeviceStatusInvalid)
   1.244 +        return "Invalid";
   1.245 +    else if (status == CgUpnpDeviceStatusRemoved)
   1.246 +        return "Removed";
   1.247  
   1.248 -/**
   1.249 - * GObject's signal handler
   1.250 - */ 
   1.251 -static void
   1.252 -_mythtv_device_found( GMythUPnP *gmyth_upnp, GMythUPnPDeviceStatus status, gchar* udn )
   1.253 -{
   1.254 -	g_debug( "Device: [status = %s, UDN = %s]\n", 
   1.255 -		gmyth_upnp_device_status_to_string( status ), udn );
   1.256 +    return "";
   1.257  }
   1.258  
   1.259  /**
   1.260   * GObject's signal handler
   1.261   */
   1.262 -static void 
   1.263 -_clinkc_mythtv_device_found ( gchar *udn, GMythUPnPDeviceStatus status )
   1.264 +static void
   1.265 +_mythtv_device_found(GMythUPnP * gmyth_upnp, GMythUPnPDeviceStatus status,
   1.266 +                     gchar * udn)
   1.267  {
   1.268 -	if ( gmyth_upnp_static != NULL && udn != NULL )
   1.269 -		g_signal_emit ( gmyth_upnp_static, 
   1.270 -			GMYTH_UPNP_GET_CLASS (gmyth_upnp_static)->device_found_handler_signal_id, 0, /* details */
   1.271 -			status, udn );
   1.272 +    g_debug("Device: [status = %s, UDN = %s]\n",
   1.273 +            gmyth_upnp_device_status_to_string(status), udn);
   1.274 +}
   1.275 +
   1.276 +/**
   1.277 + * GObject's signal handler
   1.278 + */
   1.279 +static void
   1.280 +_clinkc_mythtv_device_found(gchar * udn, GMythUPnPDeviceStatus status)
   1.281 +{
   1.282 +    if (gmyth_upnp_static != NULL && udn != NULL)
   1.283 +        g_signal_emit(gmyth_upnp_static, GMYTH_UPNP_GET_CLASS(gmyth_upnp_static)->device_found_handler_signal_id, 0,    /* details 
   1.284 +                                                                                                                         */
   1.285 +                      status, udn);
   1.286  }
   1.287  
   1.288  /**
   1.289   * Create a control point and start it.
   1.290   */
   1.291 -static gboolean
   1.292 -gmyth_upnp_initialize ( GMythUPnP *gmyth_upnp, GMythBackendInfo *gmyth_backend_info, 
   1.293 -	GMythUPnPDeviceListener device_found_handler )
   1.294 +static          gboolean
   1.295 +gmyth_upnp_initialize(GMythUPnP * gmyth_upnp,
   1.296 +                      GMythBackendInfo * gmyth_backend_info,
   1.297 +                      GMythUPnPDeviceListener device_found_handler)
   1.298  {
   1.299 -	gboolean ret = TRUE;
   1.300 +    gboolean        ret = TRUE;
   1.301  
   1.302 -	g_return_val_if_fail( gmyth_backend_info != NULL, FALSE );
   1.303 +    g_return_val_if_fail(gmyth_backend_info != NULL, FALSE);
   1.304  
   1.305 -	/* Create the cybergarage control point */
   1.306 -	gmyth_upnp->control_point = cg_upnp_controlpoint_new();
   1.307 +    /*
   1.308 +     * Create the cybergarage control point 
   1.309 +     */
   1.310 +    gmyth_upnp->control_point = cg_upnp_controlpoint_new();
   1.311  
   1.312 -	if ( device_found_handler != NULL )
   1.313 -	{
   1.314 -		GMYTH_UPNP_GET_CLASS(gmyth_upnp)->device_found_handler = device_found_handler; 
   1.315 +    if (device_found_handler != NULL) {
   1.316 +        GMYTH_UPNP_GET_CLASS(gmyth_upnp)->device_found_handler =
   1.317 +            device_found_handler;
   1.318  
   1.319 -		cg_upnp_controlpoint_setdevicelistener( gmyth_upnp->control_point, _clinkc_mythtv_device_found );
   1.320 -	}
   1.321 +        cg_upnp_controlpoint_setdevicelistener(gmyth_upnp->control_point,
   1.322 +                                               _clinkc_mythtv_device_found);
   1.323 +    }
   1.324  
   1.325 -	/* Start the control point */
   1.326 -	if ( cg_upnp_controlpoint_start( gmyth_upnp->control_point ) == FALSE)
   1.327 -	{
   1.328 -		gmyth_debug( "Unable to start UPnP control point!!!" );
   1.329 -		ret = FALSE;
   1.330 -		goto done;
   1.331 -	}
   1.332 -	else
   1.333 -	{
   1.334 -		gmyth_debug( "Control point started." );
   1.335 -	}
   1.336 +    /*
   1.337 +     * Start the control point 
   1.338 +     */
   1.339 +    if (cg_upnp_controlpoint_start(gmyth_upnp->control_point) == FALSE) {
   1.340 +        gmyth_debug("Unable to start UPnP control point!!!");
   1.341 +        ret = FALSE;
   1.342 +        goto done;
   1.343 +    } else {
   1.344 +        gmyth_debug("Control point started.");
   1.345 +    }
   1.346  
   1.347 -done:
   1.348 +  done:
   1.349  
   1.350 -	return ret;
   1.351 +    return ret;
   1.352  }
   1.353  
   1.354  static void
   1.355 -_gmyth_foreach_key_value( gchar *udn, gchar *dev, GList *upnp_servers_list )
   1.356 +_gmyth_foreach_key_value(gchar * udn, gchar * dev,
   1.357 +                         GList * upnp_servers_list)
   1.358  {
   1.359 -	GMythUPnPDevice *gmyth_upnp = g_malloc0( sizeof( GMythUPnPDevice ) );
   1.360 +    GMythUPnPDevice *gmyth_upnp = g_malloc0(sizeof(GMythUPnPDevice));
   1.361  
   1.362 -	GMythURI* uri = NULL;
   1.363 -	gmyth_upnp->uri = (gchar*) (dev);
   1.364 -	uri = gmyth_uri_new_with_value( gmyth_upnp->uri );
   1.365 +    GMythURI       *uri = NULL;
   1.366 +    gmyth_upnp->uri = (gchar *) (dev);
   1.367 +    uri = gmyth_uri_new_with_value(gmyth_upnp->uri);
   1.368  
   1.369 -	gmyth_upnp->host = gmyth_uri_get_host( uri );
   1.370 -	gmyth_upnp->port = gmyth_uri_get_port( uri );
   1.371 -	gmyth_upnp->protocol = gmyth_uri_get_protocol( uri );
   1.372 +    gmyth_upnp->host = gmyth_uri_get_host(uri);
   1.373 +    gmyth_upnp->port = gmyth_uri_get_port(uri);
   1.374 +    gmyth_upnp->protocol = gmyth_uri_get_protocol(uri);
   1.375  
   1.376 -	gmyth_debug("MythTV UPnP service [ %s, %d ].", gmyth_upnp->host, gmyth_upnp->port);
   1.377 +    gmyth_debug("MythTV UPnP service [ %s, %d ].", gmyth_upnp->host,
   1.378 +                gmyth_upnp->port);
   1.379  
   1.380 -	upnp_servers_list = g_list_append( upnp_servers_list, gmyth_upnp );
   1.381 +    upnp_servers_list = g_list_append(upnp_servers_list, gmyth_upnp);
   1.382  
   1.383 -	if ( uri != NULL )
   1.384 -	{
   1.385 -		g_object_unref( uri );
   1.386 -		uri = NULL;
   1.387 -	}
   1.388 +    if (uri != NULL) {
   1.389 +        g_object_unref(uri);
   1.390 +        uri = NULL;
   1.391 +    }
   1.392  
   1.393  }
   1.394  
   1.395 -GList *
   1.396 -gmyth_upnp_do_search_sync( GMythUPnP* gmyth_upnp )
   1.397 +GList          *
   1.398 +gmyth_upnp_do_search_sync(GMythUPnP * gmyth_upnp)
   1.399  {
   1.400 -	GList *upnp_servers_list = NULL;
   1.401 -	guint iter_count = GMYTH_UPNP_MAX_SEARCHS;
   1.402 -	/* gmyth_upnp->priv = GMYTH_UPNP_GET_PRIVATE( gmyth_upnp ); */
   1.403 +    GList          *upnp_servers_list = NULL;
   1.404 +    guint           iter_count = GMYTH_UPNP_MAX_SEARCHS;
   1.405 +    /*
   1.406 +     * gmyth_upnp->priv = GMYTH_UPNP_GET_PRIVATE( gmyth_upnp ); 
   1.407 +     */
   1.408  
   1.409 -	while ( gmyth_upnp->priv->upnp_dev_found == FALSE && ( --iter_count > 0 ) ) {
   1.410 +    while (gmyth_upnp->priv->upnp_dev_found == FALSE && (--iter_count > 0)) {
   1.411  
   1.412 -		gmyth_debug( "UPnP MythTV Client control point is searching MythTV AV Device server...\n" );
   1.413 +        gmyth_debug
   1.414 +            ("UPnP MythTV Client control point is searching MythTV AV Device server...\n");
   1.415  
   1.416 -		if ( gmyth_upnp->control_point != NULL )
   1.417 -			cg_upnp_controlpoint_search ( gmyth_upnp->control_point, 
   1.418 -					"urn:schemas-upnp-org:service:ContentDirectory:1" );
   1.419 +        if (gmyth_upnp->control_point != NULL)
   1.420 +            cg_upnp_controlpoint_search(gmyth_upnp->control_point,
   1.421 +                                        "urn:schemas-upnp-org:service:ContentDirectory:1");
   1.422  
   1.423 -		/* just to avoid clinkc pthread concurrency faults */
   1.424 -		cg_wait( 1000 );
   1.425 +        /*
   1.426 +         * just to avoid clinkc pthread concurrency faults 
   1.427 +         */
   1.428 +        cg_wait(1000);
   1.429  
   1.430 -		/* discover if it was found */
   1.431 -		gmyth_upnp->priv->upnp_dev_found = gmyth_upnp_got_mythtv_service( gmyth_upnp->control_point, &gmyth_upnp->priv->udn,
   1.432 -				&gmyth_upnp->priv->mythtv_servers );
   1.433 +        /*
   1.434 +         * discover if it was found 
   1.435 +         */
   1.436 +        gmyth_upnp->priv->upnp_dev_found =
   1.437 +            gmyth_upnp_got_mythtv_service(gmyth_upnp->control_point,
   1.438 +                                          &gmyth_upnp->priv->udn,
   1.439 +                                          &gmyth_upnp->priv->
   1.440 +                                          mythtv_servers);
   1.441  
   1.442 -	} /* while */
   1.443 +    }                           /* while */
   1.444  
   1.445 -	if ( gmyth_upnp->priv->upnp_dev_found ) {
   1.446 +    if (gmyth_upnp->priv->upnp_dev_found) {
   1.447  
   1.448 -		gmyth_debug( "Found UPnP MythTV AV Device...\n" );
   1.449 +        gmyth_debug("Found UPnP MythTV AV Device...\n");
   1.450  
   1.451 -		g_hash_table_foreach( gmyth_upnp->priv->mythtv_servers, (GHFunc)_gmyth_foreach_key_value, upnp_servers_list );
   1.452 +        g_hash_table_foreach(gmyth_upnp->priv->mythtv_servers,
   1.453 +                             (GHFunc) _gmyth_foreach_key_value,
   1.454 +                             upnp_servers_list);
   1.455  
   1.456 -	} /* if - found UPnP device  */
   1.457 -
   1.458 -	return upnp_servers_list;
   1.459 +    }
   1.460 +    /*
   1.461 +     * if - found UPnP device 
   1.462 +     */
   1.463 +    return upnp_servers_list;
   1.464  }
   1.465  
   1.466  /** 
   1.467   * Checks if got the MythTV service in the Control Point's device list.
   1.468   */
   1.469 -static gboolean
   1.470 -gmyth_upnp_got_mythtv_service( CgUpnpControlPoint* controlPt, gchar **udn, 
   1.471 -	GHashTable **mythtv_servers_lst )
   1.472 +static          gboolean
   1.473 +gmyth_upnp_got_mythtv_service(CgUpnpControlPoint * controlPt, gchar ** udn,
   1.474 +                              GHashTable ** mythtv_servers_lst)
   1.475  {
   1.476 -	
   1.477 -	g_return_val_if_fail( mythtv_servers_lst != NULL, FALSE );	
   1.478 -	g_return_val_if_fail( controlPt != NULL, FALSE );
   1.479  
   1.480 -	*mythtv_servers_lst = g_hash_table_new( g_str_hash, g_str_equal );
   1.481 -	
   1.482 -	const gchar* mythtvFriendlyName = "Myth";
   1.483 -	/* begin assertion about the size of discovered devices */
   1.484 -	gint numDevices = cg_upnp_controlpoint_getndevices(controlPt);
   1.485 -	gint cntDevs = 0;	
   1.486 -	CgUpnpDevice *childDev;
   1.487 -	gchar *devName = NULL, *dev_url = NULL;
   1.488 -	gboolean upnp_dev_found = FALSE;
   1.489 -	
   1.490 -	gmyth_debug( "UPnP MythTV AV Device list size = %d\n", numDevices );
   1.491 -	
   1.492 -	for ( childDev = cg_upnp_controlpoint_getdevices(controlPt); childDev != NULL; 
   1.493 -			childDev = cg_upnp_device_next(childDev) ) {
   1.494 -		devName = cg_upnp_device_getfriendlyname(childDev);
   1.495 -		dev_url = cg_upnp_device_getlocationfromssdppacket( childDev );
   1.496 -		gmyth_debug( "Device's friendly name = %s, and  device's URL = %s\n", devName, dev_url );
   1.497 -		if ( ( g_strstr_len( devName, strlen( devName ), mythtvFriendlyName ) != NULL ) == TRUE ) 
   1.498 -		{
   1.499 -			upnp_dev_found = TRUE;
   1.500 -			/* stores the last UDN number ID */
   1.501 -			*udn = cg_upnp_device_getudn( childDev );
   1.502 -			/* *mythtv_servers_lst = g_list_append( *mythtv_servers_lst, dev_url );  */
   1.503 -			g_hash_table_insert( *mythtv_servers_lst, (gpointer)*udn, (gpointer)dev_url );
   1.504 -		}
   1.505 -		++cntDevs;
   1.506 -	}
   1.507 -	
   1.508 -	if ( upnp_dev_found == TRUE ) {
   1.509 -		gmyth_debug( "MythTV AV Device found, from a total of %d devices.\n", cntDevs );
   1.510 -	} else if ( numDevices == cntDevs ) {
   1.511 -		gmyth_debug( "MythTV AV Device not found, from a total of %d devices.\n", cntDevs );
   1.512 -	} else {
   1.513 -		gmyth_debug( "Control Point's MythTV AV Device count is wrong: iterated over %d devices, but there are %d registered devices.\n", cntDevs, numDevices );
   1.514 -	}
   1.515 -	
   1.516 -	return upnp_dev_found;
   1.517 +    g_return_val_if_fail(mythtv_servers_lst != NULL, FALSE);
   1.518 +    g_return_val_if_fail(controlPt != NULL, FALSE);
   1.519 +
   1.520 +    *mythtv_servers_lst = g_hash_table_new(g_str_hash, g_str_equal);
   1.521 +
   1.522 +    const gchar    *mythtvFriendlyName = "Myth";
   1.523 +    /*
   1.524 +     * begin assertion about the size of discovered devices 
   1.525 +     */
   1.526 +    gint            numDevices =
   1.527 +        cg_upnp_controlpoint_getndevices(controlPt);
   1.528 +    gint            cntDevs = 0;
   1.529 +    CgUpnpDevice   *childDev;
   1.530 +    gchar          *devName = NULL,
   1.531 +        *dev_url = NULL;
   1.532 +    gboolean        upnp_dev_found = FALSE;
   1.533 +
   1.534 +    gmyth_debug("UPnP MythTV AV Device list size = %d\n", numDevices);
   1.535 +
   1.536 +    for (childDev = cg_upnp_controlpoint_getdevices(controlPt);
   1.537 +         childDev != NULL; childDev = cg_upnp_device_next(childDev)) {
   1.538 +        devName = cg_upnp_device_getfriendlyname(childDev);
   1.539 +        dev_url = cg_upnp_device_getlocationfromssdppacket(childDev);
   1.540 +        gmyth_debug
   1.541 +            ("Device's friendly name = %s, and  device's URL = %s\n",
   1.542 +             devName, dev_url);
   1.543 +        if ((g_strstr_len(devName, strlen(devName), mythtvFriendlyName) !=
   1.544 +             NULL) == TRUE) {
   1.545 +            upnp_dev_found = TRUE;
   1.546 +            /*
   1.547 +             * stores the last UDN number ID 
   1.548 +             */
   1.549 +            *udn = cg_upnp_device_getudn(childDev);
   1.550 +            /*
   1.551 +             *mythtv_servers_lst = g_list_append( *mythtv_servers_lst, dev_url );  */
   1.552 +            g_hash_table_insert(*mythtv_servers_lst, (gpointer) * udn,
   1.553 +                                (gpointer) dev_url);
   1.554 +        }
   1.555 +        ++cntDevs;
   1.556 +    }
   1.557 +
   1.558 +    if (upnp_dev_found == TRUE) {
   1.559 +        gmyth_debug
   1.560 +            ("MythTV AV Device found, from a total of %d devices.\n",
   1.561 +             cntDevs);
   1.562 +    } else if (numDevices == cntDevs) {
   1.563 +        gmyth_debug
   1.564 +            ("MythTV AV Device not found, from a total of %d devices.\n",
   1.565 +             cntDevs);
   1.566 +    } else {
   1.567 +        gmyth_debug
   1.568 +            ("Control Point's MythTV AV Device count is wrong: iterated over %d devices, but there are %d registered devices.\n",
   1.569 +             cntDevs, numDevices);
   1.570 +    }
   1.571 +
   1.572 +    return upnp_dev_found;
   1.573  
   1.574  }
   1.575  
   1.576 @@ -367,17 +412,17 @@
   1.577   * @return The GHashTable* containing all the URI values for each recognized UPnP device,
   1.578   * 			or NULL if it couldn't recognize any MythTV AV device.
   1.579   */
   1.580 -GHashTable*
   1.581 -gmyth_upnp_get_servers ( GMythUPnP *gmyth_upnp )
   1.582 +GHashTable     *
   1.583 +gmyth_upnp_get_servers(GMythUPnP * gmyth_upnp)
   1.584  {
   1.585 -	
   1.586 -	if ( NULL == gmyth_upnp || NULL == gmyth_upnp->priv->mythtv_servers ) 
   1.587 -	{
   1.588 -		gmyth_debug ("[%s] GMythUPnP has no MythTV servers recognized.\n", __FUNCTION__);
   1.589 -		return NULL;
   1.590 -	}
   1.591  
   1.592 -	return gmyth_upnp->priv->mythtv_servers;
   1.593 +    if (NULL == gmyth_upnp || NULL == gmyth_upnp->priv->mythtv_servers) {
   1.594 +        gmyth_debug("[%s] GMythUPnP has no MythTV servers recognized.\n",
   1.595 +                    __FUNCTION__);
   1.596 +        return NULL;
   1.597 +    }
   1.598 +
   1.599 +    return gmyth_upnp->priv->mythtv_servers;
   1.600  }
   1.601  
   1.602  /** Gets the GMythBackendInfo object associated to this upnp.
   1.603 @@ -385,16 +430,14 @@
   1.604   * @return The GMythBackendInfo object currently valid or NULL if the settings
   1.605   * were not opened.
   1.606   */
   1.607 -GMythBackendInfo*
   1.608 -gmyth_upnp_get_backend_info ( GMythUPnP *gmyth_upnp )
   1.609 +GMythBackendInfo *
   1.610 +gmyth_upnp_get_backend_info(GMythUPnP * gmyth_upnp)
   1.611  {
   1.612 -	
   1.613 -	if ( NULL == gmyth_upnp || NULL == gmyth_upnp->backend_info ) 
   1.614 -	{
   1.615 -		gmyth_debug ("[%s] GMythUPnP not initialized\n", __FUNCTION__);
   1.616 -		return NULL;
   1.617 -	}
   1.618  
   1.619 -	return gmyth_upnp->backend_info;
   1.620 +    if (NULL == gmyth_upnp || NULL == gmyth_upnp->backend_info) {
   1.621 +        gmyth_debug("[%s] GMythUPnP not initialized\n", __FUNCTION__);
   1.622 +        return NULL;
   1.623 +    }
   1.624 +
   1.625 +    return gmyth_upnp->backend_info;
   1.626  }
   1.627 -