• 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 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  */
24 
25 /**
26  * @file bluetooth_opp.h
27  *
28  * @brief Declares OPP role framework functions, including basic and observer functions.
29  *
30  */
31 #ifndef BLUETOOTH_OPP_H
32 #define BLUETOOTH_OPP_H
33 
34 #include <string>
35 #include <vector>
36 #include <memory>
37 
38 #include "bluetooth_def.h"
39 #include "bluetooth_remote_device.h"
40 #include "bluetooth_types.h"
41 namespace OHOS {
42 namespace Bluetooth {
43 /**
44  * @brief Bluetooth Opp Transfer Information.
45  *
46  * @since 9
47  */
48 class BLUETOOTH_API BluetoothOppTransferInformation {
49 public:
50     /**
51      * @brief A constructor used to create a <b>BluetoothOppTransferInformation</b> instance.
52      *
53      * @since 6
54      */
55     BluetoothOppTransferInformation();
56 
57     /**
58      * @brief A destructor used to delete the <b>BluetoothOppTransferInformation</b> instance.
59      *
60      * @since 6
61      */
62     ~BluetoothOppTransferInformation();
63 
64     /**
65      * @brief Get Id.
66      *
67      * @return Returns Id.
68      * @since 6
69      */
70     int GetId() const;
71 
72     /**
73      * @brief Get File Name.
74      *
75      * @return File Name.
76      * @since 6
77      */
78     std::string GetFileName() const;
79 
80     /**
81      * @brief Get File Path.
82      *
83      * @return Returns File Path.
84      * @since 6
85      */
86     std::string GetFilePath() const;
87 
88     /**
89      * @brief Get Mime Type.
90      *
91      * @since 6
92      */
93     std::string GetMimeType() const;
94 
95     /**
96      * @brief Get Device Name.
97      *
98      * @return Returns Device Name.
99      * @since 6
100      */
101     std::string GetDeviceName() const;
102 
103     /**
104      * @brief Get Device Address.
105      *
106      * @return Returns Device Address.
107      * @since 6
108      */
109     std::string GetDeviceAddress() const;
110 
111     /**
112      * @brief Get Direction.
113      *
114      * @return Returns Direction.
115      * @since 6
116      */
117     int GetDirection() const;
118 
119     /**
120      * @brief Get Status.
121      *
122      * @return Returns Status.
123      * @since 6
124      */
125     int GetStatus() const;
126 
127     /**
128      * @brief Get Failed Reason.
129      *
130      * @return Returns Failed Reason.
131      * @since 6
132      */
133     int GetFailedReason() const;
134 
135     /**
136      * @brief Get Time Stamp.
137      *
138      * @return TimeStamp.
139      * @since 6
140      */
141     uint64_t GetTimeStamp() const;
142 
143     /**
144      * @brief Get Current Bytes.
145      *
146      * @return Returns Current Bytes.
147      * @since 6
148      */
149     uint64_t GetCurrentBytes() const;
150 
151     /**
152      * @brief Get Total Bytes.
153      *
154      * @return Returns TotalBytes.
155      * @since 6
156      */
157     uint64_t GetTotalBytes() const;
158 
159     /**
160      * @brief Set Id.
161      *
162      * @param interval Id.
163      * @since 6
164      */
165     void SetId(int id);
166 
167     /**
168      * @brief Set File Name.
169      *
170      * @param interval File Name.
171      * @since 6
172      */
173     void SetFileName(std::string fileName);
174 
175     /**
176      * @brief Set File Path.
177      *
178      * @param interval File Path.
179      * @since 6
180      */
181     void SetFilePath(std::string filePath);
182 
183     /**
184      * @brief Set Mime Type.
185      *
186      * @param interval Mime Type.
187      * @since 6
188      */
189     void SetMimeType(std::string mimeType);
190 
191     /**
192      * @brief Set Device Name.
193      *
194      * @param interval Device Name.
195      * @since 6
196      */
197     void SetDeviceName(std::string deviceName);
198 
199     /**
200      * @brief Set Device Address.
201      *
202      * @param interval Device Address.
203      * @since 6
204      */
205     void SetDeviceAddress(std::string deviceAddress);
206 
207     /**
208      * @brief Set Direction.
209      *
210      * @param interval Direction.
211      * @since 6
212      */
213     void SetDirection(int direction);
214 
215     /**
216      * @brief Set Status.
217      *
218      * @param interval Status.
219      * @since 6
220      */
221     void SetStatus(int status);
222 
223     /**
224      * @brief Set Failed Reason.
225      *
226      * @param interval Failed Reason.
227      * @since 6
228      */
229     void SetFailedReason(int failedReason);
230 
231     /**
232      * @brief Set Time Stamp.
233      *
234      * @param interval Time Stamp.
235      * @since 6
236      */
237     void SetTimeStamp(uint64_t timeStamp);
238 
239     /**
240      * @brief Set Current Bytes.
241      *
242      * @param interval Current Bytes.
243      * @since 6
244      */
245     void SetCurrentBytes(uint64_t currentBytes);
246 
247     /**
248      * @brief Set Total Bytes.
249      *
250      * @param interval Total Bytes.
251      * @since 6
252      */
253     void SetTotalBytes(uint64_t totalBytes);
254 
255 private:
256     int id_ = -1;
257     std::string fileName_;
258     std::string filePath_;
259     std::string mimeType_;
260     std::string deviceName_;
261     std::string deviceAddress_;
262     int direction_ = 0;
263     int status_ = 0;
264     int failedReason_ = 0;
265     uint64_t timeStamp_ = 0;
266     uint64_t currentBytes_ = 0;
267     uint64_t totalBytes_ = 0;
268 };
269 
270 /**
271  * @brief Class for Opp Host observer functions.
272  *
273  */
274 class OppObserver {
275 public:
276     /**
277      * @brief The observer function to notify receive incoming file changed.
278      *
279      * @param transferInformation transfer Information.
280      */
OnReceiveIncomingFileChanged(const BluetoothOppTransferInformation & transferInformation)281     virtual void OnReceiveIncomingFileChanged(const BluetoothOppTransferInformation &transferInformation)
282     {}
283 
284    /**
285      * @brief The observer function to notify transfer state changed.
286      *
287      * @param transferInformation transfer Information.
288      */
OnTransferStateChanged(const BluetoothOppTransferInformation & transferInformation)289     virtual void OnTransferStateChanged(const BluetoothOppTransferInformation &transferInformation)
290     {}
291 
292     /**
293      * @brief Destroy the OppObserver object.
294      *
295      */
~OppObserver()296     virtual ~OppObserver()
297     {}
298 };
299 
300 /**
301  * @brief Class for Opp API.
302  *
303  */
304 class BLUETOOTH_API Opp {
305 public:
306     /**
307      * @brief Get the instance of Opp object.
308      *
309      * @return Returns the pointer to the Opp instance.
310      */
311     static Opp *GetProfile();
312 
313     /**
314      * @brief Send File.
315      *
316      * @return Return a bool value to confirm whether the file is successfully sent.
317      */
318     bool SendFile(std::string device, std::vector<std::string>filePaths, std::vector<std::string>mimeTypes);
319 
320     /**
321      * @brief Set Incoming File Confirmation.
322      *
323      * @return Return a bool value to confirm whether the setting is successful.
324      */
325     bool SetIncomingFileConfirmation(bool accept);
326 
327     /**
328      * @brief Get Current Transfer Information.
329      *
330      * @return Return OppTransferInformation Object.
331      */
332     BluetoothOppTransferInformation GetCurrentTransferInformation();
333 
334      /**
335      * @brief Cancel Transfer.
336      *
337      * @return Return a bool value to confirm whether the cancellation is set successfully.
338      */
339     bool CancelTransfer();
340 
341     /**
342      * @brief Register Opp observer instance.
343      *
344      * @param observer Opp observer instance.
345      */
346     void RegisterObserver(std::shared_ptr<OppObserver> observer);
347 
348     /**
349      * @brief Deregister Opp observer instance.
350      *
351      * @param observer Opp observer instance.
352      */
353     void DeregisterObserver(std::shared_ptr<OppObserver> observer);
354 
355     /**
356      * @brief Get remote Opp device list which are in the specified states.
357      *
358      * @param states List of remote device states.
359      * @return Returns the list of devices.
360      */
361     std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states);
362 
363     /**
364      * @brief Get the connection state of the specified remote Opp device.
365      *
366      * @param device Remote device object.
367      * @return Returns the connection state of the remote device.
368      */
369     int GetDeviceState(const BluetoothRemoteDevice &device);
370 
371     /**
372      * @brief The external process calls the Opp profile interface before the Bluetooth process starts. At this
373      * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the
374      * Opp proflie.
375      */
376     void Init();
377 
378     /**
379      * @brief Static Opp observer instance.
380      *
381      */
382     static OppObserver *instance_;
383 
384 private:
385     Opp();
386     ~Opp();
387     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(Opp);
388     BLUETOOTH_DECLARE_IMPL();
389 };
390 }  // namespace Bluetooth
391 }  // namespace OHOS
392 #endif  // BLUETOOTH_OPP_H