├── .gitignore ├── LICENSE.txt ├── MqttUtilities ├── Config │ └── FilterPlugin.ini ├── Content │ ├── Levels │ │ ├── TestLevel.umap │ │ └── TestLevel_BuiltData.uasset │ └── UserInterface │ │ └── AppMenu_BP.uasset ├── MqttUtilities.uplugin ├── Resources │ └── Icon128.png └── Source │ ├── MqttUtilities │ ├── MqttUtilities.Build.cs │ ├── MqttUtilities_Android_UPL.xml │ ├── MqttUtilities_IOS_UPL.xml │ ├── Private │ │ ├── Android │ │ │ ├── Java │ │ │ │ └── MqttHelper.java │ │ │ ├── MqttClient.cpp │ │ │ ├── MqttClient.h │ │ │ ├── MqttClientHolder.cpp │ │ │ ├── MqttClientHolder.h │ │ │ └── Utils │ │ │ │ ├── ConversionUtils.cpp │ │ │ │ └── ConversionUtils.h │ │ ├── IOS │ │ │ ├── MqttClient.cpp │ │ │ ├── MqttClient.h │ │ │ ├── MqttDelegate.cpp │ │ │ ├── MqttDelegate.h │ │ │ └── Utils │ │ │ │ ├── ConversionUtils.cpp │ │ │ │ └── ConversionUtils.h │ │ ├── Linux │ │ │ ├── MqttClient.cpp │ │ │ ├── MqttClient.h │ │ │ ├── MqttClientImpl.cpp │ │ │ ├── MqttClientImpl.h │ │ │ ├── MqttRunnable.cpp │ │ │ ├── MqttRunnable.h │ │ │ ├── MqttTask.cpp │ │ │ ├── MqttTask.h │ │ │ └── Utils │ │ │ │ ├── StringUtils.cpp │ │ │ │ └── StringUtils.h │ │ ├── Mac │ │ │ ├── MqttClient.cpp │ │ │ ├── MqttClient.h │ │ │ ├── MqttClientImpl.cpp │ │ │ ├── MqttClientImpl.h │ │ │ ├── MqttRunnable.cpp │ │ │ ├── MqttRunnable.h │ │ │ ├── MqttTask.cpp │ │ │ ├── MqttTask.h │ │ │ └── Utils │ │ │ │ ├── StringUtils.cpp │ │ │ │ └── StringUtils.h │ │ ├── MqttClientBase.cpp │ │ ├── MqttClientBase.h │ │ ├── MqttUtilitiesBPL.cpp │ │ ├── MqttUtilitiesModule.cpp │ │ └── Windows │ │ │ ├── MqttClient.cpp │ │ │ ├── MqttClient.h │ │ │ ├── MqttClientImpl.cpp │ │ │ ├── MqttClientImpl.h │ │ │ ├── MqttRunnable.cpp │ │ │ ├── MqttRunnable.h │ │ │ ├── MqttTask.cpp │ │ │ ├── MqttTask.h │ │ │ └── Utils │ │ │ ├── StringUtils.cpp │ │ │ └── StringUtils.h │ └── Public │ │ ├── Entities │ │ ├── MqttClientConfig.h │ │ ├── MqttConnectionData.h │ │ └── MqttMessage.h │ │ ├── IMqttUtilitiesModule.h │ │ ├── Interface │ │ └── MqttClientInterface.h │ │ └── MqttUtilitiesBPL.h │ └── ThirdParty │ ├── IOS │ ├── MQTTClient.embeddedframework.zip │ └── SocketRocket.embeddedframework.zip │ ├── Linux │ ├── libmosquitto │ │ ├── includes │ │ │ ├── alias_mosq.h │ │ │ ├── dummypthread.h │ │ │ ├── logging_mosq.h │ │ │ ├── memory_mosq.h │ │ │ ├── messages_mosq.h │ │ │ ├── misc_mosq.h │ │ │ ├── mosquitto.h │ │ │ ├── mosquitto_broker.h │ │ │ ├── mosquitto_internal.h │ │ │ ├── mosquitto_plugin.h │ │ │ ├── mqtt_protocol.h │ │ │ ├── net_mosq.h │ │ │ ├── packet_mosq.h │ │ │ ├── property_mosq.h │ │ │ ├── read_handle.h │ │ │ ├── send_mosq.h │ │ │ ├── socks_mosq.h │ │ │ ├── time_mosq.h │ │ │ ├── tls_mosq.h │ │ │ ├── util_mosq.h │ │ │ └── will_mosq.h │ │ └── libraries │ │ │ ├── libmosquitto.so │ │ │ └── libmosquitto_static.a │ └── libmosquittopp │ │ ├── includes │ │ └── mosquittopp.h │ │ └── libraries │ │ ├── libmosquittopp.so │ │ └── libmosquittopp_static.a │ ├── Mac │ ├── mosquitto │ │ ├── includes │ │ │ ├── dummypthread.h │ │ │ ├── logging_mosq.h │ │ │ ├── memory_mosq.h │ │ │ ├── messages_mosq.h │ │ │ ├── mosquitto.h │ │ │ ├── mosquitto_internal.h │ │ │ ├── mqtt3_protocol.h │ │ │ ├── net_mosq.h │ │ │ ├── read_handle.h │ │ │ ├── send_mosq.h │ │ │ ├── socks_mosq.h │ │ │ ├── time_mosq.h │ │ │ ├── tls_mosq.h │ │ │ ├── util_mosq.h │ │ │ └── will_mosq.h │ │ └── libraries │ │ │ └── mosquitto.dylib │ └── mosquittopp │ │ ├── includes │ │ └── mosquittopp.h │ │ └── libraries │ │ └── mosquittopp.dylib │ └── Win64 │ ├── mosquitto │ ├── includes │ │ ├── dummypthread.h │ │ ├── logging_mosq.h │ │ ├── memory_mosq.h │ │ ├── messages_mosq.h │ │ ├── mosquitto.h │ │ ├── mosquitto_internal.h │ │ ├── mqtt3_protocol.h │ │ ├── net_mosq.h │ │ ├── read_handle.h │ │ ├── send_mosq.h │ │ ├── socks_mosq.h │ │ ├── time_mosq.h │ │ ├── tls_mosq.h │ │ ├── util_mosq.h │ │ └── will_mosq.h │ └── libraries │ │ ├── mosquitto.dll │ │ ├── mosquitto.exp │ │ ├── mosquitto.ilk │ │ ├── mosquitto.lib │ │ └── mosquitto.pdb │ └── mosquittopp │ ├── includes │ └── mosquittopp.h │ └── libraries │ ├── mosquittopp.dll │ ├── mosquittopp.exp │ ├── mosquittopp.ilk │ ├── mosquittopp.lib │ └── mosquittopp.pdb ├── README.md └── Resources ├── AllNodes_Scr.PNG ├── Connect_Scr.PNG ├── Content_Scr.PNG ├── CreateInterface_Scr.PNG ├── Demo_Scr.jpg ├── Disconnect_Scr.PNG ├── Handlers_Scr.PNG ├── OnError_Scr.PNG ├── OnMessage_Scr.PNG ├── OnPublish_Scr.PNG ├── OnSubscribe_Scr.PNG ├── OnUnsubscribe_Scr.PNG ├── PluginSetup_Scr.png ├── Publish_Scr.PNG ├── Subscribe_Scr.PNG └── Unsubscribe_Scr.PNG /.gitignore: -------------------------------------------------------------------------------- 1 | # Prevent different SC's conflicting with each other (Git vs Snowtrack) 2 | # Do not remove this line 3 | .snow 4 | 5 | _renom/ 6 | 7 | # Visual Studio user settings files that should be ignored. 8 | .vs/ 9 | .vscode/ 10 | *.vcxproj 11 | 12 | # Visual Studio user settings files that should be ignored. 13 | # And Unreal Engine directories 14 | Saved/ 15 | Build/ 16 | Binaries/ 17 | Intermediate/ 18 | DerivedDataCache/ 19 | FileOpenOrder/ 20 | Developers/ 21 | 22 | *.pdb 23 | *-Debug.* 24 | *.tmp 25 | *.VC.db 26 | *.opensdf 27 | *.opendb 28 | *.sdf 29 | *.sln 30 | *.suo 31 | *.swp 32 | 33 | *.xcodeproj 34 | *.xcworkspace 35 | 36 | # Allow any files from /RawContent dir. 37 | # Any file in /RawContent dir will be managed by git lfs. 38 | !/RawContent/**/* 39 | 40 | # OS/platform generated files. 41 | 42 | # Windows 43 | ehthumbs.db 44 | Thumbs.db 45 | 46 | # Mac OS X 47 | .DS_Store 48 | .DS_Store? 49 | .AppleDouble 50 | .LSOverride 51 | ._* 52 | .p4ignore.txt 53 | Builds 54 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/LICENSE.txt -------------------------------------------------------------------------------- /MqttUtilities/Config/FilterPlugin.ini: -------------------------------------------------------------------------------- 1 | [FilterPlugin] 2 | ; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and 3 | ; may include "...", "*", and "?" wildcards to match directories, files, and individual characters respectively. 4 | ; 5 | ; Examples: 6 | ; /README.txt 7 | ; /Extras/... 8 | ; /Binaries/ThirdParty/*.dll 9 | -------------------------------------------------------------------------------- /MqttUtilities/Content/Levels/TestLevel.umap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Content/Levels/TestLevel.umap -------------------------------------------------------------------------------- /MqttUtilities/Content/Levels/TestLevel_BuiltData.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Content/Levels/TestLevel_BuiltData.uasset -------------------------------------------------------------------------------- /MqttUtilities/Content/UserInterface/AppMenu_BP.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Content/UserInterface/AppMenu_BP.uasset -------------------------------------------------------------------------------- /MqttUtilities/MqttUtilities.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0.0", 5 | "FriendlyName": "MQTT Utilities", 6 | "Description": "MQTT client for Unreal Engine", 7 | "Category": "Code Plugins", 8 | "CreatedBy": "Nineva Studios", 9 | "CreatedByURL": "https://ninevastudios.com/", 10 | "DocsURL": "https://github.com/NinevaStudios/MqttUtilities-UnrealEngine/wiki", 11 | "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/6371e7a3824549bba2411d0f1baa7ae0", 12 | "EngineVersion": "4.26.0", 13 | "SupportURL": "mailto:support@ninevastudios.com", 14 | "EnabledByDefault": true, 15 | "CanContainContent": true, 16 | "IsBetaVersion": false, 17 | "Installed": true, 18 | "Modules": [ 19 | { 20 | "Name": "MqttUtilities", 21 | "Type": "Runtime", 22 | "LoadingPhase": "Default", 23 | "WhitelistPlatforms": [ "Win64", "Mac", "Android", "IOS", "Linux" ] 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /MqttUtilities/Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Resources/Icon128.png -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/MqttUtilities.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | using System.IO; 4 | using UnrealBuildTool; 5 | 6 | #if UE_5_0_OR_LATER 7 | using EpicGames.Core; 8 | #else 9 | using Tools.DotNETCommon; 10 | #endif 11 | 12 | public class MqttUtilities : ModuleRules 13 | { 14 | public MqttUtilities(ReadOnlyTargetRules Target) : base(Target) 15 | { 16 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 17 | 18 | PublicIncludePaths.AddRange( 19 | new string[] { 20 | Path.Combine (ModuleDirectory, "Public") 21 | // ... add public include paths required here ... 22 | } 23 | ); 24 | 25 | 26 | PrivateIncludePaths.AddRange( 27 | new string[] { 28 | Path.Combine (ModuleDirectory, "Private") 29 | // ... add other private include paths required here ... 30 | } 31 | ); 32 | 33 | 34 | PublicDependencyModuleNames.AddRange( 35 | new string[] 36 | { 37 | "Core", 38 | // ... add other public dependencies that you statically link with here ... 39 | } 40 | ); 41 | 42 | 43 | PrivateDependencyModuleNames.AddRange( 44 | new string[] 45 | { 46 | "CoreUObject", 47 | "Engine", 48 | "Projects", 49 | // ... add private dependencies that you statically link with here ... 50 | } 51 | ); 52 | 53 | 54 | DynamicallyLoadedModuleNames.AddRange( 55 | new string[] 56 | { 57 | // ... add any modules that your module loads dynamically here ... 58 | } 59 | ); 60 | 61 | 62 | // Additional routine for Windows 63 | if (Target.Platform == UnrealTargetPlatform.Win64) 64 | { 65 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private/Windows")); 66 | 67 | LoadThirdPartyLibrary("mosquitto", Target); 68 | LoadThirdPartyLibrary("mosquittopp", Target); 69 | } 70 | 71 | // Additional routine for Mac 72 | if (Target.Platform == UnrealTargetPlatform.Mac) 73 | { 74 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private/Mac")); 75 | 76 | LoadThirdPartyLibrary("mosquitto", Target); 77 | LoadThirdPartyLibrary("mosquittopp", Target); 78 | } 79 | 80 | // Additional routine for iOS 81 | if (Target.Platform == UnrealTargetPlatform.IOS) 82 | { 83 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private/IOS")); 84 | 85 | PublicAdditionalFrameworks.Add(new Framework("MQTTClient", "../ThirdParty/IOS/MQTTClient.embeddedframework.zip")); 86 | PublicAdditionalFrameworks.Add(new Framework("SocketRocket", "../ThirdParty/IOS/SocketRocket.embeddedframework.zip")); 87 | 88 | PublicAdditionalLibraries.Add("/usr/lib/libicucore.dylib"); 89 | 90 | PublicFrameworks.AddRange( 91 | new string[] 92 | { 93 | "Foundation", 94 | "Security", 95 | "CFNetwork", 96 | "CoreData" 97 | } 98 | ); 99 | 100 | PrivateDependencyModuleNames.AddRange(new string[] { "Launch" }); 101 | string PluginPath = Utils.MakePathRelativeTo(ModuleDirectory, Target.RelativeEnginePath); 102 | 103 | AdditionalPropertiesForReceipt.Add("IOSPlugin", Path.Combine(PluginPath, "MqttUtilities_IOS_UPL.xml")); 104 | } 105 | 106 | // Additional routine for Android 107 | if (Target.Platform == UnrealTargetPlatform.Android) 108 | { 109 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private/Android")); 110 | 111 | PrivateDependencyModuleNames.AddRange(new string[] { "Launch" }); 112 | string PluginPath = Utils.MakePathRelativeTo(ModuleDirectory, Target.RelativeEnginePath); 113 | 114 | AdditionalPropertiesForReceipt.Add("AndroidPlugin", Path.Combine(PluginPath, "MqttUtilities_Android_UPL.xml")); 115 | } 116 | 117 | // Additional routine for Windows 118 | if (Target.Platform == UnrealTargetPlatform.Linux) 119 | { 120 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private/Linux")); 121 | 122 | LoadThirdPartyLibrary("libmosquitto", Target); 123 | LoadThirdPartyLibrary("libmosquittopp", Target); 124 | } 125 | } 126 | 127 | public void LoadThirdPartyLibrary(string libname, ReadOnlyTargetRules Target) 128 | { 129 | string StaticLibExtension = ".lib"; 130 | string DynamicLibExtension = string.Empty; 131 | 132 | if(Target.Platform == UnrealTargetPlatform.Win64) 133 | { 134 | DynamicLibExtension = ".dll"; 135 | } 136 | if(Target.Platform == UnrealTargetPlatform.Mac) 137 | { 138 | DynamicLibExtension = ".dylib"; 139 | } 140 | if(Target.Platform == UnrealTargetPlatform.Linux) 141 | { 142 | DynamicLibExtension = ".so"; 143 | StaticLibExtension = "_static.a"; 144 | } 145 | 146 | string ThirdPartyPath = Path.Combine(ModuleDirectory, "../ThirdParty", Target.Platform.ToString()); 147 | string LibrariesPath = Path.Combine(ThirdPartyPath, libname, "libraries"); 148 | string IncludesPath = Path.Combine(ThirdPartyPath, libname, "includes"); 149 | string BinariesPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "../../Binaries", Target.Platform.ToString())); 150 | 151 | // Link static library (Windows only) 152 | 153 | if(Target.Platform == UnrealTargetPlatform.Win64 || Target.Platform == UnrealTargetPlatform.Linux) 154 | { 155 | PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, libname + StaticLibExtension)); 156 | } 157 | 158 | // Copy dynamic library to Binaries folder 159 | 160 | if (!Directory.Exists(BinariesPath)) 161 | { 162 | Directory.CreateDirectory(BinariesPath); 163 | } 164 | 165 | if (!File.Exists(Path.Combine(BinariesPath, libname + DynamicLibExtension))) 166 | { 167 | File.Copy(Path.Combine(LibrariesPath, libname + DynamicLibExtension), Path.Combine(BinariesPath, libname + DynamicLibExtension), true); 168 | } 169 | 170 | // Set up dynamic library 171 | if (Target.Platform == UnrealTargetPlatform.Win64) 172 | { 173 | PublicDelayLoadDLLs.Add(libname + DynamicLibExtension); 174 | } 175 | if (Target.Platform == UnrealTargetPlatform.Mac) 176 | { 177 | PublicDelayLoadDLLs.Add(Path.Combine(BinariesPath, libname + DynamicLibExtension)); 178 | } 179 | if (Target.Platform == UnrealTargetPlatform.Linux) 180 | { 181 | PublicDelayLoadDLLs.Add(Path.Combine(BinariesPath, libname + DynamicLibExtension)); 182 | } 183 | 184 | RuntimeDependencies.Add(Path.Combine(BinariesPath, libname + DynamicLibExtension)); 185 | 186 | // Set up include path 187 | PublicIncludePaths.Add(IncludesPath); 188 | 189 | // Add definitions 190 | PublicDefinitions.Add(string.Format("WITH_" + libname.ToUpper() + "_BINDING={0}", 1)); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/MqttUtilities_Android_UPL.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -keep public class com.ninevastudios.mqttdemo.** { 19 | public protected *; 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | dependencies { 39 | compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0' 40 | compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' 41 | } 42 | repositories { 43 | maven { 44 | url "https://repo.eclipse.org/content/repositories/paho-snapshots/" 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/MqttUtilities_IOS_UPL.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/Java/MqttHelper.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | package com.ninevastudios.mqttdemo; 4 | 5 | import android.app.Activity; 6 | import android.util.Log; 7 | 8 | import org.eclipse.paho.android.service.MqttAndroidClient; 9 | import org.eclipse.paho.client.mqttv3.DisconnectedBufferOptions; 10 | import org.eclipse.paho.client.mqttv3.IMqttActionListener; 11 | import org.eclipse.paho.client.mqttv3.IMqttMessageListener; 12 | import org.eclipse.paho.client.mqttv3.IMqttToken; 13 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; 14 | import org.eclipse.paho.client.mqttv3.MqttException; 15 | import org.eclipse.paho.client.mqttv3.MqttMessage; 16 | 17 | public class MqttHelper { 18 | private final String TAG = "MQTT => "; 19 | 20 | private MqttAndroidClient mqttAndroidClient; 21 | 22 | public static native void onConnected(String guid); 23 | public static native void onDisconnected(String guid); 24 | public static native void onSubscribed(int messageId, int[] qos, String guid); 25 | public static native void onUnsubscribed(int messageId, String guid); 26 | public static native void onPublished(int messageId, String guid); 27 | public static native void onMessageArrived(String topic, MqttMessage message, String guid); 28 | public static native void onError(int errCode, String errMessage, String guid); 29 | 30 | private String m_Guid; 31 | 32 | public MqttHelper(Activity activity, String serverUri, String clientId, String guid) { 33 | mqttAndroidClient = new MqttAndroidClient(activity, serverUri, clientId); 34 | m_Guid = guid; 35 | } 36 | 37 | public void connect(MqttConnectOptions options) { 38 | try { 39 | mqttAndroidClient.connect(options, null, new IMqttActionListener() { 40 | @Override 41 | public void onSuccess(IMqttToken asyncActionToken) { 42 | onConnected(m_Guid); 43 | } 44 | 45 | @Override 46 | public void onFailure(IMqttToken asyncActionToken, Throwable exception) { 47 | MqttException e = asyncActionToken.getException(); 48 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 49 | } 50 | }); 51 | } catch (MqttException e) { 52 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 53 | } 54 | } 55 | 56 | public void disconnect(int quiesceTimeout) { 57 | try { 58 | if (!mqttAndroidClient.isConnected()) { 59 | Log.d(TAG, "MQTT => There is no active connection"); 60 | return; 61 | } 62 | 63 | mqttAndroidClient.disconnect(quiesceTimeout, null, new IMqttActionListener() { 64 | @Override 65 | public void onSuccess(IMqttToken asyncActionToken) { 66 | onDisconnected(m_Guid); 67 | } 68 | 69 | @Override 70 | public void onFailure(IMqttToken asyncActionToken, Throwable exception) { 71 | MqttException e = asyncActionToken.getException(); 72 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 73 | } 74 | }); 75 | } catch (MqttException e) { 76 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 77 | } 78 | } 79 | 80 | public void setDisconnectedBufferOptions(DisconnectedBufferOptions disconnectedBufferOptions) { 81 | mqttAndroidClient.setBufferOpts(disconnectedBufferOptions); 82 | } 83 | 84 | public void subscribeToTopic(final String topic, final int qos) { 85 | try { 86 | if (!mqttAndroidClient.isConnected()) { 87 | Log.d(TAG, "MQTT => There is no active connection"); 88 | return; 89 | } 90 | 91 | mqttAndroidClient.subscribe(topic, qos, this, new IMqttActionListener() { 92 | @Override 93 | public void onSuccess(IMqttToken asyncActionToken) { 94 | onSubscribed(asyncActionToken.getMessageId(), new int[] {qos}, m_Guid); 95 | } 96 | 97 | @Override 98 | public void onFailure(IMqttToken asyncActionToken, Throwable exception) { 99 | MqttException e = asyncActionToken.getException(); 100 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 101 | } 102 | }); 103 | 104 | mqttAndroidClient.subscribe(topic, qos, new IMqttMessageListener() { 105 | @Override 106 | public void messageArrived(String topic, MqttMessage message) { 107 | onMessageArrived(topic, message, m_Guid); 108 | } 109 | }); 110 | } catch (MqttException e) { 111 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 112 | } 113 | } 114 | 115 | public void unsubscribeFromTopic(final String topic) { 116 | try { 117 | if (!mqttAndroidClient.isConnected()) { 118 | Log.d(TAG, "MQTT => There is no active connection"); 119 | return; 120 | } 121 | 122 | mqttAndroidClient.unsubscribe(topic, null, new IMqttActionListener() { 123 | @Override 124 | public void onSuccess(IMqttToken asyncActionToken) { 125 | onUnsubscribed(asyncActionToken.getMessageId(), m_Guid); 126 | } 127 | 128 | @Override 129 | public void onFailure(IMqttToken asyncActionToken, Throwable exception) { 130 | MqttException e = asyncActionToken.getException(); 131 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 132 | } 133 | }); 134 | } catch (MqttException e) { 135 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 136 | } 137 | } 138 | 139 | public void publishMessage(MqttMessage message, String topic) { 140 | try { 141 | if (!mqttAndroidClient.isConnected()) { 142 | Log.d(TAG, "MQTT => There is no active connection"); 143 | return; 144 | } 145 | 146 | mqttAndroidClient.publish(topic, message, null, new IMqttActionListener() { 147 | @Override 148 | public void onSuccess(IMqttToken asyncActionToken) { 149 | onPublished(asyncActionToken.getMessageId(), m_Guid); 150 | } 151 | 152 | @Override 153 | public void onFailure(IMqttToken asyncActionToken, Throwable exception) { 154 | MqttException e = asyncActionToken.getException(); 155 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 156 | } 157 | }); 158 | } catch (MqttException e) { 159 | onError(e.getReasonCode(), e.getMessage(), m_Guid); 160 | } 161 | } 162 | 163 | public static String stringFromByteArray(byte[] data) { 164 | return new String(data); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/MqttClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClient.h" 4 | #include "MqttClientHolder.h" 5 | 6 | void UMqttClient::PostInitProperties() 7 | { 8 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => UMqttClient::PostInitProperties()")); 9 | 10 | Super::PostInitProperties(); 11 | 12 | if (UMqttClient::StaticClass()->GetDefaultObject() != this) 13 | { 14 | // add to root to avoid GC issues 15 | AddToRoot(); 16 | } 17 | } 18 | 19 | void UMqttClient::BeginDestroy() 20 | { 21 | UE_LOG(LogTemp, Warning, TEXT("GOOGLEMAPSVIEW => UGoogleMapsView::BeginDestroy()")); 22 | 23 | if (UMqttClient::StaticClass()->GetDefaultObject() != this) 24 | { 25 | MqttClientHolder::GetInstance()->RemoveClient(Guid); 26 | 27 | // remove from root so now it can be safely destroyed by GC 28 | RemoveFromRoot(); 29 | } 30 | 31 | Super::BeginDestroy(); 32 | } 33 | 34 | void UMqttClient::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 35 | { 36 | OnConnectDelegate = onConnectCallback; 37 | 38 | FJavaClassObject* javaConnectionData = ConversionUtils::ConvertToJavaConnectionData(connectionData); 39 | 40 | MqttHelperJavaObject->CallMethod(ConnectMethod, javaConnectionData->GetJObject()); 41 | } 42 | 43 | void UMqttClient::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 44 | { 45 | OnDisconnectDelegate = onDisconnectCallback; 46 | 47 | MqttHelperJavaObject->CallMethod(DisconnectMethod, 0); 48 | } 49 | 50 | void UMqttClient::Subscribe(FString topic, int qos) 51 | { 52 | if (topic.IsEmpty()) 53 | { 54 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Topic is not set. Subscription cancelled.")); 55 | return; 56 | } 57 | 58 | MqttHelperJavaObject->CallMethod(SubscribeMethod, ConversionUtils::GetJavaString(topic), qos); 59 | } 60 | 61 | void UMqttClient::Unsubscribe(FString topic) 62 | { 63 | if (topic.IsEmpty()) 64 | { 65 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Topic is not set. Unsubscription cancelled.")); 66 | return; 67 | } 68 | 69 | MqttHelperJavaObject->CallMethod(UnsubscribeMethod, ConversionUtils::GetJavaString(topic)); 70 | } 71 | 72 | void UMqttClient::Publish(FMqttMessage message) 73 | { 74 | FJavaClassObject* javaMessage = ConversionUtils::ConvertToJavaMessage(message); 75 | MqttHelperJavaObject->CallMethod(PublishMethod, javaMessage->GetJObject(), ConversionUtils::GetJavaString(message.Topic)); 76 | } 77 | 78 | void UMqttClient::Init(FMqttClientConfig configData) 79 | { 80 | FString url = FString::Printf(TEXT("tcp://%s:%d"), *configData.HostUrl, configData.Port); 81 | Guid = FGuid::NewGuid(); 82 | MqttClientHolder::GetInstance()->AddClient(Guid, this); 83 | 84 | MqttHelperJavaObject = MakeShareable(new FJavaClassObject("com/ninevastudios/mqttdemo/MqttHelper", 85 | "(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", FJavaWrapper::GameActivityThis, 86 | ConversionUtils::GetJavaString(url), ConversionUtils::GetJavaString(configData.ClientId), ConversionUtils::GetJavaString(Guid.ToString()))); 87 | 88 | ConnectMethod = MqttHelperJavaObject->GetClassMethod("connect", "(Lorg/eclipse/paho/client/mqttv3/MqttConnectOptions;)V"); 89 | DisconnectMethod = MqttHelperJavaObject->GetClassMethod("disconnect", "(I)V"); 90 | SubscribeMethod = MqttHelperJavaObject->GetClassMethod("subscribeToTopic", "(Ljava/lang/String;I)V"); 91 | UnsubscribeMethod = MqttHelperJavaObject->GetClassMethod("unsubscribeFromTopic", "(Ljava/lang/String;)V"); 92 | PublishMethod = MqttHelperJavaObject->GetClassMethod("publishMessage", "(Lorg/eclipse/paho/client/mqttv3/MqttMessage;Ljava/lang/String;)V"); 93 | } 94 | 95 | void UMqttClient::OnConnect() 96 | { 97 | OnConnectDelegate.ExecuteIfBound(); 98 | } 99 | 100 | void UMqttClient::OnDisconnect() 101 | { 102 | OnDisconnectDelegate.ExecuteIfBound(); 103 | } 104 | 105 | void UMqttClient::OnSubscribe(int messageId, TArray qos) 106 | { 107 | OnSubscribeDelegate.ExecuteIfBound(messageId, qos); 108 | } 109 | 110 | void UMqttClient::OnUnsubscribe(int messageId) 111 | { 112 | OnUnsubscribeDelegate.ExecuteIfBound(messageId); 113 | } 114 | 115 | void UMqttClient::OnPublish(int messageId) 116 | { 117 | OnPublishDelegate.ExecuteIfBound(messageId); 118 | } 119 | 120 | void UMqttClient::OnMessage(FMqttMessage message) 121 | { 122 | OnMessageDelegate.ExecuteIfBound(message); 123 | } 124 | 125 | void UMqttClient::OnError(int errCode, FString message) 126 | { 127 | OnErrorDelegate.ExecuteIfBound(errCode, message); 128 | } 129 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/MqttClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientBase.h" 6 | #include "Utils/ConversionUtils.h" 7 | 8 | #include "MqttClient.generated.h" 9 | 10 | UCLASS() 11 | class UMqttClient : public UMqttClientBase 12 | { 13 | GENERATED_BODY() 14 | 15 | public: 16 | 17 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 18 | 19 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 20 | 21 | void Subscribe(FString topic, int qos) override; 22 | 23 | void Unsubscribe(FString topic) override; 24 | 25 | void Publish(FMqttMessage message) override; 26 | 27 | public: 28 | 29 | void PostInitProperties(); 30 | void BeginDestroy(); 31 | 32 | void Init(FMqttClientConfig configData) override; 33 | 34 | void OnConnect(); 35 | void OnDisconnect(); 36 | void OnSubscribe(int messageId, TArray qos); 37 | void OnUnsubscribe(int messageId); 38 | void OnPublish(int messageId); 39 | void OnMessage(FMqttMessage message); 40 | void OnError(int errCode, FString message); 41 | 42 | private: 43 | 44 | TSharedPtr MqttHelperJavaObject; 45 | FGuid Guid; 46 | FJavaClassMethod ConnectMethod; 47 | FJavaClassMethod DisconnectMethod; 48 | FJavaClassMethod SubscribeMethod; 49 | FJavaClassMethod UnsubscribeMethod; 50 | FJavaClassMethod PublishMethod; 51 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/MqttClientHolder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClientHolder.h" 4 | #include "Async/Async.h" 5 | 6 | #if PLATFORM_ANDROID 7 | #include "Android/AndroidApplication.h" 8 | #include "Android/AndroidJNI.h" 9 | #endif 10 | 11 | static MqttClientHolder* pHolder = nullptr; 12 | 13 | MqttClientHolder::MqttClientHolder() 14 | { 15 | 16 | } 17 | 18 | MqttClientHolder * MqttClientHolder::GetInstance() 19 | { 20 | if (!pHolder) 21 | { 22 | pHolder = new MqttClientHolder(); 23 | } 24 | 25 | return pHolder; 26 | } 27 | 28 | void MqttClientHolder::AddClient(FGuid guid, UMqttClient * client) 29 | { 30 | Clients.Add(guid, client); 31 | } 32 | 33 | void MqttClientHolder::RemoveClient(FGuid guid) 34 | { 35 | Clients.Remove(guid); 36 | } 37 | 38 | UMqttClient * MqttClientHolder::GetClient(FGuid guid) const 39 | { 40 | if (Clients.Find(guid)) 41 | { 42 | return Clients[guid]; 43 | } 44 | 45 | return nullptr; 46 | } 47 | 48 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onConnected(JNIEnv* env, jclass clazz, jstring guid) 49 | { 50 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onConnected")); 51 | 52 | FString strGuid = ConversionUtils::FromJavaString(guid); 53 | 54 | if (!pHolder) 55 | { 56 | return; 57 | } 58 | 59 | FGuid clientGuid; 60 | 61 | if (FGuid::Parse(strGuid, clientGuid)) 62 | { 63 | auto client = pHolder->GetClient(clientGuid); 64 | if (client) 65 | { 66 | AsyncTask(ENamedThreads::GameThread, [=]() { 67 | client->OnConnect(); 68 | }); 69 | } 70 | } 71 | } 72 | 73 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onDisconnected(JNIEnv* env, jclass clazz, jstring guid) 74 | { 75 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onDisconnected")); 76 | 77 | FString strGuid = ConversionUtils::FromJavaString(guid); 78 | 79 | if (!pHolder) 80 | { 81 | return; 82 | } 83 | 84 | FGuid clientGuid; 85 | 86 | if (FGuid::Parse(strGuid, clientGuid)) 87 | { 88 | auto client = pHolder->GetClient(clientGuid); 89 | if (client) 90 | { 91 | AsyncTask(ENamedThreads::GameThread, [=]() { 92 | client->OnDisconnect(); 93 | }); 94 | } 95 | } 96 | } 97 | 98 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onSubscribed(JNIEnv* env, jclass clazz, int messageId, jintArray qos, jstring guid) 99 | { 100 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onSubscribed")); 101 | TArray qosArray = ConversionUtils::ConvertToIntArray(qos); 102 | 103 | FString strGuid = ConversionUtils::FromJavaString(guid); 104 | 105 | if (!pHolder) 106 | { 107 | return; 108 | } 109 | 110 | FGuid clientGuid; 111 | 112 | if (FGuid::Parse(strGuid, clientGuid)) 113 | { 114 | auto client = pHolder->GetClient(clientGuid); 115 | if (client) 116 | { 117 | AsyncTask(ENamedThreads::GameThread, [=]() { 118 | client->OnSubscribe(messageId, qosArray); 119 | }); 120 | } 121 | } 122 | } 123 | 124 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onUnsubscribed(JNIEnv* env, jclass clazz, int messageId, jstring guid) 125 | { 126 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onUnsubscribed")); 127 | 128 | FString strGuid = ConversionUtils::FromJavaString(guid); 129 | 130 | if (!pHolder) 131 | { 132 | return; 133 | } 134 | 135 | FGuid clientGuid; 136 | 137 | if (FGuid::Parse(strGuid, clientGuid)) 138 | { 139 | auto client = pHolder->GetClient(clientGuid); 140 | if (client) 141 | { 142 | AsyncTask(ENamedThreads::GameThread, [=]() { 143 | client->OnUnsubscribe(messageId); 144 | }); 145 | } 146 | } 147 | } 148 | 149 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onPublished(JNIEnv* env, jclass clazz, int messageId, jstring guid) 150 | { 151 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onPublished")); 152 | 153 | FString strGuid = ConversionUtils::FromJavaString(guid); 154 | 155 | if (!pHolder) 156 | { 157 | return; 158 | } 159 | 160 | FGuid clientGuid; 161 | 162 | if (FGuid::Parse(strGuid, clientGuid)) 163 | { 164 | auto client = pHolder->GetClient(clientGuid); 165 | if (client) 166 | { 167 | AsyncTask(ENamedThreads::GameThread, [=]() { 168 | client->OnPublish(messageId); 169 | }); 170 | } 171 | } 172 | } 173 | 174 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onMessageArrived(JNIEnv* env, jclass clazz, jstring topic, jobject javaMessage, jstring guid) 175 | { 176 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onMessageArrived")); 177 | 178 | FString strGuid = ConversionUtils::FromJavaString(guid); 179 | 180 | if (!pHolder) 181 | { 182 | return; 183 | } 184 | 185 | FGuid clientGuid; 186 | FMqttMessage message = ConversionUtils::ConvertFromJavaMessage(topic, javaMessage); 187 | 188 | if (FGuid::Parse(strGuid, clientGuid)) 189 | { 190 | auto client = pHolder->GetClient(clientGuid); 191 | if (client) 192 | { 193 | AsyncTask(ENamedThreads::GameThread, [=]() { 194 | client->OnMessage(message); 195 | }); 196 | } 197 | } 198 | } 199 | 200 | JNI_METHOD void Java_com_ninevastudios_mqttdemo_MqttHelper_onError(JNIEnv* env, jclass clazz, int errCode, jstring errMessage, jstring guid) 201 | { 202 | UE_LOG(LogTemp, Warning, TEXT("MQTTCLIENT => Java_com_ninevastudios_mqttdemo_MqttHelper_onError")); 203 | 204 | FString strGuid = ConversionUtils::FromJavaString(guid); 205 | 206 | if (!pHolder) 207 | { 208 | return; 209 | } 210 | 211 | FGuid clientGuid; 212 | 213 | FString errorMessage = ConversionUtils::FromJavaString(errMessage); 214 | 215 | if (FGuid::Parse(strGuid, clientGuid)) 216 | { 217 | auto client = pHolder->GetClient(clientGuid); 218 | if (client) 219 | { 220 | AsyncTask(ENamedThreads::GameThread, [=]() { 221 | client->OnError(errCode, errorMessage); 222 | }); 223 | } 224 | } 225 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/MqttClientHolder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClient.h" 6 | 7 | class MqttClientHolder 8 | { 9 | MqttClientHolder(); 10 | 11 | public: 12 | 13 | static MqttClientHolder* GetInstance(); 14 | 15 | void AddClient(FGuid guid, UMqttClient* client); 16 | void RemoveClient(FGuid guid); 17 | 18 | UMqttClient* GetClient(FGuid guid) const; 19 | 20 | private: 21 | 22 | TMap Clients; 23 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/Utils/ConversionUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "ConversionUtils.h" 4 | 5 | jstring ConversionUtils::GetJavaString(FString string) 6 | { 7 | JNIEnv* JEnv = AndroidJavaEnv::GetJavaEnv(); 8 | jstring local = JEnv->NewStringUTF(TCHAR_TO_UTF8(*string)); 9 | jstring result = (jstring)JEnv->NewGlobalRef(local); 10 | JEnv->DeleteLocalRef(local); 11 | return result; 12 | } 13 | 14 | jbyteArray ConversionUtils::ConvertToJByteArray(const TArray& byteArray) 15 | { 16 | JNIEnv* Env = FAndroidApplication::GetJavaEnv(); 17 | 18 | jbyteArray javaByteArray = (jbyteArray)Env->NewByteArray(byteArray.Num()); 19 | 20 | jbyte* javaByteArrayPtr = (jbyte*)malloc(byteArray.Num() * sizeof(jbyte)); 21 | 22 | for (int i = 0; i < byteArray.Num(); ++i) 23 | { 24 | javaByteArrayPtr[i] = byteArray[i]; 25 | } 26 | 27 | Env->SetByteArrayRegion(javaByteArray, 0, byteArray.Num(), javaByteArrayPtr); 28 | 29 | free(javaByteArrayPtr); 30 | 31 | return javaByteArray; 32 | } 33 | 34 | TArray ConversionUtils::ConvertToIntArray(jintArray javaArray) 35 | { 36 | TArray intArray; 37 | 38 | JNIEnv* Env = FAndroidApplication::GetJavaEnv(); 39 | 40 | jint* javaInt = Env->GetIntArrayElements(javaArray, 0); 41 | 42 | int length = Env->GetArrayLength(javaArray); 43 | 44 | for (int i = 0; i < length; i++) 45 | { 46 | intArray.Add(javaInt[i]); 47 | } 48 | 49 | return intArray; 50 | } 51 | 52 | TArray ConversionUtils::ConvertToByteArray(jbyteArray javaArray) 53 | { 54 | TArray byteArray; 55 | 56 | JNIEnv* Env = FAndroidApplication::GetJavaEnv(); 57 | 58 | jbyte* javaByte = Env->GetByteArrayElements(javaArray, 0); 59 | 60 | int length = Env->GetArrayLength(javaArray); 61 | 62 | for (int i = 0; i < length; i++) 63 | { 64 | byteArray.Add(javaByte[i]); 65 | } 66 | 67 | return byteArray; 68 | } 69 | 70 | FJavaClassObject* ConversionUtils::ConvertToJavaConnectionData(FMqttConnectionData connectionData) 71 | { 72 | FJavaClassObject* javaConnectionData = new FJavaClassObject("org/eclipse/paho/client/mqttv3/MqttConnectOptions", "()V"); 73 | FJavaClassMethod setUserNameMethod = javaConnectionData->GetClassMethod("setUserName", "(Ljava/lang/String;)V"); 74 | FJavaClassMethod setPasswordMethod = javaConnectionData->GetClassMethod("setPassword", "([C)V"); 75 | 76 | javaConnectionData->CallMethod(setUserNameMethod, GetJavaString(connectionData.Login)); 77 | 78 | jstring javaPassword = GetJavaString(connectionData.Password); 79 | JNIEnv* Env = AndroidJavaEnv::GetJavaEnv(); 80 | jclass cls = Env->GetObjectClass(javaPassword); 81 | jmethodID mid = Env->GetMethodID(cls, "toCharArray", "()[C"); 82 | jcharArray passChars = (jcharArray) Env->CallObjectMethod(javaPassword, mid); 83 | 84 | javaConnectionData->CallMethod(setPasswordMethod, passChars); 85 | 86 | return javaConnectionData; 87 | } 88 | 89 | FJavaClassObject * ConversionUtils::ConvertToJavaMessage(FMqttMessage message) 90 | { 91 | jstring javaMessageString = GetJavaString(message.Message); 92 | 93 | JNIEnv* Env = AndroidJavaEnv::GetJavaEnv(); 94 | jclass cls = Env->GetObjectClass(javaMessageString); 95 | jmethodID mid = Env->GetMethodID(cls, "getBytes", "()[B"); 96 | jbyteArray javaArray = (jbyteArray) Env->CallObjectMethod(javaMessageString, mid); 97 | 98 | FJavaClassObject* javaMessage = new FJavaClassObject("org/eclipse/paho/client/mqttv3/MqttMessage", "([B)V", javaArray); 99 | 100 | FJavaClassMethod setQosMethod = javaMessage->GetClassMethod("setQos", "(I)V"); 101 | FJavaClassMethod setRetainedMethod = javaMessage->GetClassMethod("setRetained", "(Z)V"); 102 | 103 | return javaMessage; 104 | } 105 | 106 | FMqttMessage ConversionUtils::ConvertFromJavaMessage(jstring topic, jobject javaMessage) 107 | { 108 | bool bIsOptional = false; 109 | FMqttMessage message; 110 | 111 | message.Topic = FromJavaString(topic); 112 | 113 | JNIEnv* Env = AndroidJavaEnv::GetJavaEnv(); 114 | jclass Class = Env->GetObjectClass(javaMessage); 115 | 116 | jmethodID GetPayloadMethodId = FJavaWrapper::FindMethod(Env, Class, "getPayload", "()[B", bIsOptional); 117 | jbyteArray javaPayload = (jbyteArray) Env->CallObjectMethod(javaMessage, GetPayloadMethodId); 118 | 119 | jclass helperClass = Env->FindClass("com/ninevastudios/mqttdemo/MqttHelper"); 120 | jmethodID convertArrayMethod = FJavaWrapper::FindStaticMethod(Env, helperClass, "stringFromByteArray", "([B)Ljava/lang/String;", bIsOptional); 121 | jstring javaPayloadString = (jstring) Env->CallStaticObjectMethod(helperClass, convertArrayMethod, javaPayload); 122 | message.Message = FromJavaString(javaPayloadString); 123 | 124 | jmethodID GetQosMethodId = FJavaWrapper::FindMethod(Env, Class, "getQos", "()I", bIsOptional); 125 | message.Qos = Env->CallIntMethod(javaMessage, GetQosMethodId); 126 | 127 | jmethodID GetRetainedMethodId = FJavaWrapper::FindMethod(Env, Class, "isRetained", "()Z", bIsOptional); 128 | message.Retain = Env->CallBooleanMethod(javaMessage, GetRetainedMethodId); 129 | 130 | return message; 131 | } 132 | 133 | FString ConversionUtils::FromJavaString(jstring javaString) 134 | { 135 | JNIEnv* Env = AndroidJavaEnv::GetJavaEnv(); 136 | const char * UTFString = Env->GetStringUTFChars(javaString, nullptr); 137 | FString Result(UTF8_TO_TCHAR(UTFString)); 138 | Env->ReleaseStringUTFChars(javaString, UTFString); 139 | 140 | return Result; 141 | } 142 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Android/Utils/ConversionUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "Android/AndroidJNI.h" 6 | #include "Android/AndroidApplication.h" 7 | #include "Android/AndroidJava.h" 8 | 9 | #include "Entities/MqttConnectionData.h" 10 | #include "Entities/MqttMessage.h" 11 | 12 | class ConversionUtils 13 | { 14 | 15 | public: 16 | static jstring GetJavaString(FString string); 17 | static jbyteArray ConvertToJByteArray(const TArray& byteArray); 18 | static TArray ConvertToIntArray(jintArray javaArray); 19 | static TArray ConvertToByteArray(jbyteArray javaArray); 20 | static FJavaClassObject* ConvertToJavaConnectionData(FMqttConnectionData connectionData); 21 | static FJavaClassObject* ConvertToJavaMessage(FMqttMessage message); 22 | static FMqttMessage ConvertFromJavaMessage(jstring topic, jobject javaMessage); 23 | static FString FromJavaString(jstring javaString); 24 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/MqttClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClient.h" 4 | 5 | #include "MqttDelegate.h" 6 | #include "Utils/ConversionUtils.h" 7 | 8 | #include "Async/Async.h" 9 | 10 | UMqttClient::~UMqttClient() 11 | { 12 | if(mqttSession != nil) 13 | { 14 | (MQTTSession*)CFBridgingRelease(mqttSession); 15 | mqttSession = nil; 16 | } 17 | } 18 | 19 | void UMqttClient::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 20 | { 21 | OnConnectDelegate = onConnectCallback; 22 | 23 | mqttSession.password = connectionData.Password.GetNSString(); 24 | mqttSession.userName = connectionData.Login.GetNSString(); 25 | 26 | [mqttSession connectWithConnectHandler:^(NSError *error) { 27 | if (error) { 28 | int errCode = error.code; 29 | FString errMsg = FString(error.localizedDescription); 30 | AsyncTask(ENamedThreads::GameThread, [=]() { 31 | OnErrorDelegate.ExecuteIfBound(errCode, errMsg); 32 | }); 33 | } 34 | }]; 35 | } 36 | 37 | void UMqttClient::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 38 | { 39 | OnDisconnectDelegate = onDisconnectCallback; 40 | 41 | [mqttSession disconnect]; 42 | } 43 | 44 | void UMqttClient::Subscribe(FString topic, int qos) 45 | { 46 | [mqttSession subscribeToTopic:topic.GetNSString() atLevel:ConversionUtils::ConvertIntToQosLevel(qos) subscribeHandler:^(NSError *error, NSArray *gQoss) { 47 | if (error) { 48 | int errCode = error.code; 49 | FString errMsg = FString(error.localizedDescription); 50 | AsyncTask(ENamedThreads::GameThread, [=]() { 51 | OnErrorDelegate.ExecuteIfBound(errCode, errMsg); 52 | }); 53 | } 54 | }]; 55 | } 56 | 57 | void UMqttClient::Unsubscribe(FString topic) 58 | { 59 | [mqttSession unsubscribeTopic:topic.GetNSString() unsubscribeHandler:^(NSError *error) { 60 | if (error) { 61 | int errCode = error.code; 62 | FString errMsg = FString(error.localizedDescription); 63 | AsyncTask(ENamedThreads::GameThread, [=]() { 64 | OnErrorDelegate.ExecuteIfBound(errCode, errMsg); 65 | }); 66 | } 67 | }]; 68 | } 69 | 70 | void UMqttClient::Publish(FMqttMessage message) 71 | { 72 | [mqttSession publishData:[message.Message.GetNSString() dataUsingEncoding:NSUTF8StringEncoding] onTopic:message.Topic.GetNSString() 73 | retain:message.Retain qos:ConversionUtils::ConvertIntToQosLevel(message.Qos) 74 | publishHandler:^(NSError *error) { 75 | if (error) { 76 | int errCode = error.code; 77 | FString errMsg = FString(error.localizedDescription); 78 | AsyncTask(ENamedThreads::GameThread, [=]() { 79 | OnErrorDelegate.ExecuteIfBound(errCode, errMsg); 80 | }); 81 | } 82 | }]; 83 | } 84 | 85 | void UMqttClient::Init(FMqttClientConfig configData) 86 | { 87 | MQTTCFSocketTransport *transport = [[MQTTCFSocketTransport alloc] init]; 88 | transport.host = configData.HostUrl.GetNSString(); 89 | transport.port = configData.Port; 90 | 91 | MQTTSession* session = [[MQTTSession alloc] init]; 92 | session.transport = transport; 93 | session.clientId = configData.ClientId.GetNSString(); 94 | 95 | MqttDelegate* mqttDelegate = [[MqttDelegate alloc] init]; 96 | 97 | mqttDelegate.onConnected = ^() { 98 | AsyncTask(ENamedThreads::GameThread, [=]() { 99 | OnConnectDelegate.ExecuteIfBound(); 100 | }); 101 | }; 102 | 103 | mqttDelegate.onDisconnected = ^() { 104 | AsyncTask(ENamedThreads::GameThread, [=]() { 105 | OnDisconnectDelegate.ExecuteIfBound(); 106 | }); 107 | }; 108 | 109 | mqttDelegate.onPublished = ^(int mid) { 110 | AsyncTask(ENamedThreads::GameThread, [=]() { 111 | OnPublishDelegate.ExecuteIfBound(mid); 112 | }); 113 | }; 114 | 115 | mqttDelegate.onMessageReceived = ^(FMqttMessage message) { 116 | AsyncTask(ENamedThreads::GameThread, [=]() { 117 | OnMessageDelegate.ExecuteIfBound(message); 118 | }); 119 | }; 120 | 121 | mqttDelegate.onSubscribed = ^(int mid, TArray qos) { 122 | AsyncTask(ENamedThreads::GameThread, [=]() { 123 | OnSubscribeDelegate.ExecuteIfBound(mid, qos); 124 | }); 125 | }; 126 | 127 | mqttDelegate.onUnsubscribed = ^(int mid) { 128 | AsyncTask(ENamedThreads::GameThread, [=]() { 129 | OnUnsubscribeDelegate.ExecuteIfBound(mid); 130 | }); 131 | }; 132 | 133 | session.delegate = mqttDelegate; 134 | 135 | mqttSession = (MQTTSession*)CFBridgingRetain(session); 136 | } 137 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/MqttClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientBase.h" 6 | 7 | #if PLATFORM_IOS 8 | #import 9 | #endif 10 | 11 | #include "MqttClient.generated.h" 12 | 13 | UCLASS() 14 | class UMqttClient : public UMqttClientBase 15 | { 16 | GENERATED_BODY() 17 | 18 | public: 19 | 20 | virtual ~UMqttClient(); 21 | 22 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 23 | 24 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 25 | 26 | void Subscribe(FString topic, int qos) override; 27 | 28 | void Unsubscribe(FString topic) override; 29 | 30 | void Publish(FMqttMessage message) override; 31 | 32 | public: 33 | 34 | void Init(FMqttClientConfig configData) override; 35 | 36 | private: 37 | 38 | MQTTSession* mqttSession; 39 | }; 40 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/MqttDelegate.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttDelegate.h" 4 | #include "Utils/ConversionUtils.h" 5 | 6 | @implementation MqttDelegate { 7 | 8 | } 9 | 10 | - (void)connected:(MQTTSession *)session 11 | { 12 | if (_onConnected) 13 | { 14 | _onConnected(); 15 | } 16 | } 17 | 18 | - (void)connectionClosed:(MQTTSession *)session 19 | { 20 | if (_onDisconnected) 21 | { 22 | _onDisconnected(); 23 | } 24 | } 25 | 26 | - (void)messageDelivered:(MQTTSession *)session msgID:(UInt16)msgID 27 | { 28 | if (_onPublished) 29 | { 30 | _onPublished(msgID); 31 | } 32 | } 33 | 34 | - (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString *)topic qos:(MQTTQosLevel)qos retained:(BOOL)retained mid:(unsigned int)mid 35 | { 36 | if (_onMessageReceived) 37 | { 38 | FMqttMessage message; 39 | 40 | NSString* dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 41 | 42 | message.Message = FString(dataStr); 43 | message.Topic = FString(topic); 44 | message.Retain = retained; 45 | message.Qos = ConversionUtils::GonvertQosLevelToInt(qos); 46 | 47 | _onMessageReceived(message); 48 | } 49 | } 50 | 51 | - (void)subAckReceived:(MQTTSession *)session msgID:(UInt16)msgID grantedQoss:(NSArray*)qoss 52 | { 53 | if (_onSubscribed) 54 | { 55 | TArray qos; 56 | 57 | for (NSNumber *q in qoss) 58 | { 59 | qos.Add([q intValue]); 60 | } 61 | 62 | _onSubscribed(msgID, qos); 63 | } 64 | } 65 | 66 | - (void)unsubAckReceived:(MQTTSession *)session msgID:(UInt16)msgID 67 | { 68 | if (_onUnsubscribed) 69 | { 70 | _onUnsubscribed(msgID); 71 | } 72 | } 73 | 74 | @end -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/MqttDelegate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "Entities/MqttMessage.h" 6 | 7 | #import 8 | 9 | @interface MqttDelegate : NSObject 10 | 11 | @property(nonatomic, copy) void (^onConnected)(); 12 | @property(nonatomic, copy) void (^onDisconnected)(); 13 | @property(nonatomic, copy) void (^onPublished)(int mid); 14 | @property(nonatomic, copy) void (^onMessageReceived)(FMqttMessage message); 15 | @property(nonatomic, copy) void (^onSubscribed)(int mid, TArray qos); 16 | @property(nonatomic, copy) void (^onUnsubscribed)(int mid); 17 | 18 | @end -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/Utils/ConversionUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "ConversionUtils.h" 4 | 5 | MQTTQosLevel ConversionUtils::ConvertIntToQosLevel(int qos) 6 | { 7 | MQTTQosLevel qosLevel = MQTTQosLevelAtMostOnce; 8 | 9 | switch (qos) 10 | { 11 | case 0: 12 | qosLevel = MQTTQosLevelAtMostOnce; 13 | break; 14 | case 1: 15 | qosLevel = MQTTQosLevelAtLeastOnce; 16 | break; 17 | case 2: 18 | qosLevel = MQTTQosLevelExactlyOnce; 19 | break; 20 | default: 21 | UE_LOG(LogTemp, Warning, TEXT("MQTT => ConvertIntToQosLevel wrong input qos value")); 22 | break; 23 | } 24 | 25 | return qosLevel; 26 | } 27 | 28 | int ConversionUtils::GonvertQosLevelToInt(MQTTQosLevel qosLevel) 29 | { 30 | int qos = 0; 31 | 32 | switch (qosLevel) 33 | { 34 | case MQTTQosLevelAtMostOnce: 35 | qos = 0; 36 | break; 37 | case MQTTQosLevelAtLeastOnce: 38 | qos = 1; 39 | break; 40 | case MQTTQosLevelExactlyOnce: 41 | qos = 2; 42 | break; 43 | default: 44 | UE_LOG(LogTemp, Warning, TEXT("MQTT => GonvertQosLevelToInt wrong input qosLevel value")); 45 | break; 46 | } 47 | 48 | return qos; 49 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/IOS/Utils/ConversionUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #import 6 | 7 | class ConversionUtils 8 | { 9 | public: 10 | 11 | static MQTTQosLevel ConvertIntToQosLevel(int qos); 12 | static int GonvertQosLevelToInt(MQTTQosLevel qosLevel); 13 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClient.h" 4 | #include "MqttRunnable.h" 5 | #include "MqttTask.h" 6 | #include "Utils/StringUtils.h" 7 | #include "GenericPlatform/GenericPlatformAffinity.h" 8 | #include "HAL/RunnableThread.h" 9 | 10 | void UMqttClient::BeginDestroy() 11 | { 12 | UMqttClientBase::BeginDestroy(); 13 | 14 | if (Task != nullptr) 15 | { 16 | Task->StopRunning(); 17 | } 18 | } 19 | 20 | void UMqttClient::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 21 | { 22 | OnConnectDelegate = onConnectCallback; 23 | 24 | if (Task != nullptr && Task->IsAlive()) 25 | { 26 | UE_LOG(LogTemp, Warning, TEXT("MQTT => MQTT task is already running. Disconnect and try again")); 27 | return; 28 | } 29 | 30 | if (ClientConfig.ClientId.IsEmpty()) 31 | { 32 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Client ID is not set. Connection cancelled.")); 33 | return; 34 | } 35 | 36 | /** 37 | * All communication between client and broker should be done in a separate thread. 38 | * Runnable task stores thread-safe queue for output messages (subscribe, unsubscribe, publish) 39 | * and receives broker responsen that are redirected to client. 40 | */ 41 | 42 | Task = new FMqttRunnable(this); 43 | 44 | Task->Host = std::string(TCHAR_TO_ANSI(*ClientConfig.HostUrl)); 45 | Task->ClientId = std::string(TCHAR_TO_ANSI(*ClientConfig.ClientId)); 46 | Task->Port = ClientConfig.Port; 47 | 48 | Task->Username = std::string(TCHAR_TO_ANSI(*connectionData.Login)); 49 | Task->Password = std::string(TCHAR_TO_ANSI(*connectionData.Password)); 50 | 51 | Thread = FRunnableThread::Create(Task, TEXT("MQTT"), 0, EThreadPriority::TPri_Normal, FGenericPlatformAffinity::GetNoAffinityMask()); 52 | } 53 | 54 | void UMqttClient::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 55 | { 56 | OnDisconnectDelegate = onDisconnectCallback; 57 | 58 | if (Task != nullptr) 59 | { 60 | Task->StopRunning(); 61 | } 62 | 63 | Task = nullptr; 64 | } 65 | 66 | void UMqttClient::Subscribe(FString topic, int qos) 67 | { 68 | if(Task == nullptr || !Task->IsAlive()) 69 | { 70 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 71 | return; 72 | } 73 | 74 | char* sub = StringUtils::CopyString(topic); 75 | 76 | FMqttSubscribeTaskPtr taskSubscribe = MakeShared();; 77 | taskSubscribe->type = MqttTaskType::Subscribe; 78 | taskSubscribe->qos = qos; 79 | taskSubscribe->sub = sub; 80 | 81 | Task->PushTask(taskSubscribe); 82 | } 83 | 84 | void UMqttClient::Unsubscribe(FString topic) 85 | { 86 | if(Task == nullptr || !Task->IsAlive()) 87 | { 88 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 89 | return; 90 | } 91 | 92 | char* sub = StringUtils::CopyString(topic); 93 | 94 | FMqttUnsubscribeTaskPtr taskUnsubscribe = MakeShared(); 95 | taskUnsubscribe->type = MqttTaskType::Unsubscribe; 96 | taskUnsubscribe->sub = sub; 97 | 98 | Task->PushTask(taskUnsubscribe); 99 | } 100 | 101 | void UMqttClient::Publish(FMqttMessage message) 102 | { 103 | if(Task == nullptr || !Task->IsAlive()) 104 | { 105 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 106 | return; 107 | } 108 | 109 | char* sub = StringUtils::CopyString(message.Topic); 110 | char* msg = StringUtils::CopyString(message.Message); 111 | 112 | FMqttPublishTaskPtr taskPublish = MakeShared(); 113 | taskPublish->type = MqttTaskType::Publish; 114 | taskPublish->topic = sub; 115 | taskPublish->payloadlen = (int)strlen(msg); 116 | taskPublish->payload = msg; 117 | taskPublish->qos = message.Qos; 118 | taskPublish->retain = message.Retain; 119 | 120 | Task->PushTask(taskPublish); 121 | } 122 | 123 | void UMqttClient::Init(FMqttClientConfig configData) 124 | { 125 | ClientConfig = configData; 126 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientBase.h" 6 | #include "CoreMinimal.h" 7 | 8 | #include "MqttClient.generated.h" 9 | 10 | class FMqttRunnable; 11 | 12 | UCLASS() 13 | class UMqttClient : public UMqttClientBase 14 | { 15 | GENERATED_BODY() 16 | 17 | friend class FMqttRunnable; 18 | 19 | public: 20 | 21 | void BeginDestroy() override; 22 | 23 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 24 | 25 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 26 | 27 | void Subscribe(FString topic, int qos) override; 28 | 29 | void Unsubscribe(FString topic) override; 30 | 31 | void Publish(FMqttMessage message) override; 32 | 33 | public: 34 | 35 | void Init(FMqttClientConfig configData) override; 36 | 37 | private: 38 | 39 | FMqttRunnable* Task; 40 | FRunnableThread* Thread; 41 | FMqttClientConfig ClientConfig; 42 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttClientImpl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClientImpl.h" 4 | #include "MqttRunnable.h" 5 | 6 | MqttClientImpl::MqttClientImpl(const char* id) : mosqpp::mosquittopp(id) 7 | { 8 | } 9 | 10 | MqttClientImpl::~MqttClientImpl() 11 | { 12 | } 13 | 14 | void MqttClientImpl::on_connect(int rc) 15 | { 16 | if (rc != 0) 17 | { 18 | return; 19 | } 20 | 21 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Connected")); 22 | 23 | Task->OnConnect(); 24 | } 25 | 26 | void MqttClientImpl::on_disconnect(int rc) 27 | { 28 | if (rc != 0) 29 | { 30 | return; 31 | } 32 | 33 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Disconnected")); 34 | 35 | Task->OnDisconnect(); 36 | } 37 | 38 | void MqttClientImpl::on_publish(int mid) 39 | { 40 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message published")); 41 | 42 | Task->OnPublished(mid); 43 | } 44 | 45 | void MqttClientImpl::on_message(const mosquitto_message* src) 46 | { 47 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message received")); 48 | 49 | FMqttMessage msg; 50 | 51 | msg.Topic = FString(src->topic); 52 | msg.Qos = src->qos; 53 | msg.Retain = src->retain; 54 | int PayloadLength = src->payloadlen; 55 | 56 | void* buffer = malloc(PayloadLength + 1); 57 | ((char*)buffer)[PayloadLength] = 0; 58 | 59 | if (buffer != NULL) 60 | { 61 | memcpy(buffer, src->payload, PayloadLength); 62 | } 63 | 64 | msg.Message = FString(UTF8_TO_TCHAR(buffer)); 65 | 66 | free(buffer); 67 | 68 | // Create a buffer to hold the payload without converting to FString 69 | TArray Buffer; 70 | // Allocate memory for the buffer to hold the payload 71 | Buffer.SetNumZeroed(PayloadLength); 72 | if (PayloadLength > 0) { 73 | // Copy the payload to the buffer 74 | FMemory::Memcpy(Buffer.GetData(), src->payload, PayloadLength); 75 | } 76 | msg.MessageBuffer = Buffer; 77 | 78 | Task->OnMessage(msg); 79 | } 80 | 81 | void MqttClientImpl::on_subscribe(int mid, int qos_count, const int* granted_qos) 82 | { 83 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Subscribed")); 84 | 85 | TArray qos; 86 | 87 | for (auto p = granted_qos; p < granted_qos + qos_count; ++p) 88 | { 89 | qos.Add(*p); 90 | } 91 | 92 | Task->OnSubscribe(mid, qos); 93 | } 94 | 95 | void MqttClientImpl::on_unsubscribe(int mid) 96 | { 97 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Unsubscribed")); 98 | 99 | Task->OnUnsubscribe(mid); 100 | } 101 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttClientImpl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | class FMqttRunnable; 8 | 9 | class MqttClientImpl : public mosqpp::mosquittopp 10 | { 11 | public: 12 | 13 | MqttClientImpl(const char* id); 14 | ~MqttClientImpl(); 15 | 16 | void on_connect(int rc) override; 17 | void on_disconnect(int rc) override; 18 | void on_publish(int mid) override; 19 | void on_message(const struct mosquitto_message * message) override; 20 | void on_subscribe(int mid, int qos_count, const int* granted_qos) override; 21 | void on_unsubscribe(int mid) override; 22 | 23 | FMqttRunnable* Task; 24 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttRunnable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttRunnable.h" 4 | 5 | #include "MqttClient.h" 6 | #include "MqttClientImpl.h" 7 | 8 | #include "Async/Async.h" 9 | 10 | FMqttRunnable::FMqttRunnable(UMqttClient* mqttClient) : FRunnable() 11 | ,TaskQueue(new std::queue()) 12 | ,TaskQueueLock(new FCriticalSection()) 13 | ,client(mqttClient) 14 | { 15 | } 16 | 17 | FMqttRunnable::~FMqttRunnable() 18 | { 19 | if (TaskQueueLock != nullptr) 20 | { 21 | delete TaskQueueLock; 22 | TaskQueueLock = nullptr; 23 | } 24 | 25 | if (TaskQueue != nullptr) 26 | { 27 | delete TaskQueue; 28 | TaskQueue = nullptr; 29 | } 30 | } 31 | 32 | bool FMqttRunnable::Init() 33 | { 34 | bKeepRunning = true; 35 | return true; 36 | } 37 | 38 | void FMqttRunnable::Stop() 39 | { 40 | StopRunning(); 41 | } 42 | 43 | uint32 FMqttRunnable::Run() 44 | { 45 | mosqpp::lib_init(); 46 | 47 | MqttClientImpl connection(ClientId.c_str()); 48 | 49 | connection.max_inflight_messages_set(0); 50 | connection.Task = this; 51 | 52 | int returnCode = 0; 53 | 54 | if (!Username.empty()) 55 | { 56 | connection.username_pw_set(Username.c_str(), Password.c_str()); 57 | } 58 | 59 | returnCode = connection.connect(Host.c_str(), Port, 10); 60 | 61 | if (returnCode != 0) 62 | { 63 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 64 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 65 | bKeepRunning = false; 66 | } 67 | 68 | while (bKeepRunning) 69 | { 70 | TaskQueueLock->Lock(); 71 | 72 | while (TaskQueue != nullptr) 73 | { 74 | if (TaskQueue->empty()) 75 | { 76 | break; 77 | } 78 | 79 | FMqttTaskPtr task = TaskQueue->front(); 80 | TaskQueue->pop(); 81 | 82 | switch (task->type) 83 | { 84 | case MqttTaskType::Subscribe: { 85 | auto taskSubscribe = StaticCastSharedPtr(task); 86 | returnCode = connection.subscribe(NULL, taskSubscribe->sub, taskSubscribe->qos); 87 | break; 88 | } 89 | case MqttTaskType::Unsubscribe: { 90 | auto taskUnsubscribe = StaticCastSharedPtr(task); 91 | returnCode = connection.unsubscribe(NULL, taskUnsubscribe->sub); 92 | break; 93 | } 94 | case MqttTaskType::Publish: { 95 | auto taskPublish = StaticCastSharedPtr(task); 96 | returnCode = connection.publish(NULL, taskPublish->topic, taskPublish->payloadlen, taskPublish->payload, taskPublish->qos, taskPublish->retain); 97 | break; 98 | } 99 | } 100 | 101 | if (returnCode != 0) 102 | { 103 | UE_LOG(LogTemp, Error, TEXT("MQTT => Output error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 104 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 105 | } 106 | } 107 | 108 | TaskQueueLock->Unlock(); 109 | 110 | returnCode = connection.loop(); 111 | 112 | if (returnCode != 0) 113 | { 114 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 115 | 116 | if(returnCode == MOSQ_ERR_CONN_REFUSED) 117 | { 118 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 119 | bKeepRunning = false; 120 | } 121 | else 122 | { 123 | connection.reconnect(); 124 | } 125 | } 126 | } 127 | 128 | returnCode = connection.disconnect(); 129 | 130 | if (returnCode != 0) 131 | { 132 | UE_LOG(LogTemp, Error, TEXT("MQTT => %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 133 | } 134 | 135 | delete TaskQueue; 136 | delete TaskQueueLock; 137 | 138 | TaskQueue = nullptr; 139 | TaskQueueLock = nullptr; 140 | 141 | return 0; 142 | } 143 | 144 | void FMqttRunnable::StopRunning() 145 | { 146 | bKeepRunning = false; 147 | } 148 | 149 | bool FMqttRunnable::IsAlive() const 150 | { 151 | return bKeepRunning; 152 | } 153 | 154 | void FMqttRunnable::PushTask(FMqttTaskPtr task) 155 | { 156 | TaskQueueLock->Lock(); 157 | 158 | if (TaskQueue != nullptr) 159 | { 160 | TaskQueue->push(task); 161 | } 162 | 163 | TaskQueueLock->Unlock(); 164 | } 165 | 166 | void FMqttRunnable::OnConnect() 167 | { 168 | AsyncTask(ENamedThreads::GameThread, [=]() { 169 | client->OnConnectDelegate.ExecuteIfBound(); 170 | }); 171 | } 172 | 173 | void FMqttRunnable::OnDisconnect() 174 | { 175 | AsyncTask(ENamedThreads::GameThread, [=]() { 176 | client->OnDisconnectDelegate.ExecuteIfBound(); 177 | }); 178 | } 179 | 180 | void FMqttRunnable::OnPublished(int mid) 181 | { 182 | AsyncTask(ENamedThreads::GameThread, [=]() { 183 | client->OnPublishDelegate.ExecuteIfBound(mid); 184 | }); 185 | } 186 | 187 | void FMqttRunnable::OnMessage(FMqttMessage message) 188 | { 189 | AsyncTask(ENamedThreads::GameThread, [=]() { 190 | client->OnMessageDelegate.ExecuteIfBound(message); 191 | }); 192 | } 193 | 194 | void FMqttRunnable::OnSubscribe(int mid, const TArray qos) 195 | { 196 | AsyncTask(ENamedThreads::GameThread, [=]() { 197 | client->OnSubscribeDelegate.ExecuteIfBound(mid, qos); 198 | }); 199 | } 200 | 201 | void FMqttRunnable::OnUnsubscribe(int mid) 202 | { 203 | AsyncTask(ENamedThreads::GameThread, [=]() { 204 | client->OnUnsubscribeDelegate.ExecuteIfBound(mid); 205 | }); 206 | } 207 | 208 | void FMqttRunnable::OnError(int errCode, FString message) 209 | { 210 | AsyncTask(ENamedThreads::GameThread, [=]() { 211 | client->OnErrorDelegate.ExecuteIfBound(errCode, message); 212 | }); 213 | } 214 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttRunnable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "HAL/Runnable.h" 7 | 8 | #include "Entities/MqttMessage.h" 9 | #include "MqttTask.h" 10 | 11 | #include 12 | #include 13 | 14 | class UMqttClient; 15 | 16 | class FMqttRunnable : public FRunnable 17 | { 18 | public: 19 | 20 | FMqttRunnable(UMqttClient* mqttClient); 21 | virtual ~FMqttRunnable(); 22 | 23 | bool Init() override; 24 | uint32 Run() override; 25 | void Stop() override; 26 | 27 | void PushTask(FMqttTaskPtr task); 28 | 29 | void StopRunning(); 30 | 31 | bool IsAlive() const; 32 | 33 | private: 34 | 35 | bool bKeepRunning; 36 | 37 | std::queue* TaskQueue; 38 | 39 | FCriticalSection* TaskQueueLock; 40 | 41 | UMqttClient* client; 42 | 43 | public: 44 | 45 | std::string Host; 46 | std::string ClientId; 47 | std::string Username; 48 | std::string Password; 49 | 50 | int32 Port; 51 | 52 | void OnConnect(); 53 | void OnDisconnect(); 54 | void OnPublished(int mid); 55 | void OnMessage(FMqttMessage message); 56 | void OnSubscribe(int mid, const TArray qos); 57 | void OnUnsubscribe(int mid); 58 | void OnError(int errCode, FString message); 59 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttTask.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttTask.h" 4 | 5 | FMqttSubscribeTask::FMqttSubscribeTask() : FMqttTask() 6 | ,qos(0) 7 | ,sub(nullptr) 8 | { 9 | } 10 | 11 | FMqttSubscribeTask::~FMqttSubscribeTask() 12 | { 13 | } 14 | 15 | FMqttUnsubscribeTask::FMqttUnsubscribeTask() : FMqttTask() 16 | ,sub(nullptr) 17 | { 18 | } 19 | 20 | FMqttUnsubscribeTask::~FMqttUnsubscribeTask() 21 | { 22 | if(sub != nullptr) 23 | { 24 | free(sub); 25 | sub = nullptr; 26 | } 27 | } 28 | 29 | FMqttPublishTask::FMqttPublishTask() : FMqttTask() 30 | , topic(nullptr) 31 | , payloadlen(0) 32 | , payload(nullptr) 33 | , qos(0) 34 | , retain(false) 35 | { 36 | } 37 | 38 | FMqttPublishTask::~FMqttPublishTask() 39 | { 40 | if(topic != nullptr) 41 | { 42 | free(topic); 43 | topic = nullptr; 44 | } 45 | 46 | if(payload != nullptr) 47 | { 48 | free(payload); 49 | payload = nullptr; 50 | } 51 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/MqttTask.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | enum class MqttTaskType 6 | { 7 | Publish, 8 | Subscribe, 9 | Unsubscribe, 10 | }; 11 | 12 | struct FMqttTask 13 | { 14 | MqttTaskType type; 15 | }; 16 | 17 | struct FMqttSubscribeTask : public FMqttTask 18 | { 19 | FMqttSubscribeTask(); 20 | virtual ~FMqttSubscribeTask(); 21 | 22 | int qos; 23 | char* sub; 24 | }; 25 | 26 | struct FMqttUnsubscribeTask : public FMqttTask 27 | { 28 | FMqttUnsubscribeTask(); 29 | ~FMqttUnsubscribeTask(); 30 | 31 | char* sub; 32 | }; 33 | 34 | struct FMqttPublishTask : public FMqttTask 35 | { 36 | FMqttPublishTask(); 37 | ~FMqttPublishTask(); 38 | 39 | char* topic; 40 | int payloadlen; 41 | void* payload; 42 | int qos; 43 | bool retain; 44 | }; 45 | 46 | typedef TSharedPtr FMqttSubscribeTaskPtr; 47 | typedef TSharedPtr FMqttUnsubscribeTaskPtr; 48 | typedef TSharedPtr FMqttPublishTaskPtr; 49 | typedef TSharedPtr FMqttTaskPtr; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/Utils/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "StringUtils.h" 4 | 5 | char* StringUtils::CopyString(FString str) 6 | { 7 | auto StringCaster = StringCast(static_cast(*str)); 8 | const char* originalStr = StringCaster.Get(); 9 | 10 | char *copyStr; 11 | size_t str_len; 12 | 13 | if (!originalStr) 14 | { 15 | return nullptr; 16 | } 17 | 18 | str_len = strlen(originalStr) + 1; 19 | 20 | if (nullptr == (copyStr = (char*)malloc(str_len))) 21 | { 22 | return nullptr; 23 | } 24 | 25 | memcpy(copyStr, originalStr, str_len); 26 | 27 | return copyStr; 28 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Linux/Utils/StringUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | class StringUtils 6 | { 7 | public: 8 | 9 | static char* CopyString(FString str); 10 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClient.h" 4 | #include "MqttRunnable.h" 5 | #include "MqttTask.h" 6 | #include "HAL/RunnableThread.h" 7 | #include "Utils/StringUtils.h" 8 | 9 | void UMqttClient::BeginDestroy() 10 | { 11 | UMqttClientBase::BeginDestroy(); 12 | 13 | if (Task != nullptr) 14 | { 15 | Task->StopRunning(); 16 | } 17 | } 18 | 19 | void UMqttClient::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 20 | { 21 | OnConnectDelegate = onConnectCallback; 22 | 23 | if (Task != nullptr && Task->IsAlive()) 24 | { 25 | UE_LOG(LogTemp, Warning, TEXT("MQTT => MQTT task is already running. Disconnect and try again")); 26 | return; 27 | } 28 | 29 | if (ClientConfig.ClientId.IsEmpty()) 30 | { 31 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Client ID is not set. Connection cancelled.")); 32 | return; 33 | } 34 | 35 | /** 36 | * All communication between client and broker should be done in a separate thread. 37 | * Runnable task stores thread-safe queue for output messages (subscribe, unsubscribe, publish) 38 | * and receives broker responsen that are redirected to client. 39 | */ 40 | 41 | Task = new FMqttRunnable(this, ClientConfig.EventLoopDeltaMs); 42 | 43 | Task->Host = std::string(TCHAR_TO_ANSI(*ClientConfig.HostUrl)); 44 | Task->ClientId = std::string(TCHAR_TO_ANSI(*ClientConfig.ClientId)); 45 | Task->Port = ClientConfig.Port; 46 | 47 | Task->Username = std::string(TCHAR_TO_ANSI(*connectionData.Login)); 48 | Task->Password = std::string(TCHAR_TO_ANSI(*connectionData.Password)); 49 | 50 | Thread = FRunnableThread::Create(Task, TEXT("MQTT-Test"), 0, TPri_Normal, FGenericPlatformAffinity::GetNoAffinityMask()); 51 | } 52 | 53 | void UMqttClient::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 54 | { 55 | OnDisconnectDelegate = onDisconnectCallback; 56 | 57 | if (Task != nullptr) 58 | { 59 | Task->StopRunning(); 60 | } 61 | 62 | Task = nullptr; 63 | } 64 | 65 | void UMqttClient::Subscribe(FString topic, int qos) 66 | { 67 | if(Task == nullptr || !Task->IsAlive()) 68 | { 69 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 70 | return; 71 | } 72 | 73 | char* sub = StringUtils::CopyString(topic); 74 | 75 | FMqttSubscribeTaskPtr taskSubscribe = MakeShared();; 76 | taskSubscribe->type = MqttTaskType::Subscribe; 77 | taskSubscribe->qos = qos; 78 | taskSubscribe->sub = sub; 79 | 80 | Task->PushTask(taskSubscribe); 81 | } 82 | 83 | void UMqttClient::Unsubscribe(FString topic) 84 | { 85 | if(Task == nullptr || !Task->IsAlive()) 86 | { 87 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 88 | return; 89 | } 90 | 91 | char* sub = StringUtils::CopyString(topic); 92 | 93 | FMqttUnsubscribeTaskPtr taskUnsubscribe = MakeShared(); 94 | taskUnsubscribe->type = MqttTaskType::Unsubscribe; 95 | taskUnsubscribe->sub = sub; 96 | 97 | Task->PushTask(taskUnsubscribe); 98 | } 99 | 100 | void UMqttClient::Publish(FMqttMessage message) 101 | { 102 | if(Task == nullptr || !Task->IsAlive()) 103 | { 104 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 105 | return; 106 | } 107 | 108 | char* sub = StringUtils::CopyString(message.Topic); 109 | char* msg = StringUtils::CopyString(message.Message); 110 | 111 | FMqttPublishTaskPtr taskPublish = MakeShared(); 112 | taskPublish->type = MqttTaskType::Publish; 113 | taskPublish->topic = sub; 114 | taskPublish->payloadlen = (int)strlen(msg); 115 | taskPublish->payload = msg; 116 | taskPublish->qos = message.Qos; 117 | taskPublish->retain = message.Retain; 118 | 119 | Task->PushTask(taskPublish); 120 | } 121 | 122 | void UMqttClient::Init(FMqttClientConfig configData) 123 | { 124 | ClientConfig = configData; 125 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientBase.h" 6 | #include "CoreMinimal.h" 7 | 8 | #include "MqttClient.generated.h" 9 | 10 | class FMqttRunnable; 11 | class FRunnableThread; 12 | 13 | UCLASS() 14 | class UMqttClient : public UMqttClientBase 15 | { 16 | GENERATED_BODY() 17 | 18 | friend class FMqttRunnable; 19 | 20 | public: 21 | 22 | void BeginDestroy() override; 23 | 24 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 25 | 26 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 27 | 28 | void Subscribe(FString topic, int qos) override; 29 | 30 | void Unsubscribe(FString topic) override; 31 | 32 | void Publish(FMqttMessage message) override; 33 | 34 | public: 35 | 36 | void Init(FMqttClientConfig configData) override; 37 | 38 | private: 39 | 40 | FMqttRunnable* Task; 41 | FRunnableThread* Thread; 42 | FMqttClientConfig ClientConfig; 43 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttClientImpl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClientImpl.h" 4 | #include "MqttRunnable.h" 5 | 6 | MqttClientImpl::MqttClientImpl(const char* id) : mosqpp::mosquittopp(id) 7 | { 8 | } 9 | 10 | MqttClientImpl::~MqttClientImpl() 11 | { 12 | } 13 | 14 | void MqttClientImpl::on_connect(int rc) 15 | { 16 | if (rc != 0) 17 | { 18 | return; 19 | } 20 | 21 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Connected")); 22 | 23 | Task->OnConnect(); 24 | } 25 | 26 | void MqttClientImpl::on_disconnect(int rc) 27 | { 28 | if (rc != 0) 29 | { 30 | return; 31 | } 32 | 33 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Disconnected")); 34 | 35 | Task->OnDisconnect(); 36 | } 37 | 38 | void MqttClientImpl::on_publish(int mid) 39 | { 40 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message published")); 41 | 42 | Task->OnPublished(mid); 43 | } 44 | 45 | void MqttClientImpl::on_message(const mosquitto_message* src) 46 | { 47 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message received")); 48 | 49 | FMqttMessage msg; 50 | 51 | msg.Topic = FString(src->topic); 52 | msg.Qos = src->qos; 53 | msg.Retain = src->retain; 54 | int PayloadLength = src->payloadlen; 55 | 56 | void* buffer = malloc(PayloadLength + 1); 57 | ((char*)buffer)[PayloadLength] = 0; 58 | 59 | if (buffer != NULL) 60 | { 61 | memcpy(buffer, src->payload, PayloadLength); 62 | } 63 | 64 | msg.Message = FString(UTF8_TO_TCHAR(buffer)); 65 | 66 | free(buffer); 67 | 68 | // Create a buffer to hold the payload without converting to FString 69 | TArray Buffer; 70 | // Allocate memory for the buffer to hold the payload 71 | Buffer.SetNumZeroed(PayloadLength); 72 | if (PayloadLength > 0) { 73 | // Copy the payload to the buffer 74 | FMemory::Memcpy(Buffer.GetData(), src->payload, PayloadLength); 75 | } 76 | msg.MessageBuffer = Buffer; 77 | 78 | Task->OnMessage(msg); 79 | } 80 | 81 | void MqttClientImpl::on_subscribe(int mid, int qos_count, const int* granted_qos) 82 | { 83 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Subscribed")); 84 | 85 | TArray qos; 86 | 87 | for (auto p = granted_qos; p < granted_qos + qos_count; ++p) 88 | { 89 | qos.Add(*p); 90 | } 91 | 92 | Task->OnSubscribe(mid, qos); 93 | } 94 | 95 | void MqttClientImpl::on_unsubscribe(int mid) 96 | { 97 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Unsubscribed")); 98 | 99 | Task->OnUnsubscribe(mid); 100 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttClientImpl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | class FMqttRunnable; 8 | 9 | class MqttClientImpl : public mosqpp::mosquittopp 10 | { 11 | public: 12 | 13 | MqttClientImpl(const char* id); 14 | ~MqttClientImpl(); 15 | 16 | void on_connect(int rc) override; 17 | void on_disconnect(int rc) override; 18 | void on_publish(int mid) override; 19 | void on_message(const struct mosquitto_message * message) override; 20 | void on_subscribe(int mid, int qos_count, const int* granted_qos) override; 21 | void on_unsubscribe(int mid) override; 22 | 23 | FMqttRunnable* Task; 24 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttRunnable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttRunnable.h" 4 | 5 | #include "MqttClient.h" 6 | #include "MqttClientImpl.h" 7 | 8 | #include "Async/Async.h" 9 | 10 | FMqttRunnable::FMqttRunnable(UMqttClient* mqttClient, int updateDeltaMs) : FRunnable() 11 | ,iUpdateDeltaMs(updateDeltaMs) 12 | ,TaskQueue(new std::queue()) 13 | ,TaskQueueLock(new FCriticalSection()) 14 | ,client(mqttClient) 15 | { 16 | } 17 | 18 | FMqttRunnable::~FMqttRunnable() 19 | { 20 | if (TaskQueueLock != nullptr) 21 | { 22 | delete TaskQueueLock; 23 | TaskQueueLock = nullptr; 24 | } 25 | 26 | if (TaskQueue != nullptr) 27 | { 28 | delete TaskQueue; 29 | TaskQueue = nullptr; 30 | } 31 | } 32 | 33 | bool FMqttRunnable::Init() 34 | { 35 | bKeepRunning = true; 36 | return true; 37 | } 38 | 39 | void FMqttRunnable::Stop() 40 | { 41 | StopRunning(); 42 | } 43 | 44 | uint32 FMqttRunnable::Run() 45 | { 46 | mosqpp::lib_init(); 47 | 48 | MqttClientImpl connection(ClientId.c_str()); 49 | 50 | connection.max_inflight_messages_set(0); 51 | connection.Task = this; 52 | 53 | int returnCode = 0; 54 | 55 | if (!Username.empty()) 56 | { 57 | connection.username_pw_set(Username.c_str(), Password.c_str()); 58 | } 59 | 60 | returnCode = connection.connect(Host.c_str(), Port, 10); 61 | 62 | if (returnCode != 0) 63 | { 64 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 65 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 66 | bKeepRunning = false; 67 | } 68 | 69 | while (bKeepRunning) 70 | { 71 | TaskQueueLock->Lock(); 72 | 73 | while (TaskQueue != nullptr) 74 | { 75 | if (TaskQueue->empty()) 76 | { 77 | break; 78 | } 79 | 80 | FMqttTaskPtr task = TaskQueue->front(); 81 | TaskQueue->pop(); 82 | 83 | switch (task->type) 84 | { 85 | case MqttTaskType::Subscribe: { 86 | auto taskSubscribe = StaticCastSharedPtr(task); 87 | returnCode = connection.subscribe(NULL, taskSubscribe->sub, taskSubscribe->qos); 88 | break; 89 | } 90 | case MqttTaskType::Unsubscribe: { 91 | auto taskUnsubscribe = StaticCastSharedPtr(task); 92 | returnCode = connection.unsubscribe(NULL, taskUnsubscribe->sub); 93 | break; 94 | } 95 | case MqttTaskType::Publish: { 96 | auto taskPublish = StaticCastSharedPtr(task); 97 | returnCode = connection.publish(NULL, taskPublish->topic, taskPublish->payloadlen, taskPublish->payload, taskPublish->qos, taskPublish->retain); 98 | break; 99 | } 100 | } 101 | 102 | if (returnCode != 0) 103 | { 104 | UE_LOG(LogTemp, Error, TEXT("MQTT => Output error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 105 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 106 | } 107 | } 108 | 109 | TaskQueueLock->Unlock(); 110 | 111 | returnCode = connection.loop(iUpdateDeltaMs); 112 | 113 | if (returnCode != 0) 114 | { 115 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 116 | 117 | if(returnCode == MOSQ_ERR_CONN_REFUSED) 118 | { 119 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 120 | bKeepRunning = false; 121 | } 122 | else 123 | { 124 | connection.reconnect(); 125 | } 126 | } 127 | } 128 | 129 | returnCode = connection.disconnect(); 130 | 131 | if (returnCode != 0) 132 | { 133 | UE_LOG(LogTemp, Error, TEXT("MQTT => %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 134 | } 135 | 136 | delete TaskQueue; 137 | delete TaskQueueLock; 138 | 139 | TaskQueue = nullptr; 140 | TaskQueueLock = nullptr; 141 | 142 | return 0; 143 | } 144 | 145 | void FMqttRunnable::StopRunning() 146 | { 147 | bKeepRunning = false; 148 | } 149 | 150 | bool FMqttRunnable::IsAlive() const 151 | { 152 | return bKeepRunning; 153 | } 154 | 155 | void FMqttRunnable::PushTask(FMqttTaskPtr task) 156 | { 157 | TaskQueueLock->Lock(); 158 | 159 | if (TaskQueue != nullptr) 160 | { 161 | TaskQueue->push(task); 162 | } 163 | 164 | TaskQueueLock->Unlock(); 165 | } 166 | 167 | void FMqttRunnable::OnConnect() 168 | { 169 | AsyncTask(ENamedThreads::GameThread, [=]() { 170 | client->OnConnectDelegate.ExecuteIfBound(); 171 | }); 172 | } 173 | 174 | void FMqttRunnable::OnDisconnect() 175 | { 176 | AsyncTask(ENamedThreads::GameThread, [=]() { 177 | client->OnDisconnectDelegate.ExecuteIfBound(); 178 | }); 179 | } 180 | 181 | void FMqttRunnable::OnPublished(int mid) 182 | { 183 | AsyncTask(ENamedThreads::GameThread, [=]() { 184 | client->OnPublishDelegate.ExecuteIfBound(mid); 185 | }); 186 | } 187 | 188 | void FMqttRunnable::OnMessage(FMqttMessage message) 189 | { 190 | AsyncTask(ENamedThreads::GameThread, [=]() { 191 | client->OnMessageDelegate.ExecuteIfBound(message); 192 | }); 193 | } 194 | 195 | void FMqttRunnable::OnSubscribe(int mid, const TArray qos) 196 | { 197 | AsyncTask(ENamedThreads::GameThread, [=]() { 198 | client->OnSubscribeDelegate.ExecuteIfBound(mid, qos); 199 | }); 200 | } 201 | 202 | void FMqttRunnable::OnUnsubscribe(int mid) 203 | { 204 | AsyncTask(ENamedThreads::GameThread, [=]() { 205 | client->OnUnsubscribeDelegate.ExecuteIfBound(mid); 206 | }); 207 | } 208 | 209 | void FMqttRunnable::OnError(int errCode, FString message) 210 | { 211 | AsyncTask(ENamedThreads::GameThread, [=]() { 212 | client->OnErrorDelegate.ExecuteIfBound(errCode, message); 213 | }); 214 | } 215 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttRunnable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "HAL/Runnable.h" 7 | 8 | #include "Entities/MqttMessage.h" 9 | #include "MqttTask.h" 10 | 11 | #include 12 | #include 13 | 14 | class UMqttClient; 15 | 16 | class FMqttRunnable : public FRunnable 17 | { 18 | public: 19 | 20 | FMqttRunnable(UMqttClient* mqttClient, int updateDeltaMs = -1); 21 | virtual ~FMqttRunnable(); 22 | 23 | bool Init() override; 24 | uint32 Run() override; 25 | void Stop() override; 26 | 27 | void PushTask(FMqttTaskPtr task); 28 | 29 | void StopRunning(); 30 | 31 | bool IsAlive() const; 32 | 33 | private: 34 | 35 | bool bKeepRunning; 36 | 37 | int iUpdateDeltaMs; 38 | 39 | std::queue* TaskQueue; 40 | 41 | FCriticalSection* TaskQueueLock; 42 | 43 | UPROPERTY() 44 | UMqttClient* client; 45 | 46 | public: 47 | 48 | std::string Host; 49 | std::string ClientId; 50 | std::string Username; 51 | std::string Password; 52 | 53 | int32 Port; 54 | 55 | void OnConnect(); 56 | void OnDisconnect(); 57 | void OnPublished(int mid); 58 | void OnMessage(FMqttMessage message); 59 | void OnSubscribe(int mid, const TArray qos); 60 | void OnUnsubscribe(int mid); 61 | void OnError(int errCode, FString message); 62 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttTask.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttTask.h" 4 | 5 | FMqttSubscribeTask::FMqttSubscribeTask() : FMqttTask() 6 | ,qos(0) 7 | ,sub(nullptr) 8 | { 9 | } 10 | 11 | FMqttSubscribeTask::~FMqttSubscribeTask() 12 | { 13 | } 14 | 15 | FMqttUnsubscribeTask::FMqttUnsubscribeTask() : FMqttTask() 16 | ,sub(nullptr) 17 | { 18 | } 19 | 20 | FMqttUnsubscribeTask::~FMqttUnsubscribeTask() 21 | { 22 | if(sub != nullptr) 23 | { 24 | free(sub); 25 | sub = nullptr; 26 | } 27 | } 28 | 29 | FMqttPublishTask::FMqttPublishTask() : FMqttTask() 30 | , topic(nullptr) 31 | , payloadlen(0) 32 | , payload(nullptr) 33 | , qos(0) 34 | , retain(false) 35 | { 36 | } 37 | 38 | FMqttPublishTask::~FMqttPublishTask() 39 | { 40 | if(topic != nullptr) 41 | { 42 | free(topic); 43 | topic = nullptr; 44 | } 45 | 46 | if(payload != nullptr) 47 | { 48 | free(payload); 49 | payload = nullptr; 50 | } 51 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/MqttTask.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | enum class MqttTaskType 6 | { 7 | Publish, 8 | Subscribe, 9 | Unsubscribe, 10 | }; 11 | 12 | struct FMqttTask 13 | { 14 | MqttTaskType type; 15 | }; 16 | 17 | struct FMqttSubscribeTask : public FMqttTask 18 | { 19 | FMqttSubscribeTask(); 20 | virtual ~FMqttSubscribeTask(); 21 | 22 | int qos; 23 | char* sub; 24 | }; 25 | 26 | struct FMqttUnsubscribeTask : public FMqttTask 27 | { 28 | FMqttUnsubscribeTask(); 29 | ~FMqttUnsubscribeTask(); 30 | 31 | char* sub; 32 | }; 33 | 34 | struct FMqttPublishTask : public FMqttTask 35 | { 36 | FMqttPublishTask(); 37 | ~FMqttPublishTask(); 38 | 39 | char* topic; 40 | int payloadlen; 41 | void* payload; 42 | int qos; 43 | bool retain; 44 | }; 45 | 46 | typedef TSharedPtr FMqttSubscribeTaskPtr; 47 | typedef TSharedPtr FMqttUnsubscribeTaskPtr; 48 | typedef TSharedPtr FMqttPublishTaskPtr; 49 | typedef TSharedPtr FMqttTaskPtr; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/Utils/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "StringUtils.h" 4 | 5 | char* StringUtils::CopyString(FString str) 6 | { 7 | auto StringCaster = StringCast(static_cast(*str)); 8 | const char* originalStr = StringCaster.Get(); 9 | 10 | char *copyStr; 11 | size_t str_len; 12 | 13 | if (!originalStr) 14 | { 15 | return nullptr; 16 | } 17 | 18 | str_len = strlen(originalStr) + 1; 19 | 20 | if (nullptr == (copyStr = (char*)malloc(str_len))) 21 | { 22 | return nullptr; 23 | } 24 | 25 | memcpy(copyStr, originalStr, str_len); 26 | 27 | return copyStr; 28 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Mac/Utils/StringUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | class StringUtils 6 | { 7 | public: 8 | 9 | static char* CopyString(FString str); 10 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/MqttClientBase.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClientBase.h" 4 | 5 | UMqttClientBase::~UMqttClientBase() 6 | { 7 | 8 | } 9 | 10 | void UMqttClientBase::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 11 | { 12 | // Not implementable 13 | } 14 | 15 | void UMqttClientBase::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 16 | { 17 | // Not implementable 18 | } 19 | 20 | void UMqttClientBase::Subscribe(FString topic, int qos) 21 | { 22 | // Not implementable 23 | } 24 | 25 | void UMqttClientBase::Unsubscribe(FString topic) 26 | { 27 | // Not implementable 28 | } 29 | 30 | void UMqttClientBase::Publish(FMqttMessage message) 31 | { 32 | // Not implementable 33 | } 34 | 35 | void UMqttClientBase::SetOnPublishHandler(const FOnPublishDelegate& onPublishCallback) 36 | { 37 | OnPublishDelegate = onPublishCallback; 38 | } 39 | 40 | void UMqttClientBase::SetOnMessageHandler(const FOnMessageDelegate& onMessageCallback) 41 | { 42 | OnMessageDelegate = onMessageCallback; 43 | } 44 | 45 | void UMqttClientBase::SetOnSubscribeHandler(const FOnSubscribeDelegate& onSubscribeCallback) 46 | { 47 | OnSubscribeDelegate = onSubscribeCallback; 48 | } 49 | 50 | void UMqttClientBase::SetOnUnsubscribeHandler(const FOnUnsubscribeDelegate& onUnsubscribeCallback) 51 | { 52 | OnUnsubscribeDelegate = onUnsubscribeCallback; 53 | } 54 | 55 | void UMqttClientBase::SetOnErrorHandler(const FOnMqttErrorDelegate& onErrorCallback) 56 | { 57 | OnErrorDelegate = onErrorCallback; 58 | } 59 | 60 | void UMqttClientBase::Init(FMqttClientConfig configData) 61 | { 62 | // Not implementable. Platform specific MQTT-client initialization 63 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/MqttClientBase.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "Interface/MqttClientInterface.h" 6 | 7 | #include "MqttClientBase.generated.h" 8 | 9 | UCLASS() 10 | class UMqttClientBase : public UObject, public IMqttClientInterface 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | 16 | virtual ~UMqttClientBase(); 17 | 18 | UFUNCTION(BlueprintCallable, Category = "MQTT") 19 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 20 | 21 | UFUNCTION(BlueprintCallable, Category = "MQTT") 22 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 23 | 24 | UFUNCTION(BlueprintCallable, Category = "MQTT") 25 | void Subscribe(FString topic, int qos) override; 26 | 27 | UFUNCTION(BlueprintCallable, Category = "MQTT") 28 | void Unsubscribe(FString topic) override; 29 | 30 | UFUNCTION(BlueprintCallable, Category = "MQTT") 31 | void Publish(FMqttMessage message) override; 32 | 33 | UFUNCTION(BlueprintCallable, Category = "MQTT") 34 | void SetOnPublishHandler(const FOnPublishDelegate& onPublishCallback) override; 35 | 36 | UFUNCTION(BlueprintCallable, Category = "MQTT") 37 | void SetOnMessageHandler(const FOnMessageDelegate& onMessageCallback) override; 38 | 39 | UFUNCTION(BlueprintCallable, Category = "MQTT") 40 | void SetOnSubscribeHandler(const FOnSubscribeDelegate& onSubscribeCallback) override; 41 | 42 | UFUNCTION(BlueprintCallable, Category = "MQTT") 43 | void SetOnUnsubscribeHandler(const FOnUnsubscribeDelegate& onUnsubscribeCallback) override; 44 | 45 | UFUNCTION(BlueprintCallable, Category = "MQTT") 46 | void SetOnErrorHandler(const FOnMqttErrorDelegate& onErrorCallback) override; 47 | 48 | public: 49 | 50 | /** Initialize MQTT client (for internal use only) */ 51 | virtual void Init(FMqttClientConfig configData); 52 | 53 | protected: 54 | 55 | UPROPERTY() 56 | FOnConnectDelegate OnConnectDelegate; 57 | UPROPERTY() 58 | FOnDisconnectDelegate OnDisconnectDelegate; 59 | UPROPERTY() 60 | FOnPublishDelegate OnPublishDelegate; 61 | UPROPERTY() 62 | FOnMessageDelegate OnMessageDelegate; 63 | UPROPERTY() 64 | FOnSubscribeDelegate OnSubscribeDelegate; 65 | UPROPERTY() 66 | FOnUnsubscribeDelegate OnUnsubscribeDelegate; 67 | UPROPERTY() 68 | FOnMqttErrorDelegate OnErrorDelegate; 69 | }; 70 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/MqttUtilitiesBPL.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttUtilitiesBPL.h" 4 | 5 | #if PLATFORM_WINDOWS 6 | #include "Windows/MqttClient.h" 7 | #endif 8 | 9 | #if PLATFORM_MAC 10 | #include "Mac/MqttClient.h" 11 | #endif 12 | 13 | #if PLATFORM_IOS 14 | #include "IOS/MqttClient.h" 15 | #endif 16 | 17 | #if PLATFORM_ANDROID 18 | #include "Android/MqttClient.h" 19 | #endif 20 | 21 | #if PLATFORM_LINUX 22 | #include "Linux/MqttClient.h" 23 | #endif 24 | 25 | TScriptInterface UMqttUtilitiesBPL::CreateMqttClient(FMqttClientConfig config) 26 | { 27 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Creating MQTT client...")); 28 | 29 | #if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_IOS || PLATFORM_ANDROID || PLATFORM_LINUX 30 | 31 | UMqttClient* MqttClient = NewObject(); 32 | MqttClient->Init(config); 33 | TScriptInterface MqttClientInterface; 34 | MqttClientInterface.SetObject(MqttClient); 35 | MqttClientInterface.SetInterface(Cast(MqttClient)); 36 | return MqttClientInterface; 37 | #else 38 | return nullptr; 39 | #endif 40 | 41 | } 42 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/MqttUtilitiesModule.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "IMqttUtilitiesModule.h" 4 | #include "Interfaces/IPluginManager.h" 5 | #include "HAL/PlatformProcess.h" 6 | 7 | #define LOCTEXT_NAMESPACE "MqttUtilities" 8 | 9 | class FMqttUtilitiesModule : public IMqttUtilitiesModule 10 | { 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | 14 | private: 15 | 16 | void* mDllHandleMosquitto; 17 | void* mDllHandleMosquittopp; 18 | }; 19 | 20 | IMPLEMENT_MODULE(FMqttUtilitiesModule, MqttUtilities) 21 | 22 | void FMqttUtilitiesModule::StartupModule() 23 | { 24 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 25 | 26 | // For Windows and Mac platforms dynamic libraries should be loaded manually 27 | 28 | #if PLATFORM_WINDOWS 29 | 30 | const FString PluginDir = IPluginManager::Get().FindPlugin(TEXT("MqttUtilities"))->GetBaseDir(); 31 | const FString DLLPath = PluginDir / TEXT("Binaries/Win64/"); 32 | 33 | FPlatformProcess::PushDllDirectory(*DLLPath); 34 | 35 | mDllHandleMosquitto = FPlatformProcess::GetDllHandle(*(DLLPath + "mosquitto.dll")); 36 | mDllHandleMosquittopp = FPlatformProcess::GetDllHandle(*(DLLPath + "mosquittopp.dll")); 37 | 38 | FPlatformProcess::PopDllDirectory(*DLLPath); 39 | 40 | #endif 41 | 42 | #if PLATFORM_MAC 43 | 44 | const FString PluginDir = IPluginManager::Get().FindPlugin(TEXT("MqttUtilities"))->GetBaseDir(); 45 | const FString DLLPath = PluginDir / TEXT("Binaries/Mac/"); 46 | 47 | FPlatformProcess::PushDllDirectory(*DLLPath); 48 | 49 | mDllHandleMosquitto = FPlatformProcess::GetDllHandle(*(DLLPath + "mosquitto.dylib")); 50 | mDllHandleMosquittopp = FPlatformProcess::GetDllHandle(*(DLLPath + "mosquittopp.dylib")); 51 | 52 | FPlatformProcess::PopDllDirectory(*DLLPath); 53 | 54 | #endif 55 | 56 | #if PLATFORM_LINUX 57 | 58 | const FString PluginDir = IPluginManager::Get().FindPlugin(TEXT("MqttUtilities"))->GetBaseDir(); 59 | const FString DLLPath = PluginDir / TEXT("Binaries/Linux/"); 60 | 61 | FPlatformProcess::PushDllDirectory(*DLLPath); 62 | 63 | mDllHandleMosquitto = FPlatformProcess::GetDllHandle(*(DLLPath + "libmosquitto.so")); 64 | mDllHandleMosquittopp = FPlatformProcess::GetDllHandle(*(DLLPath + "libmosquittopp.so")); 65 | 66 | FPlatformProcess::PopDllDirectory(*DLLPath); 67 | 68 | #endif 69 | 70 | } 71 | 72 | void FMqttUtilitiesModule::ShutdownModule() 73 | { 74 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 75 | // we call this function before unloading the module. 76 | 77 | #if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX 78 | 79 | if (mDllHandleMosquitto) 80 | { 81 | FPlatformProcess::FreeDllHandle(mDllHandleMosquitto); 82 | mDllHandleMosquitto = nullptr; 83 | } 84 | 85 | if (mDllHandleMosquittopp) 86 | { 87 | FPlatformProcess::FreeDllHandle(mDllHandleMosquittopp); 88 | mDllHandleMosquittopp = nullptr; 89 | } 90 | 91 | #endif 92 | } 93 | 94 | #undef LOCTEXT_NAMESPACE 95 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClient.h" 4 | #include "MqttRunnable.h" 5 | #include "MqttTask.h" 6 | #include "Utils/StringUtils.h" 7 | #include "GenericPlatform/GenericPlatformAffinity.h" 8 | #include "HAL/RunnableThread.h" 9 | 10 | void UMqttClient::BeginDestroy() 11 | { 12 | UMqttClientBase::BeginDestroy(); 13 | 14 | if (Task != nullptr) 15 | { 16 | Task->StopRunning(); 17 | } 18 | } 19 | 20 | void UMqttClient::Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) 21 | { 22 | OnConnectDelegate = onConnectCallback; 23 | 24 | if (Task != nullptr && Task->IsAlive()) 25 | { 26 | UE_LOG(LogTemp, Warning, TEXT("MQTT => MQTT task is already running. Disconnect and try again")); 27 | return; 28 | } 29 | 30 | if (ClientConfig.ClientId.IsEmpty()) 31 | { 32 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Client ID is not set. Connection cancelled.")); 33 | return; 34 | } 35 | 36 | /** 37 | * All communication between client and broker should be done in a separate thread. 38 | * Runnable task stores thread-safe queue for output messages (subscribe, unsubscribe, publish) 39 | * and receives broker responsen that are redirected to client. 40 | */ 41 | 42 | Task = new FMqttRunnable(this, ClientConfig.EventLoopDeltaMs); 43 | 44 | Task->Host = std::string(TCHAR_TO_ANSI(*ClientConfig.HostUrl)); 45 | Task->ClientId = std::string(TCHAR_TO_ANSI(*ClientConfig.ClientId)); 46 | Task->Port = ClientConfig.Port; 47 | 48 | Task->Username = std::string(TCHAR_TO_ANSI(*connectionData.Login)); 49 | Task->Password = std::string(TCHAR_TO_ANSI(*connectionData.Password)); 50 | 51 | Thread = FRunnableThread::Create(Task, TEXT("MQTT"), 0, EThreadPriority::TPri_Normal, FGenericPlatformAffinity::GetNoAffinityMask()); 52 | } 53 | 54 | void UMqttClient::Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) 55 | { 56 | OnDisconnectDelegate = onDisconnectCallback; 57 | 58 | if (Task != nullptr) 59 | { 60 | Task->StopRunning(); 61 | } 62 | 63 | Task = nullptr; 64 | } 65 | 66 | void UMqttClient::Subscribe(FString topic, int qos) 67 | { 68 | if(Task == nullptr || !Task->IsAlive()) 69 | { 70 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 71 | return; 72 | } 73 | 74 | char* sub = StringUtils::CopyString(topic); 75 | 76 | FMqttSubscribeTaskPtr taskSubscribe = MakeShared();; 77 | taskSubscribe->type = MqttTaskType::Subscribe; 78 | taskSubscribe->qos = qos; 79 | taskSubscribe->sub = sub; 80 | 81 | Task->PushTask(taskSubscribe); 82 | } 83 | 84 | void UMqttClient::Unsubscribe(FString topic) 85 | { 86 | if(Task == nullptr || !Task->IsAlive()) 87 | { 88 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 89 | return; 90 | } 91 | 92 | char* sub = StringUtils::CopyString(topic); 93 | 94 | FMqttUnsubscribeTaskPtr taskUnsubscribe = MakeShared(); 95 | taskUnsubscribe->type = MqttTaskType::Unsubscribe; 96 | taskUnsubscribe->sub = sub; 97 | 98 | Task->PushTask(taskUnsubscribe); 99 | } 100 | 101 | void UMqttClient::Publish(FMqttMessage message) 102 | { 103 | if(Task == nullptr || !Task->IsAlive()) 104 | { 105 | UE_LOG(LogTemp, Warning, TEXT("MQTT => There is no running MQTT task")); 106 | return; 107 | } 108 | 109 | char* sub = StringUtils::CopyString(message.Topic); 110 | char* msg = StringUtils::CopyString(message.Message); 111 | 112 | FMqttPublishTaskPtr taskPublish = MakeShared(); 113 | taskPublish->type = MqttTaskType::Publish; 114 | taskPublish->topic = sub; 115 | taskPublish->payloadlen = (int)strlen(msg); 116 | taskPublish->payload = msg; 117 | taskPublish->qos = message.Qos; 118 | taskPublish->retain = message.Retain; 119 | 120 | Task->PushTask(taskPublish); 121 | } 122 | 123 | void UMqttClient::Init(FMqttClientConfig configData) 124 | { 125 | ClientConfig = configData; 126 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientBase.h" 6 | #include "CoreMinimal.h" 7 | 8 | #include "MqttClient.generated.h" 9 | 10 | class FMqttRunnable; 11 | 12 | UCLASS() 13 | class UMqttClient : public UMqttClientBase 14 | { 15 | GENERATED_BODY() 16 | 17 | friend class FMqttRunnable; 18 | 19 | public: 20 | 21 | void BeginDestroy() override; 22 | 23 | void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) override; 24 | 25 | void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) override; 26 | 27 | void Subscribe(FString topic, int qos) override; 28 | 29 | void Unsubscribe(FString topic) override; 30 | 31 | void Publish(FMqttMessage message) override; 32 | 33 | public: 34 | 35 | void Init(FMqttClientConfig configData) override; 36 | 37 | private: 38 | 39 | FMqttRunnable* Task; 40 | FRunnableThread* Thread; 41 | FMqttClientConfig ClientConfig; 42 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttClientImpl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttClientImpl.h" 4 | #include "MqttRunnable.h" 5 | 6 | MqttClientImpl::MqttClientImpl(const char* id) : mosqpp::mosquittopp(id) 7 | { 8 | } 9 | 10 | MqttClientImpl::~MqttClientImpl() 11 | { 12 | } 13 | 14 | void MqttClientImpl::on_connect(int rc) 15 | { 16 | if (rc != 0) 17 | { 18 | return; 19 | } 20 | 21 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Connected")); 22 | 23 | Task->OnConnect(); 24 | } 25 | 26 | void MqttClientImpl::on_disconnect(int rc) 27 | { 28 | if (rc != 0) 29 | { 30 | return; 31 | } 32 | 33 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Disconnected")); 34 | 35 | Task->OnDisconnect(); 36 | } 37 | 38 | void MqttClientImpl::on_publish(int mid) 39 | { 40 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message published")); 41 | 42 | Task->OnPublished(mid); 43 | } 44 | 45 | void MqttClientImpl::on_message(const mosquitto_message* src) 46 | { 47 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Message received")); 48 | 49 | FMqttMessage msg; 50 | 51 | msg.Topic = FString(src->topic); 52 | msg.Qos = src->qos; 53 | msg.Retain = src->retain; 54 | int PayloadLength = src->payloadlen; 55 | 56 | void* buffer = malloc(PayloadLength + 1); 57 | ((char*)buffer)[PayloadLength] = 0; 58 | 59 | if (buffer != NULL) 60 | { 61 | memcpy(buffer, src->payload, PayloadLength); 62 | } 63 | 64 | msg.Message = FString(UTF8_TO_TCHAR(buffer)); 65 | 66 | free(buffer); 67 | 68 | // Create a buffer to hold the payload without converting to FString 69 | TArray Buffer; 70 | // Allocate memory for the buffer to hold the payload 71 | Buffer.SetNumZeroed(PayloadLength); 72 | if (PayloadLength > 0) { 73 | // Copy the payload to the buffer 74 | FMemory::Memcpy(Buffer.GetData(), src->payload, PayloadLength); 75 | } 76 | msg.MessageBuffer = Buffer; 77 | 78 | Task->OnMessage(msg); 79 | } 80 | 81 | void MqttClientImpl::on_subscribe(int mid, int qos_count, const int* granted_qos) 82 | { 83 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Subscribed")); 84 | 85 | TArray qos; 86 | 87 | for (auto p = granted_qos; p < granted_qos + qos_count; ++p) 88 | { 89 | qos.Add(*p); 90 | } 91 | 92 | Task->OnSubscribe(mid, qos); 93 | } 94 | 95 | void MqttClientImpl::on_unsubscribe(int mid) 96 | { 97 | UE_LOG(LogTemp, Warning, TEXT("MQTT => Impl: Unsubscribed")); 98 | 99 | Task->OnUnsubscribe(mid); 100 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttClientImpl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | class FMqttRunnable; 8 | 9 | class MqttClientImpl : public mosqpp::mosquittopp 10 | { 11 | public: 12 | 13 | MqttClientImpl(const char* id); 14 | ~MqttClientImpl(); 15 | 16 | void on_connect(int rc) override; 17 | void on_disconnect(int rc) override; 18 | void on_publish(int mid) override; 19 | void on_message(const struct mosquitto_message * message) override; 20 | void on_subscribe(int mid, int qos_count, const int* granted_qos) override; 21 | void on_unsubscribe(int mid) override; 22 | 23 | FMqttRunnable* Task; 24 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttRunnable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttRunnable.h" 4 | 5 | #include "MqttClient.h" 6 | #include "MqttClientImpl.h" 7 | 8 | #include "Async/Async.h" 9 | 10 | FMqttRunnable::FMqttRunnable(UMqttClient* mqttClient, int updateDeltaMs) : FRunnable() 11 | ,iUpdateDeltaMs(updateDeltaMs) 12 | ,TaskQueue(new std::queue()) 13 | ,TaskQueueLock(new FCriticalSection()) 14 | ,client(mqttClient) 15 | { 16 | } 17 | 18 | FMqttRunnable::~FMqttRunnable() 19 | { 20 | if (TaskQueueLock != nullptr) 21 | { 22 | delete TaskQueueLock; 23 | TaskQueueLock = nullptr; 24 | } 25 | 26 | if (TaskQueue != nullptr) 27 | { 28 | delete TaskQueue; 29 | TaskQueue = nullptr; 30 | } 31 | } 32 | 33 | bool FMqttRunnable::Init() 34 | { 35 | bKeepRunning = true; 36 | return true; 37 | } 38 | 39 | void FMqttRunnable::Stop() 40 | { 41 | StopRunning(); 42 | } 43 | 44 | uint32 FMqttRunnable::Run() 45 | { 46 | mosqpp::lib_init(); 47 | 48 | MqttClientImpl connection(ClientId.c_str()); 49 | 50 | connection.max_inflight_messages_set(0); 51 | connection.Task = this; 52 | 53 | int returnCode = 0; 54 | 55 | if (!Username.empty()) 56 | { 57 | connection.username_pw_set(Username.c_str(), Password.c_str()); 58 | } 59 | 60 | returnCode = connection.connect(Host.c_str(), Port, 10); 61 | 62 | if (returnCode != 0) 63 | { 64 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 65 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 66 | bKeepRunning = false; 67 | } 68 | 69 | while (bKeepRunning) 70 | { 71 | TaskQueueLock->Lock(); 72 | 73 | while (TaskQueue != nullptr) 74 | { 75 | if (TaskQueue->empty()) 76 | { 77 | break; 78 | } 79 | 80 | FMqttTaskPtr task = TaskQueue->front(); 81 | TaskQueue->pop(); 82 | 83 | switch (task->type) 84 | { 85 | case MqttTaskType::Subscribe: { 86 | auto taskSubscribe = StaticCastSharedPtr(task); 87 | returnCode = connection.subscribe(NULL, taskSubscribe->sub, taskSubscribe->qos); 88 | break; 89 | } 90 | case MqttTaskType::Unsubscribe: { 91 | auto taskUnsubscribe = StaticCastSharedPtr(task); 92 | returnCode = connection.unsubscribe(NULL, taskUnsubscribe->sub); 93 | break; 94 | } 95 | case MqttTaskType::Publish: { 96 | auto taskPublish = StaticCastSharedPtr(task); 97 | returnCode = connection.publish(NULL, taskPublish->topic, taskPublish->payloadlen, taskPublish->payload, taskPublish->qos, taskPublish->retain); 98 | break; 99 | } 100 | } 101 | 102 | if (returnCode != 0) 103 | { 104 | UE_LOG(LogTemp, Error, TEXT("MQTT => Output error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 105 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 106 | } 107 | } 108 | 109 | TaskQueueLock->Unlock(); 110 | 111 | returnCode = connection.loop(iUpdateDeltaMs); 112 | 113 | if (returnCode != 0) 114 | { 115 | UE_LOG(LogTemp, Error, TEXT("MQTT => Connection error: %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 116 | 117 | if(returnCode == MOSQ_ERR_CONN_REFUSED) 118 | { 119 | OnError(returnCode, FString(ANSI_TO_TCHAR(mosquitto_strerror(returnCode)))); 120 | bKeepRunning = false; 121 | } 122 | else 123 | { 124 | connection.reconnect(); 125 | } 126 | } 127 | } 128 | 129 | returnCode = connection.disconnect(); 130 | 131 | if (returnCode != 0) 132 | { 133 | UE_LOG(LogTemp, Error, TEXT("MQTT => %s"), ANSI_TO_TCHAR(mosquitto_strerror(returnCode))); 134 | } 135 | 136 | delete TaskQueue; 137 | delete TaskQueueLock; 138 | 139 | TaskQueue = nullptr; 140 | TaskQueueLock = nullptr; 141 | 142 | return 0; 143 | } 144 | 145 | void FMqttRunnable::StopRunning() 146 | { 147 | bKeepRunning = false; 148 | } 149 | 150 | bool FMqttRunnable::IsAlive() const 151 | { 152 | return bKeepRunning; 153 | } 154 | 155 | void FMqttRunnable::PushTask(FMqttTaskPtr task) 156 | { 157 | TaskQueueLock->Lock(); 158 | 159 | if (TaskQueue != nullptr) 160 | { 161 | TaskQueue->push(task); 162 | } 163 | 164 | TaskQueueLock->Unlock(); 165 | } 166 | 167 | void FMqttRunnable::OnConnect() 168 | { 169 | AsyncTask(ENamedThreads::GameThread, [this]() { 170 | client->OnConnectDelegate.ExecuteIfBound(); 171 | }); 172 | } 173 | 174 | void FMqttRunnable::OnDisconnect() 175 | { 176 | AsyncTask(ENamedThreads::GameThread, [this]() { 177 | client->OnDisconnectDelegate.ExecuteIfBound(); 178 | }); 179 | } 180 | 181 | void FMqttRunnable::OnPublished(int mid) 182 | { 183 | AsyncTask(ENamedThreads::GameThread, [this, mid]() { 184 | client->OnPublishDelegate.ExecuteIfBound(mid); 185 | }); 186 | } 187 | 188 | void FMqttRunnable::OnMessage(FMqttMessage message) 189 | { 190 | AsyncTask(ENamedThreads::GameThread, [this, message]() { 191 | client->OnMessageDelegate.ExecuteIfBound(message); 192 | }); 193 | } 194 | 195 | void FMqttRunnable::OnSubscribe(int mid, const TArray qos) 196 | { 197 | AsyncTask(ENamedThreads::GameThread, [this, mid, qos]() { 198 | client->OnSubscribeDelegate.ExecuteIfBound(mid, qos); 199 | }); 200 | } 201 | 202 | 203 | void FMqttRunnable::OnUnsubscribe(int mid) 204 | { 205 | AsyncTask(ENamedThreads::GameThread, [this, mid]() { 206 | client->OnUnsubscribeDelegate.ExecuteIfBound(mid); 207 | }); 208 | } 209 | 210 | 211 | void FMqttRunnable::OnError(int errCode, FString message) 212 | { 213 | AsyncTask(ENamedThreads::GameThread, [this, errCode, message]() { 214 | client->OnErrorDelegate.ExecuteIfBound(errCode, message); 215 | }); 216 | } 217 | 218 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttRunnable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "HAL/Runnable.h" 7 | 8 | #include "Entities/MqttMessage.h" 9 | #include "MqttTask.h" 10 | 11 | #include 12 | #include 13 | 14 | class UMqttClient; 15 | 16 | class FMqttRunnable : public FRunnable 17 | { 18 | public: 19 | 20 | FMqttRunnable(UMqttClient* mqttClient, int updateDeltaMs = -1); 21 | virtual ~FMqttRunnable(); 22 | 23 | bool Init() override; 24 | uint32 Run() override; 25 | void Stop() override; 26 | 27 | void PushTask(FMqttTaskPtr task); 28 | 29 | void StopRunning(); 30 | 31 | bool IsAlive() const; 32 | 33 | private: 34 | 35 | bool bKeepRunning; 36 | 37 | int iUpdateDeltaMs; 38 | 39 | std::queue* TaskQueue; 40 | 41 | FCriticalSection* TaskQueueLock; 42 | 43 | UPROPERTY() 44 | UMqttClient* client; 45 | 46 | public: 47 | 48 | std::string Host; 49 | std::string ClientId; 50 | std::string Username; 51 | std::string Password; 52 | 53 | int32 Port; 54 | 55 | void OnConnect(); 56 | void OnDisconnect(); 57 | void OnPublished(int mid); 58 | void OnMessage(FMqttMessage message); 59 | void OnSubscribe(int mid, const TArray qos); 60 | void OnUnsubscribe(int mid); 61 | void OnError(int errCode, FString message); 62 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttTask.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "MqttTask.h" 4 | 5 | FMqttSubscribeTask::FMqttSubscribeTask() : FMqttTask() 6 | ,qos(0) 7 | ,sub(nullptr) 8 | { 9 | } 10 | 11 | FMqttSubscribeTask::~FMqttSubscribeTask() 12 | { 13 | } 14 | 15 | FMqttUnsubscribeTask::FMqttUnsubscribeTask() : FMqttTask() 16 | ,sub(nullptr) 17 | { 18 | } 19 | 20 | FMqttUnsubscribeTask::~FMqttUnsubscribeTask() 21 | { 22 | if(sub != nullptr) 23 | { 24 | free(sub); 25 | sub = nullptr; 26 | } 27 | } 28 | 29 | FMqttPublishTask::FMqttPublishTask() : FMqttTask() 30 | , topic(nullptr) 31 | , payloadlen(0) 32 | , payload(nullptr) 33 | , qos(0) 34 | , retain(false) 35 | { 36 | } 37 | 38 | FMqttPublishTask::~FMqttPublishTask() 39 | { 40 | if(topic != nullptr) 41 | { 42 | free(topic); 43 | topic = nullptr; 44 | } 45 | 46 | if(payload != nullptr) 47 | { 48 | free(payload); 49 | payload = nullptr; 50 | } 51 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/MqttTask.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | enum class MqttTaskType 6 | { 7 | Publish, 8 | Subscribe, 9 | Unsubscribe, 10 | }; 11 | 12 | struct FMqttTask 13 | { 14 | MqttTaskType type; 15 | }; 16 | 17 | struct FMqttSubscribeTask : public FMqttTask 18 | { 19 | FMqttSubscribeTask(); 20 | virtual ~FMqttSubscribeTask(); 21 | 22 | int qos; 23 | char* sub; 24 | }; 25 | 26 | struct FMqttUnsubscribeTask : public FMqttTask 27 | { 28 | FMqttUnsubscribeTask(); 29 | ~FMqttUnsubscribeTask(); 30 | 31 | char* sub; 32 | }; 33 | 34 | struct FMqttPublishTask : public FMqttTask 35 | { 36 | FMqttPublishTask(); 37 | ~FMqttPublishTask(); 38 | 39 | char* topic; 40 | int payloadlen; 41 | void* payload; 42 | int qos; 43 | bool retain; 44 | }; 45 | 46 | typedef TSharedPtr FMqttSubscribeTaskPtr; 47 | typedef TSharedPtr FMqttUnsubscribeTaskPtr; 48 | typedef TSharedPtr FMqttPublishTaskPtr; 49 | typedef TSharedPtr FMqttTaskPtr; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/Utils/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #include "StringUtils.h" 4 | 5 | char* StringUtils::CopyString(FString str) 6 | { 7 | auto StringCaster = StringCast(static_cast(*str)); 8 | const char* originalStr = StringCaster.Get(); 9 | 10 | char *copyStr; 11 | size_t str_len; 12 | 13 | if (!originalStr) 14 | { 15 | return nullptr; 16 | } 17 | 18 | str_len = strlen(originalStr) + 1; 19 | 20 | if (nullptr == (copyStr = (char*)malloc(str_len))) 21 | { 22 | return nullptr; 23 | } 24 | 25 | memcpy(copyStr, originalStr, str_len); 26 | 27 | return copyStr; 28 | } -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Private/Windows/Utils/StringUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | class StringUtils 6 | { 7 | public: 8 | 9 | static char* CopyString(FString str); 10 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/Entities/MqttClientConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttClientConfig.generated.h" 6 | 7 | USTRUCT(BlueprintType) 8 | struct MQTTUTILITIES_API FMqttClientConfig 9 | { 10 | GENERATED_BODY() 11 | 12 | /** Host URL. */ 13 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 14 | FString HostUrl; 15 | 16 | /** Host port. */ 17 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 18 | int Port; 19 | 20 | /** Unique client identifier. */ 21 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 22 | FString ClientId; 23 | 24 | /** Maximum time between two pusblish/subscribe tasks executions expressed in miliseconds. */ 25 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 26 | int EventLoopDeltaMs{-1}; 27 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/Entities/MqttConnectionData.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttConnectionData.generated.h" 6 | 7 | USTRUCT(BlueprintType) 8 | struct MQTTUTILITIES_API FMqttConnectionData 9 | { 10 | GENERATED_BODY() 11 | 12 | /** User login. */ 13 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 14 | FString Login; 15 | 16 | /** User password. */ 17 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 18 | FString Password; 19 | }; 20 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/Entities/MqttMessage.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "MqttMessage.generated.h" 6 | 7 | USTRUCT(BlueprintType) 8 | struct MQTTUTILITIES_API FMqttMessage 9 | { 10 | GENERATED_BODY() 11 | 12 | /** Message content. */ 13 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 14 | FString Message; 15 | 16 | /** Message content buffer. */ 17 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 18 | TArray MessageBuffer; 19 | 20 | /** Message topic. */ 21 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 22 | FString Topic; 23 | 24 | /** Retain flag. */ 25 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 26 | bool Retain; 27 | 28 | /** Quality of signal. */ 29 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTT") 30 | int Qos; 31 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/IMqttUtilitiesModule.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "Modules/ModuleManager.h" 6 | 7 | class IMqttUtilitiesModule : public IModuleInterface 8 | { 9 | public: 10 | 11 | static inline IMqttUtilitiesModule& Get() 12 | { 13 | return FModuleManager::LoadModuleChecked("MqttUtilities"); 14 | } 15 | 16 | static inline bool IsAvailable() 17 | { 18 | return FModuleManager::Get().IsModuleLoaded("MqttUtilities"); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/Interface/MqttClientInterface.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "UObject/Interface.h" 6 | 7 | #include "Entities/MqttMessage.h" 8 | #include "Entities/MqttConnectionData.h" 9 | #include "Entities/MqttClientConfig.h" 10 | 11 | #include "MqttClientInterface.generated.h" 12 | 13 | DECLARE_DYNAMIC_DELEGATE(FOnConnectDelegate); 14 | DECLARE_DYNAMIC_DELEGATE(FOnDisconnectDelegate); 15 | DECLARE_DYNAMIC_DELEGATE_OneParam(FOnPublishDelegate, int, mid); 16 | DECLARE_DYNAMIC_DELEGATE_OneParam(FOnMessageDelegate, FMqttMessage, message); 17 | DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnSubscribeDelegate, int, mid, const TArray&, qos); 18 | DECLARE_DYNAMIC_DELEGATE_OneParam(FOnUnsubscribeDelegate, int, mid); 19 | DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnMqttErrorDelegate, int, code, FString, message); 20 | 21 | UINTERFACE(BlueprintType, meta = (CannotImplementInterfaceInBlueprint)) 22 | class MQTTUTILITIES_API UMqttClientInterface : public UInterface 23 | { 24 | GENERATED_BODY() 25 | }; 26 | 27 | class MQTTUTILITIES_API IMqttClientInterface 28 | { 29 | GENERATED_BODY() 30 | 31 | public: 32 | 33 | /** 34 | * Connect to MQTT broker 35 | * @param connectionData - structure with data required to connect to MQTT broker (host url, port, client id etc.) 36 | * @param onConnectCallback - callback function handler triigered after client successfully established connection with MQTT broker 37 | */ 38 | UFUNCTION(BlueprintCallable, Category = "MQTT") 39 | virtual void Connect(FMqttConnectionData connectionData, const FOnConnectDelegate& onConnectCallback) = 0; 40 | 41 | /** 42 | * Disconnect from MQTT broker 43 | * @param onDisconnectCallback - callback function handler triigered after client was disconnected from MQTT broker 44 | */ 45 | UFUNCTION(BlueprintCallable, Category = "MQTT") 46 | virtual void Disconnect(const FOnDisconnectDelegate& onDisconnectCallback) = 0; 47 | 48 | /** 49 | * Subscribe to topic 50 | * @param topic - name of the topic 51 | * @param qos - level of quality of service 52 | */ 53 | UFUNCTION(BlueprintCallable, Category = "MQTT") 54 | virtual void Subscribe(FString topic, int qos) = 0; 55 | 56 | /** 57 | * Unsubscribe from topic 58 | * @param topic - name of the topic 59 | */ 60 | UFUNCTION(BlueprintCallable, Category = "MQTT") 61 | virtual void Unsubscribe(FString topic) = 0; 62 | 63 | /** 64 | * Publish message 65 | * @param message - structure with message data (topic, QoS, payload etc.) 66 | */ 67 | UFUNCTION(BlueprintCallable, Category = "MQTT") 68 | virtual void Publish(FMqttMessage message) = 0; 69 | 70 | /** 71 | * Set handler for message publishing event 72 | * @param onPublishCallback - callback function handler triigered after client message was published to MQTT broker 73 | */ 74 | UFUNCTION(BlueprintCallable, Category = "MQTT") 75 | virtual void SetOnPublishHandler(const FOnPublishDelegate& onPublishCallback) = 0; 76 | 77 | /** 78 | * Set handler for message receiving event 79 | * @param onMessageCallback - callback function handler triigered after client received message from MQTT broker 80 | */ 81 | UFUNCTION(BlueprintCallable, Category = "MQTT") 82 | virtual void SetOnMessageHandler(const FOnMessageDelegate& onMessageCallback) = 0; 83 | 84 | /** 85 | * Set handler for subscription event 86 | * @param onSubscribeCallback - callback function handler triigered after client subscribed to topic exposed by MQTT broker 87 | */ 88 | UFUNCTION(BlueprintCallable, Category = "MQTT") 89 | virtual void SetOnSubscribeHandler(const FOnSubscribeDelegate& onSubscribeCallback) = 0; 90 | 91 | /** 92 | * Set handler for unsubscription event 93 | * @param onUnsubscribeCallback - callback function handler triigered after client unsubscribed from topic exposed by MQTT broker 94 | */ 95 | UFUNCTION(BlueprintCallable, Category = "MQTT") 96 | virtual void SetOnUnsubscribeHandler(const FOnUnsubscribeDelegate& onUnsubscribeCallback) = 0; 97 | 98 | /** 99 | * Set handler for error event 100 | * @param onErrorCallback - callback function handler triigered after any MQTT-related error occured 101 | */ 102 | UFUNCTION(BlueprintCallable, Category = "MQTT") 103 | virtual void SetOnErrorHandler(const FOnMqttErrorDelegate& onErrorCallback) = 0; 104 | }; 105 | -------------------------------------------------------------------------------- /MqttUtilities/Source/MqttUtilities/Public/MqttUtilitiesBPL.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 Nineva Studios 2 | 3 | #pragma once 4 | 5 | #include "Interface/MqttClientInterface.h" 6 | #include "Entities/MqttClientConfig.h" 7 | 8 | #include "Kismet/BlueprintFunctionLibrary.h" 9 | 10 | #include "MqttUtilitiesBPL.generated.h" 11 | 12 | UCLASS() 13 | class MQTTUTILITIES_API UMqttUtilitiesBPL : public UBlueprintFunctionLibrary 14 | { 15 | GENERATED_BODY() 16 | 17 | /** 18 | * Create new instance of MQTT client 19 | * 20 | * @return - reference to MQTT client interface object 21 | */ 22 | public: 23 | UFUNCTION(BlueprintCallable, Category = "MQTT") 24 | static TScriptInterface CreateMqttClient(FMqttClientConfig config); 25 | }; -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/IOS/MQTTClient.embeddedframework.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/IOS/MQTTClient.embeddedframework.zip -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/IOS/SocketRocket.embeddedframework.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/IOS/SocketRocket.embeddedframework.zip -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/alias_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef ALIAS_MOSQ_H 20 | #define ALIAS_MOSQ_H 21 | 22 | #include "mosquitto_internal.h" 23 | 24 | int alias__add(struct mosquitto *mosq, const char *topic, uint16_t alias); 25 | int alias__find(struct mosquitto *mosq, char **topic, uint16_t alias); 26 | void alias__free_all(struct mosquitto *mosq); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/dummypthread.h: -------------------------------------------------------------------------------- 1 | #ifndef DUMMYPTHREAD_H 2 | #define DUMMYPTHREAD_H 3 | 4 | #define pthread_create(A, B, C, D) 5 | #define pthread_join(A, B) 6 | #define pthread_cancel(A) 7 | #define pthread_testcancel() 8 | 9 | #define pthread_mutex_init(A, B) 10 | #define pthread_mutex_destroy(A) 11 | #define pthread_mutex_lock(A) 12 | #define pthread_mutex_unlock(A) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/logging_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef LOGGING_MOSQ_H 19 | #define LOGGING_MOSQ_H 20 | 21 | #include "mosquitto.h" 22 | 23 | #ifndef __GNUC__ 24 | #define __attribute__(attrib) 25 | #endif 26 | 27 | int log__printf(struct mosquitto *mosq, unsigned int level, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/memory_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef MEMORY_MOSQ_H 20 | #define MEMORY_MOSQ_H 21 | 22 | #include 23 | #include 24 | 25 | #if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) 26 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__GLIBC__) 27 | # define REAL_WITH_MEMORY_TRACKING 28 | # endif 29 | #endif 30 | 31 | void *mosquitto__calloc(size_t nmemb, size_t size); 32 | void mosquitto__free(void *mem); 33 | void *mosquitto__malloc(size_t size); 34 | #ifdef REAL_WITH_MEMORY_TRACKING 35 | unsigned long mosquitto__memory_used(void); 36 | unsigned long mosquitto__max_memory_used(void); 37 | #endif 38 | void *mosquitto__realloc(void *ptr, size_t size); 39 | char *mosquitto__strdup(const char *s); 40 | 41 | #ifdef WITH_BROKER 42 | void memory__set_limit(size_t lim); 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/messages_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef MESSAGES_MOSQ_H 19 | #define MESSAGES_MOSQ_H 20 | 21 | #include "mosquitto_internal.h" 22 | #include "mosquitto.h" 23 | 24 | void message__cleanup_all(struct mosquitto *mosq); 25 | void message__cleanup(struct mosquitto_message_all **message); 26 | int message__delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, int qos); 27 | int message__queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); 28 | void message__reconnect_reset(struct mosquitto *mosq, bool update_quota_only); 29 | int message__release_to_inflight(struct mosquitto *mosq, enum mosquitto_msg_direction dir); 30 | int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message, int qos); 31 | void message__retry_check(struct mosquitto *mosq); 32 | int message__out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state, int qos); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/misc_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef MISC_MOSQ_H 19 | #define MISC_MOSQ_H 20 | 21 | #include 22 | #include 23 | 24 | FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read); 25 | char *misc__trimblanks(char *str); 26 | char *fgets_extending(char **buf, int *buflen, FILE *stream); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/net_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef NET_MOSQ_H 19 | #define NET_MOSQ_H 20 | 21 | #ifndef WIN32 22 | # include 23 | #else 24 | # include 25 | # ifndef _SSIZE_T_DEFINED 26 | typedef SSIZE_T ssize_t; 27 | # define _SSIZE_T_DEFINED 28 | # endif 29 | #endif 30 | 31 | #include "mosquitto_internal.h" 32 | #include "mosquitto.h" 33 | 34 | #ifdef WIN32 35 | # define COMPAT_CLOSE(a) closesocket(a) 36 | # define COMPAT_ECONNRESET WSAECONNRESET 37 | # define COMPAT_EINTR WSAEINTR 38 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK 39 | # ifndef EINPROGRESS 40 | # define EINPROGRESS WSAEINPROGRESS 41 | # endif 42 | #else 43 | # define COMPAT_CLOSE(a) close(a) 44 | # define COMPAT_ECONNRESET ECONNRESET 45 | # define COMPAT_EINTR EINTR 46 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK 47 | #endif 48 | 49 | /* For when not using winsock libraries. */ 50 | #ifndef INVALID_SOCKET 51 | #define INVALID_SOCKET -1 52 | #endif 53 | 54 | /* Macros for accessing the MSB and LSB of a uint16_t */ 55 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) 56 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF) 57 | 58 | int net__init(void); 59 | void net__cleanup(void); 60 | 61 | #ifdef WITH_TLS 62 | void net__init_tls(void); 63 | #endif 64 | 65 | int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); 66 | int net__socket_close(struct mosquitto *mosq); 67 | int net__try_connect(const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); 68 | int net__try_connect_step1(struct mosquitto *mosq, const char *host); 69 | int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock); 70 | int net__socket_connect_step3(struct mosquitto *mosq, const char *host); 71 | int net__socket_nonblock(mosq_sock_t *sock); 72 | int net__socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); 73 | 74 | ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count); 75 | ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count); 76 | 77 | #ifdef WITH_TLS 78 | void net__print_ssl_error(struct mosquitto *mosq); 79 | int net__socket_apply_tls(struct mosquitto *mosq); 80 | int net__socket_connect_tls(struct mosquitto *mosq); 81 | int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg); 82 | UI_METHOD *net__get_ui_method(void); 83 | #define ENGINE_FINISH(e) if(e) ENGINE_finish(e) 84 | #define ENGINE_SECRET_MODE "SECRET_MODE" 85 | #define ENGINE_SECRET_MODE_SHA 0x1000 86 | #define ENGINE_PIN "PIN" 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/packet_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef PACKET_MOSQ_H 19 | #define PACKET_MOSQ_H 20 | 21 | #include "mosquitto_internal.h" 22 | #include "mosquitto.h" 23 | 24 | int packet__alloc(struct mosquitto__packet *packet); 25 | void packet__cleanup(struct mosquitto__packet *packet); 26 | void packet__cleanup_all(struct mosquitto *mosq); 27 | void packet__cleanup_all_no_locks(struct mosquitto *mosq); 28 | int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet); 29 | 30 | int packet__check_oversize(struct mosquitto *mosq, uint32_t remaining_length); 31 | 32 | int packet__read_byte(struct mosquitto__packet *packet, uint8_t *byte); 33 | int packet__read_bytes(struct mosquitto__packet *packet, void *bytes, uint32_t count); 34 | int packet__read_binary(struct mosquitto__packet *packet, uint8_t **data, uint16_t *length); 35 | int packet__read_string(struct mosquitto__packet *packet, char **str, uint16_t *length); 36 | int packet__read_uint16(struct mosquitto__packet *packet, uint16_t *word); 37 | int packet__read_uint32(struct mosquitto__packet *packet, uint32_t *word); 38 | int packet__read_varint(struct mosquitto__packet *packet, uint32_t *word, uint8_t *bytes); 39 | 40 | void packet__write_byte(struct mosquitto__packet *packet, uint8_t byte); 41 | void packet__write_bytes(struct mosquitto__packet *packet, const void *bytes, uint32_t count); 42 | void packet__write_string(struct mosquitto__packet *packet, const char *str, uint16_t length); 43 | void packet__write_uint16(struct mosquitto__packet *packet, uint16_t word); 44 | void packet__write_uint32(struct mosquitto__packet *packet, uint32_t word); 45 | int packet__write_varint(struct mosquitto__packet *packet, uint32_t word); 46 | 47 | unsigned int packet__varint_bytes(uint32_t word); 48 | 49 | int packet__write(struct mosquitto *mosq); 50 | int packet__read(struct mosquitto *mosq); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/property_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef PROPERTY_MOSQ_H 19 | #define PROPERTY_MOSQ_H 20 | 21 | #include "mosquitto_internal.h" 22 | #include "mosquitto.h" 23 | 24 | struct mqtt__string { 25 | char *v; 26 | uint16_t len; 27 | }; 28 | 29 | struct mqtt5__property { 30 | struct mqtt5__property *next; 31 | union { 32 | uint8_t i8; 33 | uint16_t i16; 34 | uint32_t i32; 35 | uint32_t varint; 36 | struct mqtt__string bin; 37 | struct mqtt__string s; 38 | } value; 39 | struct mqtt__string name; 40 | int32_t identifier; 41 | bool client_generated; 42 | }; 43 | 44 | 45 | int property__read_all(int command, struct mosquitto__packet *packet, mosquitto_property **property); 46 | int property__write_all(struct mosquitto__packet *packet, const mosquitto_property *property, bool write_len); 47 | void property__free(mosquitto_property **property); 48 | 49 | unsigned int property__get_length(const mosquitto_property *property); 50 | unsigned int property__get_length_all(const mosquitto_property *property); 51 | 52 | unsigned int property__get_remaining_length(const mosquitto_property *props); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/read_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef READ_HANDLE_H 19 | #define READ_HANDLE_H 20 | 21 | #include "mosquitto.h" 22 | struct mosquitto_db; 23 | 24 | int handle__pingreq(struct mosquitto *mosq); 25 | int handle__pingresp(struct mosquitto *mosq); 26 | #ifdef WITH_BROKER 27 | int handle__pubackcomp(struct mosquitto *mosq, const char *type); 28 | #else 29 | int handle__packet(struct mosquitto *mosq); 30 | int handle__connack(struct mosquitto *mosq); 31 | int handle__disconnect(struct mosquitto *mosq); 32 | int handle__pubackcomp(struct mosquitto *mosq, const char *type); 33 | int handle__publish(struct mosquitto *mosq); 34 | int handle__auth(struct mosquitto *mosq); 35 | #endif 36 | int handle__pubrec(struct mosquitto *mosq); 37 | int handle__pubrel(struct mosquitto *mosq); 38 | int handle__suback(struct mosquitto *mosq); 39 | int handle__unsuback(struct mosquitto *mosq); 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/send_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef SEND_MOSQ_H 19 | #define SEND_MOSQ_H 20 | 21 | #include "mosquitto.h" 22 | #include "property_mosq.h" 23 | 24 | int send__simple_command(struct mosquitto *mosq, uint8_t command); 25 | int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, uint8_t reason_code, const mosquitto_property *properties); 26 | int send__real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval); 27 | 28 | int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session, const mosquitto_property *properties); 29 | int send__disconnect(struct mosquitto *mosq, uint8_t reason_code, const mosquitto_property *properties); 30 | int send__pingreq(struct mosquitto *mosq); 31 | int send__pingresp(struct mosquitto *mosq); 32 | int send__puback(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, const mosquitto_property *properties); 33 | int send__pubcomp(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties); 34 | int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval); 35 | int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, const mosquitto_property *properties); 36 | int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties); 37 | int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos, const mosquitto_property *properties); 38 | int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, const mosquitto_property *properties); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/socks_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef SOCKS_MOSQ_H 20 | #define SOCKS_MOSQ_H 21 | 22 | int socks5__send(struct mosquitto *mosq); 23 | int socks5__read(struct mosquitto *mosq); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/time_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef TIME_MOSQ_H 20 | #define TIME_MOSQ_H 21 | 22 | time_t mosquitto_time(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/tls_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef TLS_MOSQ_H 20 | #define TLS_MOSQ_H 21 | 22 | #ifdef WITH_TLS 23 | # define SSL_DATA_PENDING(A) ((A)->ssl && SSL_pending((A)->ssl)) 24 | #else 25 | # define SSL_DATA_PENDING(A) 0 26 | #endif 27 | 28 | #ifdef WITH_TLS 29 | 30 | #include 31 | #include 32 | 33 | int mosquitto__server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx); 34 | int mosquitto__verify_certificate_hostname(X509 *cert, const char *hostname); 35 | 36 | #endif /* WITH_TLS */ 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/util_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | #ifndef UTIL_MOSQ_H 19 | #define UTIL_MOSQ_H 20 | 21 | #include 22 | 23 | #include "tls_mosq.h" 24 | #include "mosquitto.h" 25 | #include "mosquitto_internal.h" 26 | #ifdef WITH_BROKER 27 | # include "mosquitto_broker_internal.h" 28 | #endif 29 | 30 | int mosquitto__check_keepalive(struct mosquitto *mosq); 31 | uint16_t mosquitto__mid_generate(struct mosquitto *mosq); 32 | 33 | int mosquitto__set_state(struct mosquitto *mosq, enum mosquitto_client_state state); 34 | enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq); 35 | 36 | #ifdef WITH_TLS 37 | int mosquitto__hex2bin_sha1(const char *hex, unsigned char **bin); 38 | int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len); 39 | #endif 40 | 41 | int util__random_bytes(void *bytes, int count); 42 | 43 | void util__increment_receive_quota(struct mosquitto *mosq); 44 | void util__increment_send_quota(struct mosquitto *mosq); 45 | void util__decrement_receive_quota(struct mosquitto *mosq); 46 | void util__decrement_send_quota(struct mosquitto *mosq); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/includes/will_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2020 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 14 | 15 | Contributors: 16 | Roger Light - initial implementation and documentation. 17 | */ 18 | 19 | #ifndef WILL_MOSQ_H 20 | #define WILL_MOSQ_H 21 | 22 | #include "mosquitto.h" 23 | #include "mosquitto_internal.h" 24 | 25 | int will__set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties); 26 | int will__clear(struct mosquitto *mosq); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto.so -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/includes/mosquittopp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License 2.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | https://www.eclipse.org/legal/epl-2.0/ 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef MOSQUITTOPP_H 18 | #define MOSQUITTOPP_H 19 | 20 | #if defined(_WIN32) && !defined(LIBMOSQUITTO_STATIC) 21 | # ifdef mosquittopp_EXPORTS 22 | # define mosqpp_EXPORT __declspec(dllexport) 23 | # else 24 | # define mosqpp_EXPORT __declspec(dllimport) 25 | # endif 26 | #else 27 | # define mosqpp_EXPORT 28 | #endif 29 | 30 | #include 31 | #include "../../libmosquitto/includes/mosquitto.h" 32 | #include 33 | 34 | namespace mosqpp { 35 | 36 | 37 | mosqpp_EXPORT const char * strerror(int mosq_errno); 38 | mosqpp_EXPORT const char * connack_string(int connack_code); 39 | mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); 40 | mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); 41 | mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); 42 | mosqpp_EXPORT int lib_init(); 43 | mosqpp_EXPORT int lib_cleanup(); 44 | mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); 45 | mosqpp_EXPORT int validate_utf8(const char *str, int len); 46 | mosqpp_EXPORT int subscribe_simple( 47 | struct mosquitto_message **messages, 48 | int msg_count, 49 | bool retained, 50 | const char *topic, 51 | int qos=0, 52 | const char *host="localhost", 53 | int port=1883, 54 | const char *client_id=NULL, 55 | int keepalive=60, 56 | bool clean_session=true, 57 | const char *username=NULL, 58 | const char *password=NULL, 59 | const struct libmosquitto_will *will=NULL, 60 | const struct libmosquitto_tls *tls=NULL); 61 | 62 | mosqpp_EXPORT int subscribe_callback( 63 | int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), 64 | void *userdata, 65 | const char *topic, 66 | int qos=0, 67 | bool retained=true, 68 | const char *host="localhost", 69 | int port=1883, 70 | const char *client_id=NULL, 71 | int keepalive=60, 72 | bool clean_session=true, 73 | const char *username=NULL, 74 | const char *password=NULL, 75 | const struct libmosquitto_will *will=NULL, 76 | const struct libmosquitto_tls *tls=NULL); 77 | 78 | /* 79 | * Class: mosquittopp 80 | * 81 | * A mosquitto client class. This is a C++ wrapper class for the mosquitto C 82 | * library. Please see mosquitto.h for details of the functions. 83 | */ 84 | class mosqpp_EXPORT mosquittopp { 85 | private: 86 | struct mosquitto *m_mosq; 87 | public: 88 | mosquittopp(const char *id=NULL, bool clean_session=true); 89 | virtual ~mosquittopp(); 90 | 91 | int reinitialise(const char *id, bool clean_session); 92 | int socket(); 93 | int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 94 | int will_clear(); 95 | int username_pw_set(const char *username, const char *password=NULL); 96 | int connect(const char *host, int port=1883, int keepalive=60); 97 | int connect_async(const char *host, int port=1883, int keepalive=60); 98 | int connect(const char *host, int port, int keepalive, const char *bind_address); 99 | int connect_async(const char *host, int port, int keepalive, const char *bind_address); 100 | int reconnect(); 101 | int reconnect_async(); 102 | int disconnect(); 103 | int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 104 | int subscribe(int *mid, const char *sub, int qos=0); 105 | int unsubscribe(int *mid, const char *sub); 106 | void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); 107 | int max_inflight_messages_set(unsigned int max_inflight_messages); 108 | void message_retry_set(unsigned int message_retry); 109 | void user_data_set(void *userdata); 110 | 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); 111 | int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); 112 | int tls_insecure_set(bool value); 113 | int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); 114 | int opts_set(enum mosq_opt_t option, void *value); 115 | 116 | int loop(int timeout=-1, int max_packets=1); 117 | int loop_misc(); 118 | int loop_read(int max_packets=1); 119 | int loop_write(int max_packets=1); 120 | int loop_forever(int timeout=-1, int max_packets=1); 121 | int loop_start(); 122 | int loop_stop(bool force=false); 123 | bool want_write(); 124 | int threaded_set(bool threaded=true); 125 | int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); 126 | 127 | // names in the functions commented to prevent unused parameter warning 128 | virtual void on_connect(int /*rc*/) {return;} 129 | virtual void on_connect_with_flags(int /*rc*/, int /*flags*/) {return;} 130 | virtual void on_disconnect(int /*rc*/) {return;} 131 | virtual void on_publish(int /*mid*/) {return;} 132 | virtual void on_message(const struct mosquitto_message * /*message*/) {return;} 133 | virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;} 134 | virtual void on_unsubscribe(int /*mid*/) {return;} 135 | virtual void on_log(int /*level*/, const char * /*str*/) {return;} 136 | virtual void on_error() {return;} 137 | }; 138 | 139 | } 140 | #endif 141 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp.so -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/dummypthread.h: -------------------------------------------------------------------------------- 1 | #ifndef _DUMMYPTHREAD_H_ 2 | #define _DUMMYPTHREAD_H_ 3 | 4 | #define pthread_create(A, B, C, D) 5 | #define pthread_join(A, B) 6 | #define pthread_cancel(A) 7 | 8 | #define pthread_mutex_init(A, B) 9 | #define pthread_mutex_destroy(A) 10 | #define pthread_mutex_lock(A) 11 | #define pthread_mutex_unlock(A) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/logging_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _LOGGING_MOSQ_H_ 17 | #define _LOGGING_MOSQ_H_ 18 | 19 | #include 20 | 21 | int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/memory_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MEMORY_MOSQ_H_ 18 | #define _MEMORY_MOSQ_H_ 19 | 20 | #include 21 | #include 22 | 23 | #if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) && !defined(WIN32) && !defined(__SYMBIAN32__) && !defined(__ANDROID__) && !defined(__UCLIBC__) && !defined(__OpenBSD__) 24 | #define REAL_WITH_MEMORY_TRACKING 25 | #endif 26 | 27 | void *_mosquitto_calloc(size_t nmemb, size_t size); 28 | void _mosquitto_free(void *mem); 29 | void *_mosquitto_malloc(size_t size); 30 | #ifdef REAL_WITH_MEMORY_TRACKING 31 | unsigned long _mosquitto_memory_used(void); 32 | unsigned long _mosquitto_max_memory_used(void); 33 | #endif 34 | void *_mosquitto_realloc(void *ptr, size_t size); 35 | char *_mosquitto_strdup(const char *s); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/messages_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _MESSAGES_MOSQ_H_ 17 | #define _MESSAGES_MOSQ_H_ 18 | 19 | #include 20 | #include 21 | 22 | void _mosquitto_message_cleanup_all(struct mosquitto *mosq); 23 | void _mosquitto_message_cleanup(struct mosquitto_message_all **message); 24 | int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir); 25 | int _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); 26 | void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq); 27 | int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); 28 | void _mosquitto_message_retry_check(struct mosquitto *mosq); 29 | int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/mosquitto_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MOSQUITTO_INTERNAL_H_ 18 | #define _MOSQUITTO_INTERNAL_H_ 19 | 20 | #include 21 | 22 | #ifdef WIN32 23 | # include 24 | #endif 25 | 26 | #ifdef WITH_TLS 27 | # include 28 | #else 29 | # include 30 | #endif 31 | #include 32 | 33 | #if defined(WITH_THREADING) && !defined(WITH_BROKER) 34 | # include 35 | #else 36 | # include 37 | #endif 38 | 39 | #ifdef WITH_SRV 40 | # include 41 | #endif 42 | 43 | #ifdef WIN32 44 | # if _MSC_VER < 1600 45 | typedef unsigned char uint8_t; 46 | typedef unsigned short uint16_t; 47 | typedef unsigned int uint32_t; 48 | typedef unsigned long long uint64_t; 49 | # else 50 | # include 51 | # endif 52 | #else 53 | # include 54 | #endif 55 | 56 | #include "mosquitto.h" 57 | #include "time_mosq.h" 58 | #ifdef WITH_BROKER 59 | # include "uthash.h" 60 | struct mosquitto_client_msg; 61 | #endif 62 | 63 | #ifdef WIN32 64 | typedef SOCKET mosq_sock_t; 65 | #else 66 | typedef int mosq_sock_t; 67 | #endif 68 | 69 | enum mosquitto_msg_direction { 70 | mosq_md_in = 0, 71 | mosq_md_out = 1 72 | }; 73 | 74 | enum mosquitto_msg_state { 75 | mosq_ms_invalid = 0, 76 | mosq_ms_publish_qos0 = 1, 77 | mosq_ms_publish_qos1 = 2, 78 | mosq_ms_wait_for_puback = 3, 79 | mosq_ms_publish_qos2 = 4, 80 | mosq_ms_wait_for_pubrec = 5, 81 | mosq_ms_resend_pubrel = 6, 82 | mosq_ms_wait_for_pubrel = 7, 83 | mosq_ms_resend_pubcomp = 8, 84 | mosq_ms_wait_for_pubcomp = 9, 85 | mosq_ms_send_pubrec = 10, 86 | mosq_ms_queued = 11 87 | }; 88 | 89 | enum mosquitto_client_state { 90 | mosq_cs_new = 0, 91 | mosq_cs_connected = 1, 92 | mosq_cs_disconnecting = 2, 93 | mosq_cs_connect_async = 3, 94 | mosq_cs_connect_pending = 4, 95 | mosq_cs_connect_srv = 5, 96 | mosq_cs_disconnect_ws = 6, 97 | mosq_cs_disconnected = 7, 98 | mosq_cs_socks5_new = 8, 99 | mosq_cs_socks5_start = 9, 100 | mosq_cs_socks5_request = 10, 101 | mosq_cs_socks5_reply = 11, 102 | mosq_cs_socks5_auth_ok = 12, 103 | mosq_cs_socks5_userpass_reply = 13, 104 | mosq_cs_socks5_send_userpass = 14, 105 | mosq_cs_expiring = 15, 106 | }; 107 | 108 | enum _mosquitto_protocol { 109 | mosq_p_invalid = 0, 110 | mosq_p_mqtt31 = 1, 111 | mosq_p_mqtt311 = 2, 112 | mosq_p_mqtts = 3 113 | }; 114 | 115 | enum _mosquitto_transport { 116 | mosq_t_invalid = 0, 117 | mosq_t_tcp = 1, 118 | mosq_t_ws = 2, 119 | mosq_t_sctp = 3 120 | }; 121 | 122 | struct _mosquitto_packet{ 123 | uint8_t *payload; 124 | struct _mosquitto_packet *next; 125 | uint32_t remaining_mult; 126 | uint32_t remaining_length; 127 | uint32_t packet_length; 128 | uint32_t to_process; 129 | uint32_t pos; 130 | uint16_t mid; 131 | uint8_t command; 132 | int8_t remaining_count; 133 | }; 134 | 135 | struct mosquitto_message_all{ 136 | struct mosquitto_message_all *next; 137 | time_t timestamp; 138 | //enum mosquitto_msg_direction direction; 139 | enum mosquitto_msg_state state; 140 | bool dup; 141 | struct mosquitto_message msg; 142 | }; 143 | 144 | struct mosquitto { 145 | mosq_sock_t sock; 146 | #ifndef WITH_BROKER 147 | mosq_sock_t sockpairR, sockpairW; 148 | #endif 149 | enum _mosquitto_protocol protocol; 150 | char *address; 151 | char *id; 152 | char *username; 153 | char *password; 154 | uint16_t keepalive; 155 | uint16_t last_mid; 156 | enum mosquitto_client_state state; 157 | time_t last_msg_in; 158 | time_t last_msg_out; 159 | time_t ping_t; 160 | struct _mosquitto_packet in_packet; 161 | struct _mosquitto_packet *current_out_packet; 162 | struct _mosquitto_packet *out_packet; 163 | struct mosquitto_message *will; 164 | #ifdef WITH_TLS 165 | SSL *ssl; 166 | SSL_CTX *ssl_ctx; 167 | char *tls_cafile; 168 | char *tls_capath; 169 | char *tls_certfile; 170 | char *tls_keyfile; 171 | int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); 172 | char *tls_version; 173 | char *tls_ciphers; 174 | char *tls_psk; 175 | char *tls_psk_identity; 176 | int tls_cert_reqs; 177 | bool tls_insecure; 178 | #endif 179 | bool want_write; 180 | bool want_connect; 181 | #if defined(WITH_THREADING) && !defined(WITH_BROKER) 182 | pthread_mutex_t callback_mutex; 183 | pthread_mutex_t log_callback_mutex; 184 | pthread_mutex_t msgtime_mutex; 185 | pthread_mutex_t out_packet_mutex; 186 | pthread_mutex_t current_out_packet_mutex; 187 | pthread_mutex_t state_mutex; 188 | pthread_mutex_t in_message_mutex; 189 | pthread_mutex_t out_message_mutex; 190 | pthread_mutex_t mid_mutex; 191 | pthread_t thread_id; 192 | #endif 193 | bool clean_session; 194 | #ifdef WITH_BROKER 195 | bool is_dropping; 196 | bool is_bridge; 197 | struct _mqtt3_bridge *bridge; 198 | struct mosquitto_client_msg *msgs; 199 | struct mosquitto_client_msg *last_msg; 200 | int msg_count; 201 | int msg_count12; 202 | struct _mosquitto_acl_user *acl_list; 203 | struct _mqtt3_listener *listener; 204 | time_t disconnect_t; 205 | struct _mosquitto_packet *out_packet_last; 206 | struct _mosquitto_subhier **subs; 207 | int sub_count; 208 | int pollfd_index; 209 | # ifdef WITH_WEBSOCKETS 210 | # if defined(LWS_LIBRARY_VERSION_NUMBER) 211 | struct lws *wsi; 212 | # else 213 | struct libwebsocket_context *ws_context; 214 | struct libwebsocket *wsi; 215 | # endif 216 | # endif 217 | #else 218 | # ifdef WITH_SOCKS 219 | char *socks5_host; 220 | int socks5_port; 221 | char *socks5_username; 222 | char *socks5_password; 223 | # endif 224 | void *userdata; 225 | bool in_callback; 226 | unsigned int message_retry; 227 | time_t last_retry_check; 228 | struct mosquitto_message_all *in_messages; 229 | struct mosquitto_message_all *in_messages_last; 230 | struct mosquitto_message_all *out_messages; 231 | struct mosquitto_message_all *out_messages_last; 232 | void (*on_connect)(struct mosquitto *, void *userdata, int rc); 233 | void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); 234 | void (*on_publish)(struct mosquitto *, void *userdata, int mid); 235 | void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); 236 | void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, const int *granted_qos); 237 | void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); 238 | void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); 239 | //void (*on_error)(); 240 | char *host; 241 | int port; 242 | int in_queue_len; 243 | int out_queue_len; 244 | char *bind_address; 245 | unsigned int reconnect_delay; 246 | unsigned int reconnect_delay_max; 247 | bool reconnect_exponential_backoff; 248 | bool threaded; 249 | struct _mosquitto_packet *out_packet_last; 250 | int inflight_messages; 251 | int max_inflight_messages; 252 | # ifdef WITH_SRV 253 | ares_channel achan; 254 | # endif 255 | #endif 256 | 257 | #ifdef WITH_BROKER 258 | UT_hash_handle hh_id; 259 | UT_hash_handle hh_sock; 260 | struct mosquitto *for_free_next; 261 | #endif 262 | }; 263 | 264 | #define STREMPTY(str) (str[0] == '\0') 265 | 266 | #endif 267 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/mqtt3_protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MQTT3_PROTOCOL_H_ 18 | #define _MQTT3_PROTOCOL_H_ 19 | 20 | /* For version 3 of the MQTT protocol */ 21 | 22 | #define PROTOCOL_NAME_v31 "MQIsdp" 23 | #define PROTOCOL_VERSION_v31 3 24 | 25 | #define PROTOCOL_NAME_v311 "MQTT" 26 | #define PROTOCOL_VERSION_v311 4 27 | 28 | /* Message types */ 29 | #define CONNECT 0x10 30 | #define CONNACK 0x20 31 | #define PUBLISH 0x30 32 | #define PUBACK 0x40 33 | #define PUBREC 0x50 34 | #define PUBREL 0x60 35 | #define PUBCOMP 0x70 36 | #define SUBSCRIBE 0x80 37 | #define SUBACK 0x90 38 | #define UNSUBSCRIBE 0xA0 39 | #define UNSUBACK 0xB0 40 | #define PINGREQ 0xC0 41 | #define PINGRESP 0xD0 42 | #define DISCONNECT 0xE0 43 | 44 | #define CONNACK_ACCEPTED 0 45 | #define CONNACK_REFUSED_PROTOCOL_VERSION 1 46 | #define CONNACK_REFUSED_IDENTIFIER_REJECTED 2 47 | #define CONNACK_REFUSED_SERVER_UNAVAILABLE 3 48 | #define CONNACK_REFUSED_BAD_USERNAME_PASSWORD 4 49 | #define CONNACK_REFUSED_NOT_AUTHORIZED 5 50 | 51 | #define MQTT_MAX_PAYLOAD 268435455 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/net_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _NET_MOSQ_H_ 17 | #define _NET_MOSQ_H_ 18 | 19 | #ifndef WIN32 20 | #include 21 | #else 22 | #include 23 | typedef int ssize_t; 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | #ifdef WITH_BROKER 30 | struct mosquitto_db; 31 | #endif 32 | 33 | #ifdef WIN32 34 | # define COMPAT_CLOSE(a) closesocket(a) 35 | # define COMPAT_ECONNRESET WSAECONNRESET 36 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK 37 | #else 38 | # define COMPAT_CLOSE(a) close(a) 39 | # define COMPAT_ECONNRESET ECONNRESET 40 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK 41 | #endif 42 | 43 | /* For when not using winsock libraries. */ 44 | #ifndef INVALID_SOCKET 45 | #define INVALID_SOCKET -1 46 | #endif 47 | 48 | /* Macros for accessing the MSB and LSB of a uint16_t */ 49 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) 50 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF) 51 | 52 | void _mosquitto_net_init(void); 53 | void _mosquitto_net_cleanup(void); 54 | 55 | void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet); 56 | int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet); 57 | int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); 58 | #ifdef WITH_BROKER 59 | int _mosquitto_socket_close(struct mosquitto_db *db, struct mosquitto *mosq); 60 | #else 61 | int _mosquitto_socket_close(struct mosquitto *mosq); 62 | #endif 63 | int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); 64 | int _mosquitto_socket_nonblock(mosq_sock_t sock); 65 | int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); 66 | 67 | int _mosquitto_read_byte(struct _mosquitto_packet *packet, uint8_t *byte); 68 | int _mosquitto_read_bytes(struct _mosquitto_packet *packet, void *bytes, uint32_t count); 69 | int _mosquitto_read_string(struct _mosquitto_packet *packet, char **str); 70 | int _mosquitto_read_uint16(struct _mosquitto_packet *packet, uint16_t *word); 71 | 72 | void _mosquitto_write_byte(struct _mosquitto_packet *packet, uint8_t byte); 73 | void _mosquitto_write_bytes(struct _mosquitto_packet *packet, const void *bytes, uint32_t count); 74 | void _mosquitto_write_string(struct _mosquitto_packet *packet, const char *str, uint16_t length); 75 | void _mosquitto_write_uint16(struct _mosquitto_packet *packet, uint16_t word); 76 | 77 | ssize_t _mosquitto_net_read(struct mosquitto *mosq, void *buf, size_t count); 78 | ssize_t _mosquitto_net_write(struct mosquitto *mosq, void *buf, size_t count); 79 | 80 | int _mosquitto_packet_write(struct mosquitto *mosq); 81 | #ifdef WITH_BROKER 82 | int _mosquitto_packet_read(struct mosquitto_db *db, struct mosquitto *mosq); 83 | #else 84 | int _mosquitto_packet_read(struct mosquitto *mosq); 85 | #endif 86 | 87 | #ifdef WITH_TLS 88 | int _mosquitto_socket_apply_tls(struct mosquitto *mosq); 89 | int mosquitto__socket_connect_tls(struct mosquitto *mosq); 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/read_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _READ_HANDLE_H_ 17 | #define _READ_HANDLE_H_ 18 | 19 | #include 20 | struct mosquitto_db; 21 | 22 | int _mosquitto_packet_handle(struct mosquitto *mosq); 23 | int _mosquitto_handle_connack(struct mosquitto *mosq); 24 | int _mosquitto_handle_pingreq(struct mosquitto *mosq); 25 | int _mosquitto_handle_pingresp(struct mosquitto *mosq); 26 | #ifdef WITH_BROKER 27 | int _mosquitto_handle_pubackcomp(struct mosquitto_db *db, struct mosquitto *mosq, const char *type); 28 | #else 29 | int _mosquitto_handle_pubackcomp(struct mosquitto *mosq, const char *type); 30 | #endif 31 | int _mosquitto_handle_publish(struct mosquitto *mosq); 32 | int _mosquitto_handle_pubrec(struct mosquitto *mosq); 33 | int _mosquitto_handle_pubrel(struct mosquitto_db *db, struct mosquitto *mosq); 34 | int _mosquitto_handle_suback(struct mosquitto *mosq); 35 | int _mosquitto_handle_unsuback(struct mosquitto *mosq); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/send_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _SEND_MOSQ_H_ 17 | #define _SEND_MOSQ_H_ 18 | 19 | #include 20 | 21 | int _mosquitto_send_simple_command(struct mosquitto *mosq, uint8_t command); 22 | int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup); 23 | int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 24 | 25 | int _mosquitto_send_connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session); 26 | int _mosquitto_send_disconnect(struct mosquitto *mosq); 27 | int _mosquitto_send_pingreq(struct mosquitto *mosq); 28 | int _mosquitto_send_pingresp(struct mosquitto *mosq); 29 | int _mosquitto_send_puback(struct mosquitto *mosq, uint16_t mid); 30 | int _mosquitto_send_pubcomp(struct mosquitto *mosq, uint16_t mid); 31 | int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 32 | int _mosquitto_send_pubrec(struct mosquitto *mosq, uint16_t mid); 33 | int _mosquitto_send_pubrel(struct mosquitto *mosq, uint16_t mid); 34 | int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, const char *topic, uint8_t topic_qos); 35 | int _mosquitto_send_unsubscribe(struct mosquitto *mosq, int *mid, const char *topic); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/socks_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef SOCKS_MOSQ_H 18 | #define SOCKS_MOSQ_H 19 | 20 | int mosquitto__socks5_send(struct mosquitto *mosq); 21 | int mosquitto__socks5_read(struct mosquitto *mosq); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/time_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013,2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _TIME_MOSQ_H_ 18 | #define _TIME_MOSQ_H_ 19 | 20 | time_t mosquitto_time(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/tls_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013,2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _TLS_MOSQ_H_ 18 | #define _TLS_MOSQ_H_ 19 | 20 | #ifdef WITH_TLS 21 | # define SSL_DATA_PENDING(A) ((A)->ssl && SSL_pending((A)->ssl)) 22 | #else 23 | # define SSL_DATA_PENDING(A) 0 24 | #endif 25 | 26 | #ifdef WITH_TLS 27 | 28 | #include 29 | #ifdef WITH_TLS_PSK 30 | # if OPENSSL_VERSION_NUMBER >= 0x10000000 31 | # define REAL_WITH_TLS_PSK 32 | # else 33 | # warning "TLS-PSK not supported, openssl too old." 34 | # endif 35 | #endif 36 | 37 | int _mosquitto_server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx); 38 | int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname); 39 | 40 | #endif /* WITH_TLS */ 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/util_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _UTIL_MOSQ_H_ 17 | #define _UTIL_MOSQ_H_ 18 | 19 | #include 20 | 21 | #include "tls_mosq.h" 22 | #include "mosquitto.h" 23 | #include "mosquitto_internal.h" 24 | #ifdef WITH_BROKER 25 | # include "mosquitto_broker.h" 26 | #endif 27 | 28 | int _mosquitto_packet_alloc(struct _mosquitto_packet *packet); 29 | #ifdef WITH_BROKER 30 | void _mosquitto_check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq); 31 | #else 32 | void _mosquitto_check_keepalive(struct mosquitto *mosq); 33 | #endif 34 | uint16_t _mosquitto_mid_generate(struct mosquitto *mosq); 35 | FILE *_mosquitto_fopen(const char *path, const char *mode); 36 | 37 | #ifdef REAL_WITH_TLS_PSK 38 | int _mosquitto_hex2bin(const char *hex, unsigned char *bin, int bin_max_len); 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/includes/will_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _WILL_MOSQ_H_ 18 | #define _WILL_MOSQ_H_ 19 | 20 | #include 21 | #include 22 | 23 | int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); 24 | int _mosquitto_will_clear(struct mosquitto *mosq); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquitto/libraries/mosquitto.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Mac/mosquitto/libraries/mosquitto.dylib -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquittopp/includes/mosquittopp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MOSQUITTOPP_H_ 18 | #define _MOSQUITTOPP_H_ 19 | 20 | #ifdef _WIN32 21 | # ifdef mosquittopp_EXPORTS 22 | # define mosqpp_EXPORT __declspec(dllexport) 23 | # else 24 | # define mosqpp_EXPORT __declspec(dllimport) 25 | # endif 26 | #else 27 | # define mosqpp_EXPORT 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace mosqpp { 35 | 36 | mosqpp_EXPORT const char *strerror(int mosq_errno); 37 | mosqpp_EXPORT const char *connack_string(int connack_code); 38 | mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); 39 | mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); 40 | mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); 41 | mosqpp_EXPORT int lib_init(); 42 | mosqpp_EXPORT int lib_cleanup(); 43 | mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); 44 | 45 | /* 46 | * Class: mosquittopp 47 | * 48 | * A mosquitto client class. This is a C++ wrapper class for the mosquitto C 49 | * library. Please see mosquitto.h for details of the functions. 50 | */ 51 | class mosqpp_EXPORT mosquittopp { 52 | private: 53 | struct mosquitto *m_mosq; 54 | public: 55 | mosquittopp(const char *id=NULL, bool clean_session=true); 56 | virtual ~mosquittopp(); 57 | 58 | int reinitialise(const char *id, bool clean_session); 59 | int socket(); 60 | int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 61 | int will_clear(); 62 | int username_pw_set(const char *username, const char *password=NULL); 63 | int connect(const char *host, int port=1883, int keepalive=60); 64 | int connect_async(const char *host, int port=1883, int keepalive=60); 65 | int connect(const char *host, int port, int keepalive, const char *bind_address); 66 | int connect_async(const char *host, int port, int keepalive, const char *bind_address); 67 | int reconnect(); 68 | int reconnect_async(); 69 | int disconnect(); 70 | int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 71 | int subscribe(int *mid, const char *sub, int qos=0); 72 | int unsubscribe(int *mid, const char *sub); 73 | void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); 74 | int max_inflight_messages_set(unsigned int max_inflight_messages); 75 | void message_retry_set(unsigned int message_retry); 76 | void user_data_set(void *userdata); 77 | 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); 78 | int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); 79 | int tls_insecure_set(bool value); 80 | int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); 81 | int opts_set(enum mosq_opt_t option, void *value); 82 | 83 | int loop(int timeout=-1, int max_packets=1); 84 | int loop_misc(); 85 | int loop_read(int max_packets=1); 86 | int loop_write(int max_packets=1); 87 | int loop_forever(int timeout=-1, int max_packets=1); 88 | int loop_start(); 89 | int loop_stop(bool force=false); 90 | bool want_write(); 91 | int threaded_set(bool threaded=true); 92 | int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); 93 | 94 | virtual void on_connect(int rc) {return;}; 95 | virtual void on_disconnect(int rc) {return;}; 96 | virtual void on_publish(int mid) {return;}; 97 | virtual void on_message(const struct mosquitto_message *message) {return;}; 98 | virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; 99 | virtual void on_unsubscribe(int mid) {return;}; 100 | virtual void on_log(int level, const char *str) {return;}; 101 | virtual void on_error() {return;}; 102 | }; 103 | 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Mac/mosquittopp/libraries/mosquittopp.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Mac/mosquittopp/libraries/mosquittopp.dylib -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/dummypthread.h: -------------------------------------------------------------------------------- 1 | #ifndef _DUMMYPTHREAD_H_ 2 | #define _DUMMYPTHREAD_H_ 3 | 4 | #define pthread_create(A, B, C, D) 5 | #define pthread_join(A, B) 6 | #define pthread_cancel(A) 7 | 8 | #define pthread_mutex_init(A, B) 9 | #define pthread_mutex_destroy(A) 10 | #define pthread_mutex_lock(A) 11 | #define pthread_mutex_unlock(A) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/logging_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _LOGGING_MOSQ_H_ 17 | #define _LOGGING_MOSQ_H_ 18 | 19 | #include "mosquitto.h" 20 | 21 | int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/memory_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MEMORY_MOSQ_H_ 18 | #define _MEMORY_MOSQ_H_ 19 | 20 | #include 21 | #include 22 | 23 | #if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) && !defined(WIN32) && !defined(__SYMBIAN32__) && !defined(__ANDROID__) && !defined(__UCLIBC__) && !defined(__OpenBSD__) 24 | #define REAL_WITH_MEMORY_TRACKING 25 | #endif 26 | 27 | void *_mosquitto_calloc(size_t nmemb, size_t size); 28 | void _mosquitto_free(void *mem); 29 | void *_mosquitto_malloc(size_t size); 30 | #ifdef REAL_WITH_MEMORY_TRACKING 31 | unsigned long _mosquitto_memory_used(void); 32 | unsigned long _mosquitto_max_memory_used(void); 33 | #endif 34 | void *_mosquitto_realloc(void *ptr, size_t size); 35 | char *_mosquitto_strdup(const char *s); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/messages_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _MESSAGES_MOSQ_H_ 17 | #define _MESSAGES_MOSQ_H_ 18 | 19 | #include "mosquitto_internal.h" 20 | #include "mosquitto.h" 21 | 22 | void _mosquitto_message_cleanup_all(struct mosquitto *mosq); 23 | void _mosquitto_message_cleanup(struct mosquitto_message_all **message); 24 | int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir); 25 | int _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); 26 | void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq); 27 | int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); 28 | void _mosquitto_message_retry_check(struct mosquitto *mosq); 29 | int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/mqtt3_protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MQTT3_PROTOCOL_H_ 18 | #define _MQTT3_PROTOCOL_H_ 19 | 20 | /* For version 3 of the MQTT protocol */ 21 | 22 | #define PROTOCOL_NAME_v31 "MQIsdp" 23 | #define PROTOCOL_VERSION_v31 3 24 | 25 | #define PROTOCOL_NAME_v311 "MQTT" 26 | #define PROTOCOL_VERSION_v311 4 27 | 28 | /* Message types */ 29 | #define CONNECT 0x10 30 | #define CONNACK 0x20 31 | #define PUBLISH 0x30 32 | #define PUBACK 0x40 33 | #define PUBREC 0x50 34 | #define PUBREL 0x60 35 | #define PUBCOMP 0x70 36 | #define SUBSCRIBE 0x80 37 | #define SUBACK 0x90 38 | #define UNSUBSCRIBE 0xA0 39 | #define UNSUBACK 0xB0 40 | #define PINGREQ 0xC0 41 | #define PINGRESP 0xD0 42 | #define DISCONNECT 0xE0 43 | 44 | #define CONNACK_ACCEPTED 0 45 | #define CONNACK_REFUSED_PROTOCOL_VERSION 1 46 | #define CONNACK_REFUSED_IDENTIFIER_REJECTED 2 47 | #define CONNACK_REFUSED_SERVER_UNAVAILABLE 3 48 | #define CONNACK_REFUSED_BAD_USERNAME_PASSWORD 4 49 | #define CONNACK_REFUSED_NOT_AUTHORIZED 5 50 | 51 | #define MQTT_MAX_PAYLOAD 268435455 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/net_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _NET_MOSQ_H_ 17 | #define _NET_MOSQ_H_ 18 | 19 | #ifndef WIN32 20 | #include 21 | #else 22 | #include 23 | typedef int ssize_t; 24 | #endif 25 | 26 | #include "mosquitto_internal.h"" 27 | #include "mosquitto.h" 28 | 29 | #ifdef WITH_BROKER 30 | struct mosquitto_db; 31 | #endif 32 | 33 | #ifdef WIN32 34 | # define COMPAT_CLOSE(a) closesocket(a) 35 | # define COMPAT_ECONNRESET WSAECONNRESET 36 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK 37 | #else 38 | # define COMPAT_CLOSE(a) close(a) 39 | # define COMPAT_ECONNRESET ECONNRESET 40 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK 41 | #endif 42 | 43 | /* For when not using winsock libraries. */ 44 | #ifndef INVALID_SOCKET 45 | #define INVALID_SOCKET -1 46 | #endif 47 | 48 | /* Macros for accessing the MSB and LSB of a uint16_t */ 49 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) 50 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF) 51 | 52 | void _mosquitto_net_init(void); 53 | void _mosquitto_net_cleanup(void); 54 | 55 | void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet); 56 | int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet); 57 | int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); 58 | #ifdef WITH_BROKER 59 | int _mosquitto_socket_close(struct mosquitto_db *db, struct mosquitto *mosq); 60 | #else 61 | int _mosquitto_socket_close(struct mosquitto *mosq); 62 | #endif 63 | int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); 64 | int _mosquitto_socket_nonblock(mosq_sock_t sock); 65 | int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); 66 | 67 | int _mosquitto_read_byte(struct _mosquitto_packet *packet, uint8_t *byte); 68 | int _mosquitto_read_bytes(struct _mosquitto_packet *packet, void *bytes, uint32_t count); 69 | int _mosquitto_read_string(struct _mosquitto_packet *packet, char **str); 70 | int _mosquitto_read_uint16(struct _mosquitto_packet *packet, uint16_t *word); 71 | 72 | void _mosquitto_write_byte(struct _mosquitto_packet *packet, uint8_t byte); 73 | void _mosquitto_write_bytes(struct _mosquitto_packet *packet, const void *bytes, uint32_t count); 74 | void _mosquitto_write_string(struct _mosquitto_packet *packet, const char *str, uint16_t length); 75 | void _mosquitto_write_uint16(struct _mosquitto_packet *packet, uint16_t word); 76 | 77 | ssize_t _mosquitto_net_read(struct mosquitto *mosq, void *buf, size_t count); 78 | ssize_t _mosquitto_net_write(struct mosquitto *mosq, void *buf, size_t count); 79 | 80 | int _mosquitto_packet_write(struct mosquitto *mosq); 81 | #ifdef WITH_BROKER 82 | int _mosquitto_packet_read(struct mosquitto_db *db, struct mosquitto *mosq); 83 | #else 84 | int _mosquitto_packet_read(struct mosquitto *mosq); 85 | #endif 86 | 87 | #ifdef WITH_TLS 88 | int _mosquitto_socket_apply_tls(struct mosquitto *mosq); 89 | int mosquitto__socket_connect_tls(struct mosquitto *mosq); 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/read_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _READ_HANDLE_H_ 17 | #define _READ_HANDLE_H_ 18 | 19 | #include "mosquitto.h" 20 | struct mosquitto_db; 21 | 22 | int _mosquitto_packet_handle(struct mosquitto *mosq); 23 | int _mosquitto_handle_connack(struct mosquitto *mosq); 24 | int _mosquitto_handle_pingreq(struct mosquitto *mosq); 25 | int _mosquitto_handle_pingresp(struct mosquitto *mosq); 26 | #ifdef WITH_BROKER 27 | int _mosquitto_handle_pubackcomp(struct mosquitto_db *db, struct mosquitto *mosq, const char *type); 28 | #else 29 | int _mosquitto_handle_pubackcomp(struct mosquitto *mosq, const char *type); 30 | #endif 31 | int _mosquitto_handle_publish(struct mosquitto *mosq); 32 | int _mosquitto_handle_pubrec(struct mosquitto *mosq); 33 | int _mosquitto_handle_pubrel(struct mosquitto_db *db, struct mosquitto *mosq); 34 | int _mosquitto_handle_suback(struct mosquitto *mosq); 35 | int _mosquitto_handle_unsuback(struct mosquitto *mosq); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/send_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _SEND_MOSQ_H_ 17 | #define _SEND_MOSQ_H_ 18 | 19 | #include "mosquitto.h" 20 | 21 | int _mosquitto_send_simple_command(struct mosquitto *mosq, uint8_t command); 22 | int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup); 23 | int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 24 | 25 | int _mosquitto_send_connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session); 26 | int _mosquitto_send_disconnect(struct mosquitto *mosq); 27 | int _mosquitto_send_pingreq(struct mosquitto *mosq); 28 | int _mosquitto_send_pingresp(struct mosquitto *mosq); 29 | int _mosquitto_send_puback(struct mosquitto *mosq, uint16_t mid); 30 | int _mosquitto_send_pubcomp(struct mosquitto *mosq, uint16_t mid); 31 | int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 32 | int _mosquitto_send_pubrec(struct mosquitto *mosq, uint16_t mid); 33 | int _mosquitto_send_pubrel(struct mosquitto *mosq, uint16_t mid); 34 | int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, const char *topic, uint8_t topic_qos); 35 | int _mosquitto_send_unsubscribe(struct mosquitto *mosq, int *mid, const char *topic); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/socks_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef SOCKS_MOSQ_H 18 | #define SOCKS_MOSQ_H 19 | 20 | int mosquitto__socks5_send(struct mosquitto *mosq); 21 | int mosquitto__socks5_read(struct mosquitto *mosq); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/time_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013,2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _TIME_MOSQ_H_ 18 | #define _TIME_MOSQ_H_ 19 | 20 | time_t mosquitto_time(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/tls_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013,2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _TLS_MOSQ_H_ 18 | #define _TLS_MOSQ_H_ 19 | 20 | #ifdef WITH_TLS 21 | # define SSL_DATA_PENDING(A) ((A)->ssl && SSL_pending((A)->ssl)) 22 | #else 23 | # define SSL_DATA_PENDING(A) 0 24 | #endif 25 | 26 | #ifdef WITH_TLS 27 | 28 | #include 29 | #ifdef WITH_TLS_PSK 30 | # if OPENSSL_VERSION_NUMBER >= 0x10000000 31 | # define REAL_WITH_TLS_PSK 32 | # else 33 | # warning "TLS-PSK not supported, openssl too old." 34 | # endif 35 | #endif 36 | 37 | int _mosquitto_server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx); 38 | int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname); 39 | 40 | #endif /* WITH_TLS */ 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/util_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef _UTIL_MOSQ_H_ 17 | #define _UTIL_MOSQ_H_ 18 | 19 | #include 20 | 21 | #include "tls_mosq.h" 22 | #include "mosquitto.h" 23 | #include "mosquitto_internal.h" 24 | #ifdef WITH_BROKER 25 | # include "mosquitto_broker.h" 26 | #endif 27 | 28 | int _mosquitto_packet_alloc(struct _mosquitto_packet *packet); 29 | #ifdef WITH_BROKER 30 | void _mosquitto_check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq); 31 | #else 32 | void _mosquitto_check_keepalive(struct mosquitto *mosq); 33 | #endif 34 | uint16_t _mosquitto_mid_generate(struct mosquitto *mosq); 35 | FILE *_mosquitto_fopen(const char *path, const char *mode); 36 | 37 | #ifdef REAL_WITH_TLS_PSK 38 | int _mosquitto_hex2bin(const char *hex, unsigned char *bin, int bin_max_len); 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/includes/will_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2014 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _WILL_MOSQ_H_ 18 | #define _WILL_MOSQ_H_ 19 | 20 | #include "mosquitto.h" 21 | #include "mosquitto_internal.h" 22 | 23 | int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); 24 | int _mosquitto_will_clear(struct mosquitto *mosq); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.dll -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.exp -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.ilk -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.lib -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquitto/libraries/mosquitto.pdb -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/includes/mosquittopp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef _MOSQUITTOPP_H_ 18 | #define _MOSQUITTOPP_H_ 19 | 20 | #ifdef _WIN32 21 | # ifdef mosquittopp_EXPORTS 22 | # define mosqpp_EXPORT __declspec(dllexport) 23 | # else 24 | # define mosqpp_EXPORT __declspec(dllimport) 25 | # endif 26 | #else 27 | # define mosqpp_EXPORT 28 | #endif 29 | 30 | #include 31 | #include 32 | #include "../../mosquitto/includes/mosquitto.h" 33 | 34 | namespace mosqpp { 35 | 36 | mosqpp_EXPORT const char *strerror(int mosq_errno); 37 | mosqpp_EXPORT const char *connack_string(int connack_code); 38 | mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); 39 | mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); 40 | mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); 41 | mosqpp_EXPORT int lib_init(); 42 | mosqpp_EXPORT int lib_cleanup(); 43 | mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); 44 | 45 | /* 46 | * Class: mosquittopp 47 | * 48 | * A mosquitto client class. This is a C++ wrapper class for the mosquitto C 49 | * library. Please see mosquitto.h for details of the functions. 50 | */ 51 | class mosqpp_EXPORT mosquittopp { 52 | private: 53 | struct mosquitto *m_mosq; 54 | public: 55 | mosquittopp(const char *id=NULL, bool clean_session=true); 56 | virtual ~mosquittopp(); 57 | 58 | int reinitialise(const char *id, bool clean_session); 59 | int socket(); 60 | int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 61 | int will_clear(); 62 | int username_pw_set(const char *username, const char *password=NULL); 63 | int connect(const char *host, int port=1883, int keepalive=60); 64 | int connect_async(const char *host, int port=1883, int keepalive=60); 65 | int connect(const char *host, int port, int keepalive, const char *bind_address); 66 | int connect_async(const char *host, int port, int keepalive, const char *bind_address); 67 | int reconnect(); 68 | int reconnect_async(); 69 | int disconnect(); 70 | int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); 71 | int subscribe(int *mid, const char *sub, int qos=0); 72 | int unsubscribe(int *mid, const char *sub); 73 | void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); 74 | int max_inflight_messages_set(unsigned int max_inflight_messages); 75 | void message_retry_set(unsigned int message_retry); 76 | void user_data_set(void *userdata); 77 | 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); 78 | int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); 79 | int tls_insecure_set(bool value); 80 | int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); 81 | int opts_set(enum mosq_opt_t option, void *value); 82 | 83 | int loop(int timeout=-1, int max_packets=1); 84 | int loop_misc(); 85 | int loop_read(int max_packets=1); 86 | int loop_write(int max_packets=1); 87 | int loop_forever(int timeout=-1, int max_packets=1); 88 | int loop_start(); 89 | int loop_stop(bool force=false); 90 | bool want_write(); 91 | int threaded_set(bool threaded=true); 92 | int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); 93 | 94 | virtual void on_connect(int rc) {return;}; 95 | virtual void on_disconnect(int rc) {return;}; 96 | virtual void on_publish(int mid) {return;}; 97 | virtual void on_message(const struct mosquitto_message *message) {return;}; 98 | virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; 99 | virtual void on_unsubscribe(int mid) {return;}; 100 | virtual void on_log(int level, const char *str) {return;}; 101 | virtual void on_error() {return;}; 102 | }; 103 | 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.dll -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.exp -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.ilk -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.lib -------------------------------------------------------------------------------- /MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/MqttUtilities/Source/ThirdParty/Win64/mosquittopp/libraries/mosquittopp.pdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## If this repo helped you, please consider buying us a cup of coffee: 2 | 3 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8JXUYRFCZMR7G) 4 | 5 | # MQTT Utilities plugin for Unreal Engine 6 | 7 | MQTT Utilities is a plugin for Unreal Engine intended to expose MQTT client functionality to blueprints. 8 | 9 | Check out the [Documentation](https://github.com/NinevaStudios/MqttUtilities-UnrealEngine/wiki) to learn more about the plugin. 10 | 11 | Learn more about [MQTT](http://mqtt.org/) and its basic [concepts](https://mosquitto.org/man/mqtt-7.html). 12 | 13 | [Download](https://github.com/NinevaStudios/MqttUtilities-UnrealEngine/releases) demo applications for Windows/Mac/Android and try it out. Also, you can download complete demo project made with UE 4.23 and take a look how to use certain plugin features! 14 | 15 | This plugin is based on the [Eclipse Mosquitto](https://github.com/eclipse/mosquitto) client Libraries for it's base. 16 | 17 | ## Features 18 | * Establish connection with MQTT brokers 19 | * Publish messages 20 | * Receive messages with a certain topic 21 | * Unified API for Windows/Mac/Android/iOS/Linux 22 | 23 | ## Supported platforms 24 | 25 | * Windows x64 26 | + (Eclipse Mosquitto 1.4.8) 27 | * Android 28 | + (Eclipse Mosquitto 1.4.8) 29 | * iOS 30 | + (Eclipse Mosquitto 1.4.8) 31 | * Mac OS 32 | + (Eclipse Mosquitto 1.4.8) 33 | * Linux 34 | + (Eclipse Mosquitto 2.0.13) 35 | + (Tested with Ubuntu 18.04) 36 | 37 | ## List of compatible MQTT brokers 38 | 39 | * [CloudMQTT](https://www.cloudmqtt.com/) 40 | * [HiveMQ](https://www.hivemq.com/) 41 | * [flespi](https://flespi.com/mqtt-broker) 42 | * [ActiveMQ](https://activemq.apache.org/index.html) 43 | * [mosca](https://github.com/mcollina/mosca) 44 | * [Eclipse Mosquitto](https://mosquitto.org/) 45 | * [RabbitMQ](https://www.rabbitmq.com/) 46 | 47 | This list can be extended in the future. Also, even if some MQTT brokers are not listed here it doesn't necessarily mean that they are incompatible with MQTT Utilities plugin for Unreal Engine unless this is mentioned explicitly. 48 | 49 | ## Changelog 50 | 51 | ### v1.2.0 Update release 52 | 53 | + FIXED https://github.com/NinevaStudios/mqtt-utilities-unreal/pull/23 54 | + FIXED https://github.com/NinevaStudios/mqtt-utilities-unreal/pull/29 55 | + FIXED https://github.com/NinevaStudios/mqtt-utilities-unreal/pull/32 56 | + FIXED https://github.com/NinevaStudios/mqtt-utilities-unreal/pull/38 57 | 58 | ### v1.1.0 Update release 59 | 60 | + ADDED MQTT client implementation for Linux 61 | + Few README cleanup/updates 62 | 63 | ### v1.0.0 Initial release 64 | 65 | + ADDED MQTT client implementation for Windows/Mac/Android/iOS 66 | -------------------------------------------------------------------------------- /Resources/AllNodes_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/AllNodes_Scr.PNG -------------------------------------------------------------------------------- /Resources/Connect_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Connect_Scr.PNG -------------------------------------------------------------------------------- /Resources/Content_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Content_Scr.PNG -------------------------------------------------------------------------------- /Resources/CreateInterface_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/CreateInterface_Scr.PNG -------------------------------------------------------------------------------- /Resources/Demo_Scr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Demo_Scr.jpg -------------------------------------------------------------------------------- /Resources/Disconnect_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Disconnect_Scr.PNG -------------------------------------------------------------------------------- /Resources/Handlers_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Handlers_Scr.PNG -------------------------------------------------------------------------------- /Resources/OnError_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/OnError_Scr.PNG -------------------------------------------------------------------------------- /Resources/OnMessage_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/OnMessage_Scr.PNG -------------------------------------------------------------------------------- /Resources/OnPublish_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/OnPublish_Scr.PNG -------------------------------------------------------------------------------- /Resources/OnSubscribe_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/OnSubscribe_Scr.PNG -------------------------------------------------------------------------------- /Resources/OnUnsubscribe_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/OnUnsubscribe_Scr.PNG -------------------------------------------------------------------------------- /Resources/PluginSetup_Scr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/PluginSetup_Scr.png -------------------------------------------------------------------------------- /Resources/Publish_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Publish_Scr.PNG -------------------------------------------------------------------------------- /Resources/Subscribe_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Subscribe_Scr.PNG -------------------------------------------------------------------------------- /Resources/Unsubscribe_Scr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NinevaStudios/mqtt-utilities-unreal/97f22e4174e1871e6d745ad573090908e4be0d94/Resources/Unsubscribe_Scr.PNG --------------------------------------------------------------------------------