16
16
*/
17
17
18
18
#include " ChannelManager.h"
19
+ #include " TvApp-JNI.h"
20
+ #include < app-common/zap-generated/ids/Clusters.h>
21
+ #include < jni.h>
19
22
#include < lib/core/CHIPSafeCasts.h>
20
23
#include < lib/support/CHIPJNIError.h>
21
24
#include < lib/support/JniReferences.h>
24
27
using namespace chip ;
25
28
using namespace chip ::app::Clusters::Channel;
26
29
27
- namespace {
28
- static ChannelManager channelManager;
29
- } // namespace
30
+ /* * @brief Channel Cluster Init
31
+ *
32
+ * This function is called when a specific cluster is initialized. It gives the
33
+ * application an opportunity to take care of cluster initialization procedures.
34
+ * It is called exactly once for each endpoint where cluster is present.
35
+ *
36
+ * @param endpoint Ver.: always
37
+ *
38
+ */
39
+ void emberAfChannelClusterInitCallback (EndpointId endpoint)
40
+ {
41
+ ChipLogProgress (Zcl, " TV Android App: Channel::PostClusterInit" );
42
+ TvAppJNIMgr ().PostClusterInit (chip::app::Clusters::Channel::Id, endpoint);
43
+ }
30
44
31
- std::list<chip::app::Clusters::Channel::Structs::ChannelInfo::Type> ChannelManager::HandleGetChannelList ()
45
+ void ChannelManager::NewManager (jint endpoint, jobject manager)
46
+ {
47
+ ChipLogProgress (Zcl, " TV Android App: Channel::SetDefaultDelegate" );
48
+ ChannelManager * mgr = new ChannelManager ();
49
+ mgr->InitializeWithObjects (manager);
50
+ chip::app::Clusters::Channel::SetDefaultDelegate (static_cast <EndpointId>(endpoint), mgr);
51
+ }
52
+
53
+ CHIP_ERROR ChannelManager::HandleGetChannelList (chip::app::AttributeValueEncoder & aEncoder)
32
54
{
33
- std::list<Structs::ChannelInfo::Type> list;
34
55
CHIP_ERROR err = CHIP_NO_ERROR;
35
56
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
36
57
@@ -39,9 +60,17 @@ std::list<chip::app::Clusters::Channel::Structs::ChannelInfo::Type> ChannelManag
39
60
VerifyOrExit (mGetChannelListMethod != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
40
61
VerifyOrExit (env != NULL , err = CHIP_JNI_ERROR_NO_ENV);
41
62
42
- {
63
+ return aEncoder. EncodeList ([ this , env]( const auto & encoder) -> CHIP_ERROR {
43
64
jobjectArray channelInfoList = (jobjectArray) env->CallObjectMethod (mChannelManagerObject , mGetChannelListMethod );
44
- jint length = env->GetArrayLength (channelInfoList);
65
+ if (env->ExceptionCheck ())
66
+ {
67
+ ChipLogError (Zcl, " Java exception in ChannelManager::HandleGetChannelList" );
68
+ env->ExceptionDescribe ();
69
+ env->ExceptionClear ();
70
+ return CHIP_ERROR_INCORRECT_STATE;
71
+ }
72
+
73
+ jint length = env->GetArrayLength (channelInfoList);
45
74
46
75
for (jint i = 0 ; i < length; i++)
47
76
{
@@ -62,15 +91,15 @@ std::list<chip::app::Clusters::Channel::Structs::ChannelInfo::Type> ChannelManag
62
91
if (jname != NULL )
63
92
{
64
93
JniUtfString name (env, jname);
65
- channelInfo.callSign = name.charSpan ();
94
+ channelInfo.name = name.charSpan ();
66
95
}
67
96
68
97
jfieldID getJaffiliateCallSignField = env->GetFieldID (channelClass, " affiliateCallSign" , " Ljava/lang/String;" );
69
98
jstring jaffiliateCallSign = static_cast <jstring>(env->GetObjectField (channelObject, getJaffiliateCallSignField));
70
99
if (jaffiliateCallSign != NULL )
71
100
{
72
101
JniUtfString affiliateCallSign (env, jaffiliateCallSign);
73
- channelInfo.callSign = affiliateCallSign.charSpan ();
102
+ channelInfo.affiliateCallSign = affiliateCallSign.charSpan ();
74
103
}
75
104
76
105
jfieldID majorNumField = env->GetFieldID (channelClass, " majorNumber" , " I" );
@@ -79,21 +108,24 @@ std::list<chip::app::Clusters::Channel::Structs::ChannelInfo::Type> ChannelManag
79
108
80
109
jfieldID minorNumField = env->GetFieldID (channelClass, " minorNumber" , " I" );
81
110
jint jminorNum = env->GetIntField (channelObject, minorNumField);
82
- channelInfo.majorNumber = static_cast <uint16_t >(jminorNum);
83
- list.push_back (channelInfo);
111
+ channelInfo.minorNumber = static_cast <uint16_t >(jminorNum);
112
+
113
+ ReturnErrorOnFailure (encoder.Encode (channelInfo));
84
114
}
85
- }
115
+
116
+ return CHIP_NO_ERROR;
117
+ });
86
118
87
119
exit :
88
120
if (err != CHIP_NO_ERROR)
89
121
{
90
122
ChipLogError (Zcl, " ChannelManager::getChannelList status error: %s" , err.AsString ());
91
123
}
92
124
93
- return list ;
125
+ return err ;
94
126
}
95
127
96
- chip::app::Clusters::Channel::Structs::LineupInfo::Type ChannelManager::HandleGetLineup ( )
128
+ CHIP_ERROR ChannelManager::HandleGetLineup ( chip::app::AttributeValueEncoder & aEncoder )
97
129
{
98
130
chip::app::Clusters::Channel::Structs::LineupInfo::Type lineupInfo;
99
131
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -135,6 +167,8 @@ chip::app::Clusters::Channel::Structs::LineupInfo::Type ChannelManager::HandleGe
135
167
jfieldID lineupInfoTypeFild = env->GetFieldID (channelLineupClazz, " lineupInfoTypeEnum" , " I" );
136
168
jint jlineupInfoType = (env->GetIntField (channelLineupObject, lineupInfoTypeFild));
137
169
lineupInfo.lineupInfoType = static_cast <app::Clusters::Channel::LineupInfoTypeEnum>(jlineupInfoType);
170
+
171
+ err = aEncoder.Encode (lineupInfo);
138
172
}
139
173
140
174
exit :
@@ -143,10 +177,10 @@ chip::app::Clusters::Channel::Structs::LineupInfo::Type ChannelManager::HandleGe
143
177
ChipLogError (Zcl, " ChannelManager::getChannelLineup status error: %s" , err.AsString ());
144
178
}
145
179
146
- return lineupInfo ;
180
+ return err ;
147
181
}
148
182
149
- chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleGetCurrentChannel ( )
183
+ CHIP_ERROR ChannelManager::HandleGetCurrentChannel ( chip::app::AttributeValueEncoder & aEncoder )
150
184
{
151
185
chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo;
152
186
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -173,15 +207,15 @@ chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleG
173
207
if (jname != NULL )
174
208
{
175
209
JniUtfString name (env, jname);
176
- channelInfo.callSign = name.charSpan ();
210
+ channelInfo.name = name.charSpan ();
177
211
}
178
212
179
213
jfieldID getJaffiliateCallSignField = env->GetFieldID (channelClass, " affiliateCallSign" , " Ljava/lang/String;" );
180
214
jstring jaffiliateCallSign = static_cast <jstring>(env->GetObjectField (channelInfoObject, getJaffiliateCallSignField));
181
215
if (jaffiliateCallSign != NULL )
182
216
{
183
217
JniUtfString affiliateCallSign (env, jaffiliateCallSign);
184
- channelInfo.callSign = affiliateCallSign.charSpan ();
218
+ channelInfo.affiliateCallSign = affiliateCallSign.charSpan ();
185
219
}
186
220
187
221
jfieldID majorNumField = env->GetFieldID (channelClass, " majorNumber" , " I" );
@@ -190,7 +224,9 @@ chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleG
190
224
191
225
jfieldID minorNumField = env->GetFieldID (channelClass, " minorNumber" , " I" );
192
226
jint jminorNum = env->GetIntField (channelInfoObject, minorNumField);
193
- channelInfo.majorNumber = static_cast <uint16_t >(jminorNum);
227
+ channelInfo.minorNumber = static_cast <uint16_t >(jminorNum);
228
+
229
+ err = aEncoder.Encode (channelInfo);
194
230
}
195
231
196
232
exit :
@@ -199,10 +235,12 @@ chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleG
199
235
ChipLogError (Zcl, " ChannelManager::HandleGetCurrentChannel status error: %s" , err.AsString ());
200
236
}
201
237
202
- return channelInfo ;
238
+ return err ;
203
239
}
204
240
205
- Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel (const chip::CharSpan & match)
241
+ void ChannelManager::HandleChangeChannel (
242
+ const chip::CharSpan & match,
243
+ chip::app::CommandResponseHelper<chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type> & responser)
206
244
{
207
245
std::string name (match.data (), match.size ());
208
246
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
@@ -225,11 +263,15 @@ Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel(const
225
263
ChipLogError (DeviceLayer, " Java exception in ChannelManager::HandleChangeChannel" );
226
264
env->ExceptionDescribe ();
227
265
env->ExceptionClear ();
228
- return response ;
266
+ goto exit ;
229
267
}
230
268
231
269
jclass channelClass = env->GetObjectClass (channelObject);
232
270
271
+ jfieldID getErrorTypeField = env->GetFieldID (channelClass, " errorType" , " I" );
272
+ jint jerrorType = env->GetIntField (channelObject, getErrorTypeField);
273
+ response.errorType = static_cast <app::Clusters::Channel::ErrorTypeEnum>(jerrorType);
274
+
233
275
jfieldID getCallSignField = env->GetFieldID (channelClass, " callSign" , " Ljava/lang/String;" );
234
276
jstring jcallSign = static_cast <jstring>(env->GetObjectField (channelObject, getCallSignField));
235
277
if (jcallSign != NULL )
@@ -243,14 +285,14 @@ Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel(const
243
285
if (jname != NULL )
244
286
{
245
287
JniUtfString junitname (env, jname);
246
- response.channelMatch .callSign = junitname.charSpan ();
288
+ response.channelMatch .name = junitname.charSpan ();
247
289
}
248
290
jfieldID getJaffiliateCallSignField = env->GetFieldID (channelClass, " affiliateCallSign" , " Ljava/lang/String;" );
249
291
jstring jaffiliateCallSign = static_cast <jstring>(env->GetObjectField (channelObject, getJaffiliateCallSignField));
250
292
if (jaffiliateCallSign != NULL )
251
293
{
252
294
JniUtfString affiliateCallSign (env, jaffiliateCallSign);
253
- response.channelMatch .callSign = affiliateCallSign.charSpan ();
295
+ response.channelMatch .affiliateCallSign = affiliateCallSign.charSpan ();
254
296
}
255
297
256
298
jfieldID majorNumField = env->GetFieldID (channelClass, " majorNumber" , " I" );
@@ -259,12 +301,13 @@ Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel(const
259
301
260
302
jfieldID minorNumField = env->GetFieldID (channelClass, " minorNumber" , " I" );
261
303
jint jminorNum = env->GetIntField (channelObject, minorNumField);
262
- response.channelMatch .majorNumber = static_cast <uint16_t >(jminorNum);
304
+ response.channelMatch .minorNumber = static_cast <uint16_t >(jminorNum);
305
+
306
+ responser.Success (response);
263
307
}
264
308
265
309
exit :
266
-
267
- return response;
310
+ return ;
268
311
}
269
312
270
313
bool ChannelManager::HandleChangeChannelByNumber (const uint16_t & majorNumber, const uint16_t & minorNumber)
@@ -372,20 +415,3 @@ void ChannelManager::InitializeWithObjects(jobject managerObject)
372
415
env->ExceptionClear ();
373
416
}
374
417
}
375
-
376
- ChannelManager ChannelManager::sInstance ;
377
-
378
- /* * @brief Channel Cluster Init
379
- *
380
- * This function is called when a specific cluster is initialized. It gives the
381
- * application an opportunity to take care of cluster initialization procedures.
382
- * It is called exactly once for each endpoint where cluster is present.
383
- *
384
- * @param endpoint Ver.: always
385
- *
386
- */
387
- void emberAfChannelClusterInitCallback (EndpointId endpoint)
388
- {
389
- ChipLogProgress (Zcl, " TV Android App: Channel::SetDefaultDelegate" );
390
- chip::app::Clusters::Channel::SetDefaultDelegate (endpoint, &channelManager);
391
- }
0 commit comments