/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/************************************************************************/
/*                  Copyright 1996 Acorn Computers Ltd                  */
/*                                                                      */
/*  This material is the confidential trade secret and proprietary      */
/*  information of Acorn Computers. It may not be reproduced, used      */
/*  sold, or transferred to any third party without the prior written   */
/*  consent of Acorn Computers. All rights reserved.                    */
/*                                                                      */
/************************************************************************/

#ifndef __debug_remote_h
#define __debug_remote_h

#include <stdarg.h>

#define REMOTE_DEBUG_VERSION "0.03"

#ifdef REMOTE_DEBUG

/*
 * Function typedef for handlign commands sent from the server end
 */

typedef int (*remote_debug_cmd_handler)(int argc, char *argv[], void *handle);

/*
 * structure to fold session data
 */
typedef struct
{
  int  sock;
  char *info;
  unsigned char priority;
  remote_debug_cmd_handler cmd_handler;
  void *cmd_handle;
} debug_session;

/*
 * Open a connection to host specified by Inet$DebugHost and send an initial
 * connection message. All future sends via this interface will be prefixed by
 * info. A copy of info is made internally. This call will return a pointer to
 * a session structure to be used in subsequent calls.
 */
void remote_debug_open(char *info, debug_session **sess);

/*
 * Send an printf formatted string upto a max of 1024 characters to the debug
 * host. If string is prefixed by (n), this is treated as the debug priority
 * level.
 *
 * Also versions to send a neat string and one passed as a va_list.
 */
void debug_printf(debug_session *sess, char *format, ...);
void debug_vprintf(debug_session *sess, const char *format, va_list list);
void debug_dvprintf(debug_session *sess, int priority, const char *file, int line, const char *format, va_list list);
void debug_print_line(debug_session *sess, const char *debug_line);

/*
 * Register a command handler to handle commands sent from the server
 */

void remote_debug_register_cmd_handler(debug_session *sess, remote_debug_cmd_handler fn, void *handle);
/*
 * Close a previously open debug channel.
 */
void remote_debug_close(debug_session *sess);

/*
 * check the input port for any data. Call this every so often to ensure commands
 * get executed when entered rather than on the next debug write.
 */
int debug_poll(debug_session *sess);

#else

#define remote_debug_open(x,y)
#define debug_printf 1?0:printf
#define debug_vprintf(s,f,l)
#define debug_print_line(s,d)
#define remote_debug_close(x)

#endif /* REMOTE_DEBUG */

#endif