/**
 * GMyth Library
 *
 * @file gmyth/gmyth_upnp.h
 * 
 * @brief <p> GMythUPnP allows that a MythTV frontend discovers a 
 * MythTV backend, using the UPnP architecture.
 *
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
 * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *   
 */

#ifndef _GMYTH_UPNP_H_
#define _GMYTH_UPNP_H_

#include <glib.h>
#include <glib-object.h>

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <cybergarage/upnp/cupnp.h>
#include <gmyth/gmyth_backendinfo.h>

G_BEGIN_DECLS
#define GMYTH_UPNP_TYPE               (gmyth_upnp_get_type ())
#define GMYTH_UPNP(obj)          		 	(G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_UPNP_TYPE, GMythUPnP))
#define GMYTH_UPNP_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_UPNP_TYPE, GMythUPnPClass))
#define IS_GMYTH_UPNP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_UPNP_TYPE))
#define IS_GMYTH_UPNP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_UPNP_TYPE))
#define GMYTH_UPNP_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_UPNP_TYPE, GMythUPnPClass))
typedef struct _GMythUPnP GMythUPnP;
typedef struct _GMythUPnPClass GMythUPnPClass;
typedef struct _GMythUPnPPrivate GMythUPnPPrivate;

/****************************************
* Data Type
****************************************/

typedef enum upnp_device_list_status {
    GMYTH_UPNP_DEVICE_ADDED = 0,
    GMYTH_UPNP_DEVICE_UPDATED,
    GMYTH_UPNP_DEVICE_REMOVED
} GMythUPnPDeviceStatus;

typedef void    (*GMythUPnPDeviceListener) (GMythUPnP * gmyth_upnp,
                                            GMythUPnPDeviceStatus status,
                                            gchar * dev);

struct _GMythUPnPClass {
    GObjectClass    parent_class;

    /*
     * callbacks 
     */
    guint           device_found_handler_signal_id;

    GMythUPnPDeviceListener device_found_handler;

    /*
     * no one for now 
     */
};

struct _GMythUPnPDevice {
    gchar          *uri;
    gchar          *host;
    gint            port;
    gchar          *protocol;
};

typedef struct _GMythUPnPDevice GMythUPnPDevice;

struct _GMythUPnP {

    GObject         parent;
    GMythUPnPPrivate *priv;


    CgUpnpControlPoint *control_point;

    gchar          *udn;

    GMythBackendInfo *backend_info;

    gboolean        upnp_dev_found;
};

GType           gmyth_upnp_get_type(void);
GMythUPnP      *gmyth_upnp_new(GMythBackendInfo * gmyth_backend_info,
                               GMythUPnPDeviceListener handler);

GList          *gmyth_upnp_do_search_sync(GMythUPnP * gmyth_upnp);

GMythBackendInfo *gmyth_upnp_get_backend_info(GMythUPnP * gmyth_upnp);

gchar          *gmyth_upnp_device_status_to_string(GMythUPnPDeviceStatus
                                                   status);

G_END_DECLS
#endif                          /* _GMYTH_UPNP_H_ */