|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include "MessagesManager.h" |
| 19 | + |
| 20 | +#include <app-common/zap-generated/attributes/Accessors.h> |
| 21 | + |
| 22 | +using namespace std; |
| 23 | +using namespace chip::app; |
| 24 | +using namespace chip::app::Clusters::Messages; |
| 25 | +using Message = chip::app::Clusters::Messages::Structs::MessageStruct::Type; |
| 26 | + |
| 27 | +// Commands |
| 28 | +void MessagesManager::HandlePresentMessagesRequest( |
| 29 | + const chip::ByteSpan & messageId, const MessagePriorityEnum & priority, |
| 30 | + const chip::BitMask<MessageControlBitmap> & messageControl, const chip::app::DataModel::Nullable<uint32_t> & startTime, |
| 31 | + const chip::app::DataModel::Nullable<uint16_t> & duration, const chip::CharSpan & messageText, |
| 32 | + const chip::Optional<chip::app::DataModel::DecodableList<MessageResponseOption>> & responses) |
| 33 | +{ |
| 34 | + Message message{ |
| 35 | + // TODO: Enable id |
| 36 | + chip::ByteSpan(), priority, messageControl, startTime, duration, |
| 37 | + // TODO: Enable text |
| 38 | + chip::CharSpan() |
| 39 | + // TODO: Convert responses to Optional<chip::app::DataModel::List<const |
| 40 | + // chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type>> message.responses = responses; |
| 41 | + }; |
| 42 | + |
| 43 | + mMessages.push_back(message); |
| 44 | + // Add your code to present Message |
| 45 | +} |
| 46 | + |
| 47 | +void MessagesManager::HandleCancelMessagesRequest(const chip::app::DataModel::DecodableList<chip::ByteSpan> & messageIds) |
| 48 | +{ |
| 49 | + // TODO: Cancel Message |
| 50 | +} |
| 51 | + |
| 52 | +// Attributes |
| 53 | +CHIP_ERROR MessagesManager::HandleGetMessages(chip::app::AttributeValueEncoder & aEncoder) |
| 54 | +{ |
| 55 | + return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { |
| 56 | + for (Message & entry : mMessages) |
| 57 | + { |
| 58 | + ReturnErrorOnFailure(encoder.Encode(entry)); |
| 59 | + } |
| 60 | + return CHIP_NO_ERROR; |
| 61 | + }); |
| 62 | +} |
| 63 | + |
| 64 | +CHIP_ERROR MessagesManager::HandleGetActiveMessageIds(chip::app::AttributeValueEncoder & aEncoder) |
| 65 | +{ |
| 66 | + return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { |
| 67 | + for (Message & entry : mMessages) |
| 68 | + { |
| 69 | + ReturnErrorOnFailure(encoder.Encode(entry.messageID)); |
| 70 | + } |
| 71 | + return CHIP_NO_ERROR; |
| 72 | + }); |
| 73 | +} |
| 74 | + |
| 75 | +// Global Attributes |
| 76 | +uint32_t MessagesManager::GetFeatureMap(chip::EndpointId endpoint) |
| 77 | +{ |
| 78 | + uint32_t featureMap = 0; |
| 79 | + Attributes::FeatureMap::Get(endpoint, &featureMap); |
| 80 | + return featureMap; |
| 81 | +} |
0 commit comments