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 "vsync_callback_proxy.h"
17
18 #include "return_value_tester.h"
19 #include "vsync_log.h"
20
21 namespace OHOS {
22 namespace Vsync {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "VsyncCallbackProxy" };
25 }
26
VsyncCallbackProxy(const sptr<IRemoteObject> & impl)27 VsyncCallbackProxy::VsyncCallbackProxy(const sptr<IRemoteObject>& impl)
28 : IRemoteProxy<IVsyncCallback>(impl)
29 {
30 }
31
OnVsync(int64_t timestamp)32 GSError VsyncCallbackProxy::OnVsync(int64_t timestamp)
33 {
34 MessageOption opt(MessageOption::TF_ASYNC);
35 MessageParcel arg;
36 MessageParcel ret;
37
38 auto reval = arg.WriteInterfaceToken(GetDescriptor());
39 if (!ReturnValueTester::Get<bool>(reval)) {
40 VLOGE("write interface token failed");
41 return GSERROR_INVALID_ARGUMENTS;
42 }
43
44 bool retval = arg.WriteInt64(timestamp);
45 if (!ReturnValueTester::Get<bool>(retval)) {
46 VLOGE("arg.WriteInt64 failed");
47 return GSERROR_INVALID_ARGUMENTS;
48 }
49
50 int res = Remote()->SendRequest(IVSYNC_CALLBACK_ON_VSYNC, arg, ret, opt);
51 if (ReturnValueTester::Get<int>(res)) {
52 VLOG_ERROR_API(res, SendRequest);
53 return GSERROR_BINDER;
54 }
55
56 GSError err = (GSError)ReturnValueTester::Get<int>(GSERROR_OK);
57 if (err != GSERROR_OK) {
58 VLOG_FAILURE_NO(err);
59 return err;
60 }
61 return GSERROR_OK;
62 }
63 } // namespace Vsync
64 } // namespace OHOS
65