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 {
RemoteSessionCommandProcess(const sptr<IRemoteObject> & impl)21 RemoteSessionCommandProcess::RemoteSessionCommandProcess(const sptr<IRemoteObject>& impl)
22 : IRemoteProxy<IAVSessionService>(impl)
23 {
24 SLOGD("constructor");
25 }
26
ProcessCastAudioCommand(const RemoteServiceCommand command,const std::string & input,std::string & output)27 int32_t RemoteSessionCommandProcess::ProcessCastAudioCommand(const RemoteServiceCommand command,
28 const std::string& input, std::string& output)
29 {
30 AVSESSION_TRACE_SYNC_START("AVSessionServiceProxy::ProcessCastAudioCommand");
31 MessageParcel data;
32 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
33 "write interface token failed");
34 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(command), ERR_MARSHALLING, "write command failed");
35 CHECK_AND_RETURN_RET_LOG(data.WriteString(input), ERR_MARSHALLING, "write input failed");
36 MessageParcel reply;
37 MessageOption option;
38 CHECK_AND_RETURN_RET_LOG(Remote()->SendRequest(SERVICE_CMD_SEND_COMMAND_TO_REMOTE, data, reply, option) == 0,
39 ERR_RPC_SEND_REQUEST, "send request failed");
40 int32_t ret = AVSESSION_ERROR;
41 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_MARSHALLING, "read reply failed");
42 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "send remote request failed");
43 CHECK_AND_RETURN_RET_LOG(reply.ReadString(output), ERR_MARSHALLING, "read output failed");
44 return AVSESSION_SUCCESS;
45 }
46 }