1 /*
2  * Copyright (c) 2023 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 OHOS_FILEMGMT_SOFTBUS_SESSION_H
17 #define OHOS_FILEMGMT_SOFTBUS_SESSION_H
18 
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS::FileManagement::CloudSync {
24 constexpr int32_t INVALID_SESSION_ID = -1;
25 class SoftbusSession {
26 public:
27     enum DataType : int32_t {
28         TYPE_BYTES,
29         TYPE_FILE,
30     };
31     SoftbusSession(const std::string &peerDeviceId, const std::string &sessionName, DataType type);
32     virtual ~SoftbusSession() = default;
33     int32_t Start();
34     int32_t Stop();
35     int32_t SendData(const void *data, uint32_t dataLen);
36     int32_t SendFile(const std::vector<std::string> &sFileList, const std::vector<std::string> &dFileList);
37     int32_t GetSessionId();
38     DataType GetDataType();
39     std::string GetPeerDeviceId();
40     int32_t WaitSessionOpened(int sessionId);
41 
42 protected:
43     int sessionId_{INVALID_SESSION_ID};
44 
45 private:
46     void CancelReleaseSessionIfNeeded();
47     void CancelDelayReleaseSessionTask();
48     std::string ToBeAnonymous(const std::string &name);
49 
50     std::string peerDeviceId_;
51     std::string sessionName_;
52     DataType type_{TYPE_BYTES};
53     std::mutex sessionMutex_;
54 };
55 } // namespace OHOS::FileManagement::CloudSync
56 
57 #endif // OHOS_FILEMGMT_SOFTBUS_SESSION_H