• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "event_config.h"
24 
25 namespace OHOS {
26 namespace ExternalDeviceManager {
27 class DriverExtMgr : public SystemAbility, public DriverExtMgrStub {
28     DECLARE_SYSTEM_ABILITY(DriverExtMgr)
29     DECLARE_DELAYED_SINGLETON(DriverExtMgr);
30 
31 public:
32     void OnStart() override;
33     void OnStop() override;
34     int Dump(int fd, const std::vector<std::u16string> &args) override;
35     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
36     virtual ErrCode QueryDevice(int32_t &errorCode, uint32_t busType,
37         std::vector<std::shared_ptr<DeviceData>> &devices) override;
38     virtual ErrCode BindDevice(int32_t &errorCode, uint64_t deviceId,
39         const sptr<IDriverExtMgrCallback> &connectCallback) override;
40     virtual ErrCode UnBindDevice(int32_t &errorCode, uint64_t deviceId) override;
41     virtual ErrCode BindDriverWithDeviceId(int32_t &errorCode, uint64_t deviceId,
42         const sptr<IDriverExtMgrCallback> &connectCallback) override;
43     virtual ErrCode UnBindDriverWithDeviceId(int32_t &errorCode, uint64_t deviceId) override;
44     virtual ErrCode QueryDeviceInfo(int32_t &errorCode, std::vector<std::shared_ptr<DeviceInfoData>> &deviceInfos,
45         bool isByDeviceId = false, const uint64_t deviceId = 0) override;
46     virtual ErrCode QueryDriverInfo(int32_t &errorCode, std::vector<std::shared_ptr<DriverInfoData>> &driverInfos,
47         bool isByDriverUid = false, const std::string &driverUid = "") override;
48     virtual ErrCode NotifyUsbPeripheralFault(const std::string &domain, const std::string &faultName) override;
49 
50 private:
51     std::mutex connectCallbackMutex;
52     std::mutex promiseMutex_;
53     std::promise<int32_t> bmsPromise_;
54     std::promise<int32_t> accountPromise_;
55     std::promise<int32_t> commEventPromise_;
56     std::shared_future<int32_t> bmsFuture_ = bmsPromise_.get_future();
57     std::shared_future<int32_t> accountFuture_ = accountPromise_.get_future();
58     std::shared_future<int32_t> commEventFuture_ = commEventPromise_.get_future();
59     bool bmsPromiseUsed_ = false;
60     bool accountPromiseUsed_ = false;
61     bool cesPromiseUsed_ = false;
62     std::map<uint64_t, std::vector<sptr<IDriverExtMgrCallback>>> connectCallbackMap;
63     EventConfig eventConfig_;
64 };
65 } // namespace ExternalDeviceManager
66 } // namespace OHOS
67 #endif // DRIVER_EXTENSION_MANAGER_H
68