--- libaitmqtt/inc/mqttapi.h 2012/04/25 16:26:38 1.1.2.4 +++ libaitmqtt/inc/mqttapi.h 2012/05/05 13:31:48 1.1.2.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: mqttapi.h,v 1.1.2.4 2012/04/25 16:26:38 misho Exp $ +* $Id: mqttapi.h,v 1.1.2.7 2012/05/05 13:31:48 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -50,10 +50,11 @@ SUCH DAMAGE. #include "aitmqtt.h" +#ifdef API_SERVER_SIDE /* MQTT server structure & hooks */ -/* MQTT command callback. 1st argument is (mqtt_srv_t*) server handle */ -typedef int (*mqtt_cb_t)(void* /*mqtt_srv_t**/, void *); +/* MQTT command callback. 1st argument is (mqtt_srv_t*) server handle, 2nd is ready length */ +typedef int (*mqtt_cb_t)(void* /*mqtt_srv_t**/, int, void *); typedef struct { mqtt_cb_t cmds[MQTT_TYPE_MAX]; @@ -64,7 +65,6 @@ typedef struct { #define mqtt_srv_getCmd(x, _cmd) (assert((x)), (x)->cmds[(_cmd)]) -#ifdef API_SERVER_SIDE /* * mqtt_srv_Init() Init server side actor * @@ -84,10 +84,11 @@ void mqtt_srv_Fini(mqtt_srv_t ** __restrict psrv); * mqtt_srv_Dispatch() MQTT server dispatcher * * @srv = Server handle + * @rlen = Ready bytes to parse * @arg = Argument pass to command callback * return: -1 error or 0 ok */ -int mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, void *arg); +int mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, int rlen, void *arg); #endif /* @@ -100,7 +101,30 @@ int mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, voi */ int mqtt_KeepAlive(int sock, unsigned short ka, unsigned char tries); + #ifdef API_CLIENT_SIDE +/* MQTT client structure */ + +typedef struct { + int sock; + mqtt_msg_t *buf; +} mqtt_cli_t; + + +/* + * mqtt_cli_Open() - Open client connection to MQTT broker + * + * @addr = brokers address + * return: NULL error or !=NULL connected to broker + */ +mqtt_cli_t *mqtt_cli_Open(struct sockaddr *addr); +/* + * mqtt_cli_Close() - Close client connection + * + * @cli = connected client + * return: -1 error or 0 disconnected client and freed all resources + */ +int mqtt_cli_Close(mqtt_cli_t ** __restrict cli); #endif