15
15
* limitations under the License.
16
16
*/
17
17
18
+ #include < app-common/zap-generated/attributes/Accessors.h>
18
19
#include < app/util/config.h>
20
+ #include < map>
21
+
19
22
#ifdef MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER
20
23
#include " MediaInputManager.h"
21
24
22
25
using namespace std ;
23
26
using namespace chip ;
24
27
using namespace chip ::app::Clusters::MediaInput;
28
+ using Protocols::InteractionModel::Status;
25
29
26
- MediaInputManager::MediaInputManager ()
30
+ MediaInputManager::MediaInputManager (chip::EndpointId endpoint) : mEndpoint(endpoint )
27
31
{
28
- struct InputData inputData1 (1 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 1" ,
29
- " High-Definition Multimedia Interface" );
32
+ struct InputData inputData1 (1 , InputTypeEnum::kHdmi , " HDMI 1" , " High-Definition Multimedia Interface" );
30
33
mInputs .push_back(inputData1);
31
- struct InputData inputData2 (2 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 2" ,
32
- " High-Definition Multimedia Interface" );
34
+ struct InputData inputData2 (2 , InputTypeEnum::kHdmi , " HDMI 2" , " High-Definition Multimedia Interface" );
33
35
mInputs .push_back(inputData2);
34
- struct InputData inputData3 (3 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 3" ,
35
- " High-Definition Multimedia Interface" );
36
+ struct InputData inputData3 (3 , InputTypeEnum::kHdmi , " HDMI 3" , " High-Definition Multimedia Interface" );
36
37
mInputs .push_back(inputData3);
37
-
38
- mCurrentInput = 1 ;
39
38
}
40
39
41
40
CHIP_ERROR MediaInputManager::HandleGetInputList (chip::app::AttributeValueEncoder & aEncoder)
@@ -51,16 +50,32 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
51
50
52
51
uint8_t MediaInputManager::HandleGetCurrentInput ()
53
52
{
54
- return mCurrentInput ;
53
+ uint8_t currentInput = 1 ;
54
+ Status status = Attributes::CurrentInput::Get (mEndpoint , ¤tInput);
55
+ if (Status::Success != status)
56
+ {
57
+ ChipLogError (Zcl, " Unable to get CurrentInput attribute, err:0x%x" , to_underlying (status));
58
+ }
59
+ return currentInput;
55
60
}
56
61
57
62
bool MediaInputManager::HandleSelectInput (const uint8_t index)
58
63
{
64
+ if (HandleGetCurrentInput () == index )
65
+ {
66
+ ChipLogProgress (Zcl, " CurrentInput is same as new value: %u" , index );
67
+ return true ;
68
+ }
59
69
for (auto const & inputData : mInputs )
60
70
{
61
71
if (inputData.index == index )
62
72
{
63
- mCurrentInput = index ;
73
+ // Sync the CurrentInput to attribute storage while reporting changes
74
+ Status status = Attributes::CurrentInput::Set (mEndpoint , index );
75
+ if (Status::Success != status)
76
+ {
77
+ ChipLogError (Zcl, " CurrentInput is not stored successfully, err:0x%x" , to_underlying (status));
78
+ }
64
79
return true ;
65
80
}
66
81
}
@@ -70,11 +85,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
70
85
71
86
bool MediaInputManager::HandleShowInputStatus ()
72
87
{
88
+ uint8_t currentInput = HandleGetCurrentInput ();
73
89
ChipLogProgress (Zcl, " MediaInputManager::HandleShowInputStatus()" );
74
90
for (auto const & inputData : mInputs )
75
91
{
76
92
ChipLogProgress (Zcl, " [%d] type=%d selected=%d name=%s desc=%s" , inputData.index ,
77
- static_cast <uint16_t >(inputData.inputType ), (mCurrentInput == inputData.index ? 1 : 0 ),
93
+ static_cast <uint16_t >(inputData.inputType ), (currentInput == inputData.index ? 1 : 0 ),
78
94
inputData.name .c_str (), inputData.description .c_str ());
79
95
}
80
96
return true ;
@@ -99,4 +115,15 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
99
115
100
116
return false ;
101
117
}
118
+
119
+ static std::map<chip::EndpointId, std::unique_ptr<MediaInputManager>> gMediaInputManagerInstance {};
120
+
121
+ void emberAfMediaInputClusterInitCallback (EndpointId endpoint)
122
+ {
123
+ ChipLogProgress (Zcl, " TV Linux App: MediaInput::SetDefaultDelegate, endpoint=%x" , endpoint);
124
+
125
+ gMediaInputManagerInstance [endpoint] = std::make_unique<MediaInputManager>(endpoint);
126
+
127
+ SetDefaultDelegate (endpoint, gMediaInputManagerInstance [endpoint].get ());
128
+ }
102
129
#endif // MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER
0 commit comments