Skip to content

New cloud interfaces #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/interfaces/CloudProcess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
This file is part of the ArduinoIoTCloud library.
Copyright (c) 2024 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#ifndef ARDUINO_IOT_CLOUD_PROCESS
#define ARDUINO_IOT_CLOUD_PROCESS

/******************************************************************************
* INCLUDES
******************************************************************************/

#include <message/Commands.h>
#include <interfaces/MessageStream.h>
#include <assert.h>
#include <functional>

/******************************************************************************
* CLASS DECLARATION
******************************************************************************/

class CloudProcess {
public:
CloudProcess(MessageStream* stream): stream(stream) {}

/**
* Abstract method that is called whenever a message comes from Message stream
* @param m: the incoming message
*/
virtual void handleMessage(Message* m) = 0;

/**
* Abstract method that is called to update the FSM of the CloudProcess
*/
virtual void update() = 0;

protected:
/**
* Used by a derived class to send a message to the underlying messageStream
* @param msg: the message to send
*/
void deliver(Message* msg) {
assert(stream != nullptr);
stream->sendUpstream(msg);
}

private:
MessageStream* stream;
};

#endif /* ARDUINO_IOT_CLOUD_PROCESS */
40 changes: 40 additions & 0 deletions src/interfaces/MessageStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
This file is part of the ArduinoIoTCloud library.
Copyright (c) 2024 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <message/Commands.h>
#include <functional>

using upstreamFunction = std::function<void(Message*)>;

/******************************************************************************
* CLASS DECLARATION
******************************************************************************/

class MessageStream {
public:
MessageStream(upstreamFunction upstream): upstream(upstream) {}

/**
* Send message upstream
* @param m: message to send
*/
virtual inline void sendUpstream(Message* m) {
upstream(m);
}

private:
upstreamFunction upstream;
};
50 changes: 50 additions & 0 deletions src/message/Commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
This file is part of the ArduinoIoTCloud library.
Copyright (c) 2024 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <stdint.h>
#include <stddef.h>

/******************************************************************************
* TYPEDEF
******************************************************************************/

enum CommandId : uint16_t {

/* Device commands */
DeviceBeginCmdId,
ThingBeginCmdId,
ThingUpdateCmdId,
DeviceRegisteredCmdId,
DeviceAttachedCmdId,
DeviceDetachedCmdId,

/* Thing commands */
LastValuesBeginCmdId,
LastValuesUpdateCmdId,
PropertiesUpdateCmdId,

/* Generic commands */
ResetCmdId,

/* Unknown command id */
UnknownCmdId
};

struct Command {
CommandId id;
};

typedef Command Message;
Loading