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 "timer_call_back_proxy.h"
17 
18 namespace OHOS {
19 namespace MiscServices {
TimerCallbackProxy(const sptr<IRemoteObject> & object)20 TimerCallbackProxy::TimerCallbackProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<ITimerCallback>(object)
21 {
22 }
23 
~TimerCallbackProxy()24 TimerCallbackProxy::~TimerCallbackProxy()
25 {
26     TIME_HILOGD(TIME_MODULE_CLIENT, "TimerCallbackProxy instance destoryed");
27 }
28 
NotifyTimer(const uint64_t timerId,const sptr<IRemoteObject> & timerCallback)29 int32_t TimerCallbackProxy::NotifyTimer(const uint64_t timerId, const sptr<IRemoteObject> &timerCallback)
30 {
31     TIME_HILOGD(TIME_MODULE_CLIENT, "start id: %{public}" PRId64 "", timerId);
32     sptr<IRemoteObject> remote = Remote();
33     if (remote == nullptr) {
34         return E_TIME_NULLPTR;
35     }
36 
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option(MessageOption::TF_ASYNC);
40 
41     if (!data.WriteInterfaceToken(GetDescriptor())) {
42         TIME_HILOGE(TIME_MODULE_CLIENT, "write descriptor failed!");
43         return E_TIME_WRITE_PARCEL_ERROR;
44     }
45 
46     if (!data.WriteUint64(timerId)) {
47         TIME_HILOGE(TIME_MODULE_CLIENT, "write timerId failed!");
48         return E_TIME_WRITE_PARCEL_ERROR;
49     }
50     if (timerCallback != nullptr && !data.WriteRemoteObject(timerCallback)) {
51         TIME_HILOGE(TIME_MODULE_CLIENT, "write timerCallback failed!");
52         return E_TIME_WRITE_PARCEL_ERROR;
53     }
54     int ret = remote->SendRequest(static_cast<int>(ITimerCallback::Message::NOTIFY_TIMER), data, reply, option);
55     if (ret != ERR_OK) {
56         TIME_HILOGE(TIME_MODULE_CLIENT, "SendRequest is failed, error code: %{public}d", ret);
57     }
58     return ret;
59 }
60 } // namespace MiscServices
61 } // namespace OHOS
62