1 /* 2 * Copyright (c) 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 DEVICE_MANAGER_ETX_DEVICE_MGR_H 17 #define DEVICE_MANAGER_ETX_DEVICE_MGR_H 18 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <unordered_map> 23 #include <unordered_set> 24 #include "device.h" 25 #include "ext_object.h" 26 #include "single_instance.h" 27 #include "timer.h" 28 29 namespace OHOS { 30 namespace ExternalDeviceManager { 31 using namespace std; 32 class ExtDeviceManager final { 33 DECLARE_SINGLE_INSTANCE_BASE(ExtDeviceManager); 34 35 public: 36 ~ExtDeviceManager(); 37 int32_t Init(); 38 int32_t RegisterDevice(shared_ptr<DeviceInfo> devInfo); 39 int32_t UnRegisterDevice(const shared_ptr<DeviceInfo> devInfo); 40 vector<shared_ptr<DeviceInfo>> QueryDevice(const BusType busType); 41 static int32_t UpdateBundleStatusCallback( 42 int32_t bundleStatus, int32_t busType, const string &bundleName, const string &abilityName); 43 int32_t ConnectDevice(uint64_t deviceId, const sptr<IDriverExtMgrCallback> &connectCallback); 44 int32_t DisConnectDevice(uint64_t deviceId); 45 46 private: 47 ExtDeviceManager() = default; 48 void PrintMatchDriverMap(); 49 int32_t AddDevIdOfBundleInfoMap(shared_ptr<Device> device, string &bundleInfo); 50 int32_t RemoveDevIdOfBundleInfoMap(shared_ptr<Device> device, string &bundleInfo); 51 int32_t RemoveAllDevIdOfBundleInfoMap(shared_ptr<Device> device, string &bundleInfo); 52 int32_t AddBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName); 53 int32_t RemoveBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName); 54 int32_t UpdateBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName); 55 std::shared_ptr<Device> QueryDeviceByDeviceID(uint64_t deviceId); 56 void UnLoadSelf(void); 57 size_t GetTotalDeviceNum(void) const; 58 unordered_map<BusType, unordered_map<uint64_t, shared_ptr<Device>>> deviceMap_; 59 unordered_map<string, unordered_set<uint64_t>> bundleMatchMap_; // driver matching table 60 mutex deviceMapMutex_; 61 mutex bundleMatchMapMutex_; 62 Utils::Timer unloadSelftimer_ {"unLoadSelfTimer"}; 63 uint32_t unloadSelftimerId_ {UINT32_MAX}; 64 }; 65 } // namespace ExternalDeviceManager 66 } // namespace OHOS 67 #endif // DEVICE_MANAGER_ETX_DEVICE_MGR_H