Skip to content

Commit 4b9aa49

Browse files
authored
Merge pull request #443 from arduino-libraries/new-cloud-interfaces
New cloud interfaces
2 parents 1eba6a6 + ad40ac8 commit 4b9aa49

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

src/interfaces/CloudProcess.h

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
This file is part of the ArduinoIoTCloud library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#ifndef ARDUINO_IOT_CLOUD_PROCESS
12+
#define ARDUINO_IOT_CLOUD_PROCESS
13+
14+
/******************************************************************************
15+
* INCLUDES
16+
******************************************************************************/
17+
18+
#include <message/Commands.h>
19+
#include <interfaces/MessageStream.h>
20+
#include <assert.h>
21+
#include <functional>
22+
23+
/******************************************************************************
24+
* CLASS DECLARATION
25+
******************************************************************************/
26+
27+
class CloudProcess {
28+
public:
29+
CloudProcess(MessageStream* stream): stream(stream) {}
30+
31+
/**
32+
* Abstract method that is called whenever a message comes from Message stream
33+
* @param m: the incoming message
34+
*/
35+
virtual void handleMessage(Message* m) = 0;
36+
37+
/**
38+
* Abstract method that is called to update the FSM of the CloudProcess
39+
*/
40+
virtual void update() = 0;
41+
42+
protected:
43+
/**
44+
* Used by a derived class to send a message to the underlying messageStream
45+
* @param msg: the message to send
46+
*/
47+
void deliver(Message* msg) {
48+
assert(stream != nullptr);
49+
stream->sendUpstream(msg);
50+
}
51+
52+
private:
53+
MessageStream* stream;
54+
};
55+
56+
#endif /* ARDUINO_IOT_CLOUD_PROCESS */

src/interfaces/MessageStream.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
This file is part of the ArduinoIoTCloud library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
/******************************************************************************
14+
* INCLUDE
15+
******************************************************************************/
16+
17+
#include <message/Commands.h>
18+
#include <functional>
19+
20+
using upstreamFunction = std::function<void(Message*)>;
21+
22+
/******************************************************************************
23+
* CLASS DECLARATION
24+
******************************************************************************/
25+
26+
class MessageStream {
27+
public:
28+
MessageStream(upstreamFunction upstream): upstream(upstream) {}
29+
30+
/**
31+
* Send message upstream
32+
* @param m: message to send
33+
*/
34+
virtual inline void sendUpstream(Message* m) {
35+
upstream(m);
36+
}
37+
38+
private:
39+
upstreamFunction upstream;
40+
};

src/message/Commands.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
This file is part of the ArduinoIoTCloud library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
/******************************************************************************
14+
* INCLUDE
15+
******************************************************************************/
16+
17+
#include <stdint.h>
18+
#include <stddef.h>
19+
20+
/******************************************************************************
21+
* TYPEDEF
22+
******************************************************************************/
23+
24+
enum CommandId : uint16_t {
25+
26+
/* Device commands */
27+
DeviceBeginCmdId,
28+
ThingBeginCmdId,
29+
ThingUpdateCmdId,
30+
DeviceRegisteredCmdId,
31+
DeviceAttachedCmdId,
32+
DeviceDetachedCmdId,
33+
34+
/* Thing commands */
35+
LastValuesBeginCmdId,
36+
LastValuesUpdateCmdId,
37+
PropertiesUpdateCmdId,
38+
39+
/* Generic commands */
40+
ResetCmdId,
41+
42+
/* Unknown command id */
43+
UnknownCmdId
44+
};
45+
46+
struct Command {
47+
CommandId id;
48+
};
49+
50+
typedef Command Message;

0 commit comments

Comments
 (0)