|
| 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 */ |
0 commit comments