• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "event_receive_stub.h"
17 #include "event_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace EventFwk {
EventReceiveStub()21 EventReceiveStub::EventReceiveStub()
22 {
23     EVENT_LOGD("event receive stub instance is created");
24 }
25 
~EventReceiveStub()26 EventReceiveStub::~EventReceiveStub()
27 {
28     EVENT_LOGD("event receive stub instance is destroyed");
29 }
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int EventReceiveStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33     if (data.ReadInterfaceToken() != GetDescriptor()) {
34         EVENT_LOGE("local descriptor is not equal to remote");
35         return ERR_TRANSACTION_FAILED;
36     }
37     switch (code) {
38         case static_cast<uint32_t>(IEventReceive::Message::CES_NOTIFY_COMMON_EVENT): {
39             std::unique_ptr<CommonEventData> eventData(data.ReadParcelable<CommonEventData>());
40             bool ordered = data.ReadBool();
41             bool sticky = data.ReadBool();
42             if (eventData == nullptr) {
43                 EVENT_LOGE("callback stub receive common event data is nullptr");
44                 return ERR_INVALID_VALUE;
45             }
46             NotifyEvent(*eventData, ordered, sticky);
47             break;
48         }
49 
50         default:
51             EVENT_LOGW("event receive stub receives unknown code, code = %{public}u", code);
52             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53     }
54 
55     return NO_ERROR;
56 }
57 }  // namespace EventFwk
58 }  // namespace OHOS