/*
 * Inter-process Communication API: very simple messaging over sockets.
 *
 * @copyright 2008, Research In Motion Ltd.
 *
 * @version $Id: //depot/rel/dsp/ecall/2/c/testlab/ipc.h#1 $
 */

#ifndef __IPC_H__
#define __IPC_H__

#include "msg.h"

typedef struct _IpcConn IpcConn;

/* 
 * Call once to initialize.
 */
void IpcInit(void);

/* 
 * Call to open one or more IPC connections: 
 * listen => inbound, connect => outbound 
 */
IpcConn *IpcListen(const char *host, const char *port);
IpcConn *IpcConnect(const char *host, const char *port);

/*
 * Register a 'task' function that is triggered to process a message.
 * Each end of a connection requires one such function to support
 * single-threaded simulation of IPC.  This is only useful for builds with
 * ipc_sim.c and does nothing when using ipc_sock.c.
 */
void IpcRegisterTask(IpcConn *conn, BOOL (*task)(void));

/*
 * Start sending and receiving.
 */
void IpcStart(void);

/*
 * Send a message to the specified connection.
 */
void IpcSend(IpcConn *conn, const Msg *msg);

/*
 * Receive next available message from any connection.
 */
IpcConn *IpcRecv(Msg *msg);

/* 
 * Stop sending and receiving, closing all connections. 
 */
void IpcStop(void);

/*
 * Call once for final cleanup.
 */
void IpcFinal(void);

#endif
