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