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 OBEX_MP_CLIENT_H
17 #define OBEX_MP_CLIENT_H
18 
19 #include "obex_client.h"
20 
21 namespace OHOS {
22 namespace bluetooth {
23 class ObexMpClient : public ObexClient {
24 public:
25     // create obex client
26     explicit ObexMpClient(
27         const ObexClientConfig &config, ObexClientObserver &observer, utility::Dispatcher &dispatcher);
28     // destroy obex client
29     ~ObexMpClient() override = default;
30 
31     int Put(const ObexHeader &req);
32     /**
33      * @brief send obex put request \n
34      * When receiving Continue response, automatically send next Put request
35      *
36      * @param req the header of obex request for put(without body)
37      * @param reader obex body reader
38      * @return int Request processing result:0:succeeded -1:failed
39      */
40     int Put(const ObexHeader &req, std::shared_ptr<ObexBodyObject> reader);
41     /**
42      * @brief send obex get request
43      *
44      * @param req the data of obex request for get
45      * @return int Request processing result:0:succeeded -1:failed
46      */
47     int Get(const ObexHeader &req);
48     /**
49      * @brief send obex get request \n
50      * When receiving Continue response, automatically send next Get request
51      * @param req the data of obex request for get
52      * @param writer obex body writer
53      * @param srmpCount srmp request count
54      * @return int Request processing result:0:succeeded -1:failed
55      */
56     int Get(const ObexHeader &req, std::shared_ptr<ObexBodyObject> writer, int srmpCount = 0);
57     /**
58      * @brief send obex set_path request
59      *
60      * @param flag SETPATH flag \n
61      *             bit 0:backup a level before applying name (equivalent to ../ on many systems)\n
62      *                   @see OBEX_SETPATH_BACKUP
63      *             bit 1:Don’t create folder if it does not exist, return an error instead.
64      *                   @see OBEX_SETPATH_NOCREATE
65      * @param path path
66      * @return int Request processing result:0:succeeded -1:failed
67      */
68     int SetPath(uint8_t flag, const std::u16string &path);
69     /**
70      * @brief send obex set_path request
71      *
72      * @param paths path list.
73      * @return int Request processing result:0:succeeded -1:failed
74      */
75     int SetPath(const std::vector<std::u16string> &paths);
76 
77 protected:
78     void PutDataAvailable(const ObexHeader &resp) override;
79     void GetDataAvailable(const ObexHeader &resp) override;
80     void SetPathDataAvailable(const ObexHeader &resp) override;
81     void AbortDataAvailable(const ObexHeader &resp) override;
82     void HandleTransportDataBusy(uint8_t isBusy) override;
83 
84     void ProcessGetContinueData(const ObexHeader &resp);
85     void ProcessGetSuccessData(const ObexHeader &resp);
86     int ProcessSendPutWithSrm();
87 
88 private:
89     void HandlePutData(const ObexHeader &resp);
90 };
91 }  // namespace bluetooth
92 }  // namespace OHOS
93 #endif  // OBEX_MP_CLIENT_H
94