SSDP/src/include/Network/SSDP/Message.h
Go to the documentation of this file.
1 /****
2  * Message.h
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming SSDP Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <IpAddress.h>
25 
26 #define SSDP_MESSAGE_TYPE_MAP(XX) \
27  XX(notify) \
28  XX(msearch) \
29  XX(response)
30 
31 namespace SSDP
32 {
33 static const IpAddress multicastIp(239, 255, 255, 250);
34 static constexpr uint16_t multicastPort = 1900;
35 
36 DECLARE_FSTR(SSDP_DISCOVER);
37 DECLARE_FSTR(UPNP_ROOTDEVICE);
38 DECLARE_FSTR(SSDP_ALL);
39 
40 enum class MessageType {
41 #define XX(tag) tag,
43 #undef XX
44 };
45 
49 template <class HeaderClass> class BaseMessage : public HeaderClass
50 {
51 public:
52  MessageType type{MessageType::notify};
54  uint16_t remotePort{0};
55 };
56 
61 class BasicMessage : public BaseMessage<BasicHttpHeaders>
62 {
63 public:
64  HttpError parse(char* data, size_t len);
65 };
66 
71 class Message : public BaseMessage<HttpHeaders>
72 {
73 public:
74  Message() = default;
75  Message(const Message&) = default;
76  Message(const BasicMessage& msg);
77 };
78 
79 } // namespace SSDP
80 
HttpError
HTTP error codes.
Definition: HttpCommon.h:68
String toString(SSDP::MessageType type)
#define SSDP_MESSAGE_TYPE_MAP(XX)
Definition: SSDP/src/include/Network/SSDP/Message.h:26
A class to make it easier to handle and pass around IP addresses.
Definition: IpAddress.h:45
class template for messages
Definition: SSDP/src/include/Network/SSDP/Message.h:50
uint16_t remotePort
Definition: SSDP/src/include/Network/SSDP/Message.h:54
IpAddress remoteIP
Definition: SSDP/src/include/Network/SSDP/Message.h:53
MessageType type
Definition: SSDP/src/include/Network/SSDP/Message.h:52
Handles incoming messages.
Definition: SSDP/src/include/Network/SSDP/Message.h:62
HttpError parse(char *data, size_t len)
Message using regular HTTP header management class.
Definition: SSDP/src/include/Network/SSDP/Message.h:72
Message(const Message &)=default
Message()=default
Message(const BasicMessage &msg)
The String class.
Definition: WString.h:137
Definition: SSDP/src/include/Network/SSDP/Message.h:32
static const IpAddress multicastIp(239, 255, 255, 250)
MessageType
Definition: SSDP/src/include/Network/SSDP/Message.h:40
DECLARE_FSTR(SSDP_DISCOVER)
static constexpr uint16_t multicastPort
Definition: SSDP/src/include/Network/SSDP/Message.h:34