-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathprotocol.h
More file actions
1353 lines (1161 loc) · 57 KB
/
protocol.h
File metadata and controls
1353 lines (1161 loc) · 57 KB
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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* protocal const definition and implement
*/
#ifndef AMC_PROTOCOL_H
#define AMC_PROTOCOL_H
#include "amc.pb.h"
#include "header.h"
#include <cJSON.h>
// LEVEL
static const uint32_t CPU_LEVEL_0 = 0; // not change
static const uint32_t CPU_LEVEL_1 = 1; // highest
static const uint32_t CPU_LEVEL_2 = 2;
static const uint32_t CPU_LEVEL_3 = 3;
static const uint32_t GPU_LEVEL_0 = 0; // not change
static const uint32_t GPU_LEVEL_1 = 1; // highest
static const uint32_t IO_LEVEL_0 = 0; // not change
static const uint32_t IO_LEVEL_1 = 1; // highest
static const uint32_t IO_LEVEL_2 = 2;
static const uint32_t IO_LEVEL_3 = 3;
static const uint32_t JSON_VERSION = 1;
// HC register call back type
static const uint32_t REGISTER_CALLBACK_TYPE_SYSTEM_EVENT = 0x1;
static const uint32_t REGISTER_CALLBACK_TYPE_ANR = 0x2;
// HC system event definition
static const uint32_t SYSTEM_EVENT_BASE = 0x0;
static const uint32_t SYSTEM_EVENT_SLIDE_OPEN = SYSTEM_EVENT_BASE + 1;
static const uint32_t SYSTEM_EVENT_SLIDE_CLOSE = SYSTEM_EVENT_BASE + 2;
static const uint32_t SYSTEM_EVENT_BLUETOOTH_ACCEPTCALL = SYSTEM_EVENT_BASE + 3;
static const uint32_t SYSTEM_EVENT_BLUETOOTH_HANGUPCALL = SYSTEM_EVENT_BASE + 4;
static const int32_t RET_OK = 0;
//requestCpuHighFreq,requestHighIOFreq 直接返回level n
static const int32_t RET_LEVEL_1 = 1;
static const int32_t RET_LEVEL_2 = 2;
static const int32_t RET_LEVEL_3 = 3;
//预留返回值最后三位作为level,倒数第四位代表cpu level,倒数第五位代表io level,新增值继续左移
static const int32_t RET_CPU_HIGH_FREQ = 1 << 3;// 1000,即8
static const int32_t RET_HIGH_IO_FREQ = 1 << 4; // 10000,即16
static const int32_t RET_GPU_HIGH_FREQ = 1 << 5; // 100000,即32, GPU只有level 1和0,故GPU可以不使用level位,直接用100000表示level 1
//requestUnifyCpuIOThreadCoreGpu使用复合标识位
static const int32_t RET_CPU_HIGH_FREQ_LEVEL_1 = RET_CPU_HIGH_FREQ | RET_LEVEL_1; //Unify接口返回cpu level 1,1000 | 01 = 1001
static const int32_t RET_CPU_HIGH_FREQ_LEVEL_2 = RET_CPU_HIGH_FREQ | RET_LEVEL_2; //Unify接口返回cpu level 2,1000 | 10 = 1010
static const int32_t RET_CPU_HIGH_FREQ_LEVEL_3 = RET_CPU_HIGH_FREQ | RET_LEVEL_3; //Unify接口返回cpu level 3,1000 | 11 = 1011
static const int32_t RET_HIGH_IO_FREQ_LEVEL_1 = RET_HIGH_IO_FREQ | RET_LEVEL_1; //Unify接口返回io level 1,10000 | 01 = 10001
static const int32_t RET_HIGH_IO_FREQ_LEVEL_2 = RET_HIGH_IO_FREQ | RET_LEVEL_2; //Unify接口返回io level 2,10000 | 10 = 10010
static const int32_t RET_HIGH_IO_FREQ_LEVEL_3 = RET_HIGH_IO_FREQ | RET_LEVEL_3; //Unify接口返回io level 3,10000 | 11 = 10011
static const int32_t ERR_UNAUTHORIZED = -10001;
static const int32_t ERR_FUNCTION_NOT_SUPPORT = -10002;
static const int32_t ERR_SERVICE_UNAVAILABLE = -10003;
static const int32_t ERR_FAILED_DEPENDENCY = -10004;
static const int32_t ERR_PACKAGE_DECODE_FAILED = -10005;
static const int32_t ERR_PARAMETERS_WRONG = -10006;
static const int32_t ERR_CLIENT_UPGRADE_REQUIRED = -10007;
static const int32_t ERR_CLIENT_CONNECT = -20000;
static const int32_t ERR_CLIENT_DISCONNECT = -20001;
static const int32_t ERR_CLIENT_ALREADY_INIT = -20002;
// FUNC ID BEGIN , 2 ^ 16 IS MAX
static const uint32_t FUNC_BASE = 1000;
static const uint32_t FUNC_CHECK_PERMISSION = FUNC_BASE + 1;
static const uint32_t FUNC_CPU_HIGH_FREQ = FUNC_BASE + 2;
static const uint32_t FUNC_CANCEL_CPU_HIGH_FREQ = FUNC_BASE + 3;
static const uint32_t FUNC_CPU_CORE_FOR_THREAD = FUNC_BASE + 4;
static const uint32_t FUNC_CANCEL_CPU_CORE_FOR_THREAD = FUNC_BASE + 5;
static const uint32_t FUNC_HIGH_IO_FREQ = FUNC_BASE + 6;
static const uint32_t FUNC_CANCEL_HIGH_IO_FREQ = FUNC_BASE + 7;
static const uint32_t FUNC_SET_SCREEN_RESOLUTION = FUNC_BASE + 8;
static const uint32_t FUNC_RESET_SCREEN_RESOLUTION = FUNC_BASE + 9;
static const uint32_t FUNC_REG_ANR_CALLBACK = FUNC_BASE + 10;
static const uint32_t FUNC_REG_PRELOAD_BOOT_RESOURCE = FUNC_BASE + 11;
static const uint32_t FUNC_TERMINATE_APP = FUNC_BASE + 12;
static const uint32_t FUNC_UNIFY_CPU_IO_THREAD_CORE_GPU = FUNC_BASE + 13;
static const uint32_t FUNC_CANCEL_UNIFY_CPU_IO_THREAD_CORE_GPU = FUNC_BASE + 14;
static const uint32_t FUNC_REG_SYSTEM_EVENT_CALLBACK = FUNC_BASE + 15;
static const uint32_t FUNC_GPU_HIGH_FREQ = FUNC_BASE + 16;
static const uint32_t FUNC_CANCEL_GPU_HIGH_FREQ = FUNC_BASE + 17;
static const uint32_t FUNC_CONFIGURE = FUNC_BASE + 18;
static const uint32_t FUNC_GET_PARAMETERS = FUNC_BASE + 19;
static const uint32_t STATUS_NONE = 0;
static const uint32_t STATUS_REQUEST = 1;
static const uint32_t STATUS_RESET = 2;
// FUNC ID END , 2 ^ 16 IS MAX
static const uint32_t CALLBACK_TYPE_BASE = 0;
static const uint32_t CALLBACK_TYPE_STATUS = CALLBACK_TYPE_BASE + 1;
static const uint32_t CALLBACK_TYPE_DATA = CALLBACK_TYPE_BASE + 2;
//HardCoder interface
class HardCoder {
public:
virtual ~HardCoder(){}
virtual int getUidByAddress(const char *ip, int port) {
UNUSED(ip);
UNUSED(port);
return 0;
}
virtual bool checkPermission(std::vector<std::string> manufactures, std::vector<std::string> certs, int funcid, int uid, int callertid, int64_t timestamp) {
UNUSED(manufactures);
UNUSED(certs);
UNUSED(funcid);
UNUSED(uid);
UNUSED(callertid);
UNUSED(timestamp);
return true;
}
virtual int requestCpuHighFreq(int scene, int64_t action, int level, int timeoutms, int callertid, int64_t timestamp) {
UNUSED(scene);
UNUSED(action);
UNUSED(level);
UNUSED(timeoutms);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int cancelCpuHighFreq(int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int requestGpuHighFreq(int scene, int64_t action, int level, int timeoutms, int callertid, int64_t timestamp) {
UNUSED(scene);
UNUSED(timeoutms);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int cancelGpuHighFreq(int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int requestCpuCoreForThread(int scene, int64_t action, std::vector<int>bindtids, int timeoutms, int callertid, int64_t timestamp) {
UNUSED(scene);
UNUSED(action);
UNUSED(bindtids);
UNUSED(timeoutms);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int cancelCpuCoreForThread(std::vector<int>bindtids, int callertid, int64_t timestamp) {
UNUSED(bindtids);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int requestHighIOFreq(int scene, int64_t action, int level, int timeoutms, int callertid, int64_t timestamp) {
UNUSED(scene);
UNUSED(action);
UNUSED(level);
UNUSED(timeoutms);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int cancelHighIOFreq(int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int requestScreenResolution(int level, std::string uiName, int callertid, int64_t timestamp) {
UNUSED(level);
UNUSED(uiName);
UNUSED(level);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int resetScreenResolution(int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int registerAnrCallback(int uid, int callertid, int64_t timestamp) {
UNUSED(uid);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int registerSystemEventCallback(int uid, int callertid, int64_t timestamp) {
UNUSED(uid);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int registerBootPreloadResource(std::vector<std::string> file, int callertid, int64_t timestamp) {
UNUSED(file);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int terminateApp(int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int requestUnifyCpuIOThreadCoreGpu(int scene, int64_t action, int cpulevel, int iolevel, std::vector<int>bindtids, int gpulevel, int timeoutms, int callertid, int64_t timestamp) {
UNUSED(scene);
UNUSED(action);
UNUSED(cpulevel);
UNUSED(iolevel);
UNUSED(bindtids);
UNUSED(gpulevel);
UNUSED(timeoutms);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int cancelUnifyCpuIOThreadCoreGpu(int cancelcpu, int cancelio, int cancelthread, std::vector<int>bindtids, int cancelgpu, int callertid, int64_t timestamp) {
UNUSED(cancelcpu);
UNUSED(cancelio);
UNUSED(cancelthread);
UNUSED(bindtids);
UNUSED(cancelgpu);
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int configure(const std::string& data, int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
virtual int getParameters(const std::string& data, int callertid, int64_t timestamp) {
UNUSED(callertid);
UNUSED(timestamp);
return ERR_FUNCTION_NOT_SUPPORT;
}
};
class IHardCoderDataCallback{
public:
virtual int onCallback(int uid, int funcid, uint64_t requestid, int bodyFormat, uint64_t timestamp, int retCode, uint8_t *data, int len) = 0;
virtual ~IHardCoderDataCallback(){}
};
template<typename T>
class ServerDataWorker {
private:
T remote;
uint8_t *resp;
uint32_t respLen;
public:
ServerDataWorker():remote() {
resp = NULL;
respLen = 0;
}
~ServerDataWorker() {
if (resp) {
delete[] resp;
}
resp = NULL;
}
uint8_t* getResp() {
return resp;
}
uint32_t getResLen() {
return respLen;
}
T getRemote() {
return remote;
}
int64_t processSend(uint32_t funcid, T *r, uint8_t *data, uint32_t len) {//server send
remote = *r;
int64_t requestId = genRespPack(funcid, RET_OK, 0, data, len, &resp, &respLen);
pdbg("processSend funcid:%d, len:%d, remote:%d requestId:%ld, respLen:%d", funcid, len, remote, requestId, respLen);
return requestId;
}
// #lizard forgives
int64_t processReceive(int uid, T *r, AMCReqHeader *pHead, uint8_t *payload, uint32_t payloadLen, HardCoder *inst) {
if (r == NULL || (payload == NULL && payloadLen != 0)) {
perr("recvEvent DATA data or addr invalid ret len:%d, %d", payloadLen, TOINT(sizeof(AMCReqHeader)));
return -1;
}
remote = *r;
if (pHead->version < HEADER_PROTOCAL_VERSION) {
perr("CheckVersion failed:%d server:%d", pHead->version, HEADER_PROTOCAL_VERSION);
return genRespPack(pHead->funcid, ERR_CLIENT_UPGRADE_REQUIRED, pHead->requestid, NULL, 0, &resp, &respLen);;
}
// if (!inst->checkPermission(pHead->funcid, uid, pHead->callertid, pHead->timestamp)) {
// perr("checkPermission[%d, %d] failed ret ERR_UNAUTHORIZED", pHead->funcid, uid);
// genRespPack(pHead->funcid, ERR_UNAUTHORIZED, 0, NULL, 0, &resp, &respLen);
// return 0;
// }
if (pHead->funcid == FUNC_CHECK_PERMISSION) {
amc::CheckPermission p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<std::string> vec1;
std::vector<std::string> vec2;
if (ret) {
int size = p.certtags_size();
for (int i = 0; i < size; i++) {
vec1.push_back(p.certtags(i).manufacture());
vec2.push_back(p.certtags(i).cert());
}
}
int respResult = inst->checkPermission(vec1, vec2, pHead->funcid, uid, pHead->callertid, pHead->timestamp) ? 0 : ERR_UNAUTHORIZED;
pdbg("FUNC_CHECK_PERMISSION [%d,%d] resp:%d", pHead->funcid, uid, respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);;
}
if (pHead->funcid == FUNC_UNIFY_CPU_IO_THREAD_CORE_GPU) {
amc::RequestUnifyCPUIOThreadCore p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<int> vec;
if (ret) {
int size = p.bindtids_size();
for (int i = 0; i < size; i++) {
vec.push_back(p.bindtids(i));
}
}
int respResult = ret ? inst->requestUnifyCpuIOThreadCoreGpu(p.scene(),p.action(), p.cpulevel(), p.iolevel(), vec, p.gpulevel(), p.timeoutms(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_UNIFY_CPU_IO_THREAD_CORE parse:%d [%d,%d,%d,%d,%d,%d,%d] resp:%d", ret, p.scene(), TOINT(p.action()), p.cpulevel(), p.iolevel(), TOINT(p.bindtids_size()), p.gpulevel(), p.timeoutms(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CANCEL_UNIFY_CPU_IO_THREAD_CORE_GPU) {
amc::CancelUnifyCPUIOThreadCore p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<int> vec;
if (ret) {
int size = p.bindtids_size();
for (int i = 0; i < size; i++) {
vec.push_back(p.bindtids(i));
}
}
int respResult = ret ? inst->cancelUnifyCpuIOThreadCoreGpu(p.cancelcpu(), p.cancelio(), p.cancelthread(), vec,p.cancelgpu(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_CANCEL_UNIFY_CPU_IO_THREAD_CORE parse:%d [%d,%d,%d,%d,%d] resp:%d", ret, p.cancelcpu(), p.cancelio(), p.cancelthread(), TOINT(p.bindtids_size()), p.cancelgpu(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CPU_HIGH_FREQ) {
amc::RequestCPUHighFreq p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = ret ? inst->requestCpuHighFreq(p.scene(),p.action(), p.level(), p.timeoutms(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_CPU_HIGH_FREQ parse:%d [%d,%d,%d,%d] resp:%d", ret, p.scene(), TOINT(p.action()), p.level(), TOINT(p.timeoutms()), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CANCEL_CPU_HIGH_FREQ) {
int respResult = inst->cancelCpuHighFreq(pHead->callertid, pHead->timestamp);
pdbg("FUNC_CANCEL_CPU_HIGH_FREQ resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_GPU_HIGH_FREQ) {
amc::RequestGPUHighFreq p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = ret ? inst->requestGpuHighFreq(p.scene(),p.action(), p.level(), p.timeoutms(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_GPU_HIGH_FREQ parse:%d [%d,%d,%d,%d] resp:%d", ret, p.scene(), TOINT(p.action()), p.level(), TOINT(p.timeoutms()), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CANCEL_GPU_HIGH_FREQ) {
int respResult = inst->cancelGpuHighFreq(pHead->callertid, pHead->timestamp);
pdbg("FUNC_CANCEL_GPU_HIGH_FREQ resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CPU_CORE_FOR_THREAD) {
amc::RequestCPUCoreForThread p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<int> vec;
if (ret) {
int size = p.bindtids_size();
for (int i = 0; i < size; i++) {
vec.push_back(p.bindtids(i));
}
}
int respResult = ret ? inst->requestCpuCoreForThread(p.scene(), p.action(), vec, p.timeoutms(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_CPU_CORE_FOR_THREAD parse:%d [%d,%d,%d,%d] resp:%d", ret, p.scene(),TOINT(p.action()), p.bindtids_size(), TOINT(p.timeoutms()), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CANCEL_CPU_CORE_FOR_THREAD) {
amc::CancelCPUCoreForThread p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<int> vec;
if (ret) {
int size = p.bindtids_size();
for (int i = 0; i < size; i++) {
vec.push_back(p.bindtids(i));
}
}
int respResult = ret ? inst->cancelCpuCoreForThread(vec, pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_CANCEL_CPU_CORE_FOR_THREAD parse:%d [%d] resp:%d", ret, p.bindtids_size(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_HIGH_IO_FREQ) {
amc::RequestHighIOFreq p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = ret ? inst->requestHighIOFreq(p.scene(), p.action(), p.level(), p.timeoutms(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_HIGH_IO_FREQ parse:%d [%d,%d,%d,%d] resp:%d", ret, p.scene(), TOINT(p.action()), p.level(), TOINT(p.timeoutms()), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CANCEL_HIGH_IO_FREQ) {
int respResult = inst->cancelHighIOFreq(pHead->callertid, pHead->timestamp);
pdbg("FUNC_CANCEL_HIGH_IO_FREQ resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_SET_SCREEN_RESOLUTION) {
amc::RequestScreenResolution p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = ret ? inst->requestScreenResolution(p.level(), p.uiname(), pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_SET_SCREEN_RESOLUTION parse:%d [%d,%s] resp:%d", ret, p.level(), p.uiname().c_str(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_RESET_SCREEN_RESOLUTION) {
int respResult = inst->resetScreenResolution(pHead->callertid, pHead->timestamp);
pdbg("FUNC_RESET_SCREEN_RESOLUTION resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_REG_SYSTEM_EVENT_CALLBACK) {
amc::RegisterCallback p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = inst->registerSystemEventCallback(p.uid(), pHead->callertid, pHead->timestamp);
pdbg("FUNC_REG_SYSTEM_EVENT_CALLBACK parse:%d [%d,%d,%d] resp:%d", ret, p.type(), p.uid(), p.pid(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_REG_ANR_CALLBACK) {
amc::RegisterCallback p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = inst->registerAnrCallback(p.uid(), pHead->callertid, pHead->timestamp);
pdbg("FUNC_REG_ANR_CALLBACK parse:%d [%d,%d,%d] resp:%d", ret, p.type(), p.uid(), p.pid(), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_REG_PRELOAD_BOOT_RESOURCE) {
amc::RequestBootPreLoadResource p;
int ret = p.ParseFromArray(payload, payloadLen);
std::vector<std::string> vec;
if (ret) {
int size = p.filelist_size();
for (int i = 0; i < size; i++) {
vec.push_back(p.filelist(i));
}
}
int respResult = ret ? inst->registerBootPreloadResource(vec, pHead->callertid, pHead->timestamp) : ERR_PACKAGE_DECODE_FAILED;
pdbg("FUNC_REG_PRELOAD_BOOT_RESOURCE parse:%d vecSize:%d resp:%d", ret, TOINT(vec.size()), respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_TERMINATE_APP) {
int respResult = inst->terminateApp(pHead->callertid, pHead->timestamp);
pdbg("FUNC_TERMINATE_APP resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_CONFIGURE) {
amc::Configuration p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = inst->configure(p.data(), pHead->callertid, pHead->timestamp);
pdbg("FUNC_CONFIGURE resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
if (pHead->funcid == FUNC_GET_PARAMETERS) {
amc::GetParameters p;
int ret = p.ParseFromArray(payload, payloadLen);
int respResult = inst->getParameters(p.data(), pHead->callertid, pHead->timestamp);
pdbg("FUNC_GET_PARAMETERS resp:%d", respResult);
return genRespPack(pHead->funcid, respResult, pHead->requestid, NULL, 0, &resp, &respLen);
}
return genRespPack(pHead->funcid, ERR_FUNCTION_NOT_SUPPORT, pHead->requestid, NULL, 0, &resp, &respLen);
}
};
class IClientEngine {
public:
virtual bool isRunning() = 0;
virtual int64_t sendReq(int funcid, uint8_t *data, int dataLen, int tid, int64_t timestamp) = 0;
virtual ~IClientEngine(){}
};
class IC2JavaCallback {
public:
virtual int callback(int callbackType, uint64_t requestid, uint64_t timestamp, int errCode, int funcid, int dataType,
uint8_t *data, int len) = 0;
virtual ~IC2JavaCallback(){}
};
class ClientProtocal : public IHardCoderDataCallback {
protected:
virtual IClientEngine* engine() = 0;
virtual IC2JavaCallback* c2JavaCallback() = 0;
public:
ClientProtocal() {}
int64_t checkPermission(std::vector<std::string> manufactures, std::vector<std::string> certs, int pid, int uid, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CHECK_PERMISSION);
if (!manufactures.empty() && manufactures.size() == certs.size()) {
cJSON *certTags;
cJSON_AddItemToObject(jsonRequest, "certTags", certTags = cJSON_CreateArray());
for (unsigned long index = 0; index < manufactures.size(); index++) {
cJSON *certTag;
certTag = cJSON_CreateObject();
cJSON_AddStringToObject(certTag, "manufacture", manufactures[index].c_str());
cJSON_AddStringToObject(certTag, "cert", certs[index].c_str());
cJSON_AddItemToArray(certTags, certTag);
}
}
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CHECK_PERMISSION, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::CheckPermission request;
if (!manufactures.empty() && manufactures.size() == certs.size()) {
for (unsigned long index = 0; index < manufactures.size(); index++) {
amc::CertTag* certTag = request.add_certtags();
certTag->set_manufacture(manufactures[index]);
certTag->set_cert(certs[index]);
}
}
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_CHECK_PERMISSION, body, len, tid, timestamp);
}
pdbg("checkPermission requestid:%ld, pid:%d, uid:%d, local pid:%d, uid:%d, tid:%d, timestamp:%d", requestid,
pid, uid, getpid(), getuid(), tid, TOINT(timestamp / 1000000L));
return requestid;
}
int64_t requestCpuHighFreq(int scene, int64_t action, int level, int timeoutms, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CPU_HIGH_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_REQUEST);
cJSON_AddNumberToObject(jsonRequest, "scene", scene);
cJSON_AddNumberToObject(jsonRequest, "action", action);
cJSON_AddNumberToObject(jsonRequest, "cpulevel", level);
cJSON_AddNumberToObject(jsonRequest, "timeoutMs", timeoutms);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CPU_HIGH_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::RequestCPUHighFreq request;
request.set_scene(scene);
request.set_level(level);
request.set_timeoutms(timeoutms);
request.set_action(action);
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_CPU_HIGH_FREQ, body, len, tid, timestamp);
}
pdbg("requestCpuHighFreq requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" ,
requestid, scene, TOINT(action), level, timeoutms, tid, TOINT(timestamp/1000000L));
return requestid;
}
int64_t cancelCpuHighFreq(int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CANCEL_CPU_HIGH_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_RESET);
cJSON_AddNumberToObject(jsonRequest, "cpulevel", CPU_LEVEL_0);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CANCEL_CPU_HIGH_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
requestid = pEngine->sendReq(FUNC_CANCEL_CPU_HIGH_FREQ, NULL, 0, tid, timestamp);
}
pdbg("cancelCpuHighFreq requestid:%ld, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L));
return requestid;
}
int64_t requestGpuHighFreq(int scene, int64_t action, int level, int timeoutms, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_GPU_HIGH_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_REQUEST);
cJSON_AddNumberToObject(jsonRequest, "scene", scene);
cJSON_AddNumberToObject(jsonRequest, "action", action);
cJSON_AddNumberToObject(jsonRequest, "gpulevel", level);
cJSON_AddNumberToObject(jsonRequest, "timeoutMs", timeoutms);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_GPU_HIGH_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::RequestGPUHighFreq request;
request.set_scene(scene);
request.set_level(level);
request.set_timeoutms(timeoutms);
request.set_action(action);
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_GPU_HIGH_FREQ, body, len, tid, timestamp);
}
pdbg("requestGpuHighFreq requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" ,
requestid, scene, TOINT(action), level, timeoutms, tid, TOINT(timestamp/1000000L));
return requestid;
}
int64_t cancelGpuHighFreq(int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CANCEL_GPU_HIGH_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_RESET);
cJSON_AddNumberToObject(jsonRequest, "gpulevel", GPU_LEVEL_0);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CANCEL_GPU_HIGH_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
requestid = pEngine->sendReq(FUNC_CANCEL_GPU_HIGH_FREQ, NULL, 0, tid, timestamp);
}
pdbg("cancelGpuHighFreq ret:%ld, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L));
return requestid;
}
int64_t requestCpuCoreForThread(int scene, int64_t action, int *bindtids , int bindlen, int timeoutms, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CPU_CORE_FOR_THREAD);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_REQUEST);
cJSON_AddNumberToObject(jsonRequest, "scene", scene);
cJSON_AddNumberToObject(jsonRequest, "action", action);
if (bindlen > 0 && bindtids != NULL) {
cJSON *needBindTids;
cJSON_AddItemToObject(jsonRequest, "bindtids", needBindTids = cJSON_CreateArray());
for (int index = 0; index < bindlen; index++) {
cJSON_AddItemToArray(needBindTids, cJSON_CreateNumber(bindtids[index]));
}
}
cJSON_AddNumberToObject(jsonRequest, "timeoutMs", timeoutms);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CPU_CORE_FOR_THREAD, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::RequestCPUCoreForThread request;
request.set_scene(scene);
for (int index = 0; index < bindlen; index++) {
request.add_bindtids(bindtids[index]);
}
request.set_timeoutms(timeoutms);
request.set_action(action);
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_CPU_CORE_FOR_THREAD, body, len, tid, timestamp);
}
pdbg("requestCpuCoreForThread requestid:%ld, scene:%d, action:%d, bindlen:%d, timeoutms:%d", requestid, scene, TOINT(action), bindlen, timeoutms);
return requestid;
}
int64_t cancelCpuCoreForThread(int *unbindtids , int unbindlen, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
if (unbindlen <= 0 || unbindtids == NULL) {
perr("cancelCpuCoreForThread unbindlen :%d", unbindlen);
return -2;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CANCEL_CPU_CORE_FOR_THREAD);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_RESET);
if (unbindlen > 0 && unbindtids != NULL) {
cJSON *needUnBindTids;
cJSON_AddItemToObject(jsonRequest, "unbindtids", needUnBindTids = cJSON_CreateArray());
for (int index = 0; index < unbindlen; index++) {
cJSON_AddItemToArray(needUnBindTids, cJSON_CreateNumber(unbindtids[index]));
}
}
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CANCEL_CPU_CORE_FOR_THREAD, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::CancelCPUCoreForThread request;
for (int index = 0; index < unbindlen; index++) {
request.add_bindtids(unbindtids[index]);
}
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_CANCEL_CPU_CORE_FOR_THREAD, body, len, tid, timestamp);
}
pdbg("cancelCpuCoreForThread requestid:%ld, unbindlen:%d", requestid, unbindlen);
return requestid;
}
int64_t requestHighIOFreq(int scene, int64_t action, int level, int timeoutms, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_HIGH_IO_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_REQUEST);
cJSON_AddNumberToObject(jsonRequest, "scene", scene);
cJSON_AddNumberToObject(jsonRequest, "action", action);
cJSON_AddNumberToObject(jsonRequest, "iolevel", level);
cJSON_AddNumberToObject(jsonRequest, "timeoutMs", timeoutms);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_HIGH_IO_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::RequestHighIOFreq request;
request.set_scene(scene);
request.set_level(level);
request.set_timeoutms(timeoutms);
request.set_action(action);
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_HIGH_IO_FREQ, body, len, tid, timestamp);
}
pdbg("requestCpuCoreForThread requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d", requestid, scene, TOINT(action), level, timeoutms);
return requestid;
}
int64_t cancelHighIOFreq(int tid, uint64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_CANCEL_HIGH_IO_FREQ);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_RESET);
cJSON_AddNumberToObject(jsonRequest, "iolevel", IO_LEVEL_0);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_CANCEL_HIGH_IO_FREQ, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
requestid = pEngine->sendReq(FUNC_CANCEL_HIGH_IO_FREQ, NULL, 0, tid, timestamp);
}
pdbg("cancelHighIOFreq requestid:%ld", requestid);
return requestid;
}
int64_t requestScreenResolution(int level, std::string uiName, int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_SET_SCREEN_RESOLUTION);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_REQUEST);
cJSON_AddItemToObject(jsonRequest, "uiName", cJSON_CreateString(uiName.c_str()));
cJSON_AddNumberToObject(jsonRequest, "level", level);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_SET_SCREEN_RESOLUTION, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
amc::RequestScreenResolution request;
request.set_level(level);
request.set_uiname(uiName);
uint32_t len = request.ByteSize();
uint8_t body[len];
request.SerializeToArray(body, len);
requestid = pEngine->sendReq(FUNC_SET_SCREEN_RESOLUTION, body, len, tid, timestamp);
}
pdbg("requestScreenResolution requestid:%ld, level:%d, uiName:%s", requestid, level, uiName.c_str());
return requestid;
}
int64_t resetScreenResolution(int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_RESET_SCREEN_RESOLUTION);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_RESET);
char *body = cJSON_Print(jsonRequest);
std::string str(body);
uint32_t len = str.length();
cJSON_Delete(jsonRequest);
requestid = pEngine ->sendReq(FUNC_RESET_SCREEN_RESOLUTION, (uint8_t *)body, len, tid, timestamp);
free(body);
} else {
requestid = pEngine->sendReq(FUNC_RESET_SCREEN_RESOLUTION, NULL, 0, tid, timestamp);
}
pdbg("resetScreenResolution requestid:%ld ", requestid);
return requestid;
}
int64_t registerANRCallback(int tid, int64_t timestamp) {
IClientEngine *pEngine = engine();
if (!pEngine) {
return -3;
}
int64_t requestid = 0L;
if (HEADER_VERSION >= HEADER_JSON_VERSION) {//json
cJSON *jsonRequest;
jsonRequest = cJSON_CreateObject();
cJSON_AddNumberToObject(jsonRequest, "jsonVersion", JSON_VERSION);
cJSON_AddNumberToObject(jsonRequest, "funcid", FUNC_REG_ANR_CALLBACK);
cJSON_AddNumberToObject(jsonRequest, "status", STATUS_NONE);