Commit 3c7d66da authored by Alessandro Rubini's avatar Alessandro Rubini

kill MSG_SEND_AND_RET, use function instead

This removes the unmanageable MSG_SEND_AND_RET macro, turning it to a
normal function (inline, at the time being, to avoid moving from the
header to a different place).

The function is called __send_and_log because it logs too, but I'd better
move logging to the actual send and recv methods.

BTW: the message "-> FAULTY" (now removed) was wrong, because not all
errors of this function result in FAULTY state in the fsm.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 5b0bd076
......@@ -267,7 +267,7 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
/* Pack and send a White Rabbit signalling message */
int msg_issue_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
{
int len;
len = msg_pack_wrsig(ppi, wr_msg_id);
MSG_SEND_AND_RET(SIGNALING, GEN, len);
int len = msg_pack_wrsig(ppi, wr_msg_id);
return __send_and_log(ppi, len, PPM_SIGNALING, PP_NP_GEN);
}
......@@ -7,6 +7,7 @@
#define __COMMON_FUN_H
#include <ppsi/ppsi.h>
#include <ppsi/diag.h>
/* Contains all functions common to more than one state */
......@@ -36,20 +37,24 @@ int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len);
#define MSG_SEND_AND_RET(_name, _chan, _size) \
if (pp_net_ops.send(ppi, ppi->buf_out, _size,\
&ppi->last_snt_time, PP_NP_ ## _chan , 0) < _size) { \
if (pp_verbose_frames) \
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY\n", \
pp_msg_names[PPM_ ## _name], PPM_ ## _name); \
return -1; \
} \
if (pp_verbose_frames) \
PP_VPRINTF("SENT %02d %d.%09d %s\n", _size, \
ppi->last_snt_time.seconds, \
ppi->last_snt_time.nanoseconds, \
pp_msg_names[PPM_ ## _name]); \
ppi->sent_seq_id[PPM_ ## _name]++; \
static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
if (pp_net_ops.send(ppi, ppi->buf_out, msglen,
&ppi->last_snt_time, chtype, 0) < msglen) {
if (pp_verbose_frames)
PP_PRINTF("%s(%d) Message can't be sent\n",
pp_msg_names[msgtype], msgtype);
return -1;
}
/* FIXME: verbose_frames should be looped back in the send method */
if (pp_verbose_frames)
PP_VPRINTF("SENT %02d %d.%09d %s\n", msglen,
ppi->last_snt_time.seconds,
ppi->last_snt_time.nanoseconds,
pp_msg_names[msgtype]);
ppi->sent_seq_id[msgtype]++; /* FIXME: fold in the send method too? */
return 0;
}
#endif /* __COMMON_FUN_H */
......@@ -445,9 +445,9 @@ const char const *pp_msg_names[] = {
/* Pack and send on general multicast ip adress an Announce message */
int msg_issue_announce(struct pp_instance *ppi)
{
int len;
len = msg_pack_announce(ppi);
MSG_SEND_AND_RET(ANNOUNCE, GEN, len);
int len = msg_pack_announce(ppi);
return __send_and_log(ppi, len, PPM_ANNOUNCE, PP_NP_GEN);
}
/* Pack and send on event multicast ip adress a Sync message */
......@@ -460,7 +460,7 @@ int msg_issue_sync(struct pp_instance *ppi)
msg_pack_sync(ppi, &orig_tstamp);
MSG_SEND_AND_RET(SYNC, EVT, PP_SYNC_LENGTH);
return __send_and_log(ppi, PP_SYNC_LENGTH, PPM_SYNC, PP_NP_EVT);
}
/* Pack and send on general multicast ip address a FollowUp message */
......@@ -471,7 +471,8 @@ int msg_issue_followup(struct pp_instance *ppi, TimeInternal *time)
msg_pack_follow_up(ppi, &prec_orig_tstamp);
MSG_SEND_AND_RET(FOLLOW_UP, GEN, PP_FOLLOW_UP_LENGTH);
return __send_and_log(ppi, PP_FOLLOW_UP_LENGTH, PPM_FOLLOW_UP,
PP_NP_GEN);
}
/* Pack and send on event multicast ip adress a DelayReq message */
......@@ -484,7 +485,8 @@ int msg_issue_delay_req(struct pp_instance *ppi)
msg_pack_delay_req(ppi, &orig_tstamp);
MSG_SEND_AND_RET(DELAY_REQ, EVT, PP_PDELAY_REQ_LENGTH);
return __send_and_log(ppi, PP_DELAY_REQ_LENGTH, PPM_DELAY_REQ,
PP_NP_EVT);
}
/* Pack and send on event multicast ip adress a DelayResp message */
......@@ -495,5 +497,6 @@ int msg_issue_delay_resp(struct pp_instance *ppi, TimeInternal *time)
msg_pack_delay_resp(ppi, &ppi->delay_req_hdr, &rcv_tstamp);
MSG_SEND_AND_RET(DELAY_RESP, GEN, PP_DELAY_RESP_LENGTH);
return __send_and_log(ppi, PP_DELAY_RESP_LENGTH, PPM_DELAY_RESP,
PP_NP_GEN);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment