Latest updates before ctnetwork directory is moved.
This commit was SVN r83.
Этот коммит содержится в:
родитель
55b8aa9066
Коммит
c54f86cbe1
@ -7,5 +7,168 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ctchannel.h"
|
||||
#include "runtime/ctnetwork/ctchannel.h"
|
||||
|
||||
#define CHANNEL_CLS(chnl) ((lam_ctchannel_class_t *)(OBJECT(chnl)->obj_class))
|
||||
|
||||
lam_ctchannel_class_t lam_ctchannel_cls = {
|
||||
{"lam_ct_channel_t", &lam_object_cls,
|
||||
(class_init_t)lam_cth_init,
|
||||
(class_destroy_t)lam_obj_destroy},
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
|
||||
void lam_cth_init(lam_ctchannel_t *channel)
|
||||
{
|
||||
SUPER_INIT(channel, lam_ctchannel_cls.cls_parent);
|
||||
channel->cth_status = CT_CHNL_CLOSED;
|
||||
channel->cth_id = 0;
|
||||
channel->cth_timeout_secs = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* PURE VIRTUAL functions that must be
|
||||
* implemented by concrete subclasses.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* return: error code args: (channel, data, data length, bytes sent) */
|
||||
uint32_t lam_cth_send(lam_ctchannel_t *channel, const uint8_t *data,
|
||||
uint32_t data_len, uint32_t *bytes_sent)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_send(channel, data, data_len, bytes_sent);
|
||||
}
|
||||
|
||||
/* return: error code args: (channel, recv buffer, buffer length, bytes received) */
|
||||
uint32_t lam_cth_recv(lam_ctchannel_t *channel, const uint8_t *buffer,
|
||||
uint32_t buff_len, uint32_t *bytes_recvd)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_recv(channel, buffer,
|
||||
buff_len, bytes_recvd);
|
||||
}
|
||||
|
||||
/* return: error code args: (channel, msg ptr) */
|
||||
uint32_t lam_cth_get_msg(lam_ctchannel_t *channel, lam_ctmsg_t **msg)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_get_msg(channel, msg);
|
||||
}
|
||||
|
||||
/* return: error code args: (channel, recv buffer ptr, bytes received) */
|
||||
uint32_t lam_cth_get_packed_msg(lam_ctchannel_t *channel, const uint8_t **buffer,
|
||||
uint32_t *bytes_recvd)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_get_packed_msg(channel, buffer, bytes_recvd);
|
||||
}
|
||||
|
||||
/* return: error code args: (channel, msg) */
|
||||
uint32_t lam_cth_send_msg(lam_ctchannel_t *channel, lam_ctmsg_t *msg)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_send_msg(channel, msg);
|
||||
}
|
||||
|
||||
|
||||
/* return: error code args: (channel, msg ptr, msg len) */
|
||||
uint32_t lam_cth_send_packed_msg(lam_ctchannel_t *channel, const uint8_t *packed_msg,
|
||||
uint32_t msg_len)
|
||||
{
|
||||
return CHANNEL_CLS(channel)->cth_send_packed_msg(channel, packed_msg,
|
||||
msg_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* TCP channel class
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
lam_ctchannel_class_t lam_tcp_channel_cls = {
|
||||
{"lam_tcp_chnl_t", &lam_ctchannel_cls,
|
||||
(class_init_t)lam_tcpch_init,
|
||||
(class_destroy_t)lam_tcpch_destroy},
|
||||
lam_tcpch_send,
|
||||
lam_tcpch_recv,
|
||||
lam_tcpch_get_msg,
|
||||
lam_tcpch_get_packed_msg,
|
||||
lam_tcpch_send_msg,
|
||||
lam_tcpch_send_packed_msg
|
||||
};
|
||||
|
||||
void lam_tcpch_init(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
SUPER_INIT(channel, lam_tcp_channel_cls.cls_parent);
|
||||
channel->tcp_sockfd = 0;
|
||||
bzero(&(channel->tcp_addr), sizeof(channel->tcp_addr));
|
||||
channel->tcp_blocking = 0;
|
||||
}
|
||||
|
||||
void lam_tcpch_destroy(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
SUPER_DESTROY(channel, lam_tcp_channel_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send(lam_tcp_chnl_t *channel, const uint8_t *data,
|
||||
uint32_t data_len, uint32_t *bytes_sent)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t lam_tcpch_recv(lam_tcp_chnl_t *channel, const uint8_t *buffer,
|
||||
uint32_t buff_len, uint32_t *bytes_recvd)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_get_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t **msg)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_get_packed_msg(lam_tcp_chnl_t *channel, const uint8_t **buffer,
|
||||
uint32_t *bytes_recvd)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t *msg)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send_packed_msg(lam_tcp_chnl_t *channel,
|
||||
const uint8_t *packed_msg,
|
||||
uint32_t msg_len)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#ifndef CT_CHANNEL_H
|
||||
#define CT_CHANNEL_H
|
||||
|
||||
#include "lam/base/object.h"
|
||||
#include "lam/lfc/object.h"
|
||||
#include "runtime/ctnetwork/ctmessage.h"
|
||||
|
||||
|
||||
@ -30,6 +30,17 @@ typedef enum
|
||||
} lam_ctchnl_status_t;
|
||||
|
||||
|
||||
/*
|
||||
* Channel connection status
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
CT_CHNL_CLOSED = 0,
|
||||
CT_CHNL_CONNECTED,
|
||||
CT_CHNL_FAILED
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Abstract communication channel class
|
||||
@ -51,13 +62,13 @@ typedef struct lam_ctchannel_class
|
||||
uint32_t cth_recv(struct lam_ctchannel *, const uint8_t *, uint32_t, uint32_t *);
|
||||
|
||||
/* return: error code args: (channel, msg ptr) */
|
||||
uint32_t cth_get_msg(struct lam_ctchannel *, lam_ctmsg_t **msg);
|
||||
uint32_t cth_get_msg(struct lam_ctchannel *, lam_ctmsg_t **);
|
||||
|
||||
/* return: error code args: (channel, recv buffer ptr, bytes received) */
|
||||
uint32_t cth_get_packed_msg(struct lam_ctchannel *, const uint8_t **, uint32_t *);
|
||||
|
||||
/* return: error code args: (channel, msg) */
|
||||
uint32_t cth_send_msg(struct lam_ctchannel *, lam_ctmsg_t *msg);
|
||||
uint32_t cth_send_msg(struct lam_ctchannel *, lam_ctmsg_t *);
|
||||
|
||||
/* return: error code args: (channel, msg ptr, msg len) */
|
||||
uint32_t cth_send_packed_msg(struct lam_ctchannel *, const uint8_t *, uint32_t);
|
||||
@ -65,6 +76,109 @@ typedef struct lam_ctchannel_class
|
||||
} lam_ctchannel_class_t;
|
||||
|
||||
|
||||
extern lam_ctchannel_class_t lam_ctchannel_cls;
|
||||
|
||||
typedef struct lam_ctchannel
|
||||
{
|
||||
lam_object_t super;
|
||||
int cth_status;
|
||||
uint32_t cth_id;
|
||||
uint32_t cth_timeout_secs;
|
||||
} lam_ctchannel_t;
|
||||
|
||||
|
||||
void lam_cth_init(lam_ctchannel_t *channel);
|
||||
|
||||
/*
|
||||
*
|
||||
* Accessor functions
|
||||
*
|
||||
*/
|
||||
|
||||
INLINE int lam_cth_is_connected(lam_ctchannel_t *channel)
|
||||
{
|
||||
return (CT_CHNL_CONNECTED == channel->cth_status);
|
||||
}
|
||||
|
||||
INLINE uint32_t lam_cth_get_id(lam_ctchannel_t *channel) {return channel->cth_id;}
|
||||
INLINE void lam_cth_set_id(lam_ctchannel_t *channel, uint32_t cid)
|
||||
{
|
||||
channel->cth_id = cid;
|
||||
}
|
||||
|
||||
INLINE uint32_t lam_cth_get_timeout(lam_ctchannel_t *channel) {return channel->cth_timeout_secs;}
|
||||
INLINE void lam_cth_set_id(lam_ctchannel_t *channel, uint32_t timeout)
|
||||
{
|
||||
channel->cth_timeout_secs = timeout;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* PURE VIRTUAL functions that must be
|
||||
* implemented by concrete subclasses.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* return: error code args: (channel, data, data length, bytes sent) */
|
||||
uint32_t lam_cth_send(lam_ctchannel_t *channel, const uint8_t *data,
|
||||
uint32_t data_len, uint32_t *bytes_sent);
|
||||
|
||||
/* return: error code args: (channel, recv buffer, buffer length, bytes received) */
|
||||
uint32_t lam_cth_recv(lam_ctchannel_t *channel, const uint8_t *buffer,
|
||||
uint32_t buff_len, uint32_t *bytes_recvd);
|
||||
|
||||
/* return: error code args: (channel, msg ptr) */
|
||||
uint32_t lam_cth_get_msg(lam_ctchannel_t *channel, lam_ctmsg_t **msg);
|
||||
|
||||
/* return: error code args: (channel, recv buffer ptr, bytes received) */
|
||||
uint32_t lam_cth_get_packed_msg(lam_ctchannel_t *channel, const uint8_t **buffer,
|
||||
uint32_t *bytes_recvd);
|
||||
|
||||
/* return: error code args: (channel, msg) */
|
||||
uint32_t lam_cth_send_msg(lam_ctchannel_t *channel, lam_ctmsg_t *msg);
|
||||
|
||||
/* return: error code args: (channel, msg ptr, msg len) */
|
||||
uint32_t lam_cth_send_packed_msg(lam_ctchannel_t *channel, const uint8_t *packed_msg,
|
||||
uint32_t msg_len);
|
||||
|
||||
/*
|
||||
*
|
||||
* TCP channel class
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct lam_tcp_channel
|
||||
{
|
||||
lam_ctchannel_t super;
|
||||
int tcp_sockfd;
|
||||
struct sockaddr_in tcp_addr;
|
||||
int tcp_blocking;
|
||||
} lam_tcp_chnl_t;
|
||||
|
||||
extern lam_ctchannel_class_t lam_tcp_channel_cls;
|
||||
|
||||
void lam_tcpch_init(lam_tcp_chnl_t *channel);
|
||||
void lam_tcpch_destroy(lam_tcp_chnl_t *channel);
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send(lam_tcp_chnl_t *channel, const uint8_t *data,
|
||||
uint32_t data_len, uint32_t *bytes_sent);
|
||||
|
||||
uint32_t lam_tcpch_recv(lam_tcp_chnl_t *channel, const uint8_t *buffer,
|
||||
uint32_t buff_len, uint32_t *bytes_recvd);
|
||||
|
||||
uint32_t lam_tcpch_get_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t **msg);
|
||||
|
||||
uint32_t lam_tcpch_get_packed_msg(lam_tcp_chnl_t *channel, const uint8_t **buffer,
|
||||
uint32_t *bytes_recvd);
|
||||
|
||||
uint32_t lam_tcpch_send_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t *msg);
|
||||
|
||||
uint32_t lam_tcpch_send_packed_msg(lam_tcp_chnl_t *channel,
|
||||
const uint8_t *packed_msg,
|
||||
uint32_t msg_len);
|
||||
|
||||
|
||||
#endif /* CT_CHANNEL_H */
|
||||
|
||||
|
11
src/lam/ctnetwork/ctclient.c
Обычный файл
11
src/lam/ctnetwork/ctclient.c
Обычный файл
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* ctclient.c
|
||||
* LAM-MPI
|
||||
*
|
||||
* Created by Rob Aulwes on Sat Dec 27 2003.
|
||||
* Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ctclient.h"
|
||||
|
35
src/lam/ctnetwork/ctclient.h
Обычный файл
35
src/lam/ctnetwork/ctclient.h
Обычный файл
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute 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 any later version. Accordingly, this program 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.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef CT_CLIENT_H
|
||||
#define CT_CLIENT_H
|
||||
|
||||
#endif /* CT_CLIENT_H */
|
||||
|
@ -31,18 +31,41 @@
|
||||
#ifndef CT_CONTROLLER_H
|
||||
#define CT_CONTROLLER_H
|
||||
|
||||
#include "lam/base/object.h"
|
||||
#include "lam/lfc/object.h"
|
||||
#include "runtime/ctnetwork/ctnode.h"
|
||||
|
||||
typedef void (*lam_ctmsg_recvd_fn)(struct lam_ctcontroller *,
|
||||
lam_ctmsg_t *,
|
||||
void *);
|
||||
|
||||
typedef void (*lam_ctnode_failed_fn)(struct lam_ctcontroller *,
|
||||
lam_ctnode_t *,
|
||||
void *);
|
||||
|
||||
typedef struct lam_ctcontroller
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_ctnode_t ctl_node;
|
||||
void *ctl_user_info;
|
||||
lam_ctmsg_recvd_fn ctl_msg_recvd_callback;
|
||||
lam_ctnode_failed_fn ctl_node_failed_callback;
|
||||
} lam_ctctrl_t;
|
||||
|
||||
void lam_ctl_init(lam_ctctrl_t *ctrl);
|
||||
void lam_ctl_destroy(lam_ctctrl_t *ctrl);
|
||||
|
||||
INLINE void lam_ctl_set_recvd_callback(lam_ctctrl_t *ctrl, lam_ctmsg_recvd_fn callback)
|
||||
{
|
||||
ctrl->ctl_msg_recvd_callback = callback;
|
||||
}
|
||||
|
||||
|
||||
INLINE void lam_ctl_set_failed_callback(lam_ctctrl_t *ctrl, lam_ctnode_failed_fn callback)
|
||||
{
|
||||
ctrl->ctl_node_failed_callback = callback;
|
||||
}
|
||||
|
||||
|
||||
#endif /* CT_CONTROLLER_H */
|
||||
|
||||
|
||||
|
@ -28,5 +28,273 @@
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "ctmessage.h"
|
||||
#include "runtime/ctnetwork/ctmessage.h"
|
||||
#include "lam/util/malloc.h"
|
||||
|
||||
|
||||
lam_class_info_t lam_ctctrl_cls = {"lam_ct_ctrl_t", &lam_object_cls,
|
||||
(class_init_t) lam_ctc_init, (class_destroy_t)lam_ctc_destroy};
|
||||
|
||||
lam_class_info_t lam_ctmsg_cls = {"lam_ctmsg_t", &lam_object_cls,
|
||||
(class_init_t) lam_ctm_init, (class_destroy_t)lam_ctm_destroy};
|
||||
|
||||
|
||||
static const uint32_t ctrl_alloc_len = sizeof(lam_ct_ctrl_t) -
|
||||
sizeof(lam_object_t) -
|
||||
sizeof(ctrl->ctc_info);
|
||||
|
||||
void lam_ctc_init(lam_ct_ctrl_t *ctrl)
|
||||
{
|
||||
SUPER_INIT(ctrl, lam_ctctrl_cls.cls_parent);
|
||||
|
||||
ctrl->ctc_is_user_msg = 0;
|
||||
ctrl->ctc_routing_type = LAM_CT_PT2PT;
|
||||
ctrl->ctc_sender = 0;
|
||||
ctrl->ctc_dest = 0;
|
||||
ctrl->ctc_forwarding = 0;
|
||||
ctrl->ctc_client_tag = 0;
|
||||
ctrl->ctc_info_len = 0;
|
||||
ctrl->ctc_info = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lam_ctc_destroy(lam_ct_ctrl_t *ctrl)
|
||||
{
|
||||
lam_free(ctrl->ctc_info);
|
||||
SUPER_DESTROY(ctrl, lam_ctctrl_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lam_ctc_init_with(lam_ct_ctrl_t *ctrl, int routing_type,
|
||||
uint32_t sender,
|
||||
uint32_t dest)
|
||||
{
|
||||
ctrl->ctc_routing_type = routing_type;
|
||||
ctrl->ctc_sender = sender;
|
||||
ctrl->ctc_dest = dest;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_ctc_pack_size(lam_ct_ctrl_t *ctrl)
|
||||
{
|
||||
return ctrl_alloc_len + ctrl->ctc_info_len;
|
||||
}
|
||||
|
||||
uint8_t *lam_ctc_pack(lam_ct_ctrl_t *ctrl, uint32_t *len)
|
||||
{
|
||||
/* ASSERT: packed control struct looks like
|
||||
<ctc_is_user_msg (uint16_t)><ctc_routing_type (uint16_t)>
|
||||
<ctc_sender (uint32_t)><ctc_dest (uint32_t)>
|
||||
<ctc_forwarding (uint32_t)><ctc_client_tag (uint32_t)>
|
||||
<ctc_info_len (uint32_t)><ctc_info (uint8_t *)>
|
||||
*/
|
||||
uint8_t *buffer;
|
||||
|
||||
buffer = (uint8_t *)lam_malloc(ctrl_alloc_len
|
||||
+ ctrl->ctc_info_len);
|
||||
if ( 0 == buffer )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
lam_ctc_pack_buffer(ctrl, buffer, len);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
lam_ct_ctrl_t *lam_ctc_unpack(uint8_t *buffer)
|
||||
{
|
||||
lam_ct_ctrl_t *ctrl;
|
||||
|
||||
/* ASSERT: packed control struct looks like
|
||||
<ctc_is_user_msg (uint16_t)><ctc_routing_type (uint16_t)>
|
||||
<ctc_sender (uint32_t)><ctc_dest (uint32_t)>
|
||||
<ctc_forwarding (uint32_t)><ctc_client_tag (uint32_t)>
|
||||
<ctc_info_len (uint32_t)><ctc_info (uint8_t *)>
|
||||
*/
|
||||
CREATE_OBJECT(ctrl, lam_ct_ctrl_t, &lam_ctctrl_cls);
|
||||
if ( 0 == ctrl )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(&(ctrl->ctc_is_user_msg), buffer, ctrl_alloc_len);
|
||||
ctrl->ctc_info = (uint8_t *)lam_malloc(ctrl->ctc_info_len);
|
||||
if ( 0 == ctrl->ctc_info )
|
||||
{
|
||||
OBJ_RELEASE(ctrl);
|
||||
return 0;
|
||||
}
|
||||
memcpy(ctrl->ctc_info, buffer + ctrl_alloc_len, ctrl->ctc_info_len);
|
||||
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int lam_ctc_pack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer, uint32_t *len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
memcpy(buffer, &(ctrl->ctc_is_user_msg), ctrl_alloc_len);
|
||||
memcpy(buffer + ctrl_alloc_len, ctrl->ctc_info);
|
||||
*len = ctrl_alloc_len + ctrl->ctc_info_len;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int lam_ctc_unpack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer, uint32_t *len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Functions for accessing data in packed
|
||||
* control struct.
|
||||
*/
|
||||
|
||||
uint16_t lam_pk_ctc_is_user_msg(uint8_t *buffer)
|
||||
{
|
||||
return *((uint16_t *)buffer);
|
||||
}
|
||||
|
||||
uint16_t lam_pk_ctc_get_routing_type(uint8_t *buffer)
|
||||
{
|
||||
return *(uint16_t *)(buffer + sizeof(uint16_t));
|
||||
}
|
||||
|
||||
uint32_t lam_pk_ctc_get_sender(uint8_t *buffer)
|
||||
{
|
||||
return *(uint32_t *)(buffer + 2*sizeof(uint16_t));
|
||||
}
|
||||
|
||||
uint32_t lam_pkctc_get_dest(uint8_t *buffer)
|
||||
{
|
||||
return *(uint32_t *)(buffer + 2*sizeof(uint16_t) + sizeof(uint32_t));
|
||||
}
|
||||
|
||||
uint32_t lam_pk_ctc_get_forwarding(uint8_t *buffer)
|
||||
{
|
||||
return *(uint32_t *)(buffer + 2*sizeof(uint16_t)
|
||||
+ 2*sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void lam_pk_ctc_set_forwarding(uint8_t *buffer, uint32_t node)
|
||||
{
|
||||
memcpy(buffer + 2*sizeof(uint16_t) + 2*sizeof(uint32_t),
|
||||
&node, sizeof(node));
|
||||
}
|
||||
|
||||
uint8_t *lam_pk_ctc_get_info(uint8_t *buffer, uint32_t *len)
|
||||
{
|
||||
memcpy(len, buffer + ctrl_alloc_len - sizeof(uint32_t),
|
||||
sizeof(uint32_t));
|
||||
return buffer + ctrl_alloc_len;
|
||||
}
|
||||
|
||||
void lam_pk_ctc_set_info(uint8_t *buffer, uint8_t *info)
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
memcpy(&len, buffer + ctrl_alloc_len - sizeof(uint32_t),
|
||||
sizeof(uint32_t));
|
||||
memcpy(buffer + ctrl_alloc_len, info, len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Message interface
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void lam_ctm_init(lam_ctmsg_t *msg)
|
||||
{
|
||||
SUPER_INIT(msg, lam_ctmsg_cls.cls_parent);
|
||||
CREATE_OBJECT(msg->ctm_ctrl, lam_ct_ctrl_t, &lam_ctctrl_cls);
|
||||
msg->ctm_len = 0;
|
||||
msg->ctm_data = 0;
|
||||
msg->ctm_should_free = 1;
|
||||
}
|
||||
|
||||
void lam_ctm_destroy(lam_ctmsg_t *msg)
|
||||
{
|
||||
if ( msg->ctm_should_free )
|
||||
{
|
||||
lam_free(msg->ctm_data);
|
||||
}
|
||||
OBJECT_RELEASE(msg->ctm_ctrl);
|
||||
SUPER_DESTROY(msg, lam_ctmsg_cls.cls_parent);
|
||||
}
|
||||
|
||||
lam_ctmsg_t *lam_ctm_create_with(int is_user_msg, int routing_type,
|
||||
uint32_t sender,
|
||||
uint32_t dest, uint8_t *data,
|
||||
uint32_t data_len,
|
||||
int should_free)
|
||||
{
|
||||
lam_ctmsg_t *msg;
|
||||
|
||||
CREATE_OBJECT(msg, lam_ctmsg_t, &lam_ctmsg_cls);
|
||||
if ( 0 == msg )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC_INIT(msg->ctm_ctrl, &lam_ctctrl_cls);
|
||||
lam_ctc_init_with(&(msg->ctm_ctrl), sender, dest);
|
||||
msg->ctm_should_free = should_free;
|
||||
msg->ctm_data = data;
|
||||
msg->ctm_len = data_len;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
uint8_t *lam_ctm_pack(lam_ctmsg_t *msg)
|
||||
{
|
||||
/* packed msg layout
|
||||
<msg len (uint32_t)><packed ctrl><data len (uint32_t)>
|
||||
<data>
|
||||
*/
|
||||
uint32_t len;
|
||||
|
||||
|
||||
}
|
||||
|
||||
lam_ctmsg_t *lam_ctm_unpack(uint8_t *buffer)
|
||||
{
|
||||
/* packed msg layout
|
||||
<msg len (uint32_t)><packed ctrl><data len (uint32_t)>
|
||||
<data>
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions for accessing data in packed
|
||||
* msg struct.
|
||||
*/
|
||||
|
||||
uint8_t *lam_pk_ctm_get_control(uint8_t *buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t *lam_pk_ctm_get_data(uint8_t *buffer, uint32_t *len)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#ifndef CT_MESSAGE_H
|
||||
#define CT_MESSAGE_H
|
||||
|
||||
#include "lam/base/object.h"
|
||||
#include "lam/lfc/object.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -40,6 +40,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
extern lam_class_info_t lam_ctctrl_cls;
|
||||
extern lam_class_info_t lam_ctmsg_cls;
|
||||
|
||||
/*
|
||||
@ -52,6 +53,11 @@ extern lam_class_info_t lam_ctmsg_cls;
|
||||
* Message control info for routing msgs.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Message routing type
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
LAM_CT_BCAST = 1,
|
||||
@ -60,25 +66,159 @@ enum
|
||||
LAM_CT_PT2PT
|
||||
};
|
||||
|
||||
/*
|
||||
* Msg control interface to
|
||||
* contain routing information.
|
||||
* Can be reused by multiple msgs
|
||||
* if routing info is the same.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct lam_ct_ctrl
|
||||
{
|
||||
uint8_t ctc_is_user_msg; /* 1 -> msg is for user app. */
|
||||
uint8_t ctc_routing_type; /* broadcast, scatter, pt2pt, etc. */
|
||||
uint16_t ctc_len;
|
||||
lam_object_t super;
|
||||
uint16_t ctc_is_user_msg; /* 1 -> msg is for user app. */
|
||||
uint16_t ctc_routing_type; /* broadcast, scatter, pt2pt, etc. */
|
||||
uint32_t ctc_sender; /* node that initiated send. */
|
||||
uint32_t ctc_dest; /* destination node. */
|
||||
uint32_t ctc_forwarding; /* node that is relaying msg. */
|
||||
uint32_t ctc_client_tag; /* tag if client sent msg. */
|
||||
uint32_t ctc_info_len;
|
||||
uint8_t *ctc_info;
|
||||
} lam_ct_ctrl_t;
|
||||
|
||||
|
||||
void lam_ctc_init(lam_ct_ctrl_t *ctrl);
|
||||
void lam_ctc_destroy(lam_ct_ctrl_t *ctrl);
|
||||
|
||||
void lam_ctc_init_with(lam_ct_ctrl_t *ctrl, int routing_type,
|
||||
uint32_t sender,
|
||||
uint32_t dest);
|
||||
|
||||
uint32_t lam_ctc_pack_size(lam_ct_ctrl_t *ctrl);
|
||||
uint8_t *lam_ctc_pack(lam_ct_ctrl_t *ctrl, uint32_t *len);
|
||||
lam_ct_ctrl_t *lam_ctc_unpack(uint8_t *buffer);
|
||||
|
||||
int lam_ctc_pack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer, uint32_t *len);
|
||||
int lam_ctc_unpack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer, uint32_t *len);
|
||||
|
||||
/*
|
||||
* Functions for accessing data in packed
|
||||
* control struct.
|
||||
*/
|
||||
|
||||
uint16_t lam_pk_ctc_is_user_msg(uint8_t *buffer);
|
||||
|
||||
uint16_t lam_pk_ctc_get_routing_type(uint8_t *buffer);
|
||||
|
||||
uint32_t lam_pk_ctc_get_sender(uint8_t *buffer);
|
||||
|
||||
uint32_t lam_pk_ctc_get_dest(uint8_t *buffer);
|
||||
|
||||
uint32_t lam_pk_ctc_get_forwarding(uint8_t *buffer);
|
||||
void lam_pk_ctc_set_forwarding(uint8_t *buffer, uint32_t node);
|
||||
|
||||
uint8_t *lam_pk_ctc_get_info(uint8_t *buffer, uint32_t *len);
|
||||
void lam_pk_ctc_set_info(uint8_t *buffer, uint8_t *info);
|
||||
|
||||
/*
|
||||
* Accessor functions
|
||||
*/
|
||||
|
||||
INLINE uint16_t lam_ctc_get_is_user_msg(lam_ct_ctrl_t *ctrl) {return ctrl->ctc_is_user_msg;}
|
||||
INLINE uint16_t lam_ctc_set_is_user_msg(lam_ct_ctrl_t *ctrl, uint16_t yn)
|
||||
{
|
||||
ctrl->ctc_is_user_msg = yn;
|
||||
}
|
||||
|
||||
INLINE uint16_t lam_ctc_get_routing_type(lam_ct_ctrl_t *ctrl) {return ctrl->ctc_routing_type;}
|
||||
INLINE uint16_t lam_ctc_set_routing_type(lam_ct_ctrl_t *ctrl, int rtype)
|
||||
{
|
||||
ctrl->ctc_routing_type = rtype;
|
||||
}
|
||||
|
||||
INLINE uint32_t lam_ctc_get_sender(lam_ct_ctrl_t *ctrl) {return ctrl->ctc_sender;}
|
||||
INLINE void lam_ctc_set_sender(lam_ct_ctrl_t *ctrl, uint32_t sender)
|
||||
{
|
||||
ctrl->ctc_sender = sender;
|
||||
}
|
||||
|
||||
INLINE uint32_t lam_ctc_get_dest(lam_ct_ctrl_t *ctrl) {return ctrl->ctc_dest;}
|
||||
INLINE void lam_ctc_set_dest(lam_ct_ctrl_t *ctrl, uint32_t dest)
|
||||
{
|
||||
ctrl->ctc_dest = dest;
|
||||
}
|
||||
|
||||
INLINE uint32_t lam_ctc_get_forwarding(lam_ct_ctrl_t *ctrl) {return ctrl->ctc_forwarding;}
|
||||
INLINE void lam_ctc_set_forwarding(lam_ct_ctrl_t *ctrl, uint32_t node)
|
||||
{
|
||||
ctrl->ctc_forwarding = node;
|
||||
}
|
||||
|
||||
INLINE uint8_t *lam_ctc_get_info(lam_ct_ctrl_t *ctrl, uint32_t *len)
|
||||
{
|
||||
*len = ctrl->ctc_info_len;
|
||||
return ctrl->ctc_info;
|
||||
}
|
||||
|
||||
INLINE void lam_ctc_set_info(lam_ct_ctrl_t *ctrl, uint32_t len, uint8_t *info)
|
||||
{
|
||||
ctrl->ctc_info_len = len;
|
||||
ctrl->ctc_info = info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Message interface
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
typedef struct lam_ctmsg
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_ct_ctrl_t ctm_ctrl;
|
||||
lam_ct_ctrl_t *ctm_ctrl;
|
||||
uint32_t ctm_len;
|
||||
uint8_t *ctm_data;
|
||||
int ctm_should_free;
|
||||
} lam_ctmsg_t;
|
||||
|
||||
|
||||
void lam_ctm_init(lam_ctmsg_t *msg);
|
||||
void lam_ctm_destroy(lam_ctmsg_t *msg);
|
||||
|
||||
lam_ctmsg_t *lam_ctm_create_with(int is_user_msg, int routing_type,
|
||||
uint32_t sender,
|
||||
uint32_t dest, uint8_t *data,
|
||||
uint32_t data_len,
|
||||
int should_free);
|
||||
|
||||
uint8_t *lam_ctm_pack(lam_ctmsg_t *msg);
|
||||
lam_ctmsg_t *lam_ctm_unpack(uint8_t *buffer);
|
||||
|
||||
/*
|
||||
* Functions for accessing data in packed
|
||||
* msg struct.
|
||||
*/
|
||||
|
||||
uint8_t *lam_pk_ctm_get_control(uint8_t *buffer);
|
||||
uint8_t *lam_pk_ctm_get_data(uint8_t *buffer, uint32_t *len);
|
||||
|
||||
/*
|
||||
*
|
||||
* Accessor functions
|
||||
*
|
||||
*/
|
||||
|
||||
INLINE lam_ct_ctrl_t *lam_ctm_get_control(lam_ctmsg_t *msg) {return msg->ctm_ctrl;}
|
||||
INLINE void lam_ctm_set_control(lam_ctmsg_t *msg, lam_ct_ctrl_t *ctrl)
|
||||
{
|
||||
msg->ctm_ctrl = ctrl;
|
||||
}
|
||||
|
||||
|
||||
#endif /* CT_MESSAGE_H */
|
||||
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user