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 DRIVER_EXTENSION_MANAGER_H 17 #define DRIVER_EXTENSION_MANAGER_H 18 #include <singleton.h> 19 #include <system_ability.h> 20 #include <future> 21 22 #include "driver_ext_mgr_stub.h" 23 24 namespace OHOS { 25 namespace ExternalDeviceManager { 26 class DriverExtMgr : public SystemAbility, public DriverExtMgrStub { 27 DECLARE_SYSTEM_ABILITY(DriverExtMgr) 28 DECLARE_DELAYED_SINGLETON(DriverExtMgr); 29 30 public: 31 void OnStart() override; 32 void OnStop() override; 33 int Dump(int fd, const std::vector<std::u16string> &args) override; 34 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 35 UsbErrCode QueryDevice(uint32_t busType, std::vector<std::shared_ptr<DeviceData>> &devices) override; 36 UsbErrCode BindDevice(uint64_t deviceId, const sptr<IDriverExtMgrCallback> &connectCallback) override; 37 UsbErrCode UnBindDevice(uint64_t deviceId) override; 38 UsbErrCode QueryDeviceInfo(std::vector<std::shared_ptr<DeviceInfoData>> &deviceInfos, 39 bool isByDeviceId = false, const uint64_t deviceId = 0) override; 40 UsbErrCode QueryDriverInfo(std::vector<std::shared_ptr<DriverInfoData>> &driverInfos, 41 bool isByDriverUid = false, const std::string &driverUid = "") override; 42 43 private: 44 std::mutex connectCallbackMutex; 45 std::mutex promiseMutex_; 46 std::promise<int32_t> bmsPromise_; 47 std::promise<int32_t> accountPromise_; 48 std::promise<int32_t> commEventPromise_; 49 std::shared_future<int32_t> bmsFuture_ = bmsPromise_.get_future(); 50 std::shared_future<int32_t> accountFuture_ = accountPromise_.get_future(); 51 std::shared_future<int32_t> commEventFuture_ = commEventPromise_.get_future(); 52 bool bmsPromiseUsed_ = false; 53 bool accountPromiseUsed_ = false; 54 bool cesPromiseUsed_ = false; 55 std::map<uint64_t, std::vector<sptr<IDriverExtMgrCallback>>> connectCallbackMap; 56 }; 57 } // namespace ExternalDeviceManager 58 } // namespace OHOS 59 #endif // DRIVER_EXTENSION_MANAGER_H 60