1 /*
2 * Copyright (c) 2024 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 "distributed_device_profile_log.h"
17 #include "ipc_utils.h"
18 #include "message_parcel.h"
19 #include "dp_inited_callback_stub.h"
20
21 namespace OHOS {
22 namespace DistributedDeviceProfile {
23 namespace {
24 const std::string TAG = "DpInitedCallbackStub";
25 }
26
DpInitedCallbackStub()27 DpInitedCallbackStub::DpInitedCallbackStub()
28 {
29 HILOGI("constructor!");
30 }
31
~DpInitedCallbackStub()32 DpInitedCallbackStub::~DpInitedCallbackStub()
33 {
34 HILOGI("destruct!");
35 }
36
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)37 int32_t DpInitedCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
38 MessageParcel& reply, MessageOption& option)
39 {
40 HILOGI("Code = %{public}u", code);
41 std::u16string descriptor = DpInitedCallbackStub::GetDescriptor();
42 std::u16string remoteDescriptor = data.ReadInterfaceToken();
43 if (descriptor != remoteDescriptor) {
44 HILOGE("Check descriptor failed");
45 return DP_INTERFACE_CHECK_FAILED;
46 }
47 if (code != static_cast<uint32_t>(DPInterfaceCode::ON_DEVICE_PROFILE_INITED)) {
48 HILOGW("Unknown request code, code = %{public}u", code);
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 return OnDpInitedInner(data, reply);
52 }
53
OnDpInitedInner(MessageParcel & data,MessageParcel & reply)54 int32_t DpInitedCallbackStub::OnDpInitedInner(MessageParcel& data, MessageParcel& reply)
55 {
56 (void)data;
57 HILOGI("called");
58 int32_t ret = OnDpInited();
59 if (!reply.WriteInt32(ret)) {
60 HILOGE("Write reply failed");
61 return ERR_FLATTEN_OBJECT;
62 }
63 return DP_SUCCESS;
64 }
65 } // namespace DistributedDeviceProfile
66 } // namespace OHOS
67