From 7709621911c11c2bd1334ced463af8437df01c55 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 26 Jan 2016 17:06:32 +0000 Subject: [PATCH] Reorder helper function arguments for consistency. --- ChangeLog.txt | 5 ++++- examples/subscribe_simple/callback.c | 4 ++-- examples/subscribe_simple/multiple.c | 4 ++-- examples/subscribe_simple/single.c | 4 ++-- lib/cpp/mosquittopp.cpp | 13 ++++++++----- lib/cpp/mosquittopp.h | 4 ++-- lib/helpers.c | 9 +++++---- lib/mosquitto.h | 8 ++++---- man/libmosquitto.3.xml | 4 ++-- 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9e2735be..bb090f17 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -31,8 +31,11 @@ Client library: Messages will be retried when a client reconnects. - DNS-SRV support is now disabled by default. - Add mosquitto_subscribe_simple() This is a helper function to make - retrieving messages from a broker very straightforward. Examples of its user + retrieving messages from a broker very straightforward. Examples of its use are in examples/subscribe_simple. +- Add mosquitto_subscribe_callback() This is a helper function to make + processing messages from a broker very straightforward. An example of its use + is in examples/subscribe_simple. Client: - Add -x to mosquitto_sub for printing the payload in hexadecimal format. diff --git a/examples/subscribe_simple/callback.c b/examples/subscribe_simple/callback.c index 647df32c..b66afdba 100644 --- a/examples/subscribe_simple/callback.c +++ b/examples/subscribe_simple/callback.c @@ -16,8 +16,8 @@ int main(int argc, char *argv[]) mosquitto_lib_init(); rc = mosquitto_subscribe_callback( - on_message, - "irc/#", 0, NULL, + on_message, NULL, + "irc/#", 0, "test.mosquitto.org", 1883, NULL, 60, true, NULL, NULL, diff --git a/examples/subscribe_simple/multiple.c b/examples/subscribe_simple/multiple.c index 4938a06e..67dc760d 100644 --- a/examples/subscribe_simple/multiple.c +++ b/examples/subscribe_simple/multiple.c @@ -13,8 +13,8 @@ int main(int argc, char *argv[]) mosquitto_lib_init(); rc = mosquitto_subscribe_simple( - &msg, COUNT, - "irc/#", 0, true, + &msg, COUNT, true, + "irc/#", 0, "test.mosquitto.org", 1883, NULL, 60, true, NULL, NULL, diff --git a/examples/subscribe_simple/single.c b/examples/subscribe_simple/single.c index 44eb440f..b23ebd37 100644 --- a/examples/subscribe_simple/single.c +++ b/examples/subscribe_simple/single.c @@ -10,8 +10,8 @@ int main(int argc, char *argv[]) mosquitto_lib_init(); rc = mosquitto_subscribe_simple( - &msg, 1, - "irc/#", 0, true, + &msg, 1, true, + "irc/#", 0, "test.mosquitto.org", 1883, NULL, 60, true, NULL, NULL, diff --git a/lib/cpp/mosquittopp.cpp b/lib/cpp/mosquittopp.cpp index ce4198c3..541d5760 100644 --- a/lib/cpp/mosquittopp.cpp +++ b/lib/cpp/mosquittopp.cpp @@ -109,9 +109,9 @@ int topic_matches_sub(const char *sub, const char *topic, bool *result) int subscribe_simple( struct mosquitto_message **messages, int msg_count, + bool retained, const char *topic, int qos, - bool retained, const char *host, int port, const char *client_id, @@ -122,7 +122,9 @@ int subscribe_simple( const struct libmosquitto_will *will, const struct libmosquitto_tls *tls) { - return mosquitto_subscribe_simple(messages, msg_count, topic, qos, retained, + return mosquitto_subscribe_simple( + messages, msg_count, retained, + topic, qos, host, port, client_id, keepalive, clean_session, username, password, will, tls); @@ -130,10 +132,9 @@ int subscribe_simple( mosqpp_EXPORT int subscribe_callback( int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, const char *topic, int qos, - void *userdata, - bool retained, const char *host, int port, const char *client_id, @@ -144,7 +145,9 @@ mosqpp_EXPORT int subscribe_callback( const struct libmosquitto_will *will, const struct libmosquitto_tls *tls) { - return mosquitto_subscribe_callback(callback, topic, qos, userdata, retained, + return mosquitto_subscribe_callback( + callback, userdata, + topic, qos, host, port, client_id, keepalive, clean_session, username, password, will, tls); diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index 9876d370..36b05ec4 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -44,9 +44,9 @@ mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *re mosqpp_EXPORT int subscribe_simple( struct mosquitto_message **messages, int msg_count, + bool retained, const char *topic, int qos=0, - bool retained=true, const char *host="localhost", int port=1883, const char *client_id=NULL, @@ -59,9 +59,9 @@ mosqpp_EXPORT int subscribe_simple( mosqpp_EXPORT int subscribe_callback( int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, const char *topic, int qos=0, - void *userdata=NULL, bool retained=true, const char *host="localhost", int port=1883, diff --git a/lib/helpers.c b/lib/helpers.c index c36cf35f..7071ccf2 100644 --- a/lib/helpers.c +++ b/lib/helpers.c @@ -86,9 +86,9 @@ static int on_message_simple(struct mosquitto *mosq, void *obj, const struct mos libmosq_EXPORT int mosquitto_subscribe_simple( struct mosquitto_message **messages, int msg_count, + bool retained, const char *topic, int qos, - bool retained, const char *host, int port, const char *client_id, @@ -117,9 +117,9 @@ libmosq_EXPORT int mosquitto_subscribe_simple( userdata.max_msg_count = msg_count; userdata.retained = retained; - rc = mosquitto_subscribe_callback(on_message_simple, + rc = mosquitto_subscribe_callback( + on_message_simple, &userdata, topic, qos, - &userdata, host, port, client_id, keepalive, clean_session, username, password, @@ -138,11 +138,12 @@ libmosq_EXPORT int mosquitto_subscribe_simple( } } + libmosq_EXPORT int mosquitto_subscribe_callback( int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, const char *topic, int qos, - void *userdata, const char *host, int port, const char *client_id, diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 0d8ca988..1babfedc 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -1575,9 +1575,9 @@ struct libmosquitto_tls { * messages will be returned here. On error, this will be set to * NULL. * msg_count - the number of messages to retrieve. + * retained - if set to true, stale retained messages will be treated as * topic - the subscription topic to use (wildcards are allowed). * qos - the qos to use for the subscription. - * retained - if set to true, stale retained messages will be treated as * normal messages with regards to msg_count. If set to false, * they will be ignored. * host - the broker to connect to. @@ -1601,9 +1601,9 @@ struct libmosquitto_tls { libmosq_EXPORT int mosquitto_subscribe_simple( struct mosquitto_message **messages, int msg_count, + bool retained, const char *topic, int qos, - bool retained, const char *host, int port, const char *client_id, @@ -1630,9 +1630,9 @@ libmosq_EXPORT int mosquitto_subscribe_simple( * int callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) * Note that this is the same as the normal on_message callback, * except that it returns an int. + * userdata - user provided pointer that will be passed to the callback. * topic - the subscription topic to use (wildcards are allowed). * qos - the qos to use for the subscription. - * userdata - user provided pointer that will be passed to the callback. * host - the broker to connect to. * port - the network port the broker is listening on. * client_id - the client id to use, or NULL if a random client id should be @@ -1653,9 +1653,9 @@ libmosq_EXPORT int mosquitto_subscribe_simple( */ libmosq_EXPORT int mosquitto_subscribe_callback( int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, const char *topic, int qos, - void *userdata, const char *host, int port, const char *client_id, diff --git a/man/libmosquitto.3.xml b/man/libmosquitto.3.xml index 0961ff96..70e44cb3 100644 --- a/man/libmosquitto.3.xml +++ b/man/libmosquitto.3.xml @@ -375,9 +375,9 @@ int mosquitto_subscribe_simple struct mosquitto_message **message int msg_count + bool retained const char *topic intqos - bool retained const char *host int port const char *client_id @@ -391,9 +391,9 @@ int mosquitto_subscribe_callback int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *) + void *userdata const char *topic int qos - void *userdata const char *host int port const char *client_id