• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MANAGER_H
17 #define DRIVER_MANAGER_H
18 
19 #include <cstdint>
20 #include <map>
21 
22 #include "iservstat_listener_hdi.h"
23 #include "singleton.h"
24 
25 #include "driver.h"
26 #include "iauth_driver_hdi.h"
27 #include "idriver_manager.h"
28 
29 namespace OHOS {
30 namespace UserIam {
31 namespace UserAuth {
32 using namespace HDI::ServiceManager::V1_0;
33 
34 class DriverManager : public Singleton<DriverManager> {
35 public:
36     DriverManager();
37     ~DriverManager() override = default;
38     int32_t Start(const std::map<std::string, HdiConfig> &hdiName2Config);
39     void OnFrameworkReady();
40     void OnAllHdiDisconnect();
41     void SubscribeHdiDriverStatus();
42     std::shared_ptr<Driver> GetDriverByServiceName(const std::string &serviceName);
43 
44 private:
45     class HdiServiceStatusListener;
46     bool HdiConfigIsValid(const std::map<std::string, HdiConfig> &hdiName2Config);
47     void SubscribeServiceStatus();
48     void SubscribeFrameworkReadyEvent();
49 
50     std::mutex mutex_;
51     std::map<std::string, std::shared_ptr<Driver>> serviceName2Driver_;
52 };
53 
54 class DriverManager ::HdiServiceStatusListener : public ServStatListenerStub {
55 public:
56     using StatusCallback = std::function<void(const ServiceStatus &)>;
HdiServiceStatusListener(StatusCallback callback)57     explicit HdiServiceStatusListener(StatusCallback callback) : callback_(std::move(callback))
58     {
59     }
60     ~HdiServiceStatusListener() override = default;
OnReceive(const ServiceStatus & status)61     void OnReceive(const ServiceStatus &status) override
62     {
63         callback_(status);
64     }
65 
66 private:
67     StatusCallback callback_;
68 };
69 } // namespace UserAuth
70 } // namespace UserIam
71 } // namespace OHOS
72 
73 #endif // DRIVER_MANAGER_H