1 /*
2 * Copyright (c) 2021-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 #include "connect_callback_stub.h"
16
17 #include "ipc_types.h"
18 #include "hilog_tag_wrapper.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
ConnectCallbackStub()23 ConnectCallbackStub::ConnectCallbackStub() {}
24
ConnectInner(MessageParcel & data,MessageParcel & reply)25 int ConnectCallbackStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
26 {
27 string deviceId = Str16ToStr8(data.ReadString16());
28 string deviceType = Str16ToStr8(data.ReadString16());
29 Connect(deviceId, deviceType);
30 return OHOS::ERR_NONE;
31 }
32
DisconnectInner(MessageParcel & data,MessageParcel & reply)33 int ConnectCallbackStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
34 {
35 string deviceId = Str16ToStr8(data.ReadString16());
36 Disconnect(deviceId);
37 return OHOS::ERR_NONE;
38 }
39 /**
40 * @brief Remote device sends connection or disconnection request.
41 * @param Code indicators code of the connection or disconnection request function.
42 * @param data indicators receives the message object.
43 * @param reply indicators reply the message object.
44 * @return none
45 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int ConnectCallbackStub::OnRemoteRequest(
47 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
48 {
49 std::u16string token = data.ReadInterfaceToken();
50 if (token.compare(IConnectCallback::GetDescriptor()) != 0) {
51 TAG_LOGE(AAFwkTag::CONTINUATION, "Descriptor is wrong");
52 return OHOS::ERR_INVALID_REPLY;
53 }
54 switch (code) {
55 case COMMAND_CONNECT:
56 return ConnectInner(data, reply);
57 case COMMAND_DISCONNECT:
58 return DisconnectInner(data, reply);
59 }
60 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62 } // namespace AppExecFwk
63 } // namespace OHOS
64