Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-01 08:54:12

0001 /*
0002 Copyright (c) 2010-2019 Roger Light <roger@atchoo.org>
0003 
0004 All rights reserved. This program and the accompanying materials
0005 are made available under the terms of the Eclipse Public License 2.0
0006 and Eclipse Distribution License v1.0 which accompany this distribution.
0007 
0008 The Eclipse Public License is available at
0009    https://www.eclipse.org/legal/epl-2.0/
0010 and the Eclipse Distribution License is available at
0011   http://www.eclipse.org/org/documents/edl-v10.php.
0012 
0013 Contributors:
0014    Roger Light - initial implementation and documentation.
0015 */
0016 
0017 #ifndef MOSQUITTOPP_H
0018 #define MOSQUITTOPP_H
0019 
0020 #if defined(_WIN32) && !defined(LIBMOSQUITTO_STATIC)
0021 #   ifdef mosquittopp_EXPORTS
0022 #       define mosqpp_EXPORT  __declspec(dllexport)
0023 #   else
0024 #       define mosqpp_EXPORT  __declspec(dllimport)
0025 #   endif
0026 #else
0027 #   define mosqpp_EXPORT
0028 #endif
0029 
0030 #include <cstdlib>
0031 #include <mosquitto.h>
0032 #include <time.h>
0033 
0034 namespace mosqpp {
0035 
0036 
0037 mosqpp_EXPORT const char * strerror(int mosq_errno);
0038 mosqpp_EXPORT const char * connack_string(int connack_code);
0039 mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count);
0040 mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count);
0041 mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision);
0042 mosqpp_EXPORT int lib_init();
0043 mosqpp_EXPORT int lib_cleanup();
0044 mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result);
0045 mosqpp_EXPORT int validate_utf8(const char *str, int len);
0046 mosqpp_EXPORT int subscribe_simple(
0047         struct mosquitto_message **messages,
0048         int msg_count,
0049         bool retained,
0050         const char *topic,
0051         int qos=0,
0052         const char *host="localhost",
0053         int port=1883,
0054         const char *client_id=NULL,
0055         int keepalive=60,
0056         bool clean_session=true,
0057         const char *username=NULL,
0058         const char *password=NULL,
0059         const struct libmosquitto_will *will=NULL,
0060         const struct libmosquitto_tls *tls=NULL);
0061 
0062 mosqpp_EXPORT int subscribe_callback(
0063         int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *),
0064         void *userdata,
0065         const char *topic,
0066         int qos=0,
0067         const char *host="localhost",
0068         int port=1883,
0069         const char *client_id=NULL,
0070         int keepalive=60,
0071         bool clean_session=true,
0072         const char *username=NULL,
0073         const char *password=NULL,
0074         const struct libmosquitto_will *will=NULL,
0075         const struct libmosquitto_tls *tls=NULL);
0076 
0077 /*
0078  * Class: mosquittopp
0079  *
0080  * A mosquitto client class. This is a C++ wrapper class for the mosquitto C
0081  * library. Please see mosquitto.h for details of the functions.
0082  */
0083 class mosqpp_EXPORT mosquittopp {
0084     private:
0085         struct mosquitto *m_mosq;
0086     public:
0087         mosquittopp(const char *id=NULL, bool clean_session=true);
0088         virtual ~mosquittopp();
0089 
0090         int reinitialise(const char *id, bool clean_session);
0091         int socket();
0092         int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false);
0093         int will_clear();
0094         int username_pw_set(const char *username, const char *password=NULL);
0095         int connect(const char *host, int port=1883, int keepalive=60);
0096         int connect_async(const char *host, int port=1883, int keepalive=60);
0097         int connect(const char *host, int port, int keepalive, const char *bind_address);
0098         int connect_async(const char *host, int port, int keepalive, const char *bind_address);
0099         int reconnect();
0100         int reconnect_async();
0101         int disconnect();
0102         int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false);
0103         int subscribe(int *mid, const char *sub, int qos=0);
0104         int unsubscribe(int *mid, const char *sub);
0105         void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff);
0106         int max_inflight_messages_set(unsigned int max_inflight_messages);
0107         void message_retry_set(unsigned int message_retry);
0108         void user_data_set(void *userdata);
0109         int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL);
0110         int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL);
0111         int tls_insecure_set(bool value);
0112         int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL);
0113         int opts_set(enum mosq_opt_t option, void *value);
0114 
0115         int loop(int timeout=-1, int max_packets=1);
0116         int loop_misc();
0117         int loop_read(int max_packets=1);
0118         int loop_write(int max_packets=1);
0119         int loop_forever(int timeout=-1, int max_packets=1);
0120         int loop_start();
0121         int loop_stop(bool force=false);
0122         bool want_write();
0123         int threaded_set(bool threaded=true);
0124         int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL);
0125 
0126         // names in the functions commented to prevent unused parameter warning
0127         virtual void on_connect(int /*rc*/) {return;}
0128         virtual void on_connect_with_flags(int /*rc*/, int /*flags*/) {return;}
0129         virtual void on_disconnect(int /*rc*/) {return;}
0130         virtual void on_publish(int /*mid*/) {return;}
0131         virtual void on_message(const struct mosquitto_message * /*message*/) {return;}
0132         virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;}
0133         virtual void on_unsubscribe(int /*mid*/) {return;}
0134         virtual void on_log(int /*level*/, const char * /*str*/) {return;}
0135         virtual void on_error() {return;}
0136 };
0137 
0138 }
0139 #endif