version 1.1.2.1, 2011/11/22 14:49:07
|
version 1.2, 2012/01/27 15:05:38
|
Line 41 mqttFiniCallbacks(mqtt_cb_t ** __restrict cb)
|
Line 41 mqttFiniCallbacks(mqtt_cb_t ** __restrict cb)
|
free(*cb); |
free(*cb); |
*cb = NULL; |
*cb = NULL; |
} |
} |
|
|
|
/* |
|
* mqttDispatcher() MQTT Message type dispatcher |
|
* |
|
* @cb = Callback array |
|
* @buf = Received MQTT message |
|
* return: -1 error or >-1 return value from executed callback |
|
*/ |
|
inline int |
|
mqttDispatcher(mqtt_cb_t * __restrict cb, mqtt_msg_t * __restrict buf) |
|
{ |
|
struct mqtthdr *hdr; |
|
|
|
if (!cb || !buf) |
|
return -1; |
|
if (buf->msg_len < sizeof(struct mqtthdr)) { |
|
mqtt_SetErr(EINVAL, "Error:: message is too small ..."); |
|
return -1; |
|
} |
|
|
|
hdr = (struct mqtthdr *) buf->msg_base; |
|
if (hdr->mqtt_msg.type > MQTT_TYPE_MAX) { |
|
mqtt_SetErr(ENOSYS, "Error:: message type %d not implemented", hdr->mqtt_msg.type); |
|
return -1; |
|
} |
|
|
|
if (cb[hdr->mqtt_msg.type]) |
|
return cb[hdr->mqtt_msg.type](buf); |
|
|
|
mqtt_SetErr(ENOTSUP, "Error:: Unsupported message type %d", hdr->mqtt_msg.type); |
|
return -1; |
|
} |