• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 
18 #include "dbinder_log.h"
19 #include "ipc_skeleton.h"
20 
21 namespace OHOS {
22 using namespace OHOS::HiviewDFX;
23 
24 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_TEST, "RpcTestServiceProxy" };
25 static constexpr uint32_t INVAL_TOKEN_ID = 0x0;
26 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t RpcTestServiceStub::OnRemoteRequest(
28     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
29 {
30     int result = ERR_NONE;
31     switch (code) {
32         case GET_SERVICE_NAME: {
33             result = TestGetServiceName(data, reply, option);
34             break;
35         }
36         case GET_TOKENID: {
37             result = TestAccessToken(data, reply, option);
38             break;
39         }
40         case TEST_SYNC_ADD: {
41             result = TestSyncAdd(data, reply, option);
42             break;
43         }
44         default:
45             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
46     }
47     return result;
48 }
49 
TestGetServiceName(MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int32_t RpcTestServiceStub::TestGetServiceName(MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52     reply.WriteString(GetServiceName());
53     return ERR_NONE;
54 }
55 
TestAccessToken(MessageParcel & data,MessageParcel & reply,MessageOption & option)56 int32_t RpcTestServiceStub::TestAccessToken(MessageParcel &data, MessageParcel &reply, MessageOption &option)
57 {
58     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
59     if (tokenId == INVAL_TOKEN_ID) {
60         DBINDER_LOGW(LOG_LABEL, "tokenId = %{public}u", tokenId);
61     }
62     reply.WriteUint32(tokenId);
63     return ERR_NONE;
64 }
65 
TestSyncAdd(MessageParcel & data,MessageParcel & reply,MessageOption & option)66 int32_t RpcTestServiceStub::TestSyncAdd(MessageParcel &data, MessageParcel &reply, MessageOption &option)
67 {
68     int32_t value1 = data.ReadInt32();
69     int32_t value2 = data.ReadInt32();
70     reply.WriteInt32(value1 + value2);
71     return ERR_NONE;
72 }
73 } // namespace OHOS