forked from rdkcentral/rdkservices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteControl.cpp
847 lines (701 loc) · 34.1 KB
/
RemoteControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2023 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "RemoteControl.h"
#include "libIBusDaemon.h"
#include "UtilsUnused.h"
#include "UtilsCStr.h"
#include "UtilsJsonRpc.h"
#include "UtilsIarm.h"
#include "UtilsString.h"
#include <exception>
#define IARM_FACTORY_RESET_TIMEOUT (15 * 1000) // 15 seconds, in milliseconds
#define IARM_IRDB_CALLS_TIMEOUT (10 * 1000) // 10 seconds, in milliseconds
using namespace std;
#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 4
#define API_VERSION_NUMBER_PATCH 1
namespace WPEFramework {
namespace {
static Plugin::Metadata<Plugin::RemoteControl> metadata(
// Version (Major, Minor, Patch)
API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH,
// Preconditions
{},
// Terminations
{},
// Controls
{}
);
}
namespace Plugin {
SERVICE_REGISTRATION(RemoteControl, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH);
RemoteControl* RemoteControl::_instance = nullptr;
RemoteControl::RemoteControl()
: PluginHost::JSONRPC()
, m_apiVersionNumber((uint32_t)-1) /* default max uint32_t so everything gets enabled */ //TODO(MROLLINS) Can't we access this from jsonrpc interface?
{
LOGINFO("ctor");
RemoteControl::_instance = this;
Register("getApiVersionNumber", &RemoteControl::getApiVersionNumber, this);
Register("startPairing", &RemoteControl::startPairing, this);
Register("getNetStatus", &RemoteControl::getNetStatus, this);
Register("getIRDBManufacturers", &RemoteControl::getIRDBManufacturers, this);
Register("getIRDBModels", &RemoteControl::getIRDBModels, this);
Register("getIRCodesByAutoLookup", &RemoteControl::getIRCodesByAutoLookup,this);
Register("getIRCodesByNames", &RemoteControl::getIRCodesByNames, this);
Register("setIRCode", &RemoteControl::setIRCode, this);
Register("clearIRCodes", &RemoteControl::clearIRCodes, this);
Register("getLastKeypressSource", &RemoteControl::getLastKeypressSource, this);
Register("configureWakeupKeys", &RemoteControl::configureWakeupKeys, this);
Register("initializeIRDB", &RemoteControl::initializeIRDB, this);
Register("findMyRemote", &RemoteControl::findMyRemote, this);
Register("factoryReset", &RemoteControl::factoryReset, this);
m_hasOwnProcess = false;
setApiVersionNumber(1);
}
RemoteControl::~RemoteControl()
{
//LOGINFO("dtor");
}
const string RemoteControl::Initialize(PluginHost::IShell* /* service */)
{
InitializeIARM();
// On success return empty, to indicate there is no error text.
return (string());
}
void RemoteControl::Deinitialize(PluginHost::IShell* /* service */)
{
DeinitializeIARM();
RemoteControl::_instance = nullptr;
}
void RemoteControl::InitializeIARM()
{
if (Utils::IARM::init())
{
m_hasOwnProcess = true;
IARM_Result_t res;
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RCU_STATUS, remoteEventHandler) );
// Register for ControlMgr pairing-related events
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_BEGIN, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_KEY_PRESS, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_END, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT, remoteEventHandler) );
}
else
m_hasOwnProcess = false;
}
//TODO(MROLLINS) - we need to install crash handler to ensure DeinitializeIARM gets called
void RemoteControl::DeinitializeIARM()
{
if (m_hasOwnProcess)
{
IARM_Result_t res;
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RCU_STATUS, remoteEventHandler) );
// Remove handlers for ControlMgr pairing-related events
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_BEGIN, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_KEY_PRESS, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_END, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT, remoteEventHandler) );
IARM_CHECK( IARM_Bus_Disconnect() );
IARM_CHECK( IARM_Bus_Term() );
m_hasOwnProcess = false;
}
}
void RemoteControl::remoteEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
{
if (RemoteControl::_instance)
RemoteControl::_instance->iarmEventHandler(owner, eventId, data, len);
else
LOGWARN("WARNING - cannot handle btremote IARM events without a RemoteControl plugin instance!");
}
//bt handlers
void RemoteControl::iarmEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
{
if (strcmp(owner, CTRLM_MAIN_IARM_BUS_NAME))
{
LOGERR("ERROR - unexpected event: owner %s, eventId: %d, data: %p, size: %d.",
owner, (int)eventId, data, len);
return;
}
if ((data == NULL) || (len == 0))
{
LOGERR("ERROR - event with NO DATA: eventId: %d, data: %p, size: %d.", (int)eventId, data, len);
return;
}
ctrlm_main_iarm_event_json_t *eventData = static_cast<ctrlm_main_iarm_event_json_t *>(data);
switch(eventId) {
case CTRLM_RCU_IARM_EVENT_RCU_STATUS:
case CTRLM_RCU_IARM_EVENT_VALIDATION_BEGIN:
case CTRLM_RCU_IARM_EVENT_VALIDATION_KEY_PRESS:
case CTRLM_RCU_IARM_EVENT_VALIDATION_END:
case CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE:
case CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT:
LOGWARN("Got CTRLM_RCU_IARM_EVENT event.");
onStatus(eventData);
break;
default:
LOGERR("ERROR - unexpected ctrlm event: eventId: %d, data: %p, size: %d.",
(int)eventId, data, len);
break;
}
} // End iarmEventHandler()
//Begin methods
uint32_t RemoteControl::getApiVersionNumber(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
response["version"] = m_apiVersionNumber;
returnResponse(true);
}
uint32_t RemoteControl::startPairing(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_START_PAIRING, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_PAIRING Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("START PAIRING call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_PAIRING returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getNetStatus(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("GET RCU STATUS call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getIRDBManufacturers(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
// The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB.
// So increase the timeout to IARM_IRDB_CALLS_TIMEOUT
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("IRDB MANUFACTURERS call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getIRDBModels(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
// The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB.
// So increase the timeout to IARM_IRDB_CALLS_TIMEOUT
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_MODELS, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MODELS Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("IRDB MODELS call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MODELS returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getIRCodesByAutoLookup(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
// The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB.
// So increase the timeout to IARM_IRDB_CALLS_TIMEOUT
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("IRDB AUTO LOOKUP call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getIRCodesByNames(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
// The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB.
// So increase the timeout to IARM_IRDB_CALLS_TIMEOUT
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_CODES, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CODES Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("GET IR CODES call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CODES returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::setIRCode(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_SET_CODE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_SET_CODE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("SET IR CODES call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_SET_CODE returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::clearIRCodes(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("CLEAR IR CODES call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::getLastKeypressSource(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("GET LAST KEYPRESS call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::configureWakeupKeys(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("WRITE RCU WAKEUP CONFIG call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::initializeIRDB(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_INITIALIZE, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_INITIALIZE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("INITIALIZE IRDB call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_INITIALIZE returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::findMyRemote(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("FIND MY REMOTE call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE returned FAILURE!");
returnResponse(bSuccess);
}
uint32_t RemoteControl::factoryReset(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();
ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;
parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);
if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}
call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';
// The default timeout for IARM calls is 5 seconds, but this call could take longer and we need to ensure the remotes receive
// the message before the larger system factory reset operation continues. Therefore, make this timeout longer.
res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_FACTORY_RESET, (void *)call, totalsize, IARM_FACTORY_RESET_TIMEOUT);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FACTORY_RESET Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}
JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);
if (bSuccess)
LOGINFO("FACTORY RESET call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FACTORY_RESET returned FAILURE!");
returnResponse(bSuccess);
}
//End methods
//Begin ble events
void RemoteControl::onStatus(ctrlm_main_iarm_event_json_t* eventData)
{
JsonObject params;
params.FromString(eventData->payload);
sendNotify("onStatus", params);
}
//End ble events
//Begin local private utility methods
void RemoteControl::setApiVersionNumber(unsigned int apiVersionNumber)
{
LOGINFO("setting version: %d", (int)apiVersionNumber);
m_apiVersionNumber = apiVersionNumber;
}
//End local private utility methods
} // namespace Plugin
} // namespace WPEFramework