1 /*
2 * Copyright (c) 2022 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 "remote_session_command_process.h"
17 #include "avsession_log.h"
18 #include "avsession_trace.h"
19
20 namespace OHOS::AVSession {
21 // LCOV_EXCL_START
RemoteSessionCommandProcess(const sptr<IRemoteObject> & impl)22 RemoteSessionCommandProcess::RemoteSessionCommandProcess(const sptr<IRemoteObject>& impl)
23 : IRemoteProxy<IAVSessionService>(impl)
24 {
25 SLOGD("constructor");
26 }
27 // LCOV_EXCL_STOP
28
ProcessCastAudioCommand(const RemoteServiceCommand command,const std::string & input,std::string & output)29 int32_t RemoteSessionCommandProcess::ProcessCastAudioCommand(const RemoteServiceCommand command,
30 const std::string& input, std::string& output)
31 {
32 AVSESSION_TRACE_SYNC_START("AVSessionServiceProxy::ProcessCastAudioCommand");
33 MessageParcel data;
34 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
35 "write interface token failed");
36 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(command), ERR_MARSHALLING, "write command failed");
37 CHECK_AND_RETURN_RET_LOG(data.WriteString(input), ERR_MARSHALLING, "write input failed");
38 MessageParcel reply;
39 MessageOption option;
40 // LCOV_EXCL_START
41 CHECK_AND_RETURN_RET_LOG(Remote()->SendRequest(
42 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_SEND_COMMAND_TO_REMOTE),\
43 data, reply, option) == 0,
44 ERR_RPC_SEND_REQUEST, "send request failed");
45 // LCOV_EXCL_STOP
46 int32_t ret = AVSESSION_ERROR;
47 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_MARSHALLING, "read reply failed");
48 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "ProcessCastAudioCommand faild: no permission");
49 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "send remote request failed");
50 CHECK_AND_RETURN_RET_LOG(reply.ReadString(output), ERR_MARSHALLING, "read output failed");
51 return AVSESSION_SUCCESS;
52 }
53 }