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 #ifndef OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H 17 #define OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H 18 19 #include <cstdint> 20 #include <string> 21 #include <memory> 22 #include <list> 23 24 #include "device_manager_ipc_interface_code.h" 25 #include "single_instance.h" 26 #include "ipc_req.h" 27 #include "ipc_rsp.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 #define DEVICEMANAGER_MESSAGE_FAILED (-1) 32 static int32_t GetTrustedDeviceList(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 33 static int32_t GetLocalDeviceInfo(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 34 static int32_t GetUdidByNetworkId(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 35 static int32_t GetUuidByNetworkId(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 36 static int32_t StartDeviceDiscovery(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 37 static int32_t StopDeviceDiscovery(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 38 static int32_t SetUserOperation(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 39 static int32_t GetFaParam(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 40 static int32_t AuthenticateDevice(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 41 static int32_t UnAuthenticateDevice(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 42 static int32_t VerifyAuthentication(const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 43 44 typedef struct { 45 int32_t cmdCode; 46 int32_t (*MsgProcess) (const std::shared_ptr<IpcReq> &req, const std::shared_ptr<IpcRsp> &rsp); 47 } CmdMap; 48 49 static const CmdMap g_cmdMap[] = { 50 {GET_TRUST_DEVICE_LIST, GetTrustedDeviceList}, 51 {GET_LOCAL_DEVICE_INFO, GetLocalDeviceInfo}, 52 {GET_UDID_BY_NETWORK, GetUdidByNetworkId}, 53 {GET_UUID_BY_NETWORK, GetUuidByNetworkId}, 54 {START_DEVICE_DISCOVER, StartDeviceDiscovery}, 55 {STOP_DEVICE_DISCOVER, StopDeviceDiscovery}, 56 {SERVER_USER_AUTH_OPERATION, SetUserOperation}, 57 {SERVER_GET_DMFA_INFO, GetFaParam}, 58 {AUTHENTICATE_DEVICE, AuthenticateDevice}, 59 {UNAUTHENTICATE_DEVICE, UnAuthenticateDevice}, 60 {VERIFY_AUTHENTICATION, VerifyAuthentication}, 61 }; 62 63 class CommandDispatch { 64 DECLARE_SINGLE_INSTANCE(CommandDispatch); 65 public: 66 int32_t MessageSendCmd(int32_t cmdCode, const std::shared_ptr<IpcReq> &req, 67 const std::shared_ptr<IpcRsp> &rsp); 68 void AddPkgName(const std::string &pkgName); 69 void DeletePkgName(const std::string &pkgName); 70 const std::list<std::string>& GetPkgNameList() const; 71 private: 72 std::list<std::string> dmPkgName_; 73 }; 74 } // namespace DistributedHardware 75 } // namespace OHOS 76 #endif // OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H 77