Commit b00e6980 authored by Ian Craggs's avatar Ian Craggs

Merge branch 'master' into develop

parents e9bd6a4f 6645291b
from conans import ConanFile, CMake, tools
class PahocConan(ConanFile):
name = "paho.mqtt.c"
version = "1.2.0"
license = "Eclipse Public License - v 1.0"
url = "https://github.com/eclipse/paho.mqtt.c"
description = """The Eclipse Paho project provides open-source client implementations of MQTT
and MQTT-SN messaging protocols aimed at new, existing, and emerging applications for the Internet
of Things (IoT)"""
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "SSL": [True, False], "asynchronous": [True, False]}
default_options = "shared=False", "SSL=False", "asynchronous=False"
generators = "cmake"
exports_sources = "*"
def requirements(self):
if self.options.SSL:
self.requires("OpenSSL/1.0.2n@conan/stable")
def build(self):
tools.replace_in_file("CMakeLists.txt", "PROJECT(\"paho\" C)", '''PROJECT("paho" C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')
tools.replace_in_file("CMakeLists.txt", "ADD_SUBDIRECTORY(test)", "") # Disable tests
tools.replace_in_file("CMakeLists.txt",
"ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -MD)",
"ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN)") # Allow other runtimes
cmake = CMake(self)
cmake.definitions["PAHO_BUILD_DOCUMENTATION"] = False
cmake.definitions["PAHO_BUILD_SAMPLES"] = False
cmake.definitions["PAHO_BUILD_DEB_PACKAGE"] = False
cmake.definitions["PAHO_BUILD_STATIC"] = not self.options.shared
cmake.definitions["PAHO_WITH_SSL"] = self.options.SSL
cmake.configure()
cmake.build()
def package(self):
self.copy("*e*l-v10", dst="licenses")
self.copy("*.h", dst="include", src="src")
self.copy("*paho*.dll", dst="bin", keep_path=False)
self.copy("*paho*.dylib", dst="lib", keep_path=False)
self.copy("*paho*.so*", dst="lib", keep_path=False)
self.copy("*paho*.a", dst="lib", keep_path=False)
self.copy("*paho*.lib", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = []
if self.options.shared and self:
if self.options.asynchronous:
if self.options.SSL:
self.cpp_info.libs.append("paho-mqtt3as")
else:
self.cpp_info.libs.append("paho-mqtt3a")
else:
if self.options.SSL:
self.cpp_info.libs.append("paho-mqtt3cs")
else:
self.cpp_info.libs.append("paho-mqtt3c")
else:
if self.options.asynchronous:
if self.options.SSL:
self.cpp_info.libs.append("paho-mqtt3as-static")
else:
self.cpp_info.libs.append("paho-mqtt3a-static")
else:
if self.options.SSL:
self.cpp_info.libs.append("paho-mqtt3cs-static")
else:
self.cpp_info.libs.append("paho-mqtt3c-static")
if self.settings.os == "Windows":
if not self.options.shared:
self.cpp_info.libs.append("ws2_32")
if self.settings.compiler == "gcc":
self.cpp_info.libs.append("wsock32") # (MinGW) needed?
else:
if self.settings.os == "Linux":
self.cpp_info.libs.append("c")
self.cpp_info.libs.append("dl")
self.cpp_info.libs.append("pthread")
elif self.settings.os == "FreeBSD":
self.cpp_info.libs.append("compat")
self.cpp_info.libs.append("pthread")
else:
self.cpp_info.libs.append("c")
self.cpp_info.libs.append("pthread")
def configure(self):
del self.settings.compiler.libcxx
/*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved.
* Copyright (c) 2018 Wind River Systems, Inc. and others. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -12,6 +12,7 @@
*
* Contributors:
* Keith Holman - initial implementation and documentation
* Ian Craggs - use memory tracking
*******************************************************************************/
#include <stdint.h>
......@@ -82,6 +83,8 @@
#include <openssl/rand.h>
#endif /* if defined(OPENSSL) */
#include "Heap.h"
/** @brief raw uuid type */
typedef unsigned char uuid_t[16];
......@@ -308,7 +311,10 @@ int WebSocket_connect( networkHandles *net, const char *uri )
const char *topic = NULL;
/* Generate UUID */
net->websocket_key = realloc(net->websocket_key, 25u);
if (net->websocket_key == NULL)
net->websocket_key = malloc(25u);
else
net->websocket_key = realloc(net->websocket_key, 25u);
#if defined(WIN32) || defined(WIN64)
UUID uuid;
ZeroMemory( &uuid, sizeof(UUID) );
......@@ -426,7 +432,10 @@ void WebSocket_close(networkHandles *net, int status_code, const char *reason)
free( buf0 );
}
if ( net->websocket_key )
{
free( net->websocket_key );
net->websocket_key = NULL;
}
}
/**
......@@ -784,7 +793,10 @@ int WebSocket_receiveFrame(networkHandles *net,
if ( res )
cur_len = res->len;
res = realloc( res, sizeof(struct ws_frame) + cur_len + len );
if (res == NULL)
res = malloc( sizeof(struct ws_frame) + cur_len + len );
else
res = realloc( res, sizeof(struct ws_frame) + cur_len + len );
memcpy( (unsigned char *)res + sizeof(struct ws_frame) + cur_len, b, len );
res->pos = 0u;
res->len = cur_len + len;
......
project(test_package C)
cmake_minimum_required(VERSION 2.8.11)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
file(GLOB SOURCE_FILES *.c)
message("LIBS: ${CONAN_LIBS}")
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
\ No newline at end of file
from conans import ConanFile, CMake, tools, RunEnvironment
import os
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def imports(self):
self.copy("*paho*.dll", dst="bin", src="bin")
self.copy("*paho*.dylib*", dst="bin", src="lib")
def test(self):
with tools.environment_append(RunEnvironment(self).vars):
bin_path = os.path.join("bin", "test_package")
if self.settings.os == "Windows":
self.run(bin_path)
elif self.settings.os == "Macos":
self.run("DYLD_LIBRARY_PATH=%s %s" % (os.environ.get('DYLD_LIBRARY_PATH', ''), bin_path))
else:
self.run("LD_LIBRARY_PATH=%s %s" % (os.environ.get('LD_LIBRARY_PATH', ''), bin_path))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883"
#define CLIENTID "ExampleClientSub"
#define TOPIC "MQTT Examples"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
volatile MQTTClient_deliveryToken deliveredtoken;
void delivered(void *context, MQTTClient_deliveryToken dt)
{
printf("Message with token value %d delivery confirmed\n", dt);
deliveredtoken = dt;
}
int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message)
{
int i;
char *payloadptr;
printf("Message arrived\n");
printf(" topic: %s\n", topicName);
printf(" message: ");
payloadptr = message->payload;
for (i = 0; i < message->payloadlen; i++)
{
putchar(*payloadptr++);
}
putchar('\n');
MQTTClient_freeMessage(&message);
MQTTClient_free(topicName);
return 1;
}
void connlost(void *context, char *cause)
{
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
}
int main(int argc, char *argv[])
{
printf("\nCreating MQTTClient\n");
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_create(&client, ADDRESS, CLIENTID,
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
MQTTClient_destroy(&client);
printf("\nExiting\n");
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment