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 DFS_SOFTBUS_AGENT_H 17 #define DFS_SOFTBUS_AGENT_H 18 19 #include <condition_variable> 20 #include <list> 21 #include <unordered_map> 22 23 #include "dfsu_singleton.h" 24 #include "i_filetransfer_callback.h" 25 26 namespace OHOS { 27 namespace Storage { 28 namespace DistributedFile { 29 class SoftbusAgent : public std::enable_shared_from_this<SoftbusAgent>, public Utils::DfsuSingleton<SoftbusAgent> { 30 DECLARE_SINGLETON(SoftbusAgent); 31 32 public: 33 void RegisterSessionListener(); 34 void RegisterFileListener(); 35 void UnRegisterSessionListener(); 36 void OnDeviceOnline(const std::string &cid); 37 void OnDeviceOffline(const std::string &cid); 38 void AllDevicesOffline(); 39 void OnSessionOpened(const int sessionId, const int result); 40 void OnSessionClosed(int sessionId); 41 int SendFile(const std::string &cid, const char *sFileList[], const char *dFileList[], uint32_t fileCnt); 42 void OnSendFileFinished(const int sessionId, const std::string firstFile); 43 void OnFileTransError(const int sessionId); 44 void OnReceiveFileFinished(const int sessionId, const std::string files, int fileCnt); 45 void SetTransCallback(sptr<IFileTransferCallback> &callback); 46 void RemoveTransCallbak(); 47 48 protected: 49 void StartInstance() override; 50 void StopInstance() override; 51 void OpenSession(const std::string &cid); 52 void CloseSession(const std::string &cid); 53 std::string GetPeerDevId(const int sessionId); 54 55 private: 56 std::string sessionName_ { "DistributedFileService" }; 57 std::mutex sessionMapMux_; 58 std::unordered_map<std::string, std::list<int>> cidToSessionID_; 59 60 std::mutex getSessionCVMut_; 61 std::condition_variable getSessionCV_; 62 sptr<IFileTransferCallback> notifyCallback_ = nullptr; 63 }; 64 } // namespace DistributedFile 65 } // namespace Storage 66 } // namespace OHOS 67 #endif // DFS_SOFTBUS_AGENT_H