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