Making constructors and destructors static
This commit was SVN r726.
Этот коммит содержится в:
родитель
a8636277af
Коммит
d4087af051
@ -9,19 +9,8 @@
|
||||
#define CHANNEL_CLS(chnl) \
|
||||
((lam_ctchannel_class_t *)(((lam_object_t *) chnl)->obj_class))
|
||||
|
||||
lam_ctchannel_class_t lam_ct_channel_t_class_info = {
|
||||
{
|
||||
"lam_ct_channel_t",
|
||||
CLASS_INFO(lam_object_t),
|
||||
(lam_construct_t)lam_cth_construct,
|
||||
(lam_destruct_t)lam_object_destruct
|
||||
},
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
|
||||
void lam_cth_construct(lam_ctchannel_t *channel)
|
||||
static void lam_cth_construct(lam_ctchannel_t *channel)
|
||||
{
|
||||
OBJ_CONSTRUCT_SUPER(channel, lam_object_t);
|
||||
channel->cth_status = CT_CHNL_CLOSED;
|
||||
@ -29,6 +18,24 @@ void lam_cth_construct(lam_ctchannel_t *channel)
|
||||
channel->cth_timeout_secs = 0;
|
||||
}
|
||||
|
||||
|
||||
static void lam_cth_construct(lam_ctchannel_t *channel)
|
||||
{
|
||||
OBJ_DESTRUCT_SUPER(channel, lam_object_t);
|
||||
}
|
||||
|
||||
|
||||
lam_ctchannel_class_t lam_ct_channel_t_class_info = {
|
||||
{
|
||||
"lam_ct_channel_t",
|
||||
CLASS_INFO(lam_object_t),
|
||||
(lam_construct_t) lam_cth_construct,
|
||||
(lam_destruct_t) lam_object_destruct
|
||||
},
|
||||
NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* PURE VIRTUAL functions that must be
|
||||
@ -38,14 +45,15 @@ void lam_cth_construct(lam_ctchannel_t *channel)
|
||||
|
||||
|
||||
/* 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 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 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 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,
|
||||
@ -59,10 +67,12 @@ 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 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 CHANNEL_CLS(channel)->cth_get_packed_msg(channel, buffer,
|
||||
bytes_recvd);
|
||||
}
|
||||
|
||||
/* return: error code args: (channel, msg) */
|
||||
@ -73,11 +83,12 @@ 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 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);
|
||||
msg_len);
|
||||
}
|
||||
|
||||
|
||||
@ -92,7 +103,22 @@ uint32_t lam_cth_send_packed_msg(lam_ctchannel_t *channel, const uint8_t *packed
|
||||
*/
|
||||
|
||||
|
||||
lam_ctchannel_class_t lam_tcp_chnl_t_class_info = {
|
||||
static void lam_tcpch_construct(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
OBJ_CONSTRUCT_SUPER(channel, lam_object_t);
|
||||
channel->tcp_sockfd = 0;
|
||||
memset(&(channel->tcp_addr), 0, sizeof(channel->tcp_addr));
|
||||
channel->tcp_blocking = 0;
|
||||
}
|
||||
|
||||
|
||||
static void lam_tcpch_destruct(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
OBJ_DESTRUCT_SUPER(channel, lam_ct_channel_t);
|
||||
}
|
||||
|
||||
|
||||
lam_ctchannel_class_t lam_tcp_chnl_t_class_info = {
|
||||
{
|
||||
"lam_tcp_chnl_t",
|
||||
CLASS_INFO(lam_ctchannel_t),
|
||||
@ -107,72 +133,56 @@ lam_ctchannel_class_t lam_tcp_chnl_t_class_info = {
|
||||
lam_tcpch_send_packed_msg
|
||||
};
|
||||
|
||||
void lam_tcpch_construct(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
OBJ_CONSTRUCT_SUPER(channel, lam_object_t);
|
||||
channel->tcp_sockfd = 0;
|
||||
memset(&(channel->tcp_addr), 0, sizeof(channel->tcp_addr));
|
||||
channel->tcp_blocking = 0;
|
||||
}
|
||||
|
||||
void lam_tcpch_destruct(lam_tcp_chnl_t *channel)
|
||||
{
|
||||
OBJ_DESTRUCT_SUPER(channel, lam_ct_channel_t);
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send(lam_tcp_chnl_t *channel, const uint8_t *data,
|
||||
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_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t lam_tcpch_recv(lam_tcp_chnl_t *channel, const uint8_t *buffer,
|
||||
|
||||
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_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_get_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t **msg)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_get_packed_msg(lam_tcp_chnl_t *channel, const uint8_t **buffer,
|
||||
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_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send_msg(lam_tcp_chnl_t *channel, lam_ctmsg_t *msg)
|
||||
{
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lam_tcpch_send_packed_msg(lam_tcp_chnl_t *channel,
|
||||
const uint8_t *packed_msg,
|
||||
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_ERR_OK;
|
||||
|
||||
uint32_t ret = CT_CHNL_ERR_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -109,8 +109,6 @@ typedef struct lam_ctchannel
|
||||
} lam_ctchannel_t;
|
||||
|
||||
|
||||
void lam_cth_construct(lam_ctchannel_t *channel);
|
||||
|
||||
/*
|
||||
*
|
||||
* Accessor functions
|
||||
@ -191,10 +189,6 @@ typedef struct lam_tcp_channel
|
||||
|
||||
extern lam_ctchannel_class_t lam_tcp_chnl_t_class_info;
|
||||
|
||||
void lam_tcpch_construct(lam_tcp_chnl_t *channel);
|
||||
void lam_tcpch_destruct(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);
|
||||
|
||||
|
@ -8,27 +8,27 @@
|
||||
|
||||
lam_class_info_t lam_ct_ctrl_t_class_info = {
|
||||
"lam_ct_ctrl_t",
|
||||
CLASS_INFO(lam_object_t),
|
||||
CLASS_INFO(lam_object_t),
|
||||
(lam_construct_t) lam_ctc_construct,
|
||||
(lam_destruct_t) lam_ctc_destruct
|
||||
};
|
||||
|
||||
|
||||
lam_class_info_t lam_ctmsg_t_class_info = {
|
||||
"lam_ctmsg_t",
|
||||
CLASS_INFO(lam_object_t),
|
||||
CLASS_INFO(lam_object_t),
|
||||
(lam_construct_t) lam_ctm_construct,
|
||||
(lam_destruct_t) lam_ctm_destruct
|
||||
};
|
||||
|
||||
|
||||
static const uint32_t ctrl_alloc_len = sizeof(lam_ct_ctrl_t) -
|
||||
sizeof(lam_object_t) -
|
||||
sizeof(ctrl->ctc_info);
|
||||
sizeof(lam_object_t) - sizeof(ctrl->ctc_info);
|
||||
|
||||
void lam_ctc_construct(lam_ct_ctrl_t *ctrl)
|
||||
{
|
||||
OBJ_CONSTRUCT_SUPER(ctrl, lam_object_t);
|
||||
|
||||
|
||||
ctrl->ctc_is_user_msg = 0;
|
||||
ctrl->ctc_routing_type = LAM_CT_PT2PT;
|
||||
ctrl->ctc_sender = 0;
|
||||
@ -50,8 +50,7 @@ void lam_ctc_destruct(lam_ct_ctrl_t *ctrl)
|
||||
|
||||
|
||||
void lam_ctc_construct_with(lam_ct_ctrl_t *ctrl, int routing_type,
|
||||
uint32_t sender,
|
||||
uint32_t dest)
|
||||
uint32_t sender, uint32_t dest)
|
||||
{
|
||||
ctrl->ctc_routing_type = routing_type;
|
||||
ctrl->ctc_sender = sender;
|
||||
@ -67,21 +66,19 @@ uint32_t lam_ctc_pack_size(lam_ct_ctrl_t *ctrl)
|
||||
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;
|
||||
<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;
|
||||
}
|
||||
|
||||
@ -89,51 +86,51 @@ uint8_t *lam_ctc_pack(lam_ct_ctrl_t *ctrl, uint32_t *len)
|
||||
|
||||
lam_ct_ctrl_t *lam_ctc_unpack(uint8_t *buffer)
|
||||
{
|
||||
lam_ct_ctrl_t *ctrl;
|
||||
|
||||
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 *)>
|
||||
*/
|
||||
<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 *)>
|
||||
*/
|
||||
ctrl = OBJ_NEW(lam_ct_ctrl_t);
|
||||
if ( 0 == ctrl )
|
||||
{
|
||||
return 0;
|
||||
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 )
|
||||
{
|
||||
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 lam_ctc_pack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer,
|
||||
uint32_t *len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
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;
|
||||
|
||||
int lam_ctc_unpack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer,
|
||||
uint32_t *len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -146,33 +143,34 @@ int lam_ctc_unpack_buffer(lam_ct_ctrl_t *ctrl, uint8_t *buffer, uint32_t *len)
|
||||
|
||||
uint16_t lam_pk_ctc_is_user_msg(uint8_t *buffer)
|
||||
{
|
||||
return *((uint16_t *)buffer);
|
||||
return *((uint16_t *) buffer);
|
||||
}
|
||||
|
||||
uint16_t lam_pk_ctc_get_routing_type(uint8_t *buffer)
|
||||
{
|
||||
return *(uint16_t *)(buffer + sizeof(uint16_t));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
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),
|
||||
memcpy(buffer + 2 * sizeof(uint16_t) + 2 * sizeof(uint32_t),
|
||||
&node, sizeof(node));
|
||||
}
|
||||
|
||||
@ -185,8 +183,8 @@ 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)
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
uint32_t len;
|
||||
|
||||
memcpy(&len, buffer + ctrl_alloc_len - sizeof(uint32_t),
|
||||
sizeof(uint32_t));
|
||||
memcpy(buffer + ctrl_alloc_len, info, len);
|
||||
@ -211,9 +209,8 @@ void lam_ctm_construct(lam_ctmsg_t *msg)
|
||||
|
||||
void lam_ctm_destruct(lam_ctmsg_t *msg)
|
||||
{
|
||||
if ( msg->ctm_should_free )
|
||||
{
|
||||
lam_free(msg->ctm_data);
|
||||
if (msg->ctm_should_free) {
|
||||
lam_free(msg->ctm_data);
|
||||
}
|
||||
OBJECT_RELEASE(msg->ctm_ctrl);
|
||||
OBJ_DESTRUCT_SUPER(msg, lam_object_t);
|
||||
@ -222,44 +219,42 @@ void lam_ctm_destruct(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)
|
||||
uint32_t data_len, int should_free)
|
||||
{
|
||||
lam_ctmsg_t *msg;
|
||||
|
||||
lam_ctmsg_t *msg;
|
||||
|
||||
msg = OBJ_NEW(lam_ctmsg_t);
|
||||
if ( 0 == msg )
|
||||
{
|
||||
return 0;
|
||||
if (0 == msg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
OBJ_CONSTRUCT(&msg->ctm_ctrl, lam_ct_ctrl_t);
|
||||
lam_ctc_construct_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>
|
||||
<msg len (uint32_t)><packed ctrl><data len (uint32_t)>
|
||||
<data>
|
||||
*/
|
||||
uint32_t len;
|
||||
|
||||
|
||||
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>
|
||||
*/
|
||||
|
||||
<msg len (uint32_t)><packed ctrl><data len (uint32_t)>
|
||||
<data>
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -269,10 +264,10 @@ lam_ctmsg_t *lam_ctm_unpack(uint8_t *buffer)
|
||||
|
||||
uint8_t *lam_pk_ctm_get_control(uint8_t *buffer)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint8_t *lam_pk_ctm_get_data(uint8_t *buffer, uint32_t *len)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user