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 "event_receive_proxy.h"
17 #include "event_log_wrapper.h"
18
19 namespace OHOS {
20 namespace EventFwk {
EventReceiveProxy(const sptr<IRemoteObject> & object)21 EventReceiveProxy::EventReceiveProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IEventReceive>(object)
22 {
23 EVENT_LOGD("event receive proxy instance is created");
24 }
25
~EventReceiveProxy()26 EventReceiveProxy::~EventReceiveProxy()
27 {
28 EVENT_LOGD("event receive proxy is destroyed");
29 }
30
NotifyEvent(const CommonEventData & commonEventData,const bool & ordered,const bool & sticky)31 void EventReceiveProxy::NotifyEvent(const CommonEventData &commonEventData, const bool &ordered, const bool &sticky)
32 {
33 EVENT_LOGD("start");
34
35 MessageParcel data;
36 MessageParcel reply;
37 MessageOption option(MessageOption::TF_ASYNC);
38
39 if (!data.WriteInterfaceToken(GetDescriptor())) {
40 EVENT_LOGE("Failed to write InterfaceToken");
41 return;
42 }
43
44 sptr<IRemoteObject> remote = Remote();
45 if (remote == nullptr) {
46 EVENT_LOGE("Failed to send cmd to service due to remote object is null");
47 return;
48 }
49
50 if (!data.WriteParcelable(&commonEventData)) {
51 EVENT_LOGE("Failed to write parcelable");
52 return;
53 }
54
55 if (!data.WriteBool(ordered)) {
56 EVENT_LOGE("Failed to write Bool");
57 return;
58 }
59
60 if (!data.WriteBool(sticky)) {
61 EVENT_LOGE("Failed to write Bool");
62 return;
63 }
64
65 int32_t result = remote->SendRequest(
66 static_cast<uint32_t>(CommonEventInterfaceCode::CES_NOTIFY_COMMON_EVENT), data, reply, option);
67 if (result != OHOS::NO_ERROR) {
68 EVENT_LOGE("Failed to SendRequest, error code: %{public}d", result);
69 return;
70 }
71
72 EVENT_LOGD("end");
73 }
74 } // namespace EventFwk
75 } // namespace OHOS