1 /*
2  * Copyright (c) 2022 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_notify_callback_proxy.h"
17 
18 namespace OHOS {
19 namespace MiscServices {
TimerNotifyCallbackProxy(const sptr<IRemoteObject> & object)20 TimerNotifyCallbackProxy::TimerNotifyCallbackProxy(const sptr<IRemoteObject> &object)
21     :IRemoteProxy<ITimerNotifyCallback>(object)
22 {
23 }
24 
~TimerNotifyCallbackProxy()25 TimerNotifyCallbackProxy::~TimerNotifyCallbackProxy()
26 {
27     TIME_HILOGD(TIME_MODULE_CLIENT, "TimerNotifyCallbackProxy instance destoryed");
28 }
29 
Finish(uint64_t timerId)30 void TimerNotifyCallbackProxy::Finish(uint64_t timerId)
31 {
32     TIME_HILOGD(TIME_MODULE_CLIENT, "start id:%{public}" PRId64 "", timerId);
33     sptr<IRemoteObject> remote = Remote();
34     if (remote == nullptr) {
35         return;
36     }
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option;
40 
41     if (!data.WriteInterfaceToken(GetDescriptor())) {
42         TIME_HILOGE(TIME_MODULE_CLIENT, "write descriptor failed!");
43         return;
44     }
45 
46     if (!data.WriteUint64(timerId)) {
47         TIME_HILOGE(TIME_MODULE_CLIENT, "write timerId failed!");
48         return;
49     }
50     int ret = remote->SendRequest(static_cast<int>(ITimerNotifyCallback::Message::FINISH), data, reply, option);
51     if (ret != ERR_OK) {
52         TIME_HILOGE(TIME_MODULE_CLIENT, "SendRequest is failed, error code: %{public}d", ret);
53     }
54 }
55 } // namespace MiscServices
56 } // namespace OHOS