aboutsummaryrefslogtreecommitdiffstats
path: root/src/tbf.h
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-12-28 18:49:12 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-01 13:58:13 +0100
commitaa9daa1b9dfc74deb2ab4993f74ba61ee2712f73 (patch)
tree2b83b2e2820dcb02bc5fada8a4db45bd36ef3ba2 /src/tbf.h
parent38f18698b3413bf3e608026aff519427af740335 (diff)
tbf: Replace static casts by calls to as_ul_tbf/as_dl_tbf
Currently casts from gprs_rlcmac_tbf to gprs_rlcmac_ul_tbf and gprs_rlcmac_dl_tbf are done by using static_cast. This doesn't provide protection against converting a gprs_rlcmac_ul_tbf pointer to a gprs_rlcmac_dl_tbf pointer and vice versa. This commit provides two functions as_ul_tbf and as_dl_tbf, that behave similar like dynamic_cast but use the direction field instead of RTTI. Sponsored-by: On-Waves ehf
Diffstat (limited to 'src/tbf.h')
-rw-r--r--src/tbf.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tbf.h b/src/tbf.h
index a3a2eeba..190101bf 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -452,6 +452,23 @@ inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir
return (enum gprs_rlcmac_tbf_direction)
((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF);
}
+
+inline gprs_rlcmac_ul_tbf *as_ul_tbf(gprs_rlcmac_tbf *tbf)
+{
+ if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
+ return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
+ else
+ return NULL;
+}
+
+inline gprs_rlcmac_dl_tbf *as_dl_tbf(gprs_rlcmac_tbf *tbf)
+{
+ if (tbf && tbf->direction == GPRS_RLCMAC_DL_TBF)
+ return static_cast<gprs_rlcmac_dl_tbf *>(tbf);
+ else
+ return NULL;
+}
+
#endif
#ifdef __cplusplus