Uniot Core
0.8.1
Loading...
Searching...
No Matches
MQTTPath.h
Go to the documentation of this file.
1/*
2 * This is a part of the Uniot project.
3 * Copyright (C) 2016-2020 Uniot <contact@uniot.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <Credentials.h>
22
23namespace uniot
24{
37{
38public:
44 MQTTPath(const Credentials &credentials) : mPrefix("PUBLIC_UNIOT"), mpCredentials(&credentials)
45 {
46 }
47
53 inline const String& getDeviceId() const
54 {
55 return mpCredentials->getDeviceId();
56 }
57
63 inline const String& getOwnerId() const
64 {
65 return mpCredentials->getOwnerId();
66 }
67
77 String buildDevicePath(const String &topic) const
78 {
79 return mPrefix + "/"
80 + "users/"
81 + mpCredentials->getOwnerId() + "/"
82 + "devices/"
83 + mpCredentials->getDeviceId() + "/"
84 + topic;
85 }
86
97 String buildGroupPath(const String& groupId, const String &topic) const
98 {
99 return mPrefix + "/"
100 + "users/"
101 + mpCredentials->getOwnerId() + "/"
102 + "groups/"
103 + groupId + "/"
104 + topic;
105 }
106
116 String buildPublicPath(const String &topic) const
117 {
118 return mPrefix + "/"
119 + topic;
120 }
121
128 {
129 return mpCredentials;
130 }
131
132private:
136 const String mPrefix;
137
141 const Credentials *mpCredentials;
142};
143
144} // namespace uniot
Manages device identity and cryptographic credentials for Uniot devices.
Definition Credentials.h:61
const String & getOwnerId() const
Gets the owner ID from the credentials.
Definition MQTTPath.h:63
String buildPublicPath(const String &topic) const
Builds an MQTT topic path for public communication.
Definition MQTTPath.h:116
String buildDevicePath(const String &topic) const
Builds an MQTT topic path for device-specific communication.
Definition MQTTPath.h:77
MQTTPath(const Credentials &credentials)
Constructs an MQTTPath instance with device credentials.
Definition MQTTPath.h:44
const Credentials * getCredentials() const
Gets the credentials object used by this instance.
Definition MQTTPath.h:127
String buildGroupPath(const String &groupId, const String &topic) const
Builds an MQTT topic path for group-level communication.
Definition MQTTPath.h:97
const String & getDeviceId() const
Gets the device ID from the credentials.
Definition MQTTPath.h:53
Contains all classes and functions related to the Uniot Core.