1 /*
2 * Copyright (C) 2025 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 "rpc_test_service_proxy.h"
17 #include "dbinder_log.h"
18
19 namespace OHOS {
20 using namespace OHOS::HiviewDFX;
21
22 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_TEST, "RpcTestServiceProxy" };
23
RpcTestServiceProxy(const sptr<IRemoteObject> & impl)24 RpcTestServiceProxy::RpcTestServiceProxy(const sptr<IRemoteObject> &impl)
25 : IRemoteProxy<IRpcTestService>(impl)
26 {
27 }
28
TestGetProto()29 int32_t RpcTestServiceProxy::TestGetProto()
30 {
31 auto object = Remote();
32 if (object == nullptr) {
33 DBINDER_LOGE(LOG_LABEL, "The obtained proxy is a null pointer");
34 return IRemoteObject::IF_PROT_ERROR;
35 }
36 sptr<IPCObjectProxy> proxy = reinterpret_cast<IPCObjectProxy *>(object.GetRefPtr());
37 return proxy->GetProto();
38 }
39
TestAddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> & recipient)40 bool RpcTestServiceProxy::TestAddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> &recipient)
41 {
42 bool ret = Remote()->AddDeathRecipient(recipient);
43 if (!ret) {
44 DBINDER_LOGE(LOG_LABEL, "Add death recipient failed");
45 }
46 return ret;
47 }
48
TestGetServiceName(MessageParcel & data,MessageParcel & reply,MessageOption & option)49 int32_t RpcTestServiceProxy::TestGetServiceName(MessageParcel &data, MessageParcel &reply, MessageOption &option)
50 {
51 int ret = Remote()->SendRequest(GET_SERVICE_NAME, data, reply, option);
52 if (ret != ERR_NONE) {
53 DBINDER_LOGE(LOG_LABEL, "Send request failed ret = %{public}d", ret);
54 }
55 return ret;
56 }
57
TestAccessToken(MessageParcel & data,MessageParcel & reply,MessageOption & option)58 int32_t RpcTestServiceProxy::TestAccessToken(MessageParcel &data, MessageParcel &reply, MessageOption &option)
59 {
60 int32_t ret = Remote()->SendRequest(GET_TOKENID, data, reply, option);
61 if (ret != ERR_NONE) {
62 DBINDER_LOGE(LOG_LABEL, "Send request failed ret = %{public}d", ret);
63 }
64 return ret;
65 }
66
TestSyncAdd(MessageParcel & data,MessageParcel & reply,MessageOption & option)67 int32_t RpcTestServiceProxy::TestSyncAdd(MessageParcel &data, MessageParcel &reply, MessageOption &option)
68 {
69 int32_t ret = Remote()->SendRequest(TEST_SYNC_ADD, data, reply, option);
70 if (ret != ERR_NONE) {
71 DBINDER_LOGE(LOG_LABEL, "Send request failed ret = %{public}d", ret);
72 }
73 return ret;
74 }
75 } // namespace OHOS