Comments (1)
Threading isn't required, and in fact no OS primitive is used (except for network).
However, as you've found, you need to define few primitives for the library to work:
- You need to define types. eMQTT5 expect types of specific length, so it can't rely on int or long to expect 32 bits or 64 bits integer.
- Locking and atomic primitives. While it doesn't requires threads to work, the code is generic and if used in multithread environment, the shared access are protected by
Lock
andMutex
. You can define then to a plain wrapper over a boolean if you don't need them (see MQTTClient.cpp around line 347 for an implementation with atomic boolean). - Basic lib C functions.
- Network primitives (if you use LWIP, you'll have to redirect the include to LWIP primitives)
- Break into Debugger (if building in Debug mode)
Defining the types:
If I were you, I would try to find a specific preprocessor definition for your platform (something your compiler defines that other compiler don't. For example, on linux, we have _LINUX
or ESP_PLATFORM
on ESP32. At worst, you can add a -DRA6M5
to your compiler flags.
Typically, in Types.hpp
look at the line 219 for the definition of ESP32 platform and write something equivalent at line 268:
#elif defined(RA6M5)
#include <stdlib.h>
#include <string.h>
// We need BSD socket here and TCP_NODELAY
#include <whereis/socket.h> // We need close, connect, bind, setsockopt, getsockopt, fcntl
// We need gethostbyname or getaddrinfo
#include <whereis/netdb.h>
// We need va_args for printf like dump functions
#include <stdarg.h>
#ifndef DontWantUINT8
typedef unsigned char uint8;
#endif
#ifndef DontWantUINT32
typedef unsigned int uint32;
#endif
#ifndef DontWantUINT16
typedef unsigned short uint16;
#endif
#ifndef DontWantUINT64
typedef unsigned long long uint64;
#endif
#ifndef DontWantINT8
typedef signed char int8;
#endif
#ifndef DontWantINT32
typedef signed int int32;
#endif
#ifndef DontWantINT16
typedef signed short int16;
#endif
#ifndef DontWantINT64
typedef long long int64;
#endif
#ifndef DontWantNativeInt
typedef intptr_t nativeint;
#endif
#define PF_LLD "%lld"
#define PF_LLU "%llu"
/** Unless you run on embedded OS, you'll not need those functions
@return int value you need to pass to leaveAtomicSection */
extern "C" int enterAtomicSection() { return 0; } // You might need `asm volatile("": : :"memory")` here, if you use GCC
/** Unless you run on embedded OS, you'll not need those functions */
extern "C" void leaveAtomicSection(int) { }
#else // Previously: line 268
Debugging
If you need to debug your code, the library will call breakUnderDebugger()
on assert. It's defined in Platform.hpp
. Without an OS, it can't capture the frame and callback. Yet, you can add a section like this:
#elif defined (RA6M5)
*(char*)42 = 0; // This will crash the CPU instantly. If the debugger is attached, this should trigger an exception, you need to find the return address for this function on the stack and jump back to the return address to find where it failed, or place a breakpoint on this line, skip the instruction and return step by step to find where it failed.
#else
Wrapping the threads
In Types.hpp
around line 363, you will have to replace this:
#ifdef _WIN32
typedef HANDLE HTHREAD;
typedef HANDLE HMUTEX;
typedef HANDLE OEVENT;
#else
typedef pthread_t HTHREAD;
typedef pthread_mutex_t HMUTEX;
typedef pthread_mutex_t OEVENT;
#endif
to this:
#ifdef _WIN32
typedef HANDLE HTHREAD;
typedef HANDLE HMUTEX;
typedef HANDLE OEVENT;
#elif defined(RA6M5)
// This isn't used anywhere anyway
typedef void * HTHREAD;
typedef int HMUTEX;
typedef int OEVENT;
#else
typedef pthread_t HTHREAD;
typedef pthread_mutex_t HMUTEX;
typedef pthread_mutex_t OEVENT;
#endif
That should be it.
Once you have a working port, feel free to create a PR, I'll happily merge it.
from emqtt5.
Related Issues (18)
- Cannot build with MQTTOnlyBSDSocket set to 0 [Windows build] HOT 7
- Problems including the library HOT 11
- Publisher and Subscriber in the same client HOT 12
- execinfo.h does not exist in alpine linux 3.19 HOT 2
- read properties of received packet HOT 9
- readFrom() return BadData for 4-byte buffer HOT 2
- Linux specific int types HOT 3
- Adding properties to PUBLISH packet. HOT 4
- missing functions getEthernetRate and getWIFIRate HOT 9
- Why there is no release version ? HOT 3
- How to connect without ClientID? HOT 1
- Calling ConnectTo multiple times if the connection is not successful is not working HOT 2
- eMQTT5 does not install at all HOT 1
- There seems no definition of Platform::free and so on for macOS. HOT 18
- Clean source dependency for readability HOT 6
- No support for unsubscribing HOT 4
- Stuck in eventLoop HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emqtt5.