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 {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t SysEventCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
28     MessageParcel& reply, MessageOption& option)
29 {
30     std::u16string descripter = SysEventCallbackStub::GetDescriptor();
31     std::u16string remoteDescripter = data.ReadInterfaceToken();
32     if (descripter != remoteDescripter) {
33         HILOG_ERROR(LOG_CORE, "read descriptor failed.");
34         return ERR_INVALID_VALUE;
35     }
36     switch (code) {
37         case HANDLE: {
38             std::u16string domain;
39             bool ret = data.ReadString16(domain);
40             if (!ret) {
41                 HILOG_ERROR(LOG_CORE, "parcel read domain failed.");
42                 return ERR_FLATTEN_OBJECT;
43             }
44             std::u16string eventName;
45             ret = data.ReadString16(eventName);
46             if (!ret) {
47                 HILOG_ERROR(LOG_CORE, "parcel read name failed.");
48                 return ERR_FLATTEN_OBJECT;
49             }
50             uint32_t eventType = 0;
51             ret = data.ReadUint32(eventType);
52             if (!ret) {
53                 HILOG_ERROR(LOG_CORE, "parcel read type failed.");
54                 return ERR_FLATTEN_OBJECT;
55             }
56             std::u16string eventDetail;
57             ret = data.ReadString16(eventDetail);
58             if (!ret) {
59                 HILOG_ERROR(LOG_CORE, "parcel read detail failed.");
60                 return ERR_FLATTEN_OBJECT;
61             }
62             Handle(domain, eventName, eventType, eventDetail);
63             return ERR_OK;
64         }
65         default:
66             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67     }
68 }
69 } // namespace HiviewDFX
70 } // namespace OHOS
71