/*
    GDAM - Geoff & Dave's Audio Mixer
    Copyright (C) 1999    Dave Benson, Geoff Matters.

    This library 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 library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

    Contact:
        daveb@ffem.org <Dave Benson>
        geoff@ugcs.caltech.edu <Geoff Matters>
*/
#ifndef __GDAM_DISPATCH_H_
#define __GDAM_DISPATCH_H_

#include "gdassource.h"
#include "gdamsink.h"
#include "gdampermissions.h"
#include "gdamconnection.h"

/*
 * Code which handles the global communication.
 *
 * In particular the gdas_source_id/gdam_device_id interface
 * is accessible here.
 */

GdasSource      *gdam_dispatch_get_source(int              gdas_source_id);
GdamSink        *gdam_dispatch_get_sink  (int              gdam_sink_id);
GdamServerObject *gdam_dispatch_get_server_object(int sink_id);

/* The buffer passed in has already had the length stripped
 * from it. */
GdamBuffer      *gdam_dispatch_buffer    (GdamConnection  *connection,
                                          GdamPermissions *perms,
                                          GdamBuffer      *command);
GdasSource      *gdam_dispatch_source_from_buffer(GdamBuffer *source);

void             gdam_dispatch_set_log   (const char *filename);

/*
 * Obtain unique global identifying numbers; used by GdamServerObject
 * exclusively.
 */
int gdam_dispatch_obtain_global_id(GdamServerObject *server_object);
void gdam_dispatch_release_global_id(int device_id);

void gdam_dispatch_log(const char *fmt, ...);

/* From gdamdispatchmessage.c:  private. */
typedef enum _GdamDispatchResult {
	GDAM_DISPATCH_SUCCESS,
	GDAM_DISPATCH_INDICATE_SUCCESS,
	GDAM_DISPATCH_FAIL,
	GDAM_DISPATCH_INDICATE_FAIL,
	GDAM_DISPATCH_TOO_SHORT
} GdamDispatchResult;

typedef GdamDispatchResult
              (*GdamDispatchMessageFunc)(GdamConnection  *connection,
                                         GdamPermissions *perms,
                                         GdamBuffer      *command,
                                         GdamBuffer      *returned_val);

GdamDispatchMessageFunc gdam_dispatch_message_find_by_type(int i);
#endif
