ESP3D/esp3d/src/core/esp3d_message.h
Luc a10a7f74bf
Refactoring internal clients (#987)
* Remove all output flags
* Masse replace name function / class to sync with ESP3D-TFT
* Create ESP3DMessageManager  class to handle messages creation / deletion (import functions of ESp3DClient from ESp3D-TFT)
*  Move to new messaging API of ESP3D-TFT
* Remove empty line from remote screen dispatching
* Replace \n to space and \r to nothing in remote screen dispatching
* Add missing default entry for sensor device
* Fix buzzer for ESP32 missing ledc initialization with latest core
* Move formatBytes to esp3d_string
* Add welcome message to telnet connection\
* Add display to the new messaging API
* Add sticky authentication on Serial / SerialBridge /Telnet/Data web socket and BT
* Log simplification
* Use enum class instead of typdef enum for ESP3DAuthenticationLevel  to be sure correct enum is used
* (v3) Home Assistant notification support (#971)
* Add notification via post request
* Extend t1 size to 255 bytes
* Hide Home Assistant notifications from web UI (#974)
* Sync with ESP3DLib on serial_socket
* Add some sanity check to avoid unnecessary message copies
* Update ESP0.cpp

---------

Co-authored-by: David Buezas <dbuezas@users.noreply.github.com>
2024-01-03 10:46:13 +08:00

89 lines
2.8 KiB
C++

/*
esp3d_message.h - output functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define ESP_OUTPUT_IP_ADDRESS 0
#define ESP_OUTPUT_STATUS 1
#define ESP_OUTPUT_PROGRESS 2
#define ESP_OUTPUT_STATE 3
#define ESP_STATE_DISCONNECTED 0
#ifndef _ESP3DOUTPUT_H
#define _ESP3DOUTPUT_H
#include "../include/esp3d_config.h"
#ifdef HTTP_FEATURE
#if defined(ARDUINO_ARCH_ESP32)
class WebServer;
#define WEBSERVER WebServer
#endif // ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#define WEBSERVER ESP8266WebServer
#endif // ARDUINO_ARCH_ESP8266
#endif // HTTP_FEATURE
#include "../modules/authentication/authentication_level_types.h"
#include "esp3d_client_types.h"
enum class ESP3DMessageType : uint8_t { head, core, tail, unique };
union ESP3DRequest {
uint id;
uint code;
#ifdef HTTP_FEATURE
WEBSERVER *http_request;
#endif // HTTP_FEATURE
};
extern ESP3DRequest no_id;
struct ESP3DMessage {
uint8_t *data;
size_t size;
ESP3DClientType origin;
ESP3DClientType target;
ESP3DAuthenticationLevel authentication_level;
ESP3DRequest request_id;
ESP3DMessageType type;
};
class ESP3DMessageManager final {
public:
static ESP3DMessage *newMsg();
static ESP3DMessage *newMsg(ESP3DRequest requestId);
static bool deleteMsg(ESP3DMessage *message);
static bool copyMsgInfos(ESP3DMessage *newMsgPtr, ESP3DMessage msg);
static ESP3DMessage *copyMsgInfos(ESP3DMessage msg);
static ESP3DMessage *copyMsg(ESP3DMessage msg);
static ESP3DMessage *newMsg(ESP3DClientType origin, ESP3DClientType target,
const uint8_t *data, size_t length,
ESP3DAuthenticationLevel authentication_level =
ESP3DAuthenticationLevel::guest);
static ESP3DMessage *newMsg(ESP3DClientType origin, ESP3DClientType target,
ESP3DAuthenticationLevel authentication_level =
ESP3DAuthenticationLevel::guest);
static bool setDataContent(ESP3DMessage *msg, const uint8_t *data,
size_t length);
};
#endif //_ESP3DOUTPUT_H