• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "res_sched_event_listener_proxy.h"
17 
18 #include "ipc_types.h"
19 #include "ipc_util.h"
20 #include "iremote_object.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 #include "res_sched_errors.h"
24 #include "res_sched_log.h"
25 #include "res_sched_ipc_interface_code.h"
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
OnReceiveEvent(uint32_t eventType,uint32_t eventValue,uint32_t listenerGroup,const nlohmann::json & extInfo)29 void ResSchedEventListenerProxy::OnReceiveEvent(uint32_t eventType, uint32_t eventValue, uint32_t listenerGroup,
30     const nlohmann::json& extInfo)
31 {
32     int32_t error;
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option = { MessageOption::TF_ASYNC };
36     error = WriteParcelForReceiveEvent(eventType, eventValue, listenerGroup, extInfo, data);
37     if (error != NO_ERROR) {
38         RESSCHED_LOGE("%{public}s:write parcel error: %{public}d.", __func__, error);
39         return;
40     }
41     error = Remote()->SendRequest(static_cast<uint32_t>(ResourceScedulEventListenerCode::RECEIVE_EVENT),
42         data, reply, option);
43     if (error != NO_ERROR) {
44         RESSCHED_LOGE("%{public}s:Send request error: %{public}d.", __func__, error);
45         return;
46     }
47     RESSCHED_LOGD("%{public}s, success.", __func__);
48 }
49 
WriteParcelForReceiveEvent(const uint32_t eventType,const uint32_t eventValue,const uint32_t listenerGroup,const nlohmann::json & extInfo,MessageParcel & data)50 int32_t ResSchedEventListenerProxy::WriteParcelForReceiveEvent(const uint32_t eventType,
51     const uint32_t eventValue, const uint32_t listenerGroup, const nlohmann::json& extInfo, MessageParcel& data)
52 {
53     WRITE_PARCEL(data, InterfaceToken, ResSchedEventListenerProxy::GetDescriptor(), RES_SCHED_DATA_ERROR,
54         ResSchedEventListenerProxy);
55     WRITE_PARCEL(data, Uint32, eventType, RES_SCHED_DATA_ERROR, ResSchedEventListenerProxy);
56     WRITE_PARCEL(data, Uint32, eventValue, RES_SCHED_DATA_ERROR, ResSchedEventListenerProxy);
57     WRITE_PARCEL(data, Uint32, listenerGroup, RES_SCHED_DATA_ERROR, ResSchedEventListenerProxy);
58     WRITE_PARCEL(data, String, extInfo.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace),
59         RES_SCHED_DATA_ERROR, ResSchedEventListenerProxy);
60     return NO_ERROR;
61 }
62 } // namespace ResourceSchedule
63 } // namespace OHOS
64