16
16
*/
17
17
18
18
#include < app/util/config.h>
19
+ #include < app-common/zap-generated/attributes/Accessors.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
32
struct InputData inputData1 (1 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 1" ,
29
33
" High-Definition Multimedia Interface" );
@@ -35,7 +39,13 @@ MediaInputManager::MediaInputManager()
35
39
" High-Definition Multimedia Interface" );
36
40
mInputs .push_back(inputData3);
37
41
38
- mCurrentInput = 1 ;
42
+ // Sync the attributes from delegate
43
+ Status status = Attributes::CurrentInput::Get (endpoint, &mCurrentInput );
44
+
45
+ if (Status::Success != status) {
46
+ ChipLogError (Zcl, " Unable to save CurrentInput attribute " );
47
+ mCurrentInput = 1 ;
48
+ }
39
49
}
40
50
41
51
CHIP_ERROR MediaInputManager::HandleGetInputList (chip::app::AttributeValueEncoder & aEncoder)
@@ -56,11 +66,20 @@ uint8_t MediaInputManager::HandleGetCurrentInput()
56
66
57
67
bool MediaInputManager::HandleSelectInput (const uint8_t index)
58
68
{
69
+ if (mCurrentInput == index ) {
70
+ ChipLogProgress (Zcl, " CurrentInput is same as new value: %u" , index );
71
+ return true ;
72
+ }
59
73
for (auto const & inputData : mInputs )
60
74
{
61
75
if (inputData.index == index )
62
76
{
63
77
mCurrentInput = index ;
78
+ // Sync the CurrentInput to attribute storage while reporting changes
79
+ Status status = chip::app::Clusters::MediaInput::Attributes::CurrentInput::Set (mEndpoint , index );
80
+ if (Status::Success != status) {
81
+ ChipLogError (Zcl, " CurrentInput is not stored successfully" );
82
+ }
64
83
return true ;
65
84
}
66
85
}
@@ -100,10 +119,14 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
100
119
return false ;
101
120
}
102
121
103
- static MediaInputManager mediaInputManager ;
122
+ static std::map<chip::EndpointId, std::unique_ptr< MediaInputManager>> gMediaInputManagerInstance {} ;
104
123
void emberAfMediaInputClusterInitCallback (EndpointId endpoint)
105
124
{
106
- ChipLogProgress (Zcl, " TV Linux App: MediaInput::SetDefaultDelegate" );
107
- chip::app::Clusters::MediaInput::SetDefaultDelegate (endpoint, &mediaInputManager);
125
+ ChipLogProgress (Zcl, " TV Linux App: MediaInput::SetDefaultDelegate, endpoint=%x" , endpoint);
126
+
127
+ gMediaInputManagerInstance [endpoint] = std::make_unique<MediaInputManager>(endpoint);
128
+
129
+ chip::app::Clusters::MediaInput::SetDefaultDelegate (endpoint, gMediaInputManagerInstance [endpoint].get ());
130
+
108
131
}
109
132
#endif // MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER
0 commit comments