On 08/27/2015 01:26 PM, Lukas Slebodnik wrote:
Petr, what do you think about small simplification.
#include "providers/data_provider_req.h"
+#define be_req_to_str(req_type, be_req_t) \
((req_type) & BE_REQ_FAST) \
? "FAST " #be_req_t \
: #be_req_t
- const char *be_req2str(dbus_uint32_t req_type) { switch (req_type & BE_REQ_TYPE_MASK) { case BE_REQ_USER:
return req_type & BE_REQ_FAST ?
"FAST BE_REQ_USER" : "BE_REQ_USER";
return be_req_to_str(req_type, BE_REQ_USER); case BE_REQ_GROUP: return req_type & BE_REQ_FAST ? "FAST BE_REQ_GROUP" : "BE_REQ_GROUP";
The result of preprocessor is almost the same and code look little bit simpler.
const char *be_req2str(dbus_uint32_t req_type) { switch (req_type & 0x00FF) { case 0x0001: return ((req_type) & 0x1000) ? "FAST " "BE_REQ_USER" : "BE_REQ_USER"; case 0x0002: return req_type & 0x1000 ? "FAST BE_REQ_GROUP" : "BE_REQ_GROUP"; case 0x0003: return req_type & 0x1000 ? "FAST BE_REQ_INITGROUPS" : "BE_REQ_INITGROUPS";
Feel free to rename macro; it's just a POC version.
LS
Thanks.
There is improved patch attached.
Petr