Commit 0d0b81bb authored by Alessandro Rubini's avatar Alessandro Rubini

Merge branch 'simplify sending'

This small patch-set removes the MSG_SEND_AND_RET function and its
variants.  I find it extremely hard to read multi-line macros,
and also having a function returns implicitly by calling a macro.

I understand why this was born, but now I feel really better with the
code.
parents e7b43913 3c7d66da
...@@ -267,7 +267,7 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf, ...@@ -267,7 +267,7 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
/* Pack and send a White Rabbit signalling message */ /* Pack and send a White Rabbit signalling message */
int msg_issue_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id) int msg_issue_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
{ {
int len; int len = msg_pack_wrsig(ppi, wr_msg_id);
len = msg_pack_wrsig(ppi, wr_msg_id);
MSG_SEND_AND_RET_VARLEN(SIGNALING, GEN, 0, len); return __send_and_log(ppi, len, PPM_SIGNALING, PP_NP_GEN);
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define __COMMON_FUN_H #define __COMMON_FUN_H
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include <ppsi/diag.h>
/* Contains all functions common to more than one state */ /* Contains all functions common to more than one state */
...@@ -36,23 +37,24 @@ int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf, ...@@ -36,23 +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 st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len); int len);
#define MSG_SEND_AND_RET_VARLEN(x, y, z, w) \ static inline int __send_and_log(struct pp_instance *ppi, int msglen,
if (pp_net_ops.send(ppi, ppi->buf_out, w,\ int msgtype, int chtype)
&ppi->last_snt_time, PP_NP_##y , z) < w) { \ {
if (pp_verbose_frames) \ if (pp_net_ops.send(ppi, ppi->buf_out, msglen,
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY\n", \ &ppi->last_snt_time, chtype, 0) < msglen) {
pp_msg_names[PPM_##x], PPM_##x); \ if (pp_verbose_frames)
return -1; \ PP_PRINTF("%s(%d) Message can't be sent\n",
} \ pp_msg_names[msgtype], msgtype);
if (pp_verbose_frames) \ return -1;
PP_VPRINTF("SENT %02d %d.%09d %s\n", w, \ }
ppi->last_snt_time.seconds, \ /* FIXME: verbose_frames should be looped back in the send method */
ppi->last_snt_time.nanoseconds, \ if (pp_verbose_frames)
pp_msg_names[PPM_##x]); \ PP_VPRINTF("SENT %02d %d.%09d %s\n", msglen,
ppi->sent_seq_id[PPM_## x]++; \ 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; return 0;
}
#define MSG_SEND_AND_RET(x,y,z)\
MSG_SEND_AND_RET_VARLEN(x,y,z,PP_## x ##_LENGTH)
#endif /* __COMMON_FUN_H */ #endif /* __COMMON_FUN_H */
...@@ -445,9 +445,9 @@ const char const *pp_msg_names[] = { ...@@ -445,9 +445,9 @@ const char const *pp_msg_names[] = {
/* Pack and send on general multicast ip adress an Announce message */ /* Pack and send on general multicast ip adress an Announce message */
int msg_issue_announce(struct pp_instance *ppi) int msg_issue_announce(struct pp_instance *ppi)
{ {
int len; int len = msg_pack_announce(ppi);
len = msg_pack_announce(ppi);
MSG_SEND_AND_RET_VARLEN(ANNOUNCE, GEN, 0, len); return __send_and_log(ppi, len, PPM_ANNOUNCE, PP_NP_GEN);
} }
/* Pack and send on event multicast ip adress a Sync message */ /* Pack and send on event multicast ip adress a Sync message */
...@@ -460,7 +460,7 @@ int msg_issue_sync(struct pp_instance *ppi) ...@@ -460,7 +460,7 @@ int msg_issue_sync(struct pp_instance *ppi)
msg_pack_sync(ppi, &orig_tstamp); msg_pack_sync(ppi, &orig_tstamp);
MSG_SEND_AND_RET(SYNC, EVT, 0); return __send_and_log(ppi, PP_SYNC_LENGTH, PPM_SYNC, PP_NP_EVT);
} }
/* Pack and send on general multicast ip address a FollowUp message */ /* 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) ...@@ -471,7 +471,8 @@ int msg_issue_followup(struct pp_instance *ppi, TimeInternal *time)
msg_pack_follow_up(ppi, &prec_orig_tstamp); msg_pack_follow_up(ppi, &prec_orig_tstamp);
MSG_SEND_AND_RET(FOLLOW_UP, GEN, 0); 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 */ /* Pack and send on event multicast ip adress a DelayReq message */
...@@ -484,7 +485,8 @@ int msg_issue_delay_req(struct pp_instance *ppi) ...@@ -484,7 +485,8 @@ int msg_issue_delay_req(struct pp_instance *ppi)
msg_pack_delay_req(ppi, &orig_tstamp); msg_pack_delay_req(ppi, &orig_tstamp);
MSG_SEND_AND_RET(DELAY_REQ, EVT, 0); 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 */ /* 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) ...@@ -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_pack_delay_resp(ppi, &ppi->delay_req_hdr, &rcv_tstamp);
MSG_SEND_AND_RET(DELAY_RESP, GEN, 0); 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