1 /*
2  * Copyright (c) 2021-2022 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_proxy.h"
17 
18 #include "errors.h"
19 #include "hiview_logger.h"
20 
21 namespace OHOS {
22 namespace HiviewDFX {
23 DEFINE_LOG_TAG("HiView-SysEventCallbackProxy");
Handle(const std::u16string & domain,const std::u16string & eventName,uint32_t eventType,const std::u16string & eventDetail)24 void SysEventCallbackProxy::Handle(const std::u16string& domain, const std::u16string& eventName, uint32_t eventType,
25     const std::u16string& eventDetail)
26 {
27     auto remote = Remote();
28     if (remote == nullptr) {
29         HIVIEW_LOGE("SysEventService Remote is NULL.");
30         return;
31     }
32     MessageParcel data;
33     if (!data.WriteInterfaceToken(SysEventCallbackProxy::GetDescriptor())) {
34         HIVIEW_LOGE("write descriptor failed.");
35         return;
36     }
37     bool ret = data.WriteString16(domain) && data.WriteString16(eventName) &&
38         data.WriteUint32(eventType) && data.WriteString16(eventDetail);
39     if (!ret) {
40         HIVIEW_LOGE("parcel write params failed.");
41         return;
42     }
43     MessageParcel reply;
44     MessageOption option = {MessageOption::TF_ASYNC};
45     int32_t res = remote->SendRequest(
46         static_cast<uint32_t>(SysEventCallbackInterfaceCode::HANDLE), data, reply, option);
47     if (res != ERR_OK) {
48         HIVIEW_LOGE("send request failed, error is %{public}d.", res);
49     }
50 }
51 } // namespace HiviewDFX
52 } // namespace OHOS
53