Skip to content

Commit babc03e

Browse files
TV Matter Media: Add logic to message cluster (#31943)
* Adding basic logic * Updates * Update message cluster * Update copyright * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent cda0379 commit babc03e

File tree

10 files changed

+510
-14
lines changed

10 files changed

+510
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
using namespace std;
21+
using namespace chip::app;
22+
using namespace chip::app::Clusters::Messages;
23+
24+
// Commands
25+
void MessagesManager::HandlePresentMessagesRequest(
26+
const chip::ByteSpan & messageId, const MessagePriorityEnum & priority,
27+
const chip::BitMask<MessageControlBitmap> & messageControl, const chip::app::DataModel::Nullable<uint32_t> & startTime,
28+
const chip::app::DataModel::Nullable<uint16_t> & duration, const chip::CharSpan & messageText,
29+
const chip::Optional<chip::app::DataModel::DecodableList<MessageResponseOption>> & responses)
30+
{
31+
// TODO: Present Message
32+
}
33+
34+
void MessagesManager::HandleCancelMessagesRequest(const chip::app::DataModel::DecodableList<chip::ByteSpan> & messageIds)
35+
{
36+
// TODO: Cancel Message
37+
}
38+
39+
// Attributes
40+
CHIP_ERROR MessagesManager::HandleGetMessages(chip::app::AttributeValueEncoder & aEncoder)
41+
{
42+
return aEncoder.EncodeEmptyList();
43+
}
44+
45+
CHIP_ERROR MessagesManager::HandleGetActiveMessageIds(chip::app::AttributeValueEncoder & aEncoder)
46+
{
47+
return aEncoder.EncodeEmptyList();
48+
}
49+
50+
// Global Attributes
51+
uint32_t MessagesManager::GetFeatureMap(chip::EndpointId endpoint)
52+
{
53+
return 1;
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
#pragma once
19+
20+
#include <app/clusters/messages-server/messages-server.h>
21+
#include <list>
22+
23+
class MessagesManager : public chip::app::Clusters::Messages::Delegate
24+
{
25+
public:
26+
// Commands
27+
void HandlePresentMessagesRequest(
28+
const chip::ByteSpan & messageId, const chip::app::Clusters::Messages::MessagePriorityEnum & priority,
29+
const chip::BitMask<chip::app::Clusters::Messages::MessageControlBitmap> & messageControl,
30+
const chip::app::DataModel::Nullable<uint32_t> & startTime, const chip::app::DataModel::Nullable<uint16_t> & duration,
31+
const chip::CharSpan & messageText,
32+
const chip::Optional<chip::app::DataModel::DecodableList<
33+
chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::DecodableType>> & responses) override;
34+
void HandleCancelMessagesRequest(const chip::app::DataModel::DecodableList<chip::ByteSpan> & messageIds) override;
35+
36+
// Attributes
37+
CHIP_ERROR HandleGetMessages(chip::app::AttributeValueEncoder & aEncoder) override;
38+
CHIP_ERROR HandleGetActiveMessageIds(chip::app::AttributeValueEncoder & aEncoder) override;
39+
40+
// Global Attributes
41+
uint32_t GetFeatureMap(chip::EndpointId endpoint) override;
42+
43+
protected:
44+
std::list<std::string> mMessages;
45+
};

examples/tv-app/tv-common/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ source_set("tv-common-sources") {
6464
"clusters/media-input/MediaInputManager.h",
6565
"clusters/media-playback/MediaPlaybackManager.cpp",
6666
"clusters/media-playback/MediaPlaybackManager.h",
67+
"clusters/messages/MessagesManager.cpp",
68+
"clusters/messages/MessagesManager.h",
6769
"clusters/target-navigator/TargetNavigatorManager.cpp",
6870
"clusters/target-navigator/TargetNavigatorManager.h",
6971
"clusters/wake-on-lan/WakeOnLanManager.cpp",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#pragma once
19+
20+
#include <app/clusters/messages-server/messages-server.h>
21+
22+
#include <iostream>
23+
#include <list>
24+
25+
class MessagesManager : public chip::app::Clusters::Messages::Delegate
26+
{
27+
public:
28+
// Commands
29+
void HandlePresentMessagesRequest(
30+
const chip::ByteSpan & messageId, const chip::app::Clusters::Messages::MessagePriorityEnum & priority,
31+
const chip::BitMask<chip::app::Clusters::Messages::MessageControlBitmap> & messageControl,
32+
const chip::app::DataModel::Nullable<uint32_t> & startTime, const chip::app::DataModel::Nullable<uint16_t> & duration,
33+
const chip::CharSpan & messageText,
34+
const chip::Optional<
35+
chip::app::DataModel::DecodableList<chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type>> &
36+
responses) override;
37+
void HandleCancelMessagesRequest(const chip::app::DataModel::DecodableList<chip::ByteSpan> & messageIds) override;
38+
39+
// Attributes
40+
CHIP_ERROR HandleGetMessages(chip::app::AttributeValueEncoder & aEncoder) override;
41+
CHIP_ERROR HandleGetActiveMessageIds(chip::app::AttributeValueEncoder & aEncoder) override;
42+
43+
// Global Attributes
44+
uint32_t GetFeatureMap(chip::EndpointId endpoint) override;
45+
46+
protected:
47+
std::list<chip::app::Clusters::Messages::Structs::MessageStruct::Type> mMessages;
48+
};

examples/tv-app/tv-common/src/ZCLCallbacks.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "low-power/LowPowerManager.h"
3838
#include "media-input/MediaInputManager.h"
3939
#include "media-playback/MediaPlaybackManager.h"
40+
#include "messages/MessagesManager.h"
4041
#include "target-navigator/TargetNavigatorManager.h"
4142
#include "wake-on-lan/WakeOnLanManager.h"
4243

@@ -56,6 +57,7 @@ static KeypadInputManager keypadInputManager;
5657
static LowPowerManager lowPowerManager;
5758
static MediaInputManager mediaInputManager;
5859
static MediaPlaybackManager mediaPlaybackManager;
60+
static MessagesManager messagesManager;
5961
static TargetNavigatorManager targetNavigatorManager;
6062
static WakeOnLanManager wakeOnLanManager;
6163
} // namespace
@@ -170,6 +172,12 @@ void emberAfMediaPlaybackClusterInitCallback(EndpointId endpoint)
170172
MediaPlayback::SetDefaultDelegate(endpoint, &mediaPlaybackManager);
171173
}
172174

175+
void emberAfMessagesClusterInitCallback(EndpointId endpoint)
176+
{
177+
ChipLogProgress(Zcl, "TV Linux App: Messages::SetDefaultDelegate");
178+
Messages::SetDefaultDelegate(endpoint, &messagesManager);
179+
}
180+
173181
void emberAfTargetNavigatorClusterInitCallback(EndpointId endpoint)
174182
{
175183
ChipLogProgress(Zcl, "TV Linux App: TargetNavigator::SetDefaultDelegate");

examples/tv-app/tv-common/tv-app.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ macro(chip_add_tv_app_common target)
6262
${CHIP_TV_COMMON_BASE_DIR}/clusters/low-power/LowPowerManager.cpp
6363
${CHIP_TV_COMMON_BASE_DIR}/clusters/media-input/MediaInputManager.cpp
6464
${CHIP_TV_COMMON_BASE_DIR}/clusters/media-playback/MediaPlaybackManager.cpp
65+
${CHIP_TV_COMMON_BASE_DIR}/clusters/messages/MessagesManager.cpp
6566
${CHIP_TV_COMMON_BASE_DIR}/clusters/target-navigator/TargetNavigatorManager.cpp
6667
${CHIP_TV_COMMON_BASE_DIR}/clusters/wake-on-lan/WakeOnLanManager.cpp
6768

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app-common/zap-generated/cluster-objects.h>
22+
23+
#include <app/AttributeAccessInterface.h>
24+
#include <app/CommandResponseHelper.h>
25+
#include <app/util/af.h>
26+
27+
namespace chip {
28+
namespace app {
29+
namespace Clusters {
30+
namespace Messages {
31+
32+
using MessageResponseOption = chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type;
33+
34+
class Delegate
35+
{
36+
public:
37+
// Commands
38+
virtual void
39+
HandlePresentMessagesRequest(const ByteSpan & messageId, const MessagePriorityEnum & priority,
40+
const chip::BitMask<MessageControlBitmap> & messageControl,
41+
const DataModel::Nullable<uint32_t> & startTime, const DataModel::Nullable<uint16_t> & duration,
42+
const CharSpan & messageText,
43+
const chip::Optional<DataModel::DecodableList<MessageResponseOption>> & responses) = 0;
44+
virtual void HandleCancelMessagesRequest(const DataModel::DecodableList<chip::ByteSpan> & messageIds) = 0;
45+
46+
// Attributes
47+
virtual CHIP_ERROR HandleGetMessages(app::AttributeValueEncoder & aEncoder) = 0;
48+
virtual CHIP_ERROR HandleGetActiveMessageIds(app::AttributeValueEncoder & aEncoder) = 0;
49+
50+
// Global Attributes
51+
bool HasFeature(chip::EndpointId endpoint, Feature feature);
52+
virtual uint32_t GetFeatureMap(chip::EndpointId endpoint) = 0;
53+
54+
virtual ~Delegate() = default;
55+
};
56+
57+
} // namespace Messages
58+
} // namespace Clusters
59+
} // namespace app
60+
} // namespace chip

0 commit comments

Comments
 (0)