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 "sys_event_callback_stub.h"
17
18 #include <string>
19
20 #include "errors.h"
21 #include "hilog/log.h"
22 #include "ipc_object_stub.h"
23 #include "ipc_types.h"
24
25 namespace OHOS {
26 namespace HiviewDFX {
27 static constexpr HiLogLabel LABEL = { LOG_CORE, 0xD002D08, "HiView-SysEventCallbackStub" };
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t SysEventCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
29 MessageParcel& reply, MessageOption& option)
30 {
31 std::u16string descripter = SysEventCallbackStub::GetDescriptor();
32 std::u16string remoteDescripter = data.ReadInterfaceToken();
33 if (descripter != remoteDescripter) {
34 HiLog::Error(LABEL, "read descriptor failed.");
35 return ERR_INVALID_VALUE;
36 }
37 switch (code) {
38 case HANDLE: {
39 std::u16string domain;
40 bool ret = data.ReadString16(domain);
41 if (!ret) {
42 HiLog::Error(LABEL, "parcel read domain failed.");
43 return ERR_FLATTEN_OBJECT;
44 }
45 std::u16string eventName;
46 ret = data.ReadString16(eventName);
47 if (!ret) {
48 HiLog::Error(LABEL, "parcel read name failed.");
49 return ERR_FLATTEN_OBJECT;
50 }
51 uint32_t eventType = 0;
52 ret = data.ReadUint32(eventType);
53 if (!ret) {
54 HiLog::Error(LABEL, "parcel read type failed.");
55 return ERR_FLATTEN_OBJECT;
56 }
57 std::u16string eventDetail;
58 ret = data.ReadString16(eventDetail);
59 if (!ret) {
60 HiLog::Error(LABEL, "parcel read detail failed.");
61 return ERR_FLATTEN_OBJECT;
62 }
63 Handle(domain, eventName, eventType, eventDetail);
64 return ERR_OK;
65 }
66 default:
67 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
68 }
69 }
70 } // namespace HiviewDFX
71 } // namespace OHOS
72