src/lib/msg_proto.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 May 2009 01:17:36 +0300
branchnew-lib-errors
changeset 219 cefec18b8268
parent 196 src/msg_proto.h@873796250c60
permissions -rw-r--r--
some of the lib/transport stuff compiles
#ifndef LIBQMSK_MSG_PROTO_H
#define LIBQMSK_MSG_PROTO_H

/**
 * @param
 *
 * Support for simple protocols that send/recieve length-prefixed messages over a transport stream.
 *
 * This implementation is mostly geared towards handling a reasonable number of reasonably sized messages in a
 * reasonable way. Hence, 
 */
#include "transport.h"

/** 
 * Protocol state struct
 */
struct msg_proto;

/**
 * User callbacks
 */
struct msg_proto_callbacks {
    /**
     * Message recieved.
     *
     * XXX: currently you must not call msg_proto_destroy from within this callback
     */
    void (*on_msg) (struct msg_proto *proto, void *data, size_t len, void *arg);

    /**
     * Transport/protocol error occured in event handling.
     */
    void (*on_error) (struct msg_proto *proto, const error_t *err, void *arg);
};

/**
 * Create a msg_proto state using the given transport.
 *
 * This will install our callback handlers on the given transport.
 */
err_t msg_proto_create (struct msg_proto **proto_ptr, transport_t *transport, const struct msg_proto_callbacks *cb_tbl, void *cb_arg, error_t *err);

/**
 * Send a message to the other endpoint
 */
err_t msg_proto_send (struct msg_proto *proto, const void *data, size_t len, error_t *err);

/**
 * Destroy the protocol state and transport
 */
void msg_proto_destroy (struct msg_proto *proto);


#endif