1 /*
2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hidump_adapter.h"
17 #include "hc_log.h"
18 #include "string.h"
19
20 static DumpCallBack g_dumpCallBack = NULL;
21 static PerformanceDumpCallBack g_performDumpCallback = NULL;
22
DumpByArgs(int fd,StringVector * strArgVec)23 static void DumpByArgs(int fd, StringVector *strArgVec)
24 {
25 HcString strArg = strArgVec->get(strArgVec, 0);
26 if (strcmp(StringGet(&strArg), PERFORM_DUMP_ARG) == 0) {
27 if (g_performDumpCallback != NULL) {
28 g_performDumpCallback(fd, strArgVec);
29 }
30 } else {
31 LOGE("Invalid dumper command!");
32 }
33 }
34
DevAuthDump(int fd,StringVector * strArgVec)35 void DevAuthDump(int fd, StringVector *strArgVec)
36 {
37 if (strArgVec == NULL) {
38 LOGE("Dumper arguments vector is null!");
39 return;
40 }
41 if (strArgVec->size(strArgVec) == 0) {
42 if (g_dumpCallBack != NULL) {
43 g_dumpCallBack(fd);
44 }
45 } else {
46 DumpByArgs(fd, strArgVec);
47 }
48 }
49
RegisterDumpFunc(DumpCallBack func)50 void RegisterDumpFunc(DumpCallBack func)
51 {
52 g_dumpCallBack = func;
53 }
54
RegisterPerformDumpFunc(PerformanceDumpCallBack func)55 void RegisterPerformDumpFunc(PerformanceDumpCallBack func)
56 {
57 g_performDumpCallback = func;
58 }