• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CredDumpCallBack g_credDumpCallBack = NULL;
22 static PerformanceDumpCallBack g_performDumpCallback = NULL;
23 
DumpByArgs(int fd,StringVector * strArgVec)24 static void DumpByArgs(int fd, StringVector *strArgVec)
25 {
26     HcString strArg = strArgVec->get(strArgVec, 0);
27     if (strcmp(StringGet(&strArg), PERFORM_DUMP_ARG) == 0) {
28         if (g_performDumpCallback != NULL) {
29             g_performDumpCallback(fd, strArgVec);
30         }
31     } else {
32         LOGE("Invalid dumper command!");
33     }
34 }
35 
DevAuthDump(int fd,StringVector * strArgVec)36 void DevAuthDump(int fd, StringVector *strArgVec)
37 {
38     if (strArgVec == NULL) {
39         LOGE("Dumper arguments vector is null!");
40         return;
41     }
42     if (strArgVec->size(strArgVec) == 0) {
43         if (g_dumpCallBack != NULL) {
44             g_dumpCallBack(fd);
45         }
46         if (g_credDumpCallBack != NULL) {
47             g_credDumpCallBack(fd);
48         }
49     } else {
50         DumpByArgs(fd, strArgVec);
51     }
52 }
53 
RegisterDumpFunc(DumpCallBack func)54 void RegisterDumpFunc(DumpCallBack func)
55 {
56     g_dumpCallBack = func;
57 }
58 
RegisterCredDumpFunc(CredDumpCallBack func)59 void RegisterCredDumpFunc(CredDumpCallBack func)
60 {
61     g_credDumpCallBack = func;
62 }
63 
RegisterPerformDumpFunc(PerformanceDumpCallBack func)64 void RegisterPerformDumpFunc(PerformanceDumpCallBack func)
65 {
66     g_performDumpCallback = func;
67 }