• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 INTERFACE_PROFILE_MAP_MSE_H
17 #define INTERFACE_PROFILE_MAP_MSE_H
18 
19 #include "interface_profile.h"
20 #include <vector>
21 
22 namespace OHOS {
23 namespace bluetooth {
24 /**
25  * @brief Callback function api of Map service, including connection, disconnection and authorization.
26  *
27  * @since 6
28  */
29 class IMapMseObserver {
30 public:
31     /**
32      * @brief A destructor used to delete the Map Service Observer instance.
33      *
34      * @since 6
35      */
36     virtual ~IMapMseObserver() = default;
37 
38     /**
39      * @brief Callback function when the connection state changes.
40      *
41      * @param device  the remote bluetooth device.
42      * @param state   the connection status.
43      *     @c BTConnectState::CONNECTING : the state is connecting.
44      *     @c BTConnectState::CONNECTED : the state is connected.
45      *     @c BTConnectState::DISCONNECTING : the state is disconnecting.
46      *     @c BTConnectState::DISCONNECTED : the state is disconnected.
47      * @since 6
48      */
OnConnectionStateChanged(const RawAddress & remoteAddr,int state)49     virtual void OnConnectionStateChanged(const RawAddress &remoteAddr, int state){};
50 
51     /**
52      * @brief Called to validate if a connection to the bluetooth device should be accepted.
53      *
54      * @param remoteAddr  the connecting bluetooth device.
55      * @since 6
56      */
OnPermission(const RawAddress & remoteAddr)57     virtual void OnPermission(const RawAddress &remoteAddr){};
58 };
59 
60 /**
61  * @brief Map service API.
62  *
63  * @since 6
64  */
65 class IProfileMapMse : public IProfile {
66 public:
67     /**
68      * @brief A destructor used to delete the Map service Observer instance.
69      *
70      * @since 6
71      */
72     virtual ~IProfileMapMse() = default;
73 
74     /**
75      * @brief Register the callback of map service.
76      *
77      * @param mapMseObserver  Reference to the map service observer.
78      * @since 6
79      */
80     virtual void RegisterObserver(IMapMseObserver &mapMseObserver) = 0;
81 
82     /**
83      * @brief Unregister the callback of map service.
84      *
85      * @param mapMseObserver  Reference to the map service observer.
86      * @since 6
87      */
88     virtual void DeregisterObserver(IMapMseObserver &mapMseObserver) = 0;
89 
90     /**
91      * @brief Get the connection status of the server.
92      *
93      * @return Returns connection state of map profile.
94      * @since 6
95      */
96     virtual int GetState(void) = 0;
97 
98     /**
99      * @brief Disconnect bluetooth connection service.
100      *
101      * @param device  Reference to the remote bluetooth device.
102      * @return Returns true if the operation is successful;returns false if the operation fails.
103      * @since 6
104      */
105     virtual int Disconnect(const RawAddress &device) = 0;
106 
107     /**
108      * @brief Get whether bluetooth device is connected.
109      *
110      * @param device  Reference to the remote bluetooth device.
111      * @return Returns true if the connection is successful;returns false if the connection fails.
112      * @since 6
113      */
114     virtual bool IsConnected(const RawAddress &device) = 0;
115 
116     /**
117      * @brief Get the device list through the connection status.
118      *
119      * @param  states  Reference to the connection status.
120      *     @c  BTConnectState::CONNECTING : the state is connecting.
121      *     @c  BTConnectState::CONNECTED : the state is connected.
122      *     @c  BTConnectState::DISCONNECTING : the state is disconnecting.
123      *     @c  BTConnectState::DISCONNECTED : the state is disconnected.
124      * @return Returns the bluetooth address in the specified status.
125      * @since 6
126      */
127     virtual std::vector<RawAddress> GetDevicesByStates(std::vector<int> states) = 0;
128 
129     /**
130      * @brief Get the connection status of the specified device.
131      *
132      * @param device Reference to the remote bluetooth device.
133      * @return Returns the connection status of the specified bluetooth address.
134      * @since 6
135      */
136     virtual int GetConnectionState(const RawAddress &device) = 0;
137 
138     /**
139      * @brief Set the connection policy of the specified device.
140      *
141      * @param device Reference to the remote bluetooth device.
142      * @param strategy Reference to the connection policy,
143      *     @c BTStrategyType::CONNECTION_UNKNOWN : the connection policy for unkown state.
144      *     @c BTStrategyType::CONNECTION_ALLOWED : the connection policy for allowed state.
145      *     @c BTStrategyType::CONNECTION_FORBIDDEN : the connection policy for forbidden state.
146      * @return Returns true if the operation is successful;returns false if the operation fails.
147      * @since 6
148      */
149     virtual bool SetConnectionStrategy(const RawAddress &device, int strategy) = 0;
150 
151     /**
152      * @brief Get the connection policy of the specified device.
153      *
154      * @param device Reference to the remote bluetooth device.
155      * @return Returns the connection police of the specified bluetooth address.
156      * @since 6
157      */
158     virtual int GetConnectionStrategy(const RawAddress &device) = 0;
159 
160     /**
161      * @brief Set whether to authorize the connection.
162      *
163      * @param device Reference to the remote bluetooth device.
164      * @param allow Reference to grant authorization.
165      *     @c true : accept connection.
166      *     @c false : reject connection.
167      * @since 6
168      */
169     virtual void GrantPermission(const RawAddress &device, bool allow, bool save = false) = 0;
170 };
171 }  // namespace bluetooth
172 }  // namespace OHOS
173 
174 #endif  // INTERFACE_PROFILE_MAP_MSE_H