340 lines
12 KiB
C
340 lines
12 KiB
C
/*
|
|
******************************************************************************
|
|
* HEADER FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_channel.h,v $ $Revision: 1.3.2.2 $
|
|
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike_channel.h,v $
|
|
* $Author: ulf $ $Date: 2011-11-16 10:33:31 $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Erik Dahlberg <erik.dahlberg@windriver.com>
|
|
******************************************************************************
|
|
*/
|
|
|
|
#ifndef IPIKE_CHANNEL_H_
|
|
#define IPIKE_CHANNEL_H_
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
#include "ipike_config.h"
|
|
|
|
#ifdef IPIKE_USE_EVENT_LOG
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/* Static initialization of a channel message */
|
|
#define IPIKE_CHANNEL_MSG_INIT_STATIC(_msg, _buf) \
|
|
do { \
|
|
ipcom_memset(&_buf, 0, sizeof(_buf)); \
|
|
_msg = (Ipike_channel_msg *) &_buf; \
|
|
_msg->len = (Ip_u16) sizeof(_buf); \
|
|
} while(0)
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/* Channel status */
|
|
typedef enum Ipike_channel_status_enum
|
|
{
|
|
IPIKE_CHANNEL_OK = 0,
|
|
IPIKE_CHANNEL_CLOSED = 1,
|
|
IPIKE_CHANNEL_ERROR = 2,
|
|
} Ipike_channel_status;
|
|
|
|
/* IKE channel object */
|
|
typedef struct Ipike_channel_struct Ipike_channel;
|
|
|
|
/* IKE channel server object */
|
|
typedef struct Ipike_channel_server_struct Ipike_channel_server;
|
|
|
|
/* IKE channel address object */
|
|
typedef struct Ipike_channel_addr_struct Ipike_channel_addr;
|
|
|
|
/* Channel message header which all type of messages must include */
|
|
typedef struct Ipike_channel_msg_struct
|
|
{
|
|
Ip_u16 type;
|
|
Ip_u16 len;
|
|
} Ipike_channel_msg;
|
|
|
|
/* Channel server callback for channel state updates */
|
|
typedef int (*Ipike_channel_server_cb) (Ipike_channel *channel);
|
|
|
|
/* Channel server callback for receiving messages */
|
|
typedef int (*Ipike_channel_server_receive_cb)
|
|
(
|
|
Ipike_channel * channel,
|
|
Ipike_channel_msg * msg
|
|
);
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_msg_create
|
|
*===========================================================================
|
|
* Description: Creates and allocates a channel message of size 'len'
|
|
* dynamically.
|
|
* Parameters: len - desired length of message.
|
|
* Returns: A pointer to a new channel message or
|
|
* IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL Ipike_channel_msg *
|
|
ipike_channel_msg_create(
|
|
Ip_u16 len);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* Ipike_channel_msg_destroy
|
|
*===========================================================================
|
|
* Description: Creates and allocates a channel message of size 'len'
|
|
* dynamically.
|
|
* Parameters: len - desired length of message.
|
|
* Returns: A pointer to a new channel message or
|
|
* IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_channel_msg_destroy(
|
|
Ipike_channel_msg *msg);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_addr_create
|
|
*===========================================================================
|
|
* Description: Creates a new channel address from a string.
|
|
* Parameters: caddr_str - String representation of a channel address.
|
|
* Returns: The new channel address or
|
|
* IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL Ipike_channel_addr *
|
|
ipike_channel_addr_create(
|
|
const char * caddr_str);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_addr_destroy
|
|
*===========================================================================
|
|
* Description: Creates and allocates a channel message of size 'len'
|
|
* dynamically.
|
|
* Parameters: len - desired length of message.
|
|
* Returns: A pointer to a new channel message or
|
|
* IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_channel_addr_destroy(
|
|
Ipike_channel_addr * caddr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_open
|
|
*===========================================================================
|
|
* Description: Creates and opens up a channel to the endpoint specified by
|
|
* the channel address.
|
|
* Parameters: caddr - Channel address
|
|
* Returns: A new channel object of IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL Ipike_channel *
|
|
ipike_channel_open(
|
|
Ipike_channel_addr * caddr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_close
|
|
*===========================================================================
|
|
* Description: Creates and allocates a channel message of size 'len'
|
|
* dynamically.
|
|
* Parameters: len - desired length of message.
|
|
* Returns: A pointer to a new channel message or
|
|
* IP_NULL on failure
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_channel_close(
|
|
Ipike_channel * channel);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_destroy
|
|
*===========================================================================
|
|
* Description: Destroys and closes a channel.
|
|
* Parameters: channel - Channel
|
|
* Returns:
|
|
*/
|
|
IP_PUBLIC void
|
|
ipike_channel_destroy(
|
|
Ipike_channel * channel);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_send_msg
|
|
*===========================================================================
|
|
* Description: Sends a message on a channel.
|
|
*
|
|
* Parameters: channel - Channel
|
|
* msg - Channel message
|
|
* Returns: IPIKE_CHANNEL_OK - Message was sent successfully.
|
|
* IPIKE_CHANNEL_CLOSED
|
|
* IPIKE_CHANNEL_ERROR
|
|
*/
|
|
IP_GLOBAL Ipike_channel_status
|
|
ipike_channel_send_msg(
|
|
Ipike_channel * channel,
|
|
Ipike_channel_msg * msg);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_receive_msg
|
|
*===========================================================================
|
|
* Description: Receive a message on a channel, will block until a message
|
|
* is received or the channel is closed. If *msg is IP_NULL a
|
|
* new message will be dynamically allocated and used as storage
|
|
* for the received message, otherwise it will use the message
|
|
* buffer *msg.
|
|
*
|
|
* Parameters: channel - Channel
|
|
* msg - Channel message
|
|
*
|
|
* Returns: IPIKE_CHANNEL_OK - Message was received successfully.
|
|
* IPIKE_CHANNEL_CLOSED
|
|
* IPIKE_CHANNEL_ERROR
|
|
*/
|
|
IP_GLOBAL Ipike_channel_status
|
|
ipike_channel_receive_msg(
|
|
Ipike_channel * channel,
|
|
Ipike_channel_msg ** msg);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_server_create
|
|
*===========================================================================
|
|
* Description: Creates a channel server which are listening on the provided
|
|
* channel server address.
|
|
* Parameters: caddr - Channel server address.
|
|
* on_connect_cb - Callback which is called when a new channel
|
|
* is opened.
|
|
* on_close_cb - Callback which is called when a channel is
|
|
* closed.
|
|
* on_receive_cb - Callback which is called when a message is
|
|
* received on a channel.
|
|
*
|
|
* Returns: Channel server object
|
|
*/
|
|
IP_GLOBAL Ipike_channel_server *
|
|
ipike_channel_server_create(
|
|
Ipike_channel_addr * caddr,
|
|
Ipike_channel_server_cb on_open_cb,
|
|
Ipike_channel_server_cb on_close_cb,
|
|
Ipike_channel_server_receive_cb on_receive_cb);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_server_destroy
|
|
*===========================================================================
|
|
* Description: Closes all channels and destroys the channel server object.
|
|
* Parameters: cserver - Channel server object.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_channel_server_destroy(
|
|
Ipike_channel_server * cserver);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_server_broadcast_msg
|
|
*===========================================================================
|
|
* Description: Broadcasts a message on all channels that are managed by
|
|
* the channel server.
|
|
*
|
|
* Parameters: cserver - Channel server object.
|
|
* msg - Message to broadcast
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_channel_server_broadcast_msg(
|
|
Ipike_channel_server * cserver,
|
|
Ipike_channel_msg * msg);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_server_add_fds
|
|
*===========================================================================
|
|
* Description: Adds any internal sockets held be the channel server into the
|
|
* file descriptor set.
|
|
*
|
|
* Parameters: cserver - Channel server object.
|
|
* read_fds - Read file descriptor set.
|
|
* write_fds - Write file descriptor set.
|
|
* Returns: The largest file descriptor that was added, or
|
|
* -1 if no file descriptor was added.
|
|
*/
|
|
IP_GLOBAL int
|
|
ipike_channel_server_add_fds(
|
|
Ipike_channel_server * cserver,
|
|
Ip_fd_set * read_fds,
|
|
Ip_fd_set * write_fds);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_channel_server_process
|
|
*===========================================================================
|
|
* Description: Process internal sockets inside the channel server which has
|
|
* been added with ipike_channel_server_add_fds.
|
|
*
|
|
* Parameters: cserver - Channel server object.
|
|
* read_fds - Read file descriptor set.
|
|
* write_fds - Write file descriptor set.
|
|
* Returns: The number of processed file descriptors, 0 if no file
|
|
* descriptors were processed.
|
|
*/
|
|
IP_GLOBAL int
|
|
ipike_channel_server_process(
|
|
Ipike_channel_server * cserver,
|
|
Ip_fd_set * read_fds,
|
|
Ip_fd_set * write_fds);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IPIKE_CHANNEL_H_ */
|
|
|
|
#endif /* IPIKE_USE_EVENT_LOG */
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|
|
|