1 /*
2  * Copyright (c) 2023 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_log_wrapper.h"
17 #include "static_subscriber_proxy.h"
18 
19 namespace OHOS {
20 namespace EventFwk {
OnReceiveEvent(CommonEventData * inData)21 ErrCode StaticSubscriberProxy::OnReceiveEvent(CommonEventData* inData)
22 {
23     MessageParcel data;
24     MessageParcel reply;
25     MessageOption option(MessageOption::TF_SYNC);
26 
27     if (!data.WriteInterfaceToken(GetDescriptor())) {
28         return ERR_INVALID_VALUE;
29     }
30 
31     data.WriteParcelable(inData);
32 
33     sptr<IRemoteObject> remote = Remote();
34     if (remote == nullptr) {
35         EVENT_LOGE("Remote is NULL");
36         return ERR_TRANSACTION_FAILED;
37     }
38 
39     int32_t st = remote->SendRequest(static_cast<uint32_t>(CommonEventInterfaceCode::COMMAND_ON_RECEIVE_EVENT),
40         data, reply, option);
41     if (st != ERR_NONE) {
42         return st;
43     }
44 
45     ErrCode ec = reply.ReadInt32();
46     if (FAILED(ec)) {
47         return ec;
48     }
49 
50     return ERR_OK;
51 }
52 } // namespace EventFwk
53 } // namespace OHOS
54