/* connectmgr.c - Implementation of UPnP ConnectionManager
 *
 * Copyright (C) 2005, 2007  Oskar Liljeblad
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 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 Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include <config.h>
#include <stdbool.h>		/* Gnulib/C99 */
#include <upnp/upnp.h>		/* libupnp */
#include <upnp/upnptools.h>	/* libupnp */
#include "gmediaserver.h"

static bool
connectmgr_get_protocol_info(ActionEvent *event)
{
    /* The SOURCE used to be "http-get:*:audio/mpeg:*" but now we support
     * a variety of MIME types. Instead of listing them one and one (like
     * this: "http-get:*:audio/mpeg:*,http-get:*:audio/m3u:*,..") we use
     * this generic string which is accepted according to the standard.
     */
    upnp_add_response(event, "SOURCE", "http-get:*:*:*");
    upnp_add_response(event, "SINK", "");
    return event->status;
}

static bool
connectmgr_get_current_connection_ids(ActionEvent *event)
{
    upnp_add_response(event, "ConnectionIDs", "0");
    return event->status;
}

static bool
connectmgr_get_current_connection_info(ActionEvent *event)
{
    upnp_add_response(event, "ConnectionID", "0");
    upnp_add_response(event, "RcsID", "-1");
    upnp_add_response(event, "AVTransportID", "-1");
    upnp_add_response(event, "ProtocolInfo", "http-get:*:audio/mpeg:*"); /* XXX format */
    upnp_add_response(event, "PeerConnectionManager", "");
    upnp_add_response(event, "PeerConnectionID", "-1");
    upnp_add_response(event, "Direction", "Output");
    upnp_add_response(event, "Status", "OK");
    return event->status;
}

ServiceVariable connectmgr_service_variables[] = {
  { "SourceProtocolInfo", "http-get:*:*:*" },
  { "SinkProtocolInfo", "" },
  { "CurrentConnectionIDs", "0" },
  { 0, }
};

ServiceAction connectmgr_service_actions[] = {
  { "GetProtocolInfo", connectmgr_get_protocol_info },
/*{ "PrepareForConnection", connectmgr_prepare_for_connection },*/
/*{ "ConnectionComplete", connectmgr_connection_complete },*/
  { "GetCurrentConnectionIDs", connectmgr_get_current_connection_ids },
  { "GetCurrentConnectionInfo", connectmgr_get_current_connection_info },
  { 0, }
};
