1 /*
2 * Copyright (c) 2021 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 "ipc_server_client_proxy.h"
17
18 #include "ipc_types.h"
19
20 #include "ipc_cmd_register.h"
21 #include "ipc_def.h"
22 #include "device_manager_log.h"
23 #include "device_manager_errno.h"
24
25 namespace OHOS {
26 namespace DistributedHardware {
SendCmd(int32_t cmdCode,std::shared_ptr<IpcReq> req,std::shared_ptr<IpcRsp> rsp)27 int32_t IpcServerClientProxy::SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
28 {
29 sptr<IRemoteObject> remote = Remote();
30 if (remote == nullptr) {
31 DMLOG(DM_LOG_ERROR, "remote service null");
32 return DEVICEMANAGER_NULLPTR;
33 }
34
35 MessageParcel data;
36 MessageParcel reply;
37 MessageOption option;
38 if (!data.WriteInterfaceToken(GetDescriptor())) {
39 DMLOG(DM_LOG_ERROR, "WriteInterfaceToken fail!");
40 return DEVICEMANAGER_IPC_WRITE_TOKEN_ERROR;
41 }
42 if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DEVICEMANAGER_OK) {
43 return DEVICEMANAGER_FAILED;
44 }
45 if (remote->SendRequest(cmdCode, data, reply, option) != DEVICEMANAGER_OK) {
46 DMLOG(DM_LOG_ERROR, "SendRequest fail, cmd:%d", cmdCode);
47 return DEVICEMANAGER_IPC_FAILED;
48 }
49 return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);
50 }
51 } // namespace DistributedHardware
52 } // namespace OHOS
53