• 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 OPP_TRANSFER_H
17 #define OPP_TRANSFER_H
18 
19 #include "opp_obex_client.h"
20 
21 #include "timer.h"
22 
23 namespace OHOS {
24 namespace bluetooth {
25 class OppTransfer {
26 public:
27     OppTransfer(const std::string &address, const std::vector<std::string> filePaths,
28         const std::vector<std::string> mimeTypes, int direction);
29     ~OppTransfer();
30 
31     void CreateOppTransfer(const std::string &address, const std::vector<std::string> filePaths,
32         const std::vector<std::string> mimeTypes, int direction);
33     int ConnectObex(const ObexClientConfig &config, utility::Dispatcher &dispatcher);
34     int DisconnectObex() const;
35     int CancelTransfer();
36     IOppTransferInformation GetCurrentTransferInformation();
37     int AcceptConnect();
38     int SetIncomingFileConfirmation(bool accept);
39     int StartTransfer();
40     std::string GetDeviceAddress();
41     int GetDirection() const;
42     int GetFileNumber() const;
43     void OnObexDisconnected();
44     void OnReceiveIncomingConnect(ObexServerSession &session, uint32_t connectId);
45     void OnReceiveIncomingFile(IOppTransferInformation info);
46     void OnTransferStateChange(int state, int reason);
47     void OnTransferPositionChange(size_t position) const;
48 
49 private:
50     void IncomingConnectTimeout();
51     void IncomingFileTimeout();
52     void OnTransferStateChangeRunning();
53     void OnTransferStateChangeSuccess();
54     void OnTransferStateChangeFaild(int reason);
55     size_t GetFileLength(std::string filePath) const;
56     std::string GetFileNameFromPath(std::string filePath) const;
57 
58     std::queue<IOppTransferInformation> fileList_ {};
59     std::unique_ptr<IOppTransferInformation> curretTransferInfo_ {nullptr};
60     std::unique_ptr<OppObexClient> obexClient_ {nullptr};
61     static int currentTransferId_;
62     bool isConnected_ = false;
63     time_t timeStamp_ = 0;
64     int direction_ = OPP_TRANSFER_DIRECTION_OUTBOND;
65     int confirm_ = OPP_TRANSFER_CONFIRM_PENDING;
66     ObexServerSession *obexSession_ = nullptr;
67     uint32_t connectId_ = 0;
68     std::string address_;
69     std::string deviceName_;
70     std::unique_ptr<utility::Timer> incomingConnectTimer_ {nullptr};
71     std::unique_ptr<utility::Timer> incomingFileTimer_ {nullptr};
72 };
73 }  // namespace bluetooth
74 }  // namespace OHOS
75 #endif  // PBAP_PSE_OBEX_SERVER_H
76