1 /*
2  * Copyright (C) 2021-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 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines profile services manager for bluetooth system.
21  *
22  * @since 6
23  */
24 
25 /**
26  * @file profile_service_manager.h
27  *
28  * @brief system state machine interface.
29  *
30  * @since 6
31  */
32 
33 #ifndef PROFILE_SERVICE_MANAGER_H
34 #define PROFILE_SERVICE_MANAGER_H
35 
36 #include <map>
37 #include <vector>
38 
39 #include "interface_profile.h"
40 #include "interface_profile_manager.h"
41 #include "util/dispatcher.h"
42 
43 namespace OHOS {
44 namespace bluetooth {
45 /**
46  * @brief Represents profile service manager.
47  *
48  * @since 6
49  */
50 class ProfileServiceManager : public IProfileManager {
51 public:
52     /**
53      * @brief Get profile service manager singleton instance pointer.
54      *
55      * @return Returns the singleton instance pointer.
56      * @since 6
57      */
58     static ProfileServiceManager *GetInstance();
59 
60     /**
61      * @brief Initialize profile service manager.
62      *
63      * @param dispatch The dispatch used in profile service manager.
64      * @since 6
65      */
66     static void Initialize(utility::Dispatcher &dispatch);
67 
68     /**
69      * @brief Uninitialize profile service manager.
70      *
71      * @since 6
72      */
73     static void Uninitialize();
74 
75     // framework function
76     /**
77      * @brief Get profile service pointer.
78      *
79      * @param name Profile service name.
80      * @return Returns the profile service pointer.
81      * @since 6
82      */
83     IProfile *GetProfileService(const std::string &name) const override;
84 
85     /**
86      * @brief Create profile services according to config.xml.
87      *
88      * @since 6
89      */
90     void Start() const;
91 
92     /**
93      * @brief Delete all profile services when Start() create.
94      *
95      * @since 6
96      */
97     void Stop() const;
98 
99     /**
100      * @brief Enable profile services.
101      *
102      * @param transport Adapter transport.
103      * @return Returns <b>true</b> if the operation is successful;
104      *         returns <b>false</b> if the operation fails.
105      * @since 6
106      */
107     bool Enable(const BTTransport transport) const;
108 
109     /**
110      * @brief Set all profile services states as turn on.
111      *
112      * @param transport Adapter transport.
113      * @since 6
114      */
115     void OnAllEnabled(const BTTransport transport) const;
116 
117     /**
118      * @brief Disable profile services.
119      *
120      * @param transport Adapter transport.
121      * @return Returns <b>true</b> if the operation is successful;
122      *         returns <b>false</b> if the operation fails.
123      * @since 6
124      */
125     bool Disable(const BTTransport transport) const;
126 
127     /**
128      * @brief Set all profile services states as turn off.
129      *
130      * @param transport Adapter transport.
131      * @since 6
132      */
133     void OnAllDisabled(const BTTransport transport) const;
134 
135     /**
136      * @brief Get profile service ID list.
137      *
138      * @return Returns vector of enabled profile services ID.
139      * @since 6
140      */
141     std::vector<uint32_t> GetProfileServicesList() const override;
142 
143     /**
144      * @brief Get profile service connect state.
145      *
146      * @param profileID Profile service ID.
147      * @return Returns connect state for designated profile service.
148      * @since 6
149      */
150     BTConnectState GetProfileServiceConnectState(const uint32_t profileID) const override;
151 
152     /**
153      * @brief Get local device supported uuids.
154      *
155      * @param[out] Vector which use to return support uuids.
156      * @since 6
157      */
158     void GetProfileServicesSupportedUuids(std::vector<std::string> &uuids) const override;
159     /**
160      * @brief Get all profile services connect state.
161      *
162      * @return Returns profile services connect state.
163      * @since 6
164      */
165     BTConnectState GetProfileServicesConnectState() const;
166 
167     /**
168      * @brief Profile service enable complete notify.
169      *
170      * @param profileID Profile service ID.
171      * @param ret Profile service enable operation result.
172      * @since 6
173      */
174     void OnEnable(const std::string &name, bool ret) const;
175 
176     /**
177      * @brief Profile service disable complete notify.
178      *
179      * @param profileID Profile service ID.
180      * @param ret Profile service disable operation result.
181      * @since 6
182      */
183     void OnDisable(const std::string &name, bool ret) const;
184 
185     /**
186      * @brief A constructor used to create an <b>ProfileServiceManager</b> instance.
187      *
188      * @param dispatch The dispatch used in profile service manager.
189      * @since 6
190      */
191     explicit ProfileServiceManager(utility::Dispatcher &dispatch);
192 
193     /**
194      * @brief A destructor used to delete the <b>ProfileServiceManager</b> instance.
195      *
196      * @since 6
197      */
198     ~ProfileServiceManager();
199 
200 private:
201     ProfileServiceManager() = delete;
202 
203     void CreateConfigSupportProfiles() const;
204     void CreateClassicProfileServices() const;
205     void CreateBleProfileServices() const;
206 
207     void EnableProfiles(const BTTransport transport) const;
208     void DisableProfiles(const BTTransport transport) const;
209     void EnableCompleteProcess(const std::string &name, bool ret) const;
210     void DisableCompleteProcess(const std::string &name, bool ret) const;
211     void EnableCompleteNotify(const BTTransport transport) const;
212     void DisableCompleteNotify(const BTTransport transport) const;
213     bool IsAllEnabled(const BTTransport transport) const;
214     bool IsProfilesTurning(const BTTransport transport) const;
215     bool IsAllDisabled(const BTTransport transport) const;
216     void CheckWaitEnableProfiles(const std::string &name, const BTTransport transport) const;
217 
218     BT_DISALLOW_COPY_AND_ASSIGN(ProfileServiceManager);
219     DECLARE_IMPL();
220 };
221 }  // namespace bluetooth
222 }  // namespace OHOS
223 
224 #endif  // PROFILE_SERVICE_MANAGER_H