123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- namespace mqtt {
- class iasync_client;
- class topic
- {
-
- iasync_client& cli_;
-
- string name_;
-
- int qos_;
-
- bool retained_;
- public:
-
- using ptr_t = std::shared_ptr<topic>;
-
- using const_ptr_t = std::shared_ptr<const topic>;
-
- topic(iasync_client& cli, const string& name,
- int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
- : cli_(cli), name_(name), qos_(qos), retained_(retained) {}
-
- static ptr_t create(iasync_client& cli, const string& name,
- int qos=message::DFLT_QOS,
- bool retained=message::DFLT_RETAINED) {
- return std::make_shared<topic>(cli, name, qos, retained);
- }
-
- iasync_client& get_client() { return cli_; }
-
- const string& get_name() const { return name_; }
-
- static std::vector<std::string> split(const std::string& topic);
-
- int get_qos() const { return qos_; }
-
- bool get_retained() const { return retained_; }
-
- void set_qos(int qos) {
- message::validate_qos(qos);
- qos_ = qos;
- }
-
- void set_retained(bool retained) { retained_ = retained; }
-
- delivery_token_ptr publish(const void* payload, size_t n);
-
- delivery_token_ptr publish(const void* payload, size_t n,
- int qos, bool retained);
-
- delivery_token_ptr publish(binary_ref payload);
-
- delivery_token_ptr publish(binary_ref payload, int qos, bool retained);
-
- token_ptr subscribe(const subscribe_options& opts=subscribe_options());
-
- string to_string() const { return name_; }
- };
- using topic_ptr = topic::ptr_t ;
- using const_topic_ptr = topic::const_ptr_t ;
- class topic_filter
- {
-
- std::vector<string> fields_;
- public:
-
- explicit topic_filter(const string& filter);
-
- static bool has_wildcards(const string& topic);
-
- bool has_wildcards() const;
-
- bool matches(const string& topic) const;
- };
- }
|