1 /*
2 * Copyright (c) 2021 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 "ipc/graphic_dumper_command_stub.h"
17
18 #include "graphic_dumper_hilog.h"
19 #include "graphic_dumper_server.h"
20 #include "ipc/igraphic_dumper_command.h"
21
22 namespace OHOS {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperCommandStub" };
25 }
26
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t GraphicDumperCommandStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
28 MessageParcel& reply, MessageOption& option)
29 {
30 auto remoteDescriptor = data.ReadInterfaceToken();
31 if (GetDescriptor() != remoteDescriptor) {
32 return 1;
33 }
34 switch (code) {
35 case IGRAPHIC_DUMPER_COMMAND_GET_CONFIG: {
36 std::string k = data.ReadString();
37 std::string v = data.ReadString();
38 GSError ret = GetConfig(k, v);
39 reply.WriteInt32(ret);
40 reply.WriteString(v);
41 break;
42 }
43
44 case IGRAPHIC_DUMPER_COMMAND_SET_CONFIG: {
45 std::string k = data.ReadString();
46 std::string v = data.ReadString();
47 GSError ret = SetConfig(k, v);
48 reply.WriteInt32(ret);
49 break;
50 }
51
52 case IGRAPHIC_DUMPER_COMMAND_DUMP: {
53 std::string v = data.ReadString();
54 GSError ret = Dump(v);
55 reply.WriteInt32(ret);
56 break;
57 }
58
59 case IGRAPHIC_DUMPER_COMMAND_GET_LOG: {
60 std::string tag = data.ReadString();
61 std::string log = "";
62 GSError ret = GetLog(tag, log);
63 reply.WriteInt32(ret);
64 break;
65 }
66 case IGRAPHIC_DUMPER_COMMAND_ADD_INFO_LISTENER: {
67 auto tag = data.ReadString();
68 auto remoteObject = data.ReadRemoteObject();
69 if (remoteObject == nullptr) {
70 reply.WriteInt32(GSERROR_INVALID_ARGUMENTS);
71 GDLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
72 break;
73 }
74
75 auto l = iface_cast<IGraphicDumperInfoListener>(remoteObject);
76 GSError ret = AddInfoListener(tag, l);
77 reply.WriteInt32(ret);
78 if (ret != GSERROR_OK) {
79 GDLOG_FAILURE_NO(ret);
80 }
81 break;
82 }
83 default: {
84 return 1;
85 }
86 }
87 return 0;
88 }
89
GetConfig(const std::string & k,std::string & v)90 GSError GraphicDumperCommandStub::GetConfig(const std::string &k, std::string &v)
91 {
92 GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
93 GraphicDumperServer::GetInstance()->GetConfig(k, v);
94 GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
95 return GSERROR_OK;
96 }
97
SetConfig(const std::string & k,const std::string & v)98 GSError GraphicDumperCommandStub::SetConfig(const std::string &k, const std::string &v)
99 {
100 GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
101 GraphicDumperServer::GetInstance()->SetConfig(k, v);
102 return GSERROR_OK;
103 }
104
Dump(const std::string & tag)105 GSError GraphicDumperCommandStub::Dump(const std::string &tag)
106 {
107 GDLOGFE("%{public}s", tag.c_str());
108 GraphicDumperServer::GetInstance()->Dump(tag);
109 return GSERROR_OK;
110 }
111
GetLog(const std::string & tag,std::string & log)112 GSError GraphicDumperCommandStub::GetLog(const std::string &tag, std::string &log)
113 {
114 GDLOGFE("%{public}s -> %{public}s", tag.c_str(), log.c_str());
115 GraphicDumperServer::GetInstance()->GetLog(tag, log);
116 return GSERROR_OK;
117 }
118
AddInfoListener(const std::string & tag,sptr<IGraphicDumperInfoListener> & listener)119 GSError GraphicDumperCommandStub::AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener)
120 {
121 GDLOGFE("");
122 if (listener == nullptr) {
123 return GSERROR_INVALID_ARGUMENTS;
124 }
125 return GraphicDumperServer::GetInstance()->AddInfoListener(listener);
126 }
127 } // namespace OHOS
128