• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_listener.h"
17 
18 #include "device_manager_ipc_interface_code.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 #include "ipc_server_stub.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
SendRequest(int32_t cmdCode,std::shared_ptr<IpcReq> req,std::shared_ptr<IpcRsp> rsp)25 int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
26 {
27     if (rsp == nullptr) {
28         return ERR_DM_INPUT_PARA_INVALID;
29     }
30     if (cmdCode < 0 || cmdCode >= IPC_MSG_BUTT) {
31         LOGE("IpcServerListener::SendRequest cmdCode param invalid!");
32         return ERR_DM_UNSUPPORTED_IPC_COMMAND;
33     }
34     std::string pkgName = req->GetPkgName();
35     if (pkgName.empty()) {
36         LOGE("Invalid parameter, pkgName is empty.");
37         return ERR_DM_INPUT_PARA_INVALID;
38     }
39     sptr<IpcRemoteBroker> listener = IpcServerStub::GetInstance().GetDmListener(pkgName);
40     if (listener == nullptr) {
41         LOGI("cannot get listener for package:%{public}s.", pkgName.c_str());
42         return ERR_DM_POINT_NULL;
43     }
44     return listener->SendCmd(cmdCode, req, rsp);
45 }
46 
GetAllPkgName()47 std::vector<std::string> IpcServerListener::GetAllPkgName()
48 {
49     return IpcServerStub::GetInstance().GetAllPkgName();
50 }
51 
SendAll(int32_t cmdCode,std::shared_ptr<IpcReq> req,std::shared_ptr<IpcRsp> rsp)52 int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
53 {
54     if (cmdCode < 0 || cmdCode >= IPC_MSG_BUTT) {
55         LOGE("IpcServerListener::SendAll cmdCode param invalid!");
56         return ERR_DM_UNSUPPORTED_IPC_COMMAND;
57     }
58     int32_t ret = IpcServerStub::GetInstance().SendALL(cmdCode, req, rsp);
59     if (ret != DM_OK) {
60         LOGE("IpcServerListener::SendAll failed!");
61         return ret;
62     }
63     return DM_OK;
64 }
65 } // namespace DistributedHardware
66 } // namespace OHOS
67