1 /* 2 * Copyright (c) 2024 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 FILEMANAGEMENT_DFS_SERVICE_ALL_CONNECT_MANAGER_H 17 #define FILEMANAGEMENT_DFS_SERVICE_ALL_CONNECT_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "block_object.h" 25 #include "service_collaboration_manager_capi.h" 26 27 namespace OHOS { 28 namespace Storage { 29 namespace DistributedFile { 30 enum class DfsConnectCode { 31 OPEN_P2P = 1, 32 PUSH_ASSET, 33 COPY_FILE, 34 }; 35 36 class AllConnectManager { 37 public: 38 static AllConnectManager &GetInstance(); 39 int32_t InitAllConnectManager(); 40 int32_t UnInitAllConnectManager(); 41 int32_t PublishServiceState(DfsConnectCode code, const std::string &peerNetworkId, 42 ServiceCollaborationManagerBussinessStatus state); 43 int32_t ApplyAdvancedResource(const std::string &peerNetworkId, 44 ServiceCollaborationManager_ResourceRequestInfoSets *resourceRequest); 45 std::shared_ptr<ServiceCollaborationManager_ResourceRequestInfoSets> BuildResourceRequest(); 46 47 private: 48 AllConnectManager(); 49 ~AllConnectManager() = default; 50 int32_t GetAllConnectSoLoad(); 51 int32_t RegisterLifecycleCallback(); 52 int32_t UnRegisterLifecycleCallback(); 53 bool GetPublicState(DfsConnectCode code, const std::string &peerNetworkId, 54 ServiceCollaborationManagerBussinessStatus state); 55 56 static int32_t OnStop(const char *peerNetworkId); 57 static int32_t ApplyResult(int32_t errorcode, int32_t result, const char *reason); 58 59 std::mutex allConnectLock_; 60 void *dllHandle_ = nullptr; 61 62 ServiceCollaborationManager_API allConnect_ = { 63 .ServiceCollaborationManager_PublishServiceState = nullptr, 64 .ServiceCollaborationManager_ApplyAdvancedResource = nullptr, 65 .ServiceCollaborationManager_RegisterLifecycleCallback = nullptr, 66 .ServiceCollaborationManager_UnRegisterLifecycleCallback = nullptr, 67 }; 68 ServiceCollaborationManager_Callback allConnectCallback_; 69 std::shared_ptr<ServiceCollaborationManager_HardwareRequestInfo> remoteHardwareList_; 70 std::shared_ptr<ServiceCollaborationManager_HardwareRequestInfo> localHardwareList_; 71 std::shared_ptr<ServiceCollaborationManager_CommunicationRequestInfo> communicationRequest_; 72 73 std::mutex connectStatesMutex_; 74 std::map<std::string, std::map<DfsConnectCode, ServiceCollaborationManagerBussinessStatus>> connectStates_; 75 76 static std::shared_ptr<BlockObject<bool>> applyResultBlock_; 77 static constexpr uint32_t BLOCK_INTERVAL_ALLCONNECT = 60 * 1000; 78 static inline const std::string SERVICE_NAME {"Distributedfile"}; 79 }; 80 81 } // namespace DistributedFile 82 } // namespace Storage 83 } // namespace OHOS 84 #endif // FILEMANAGEMENT_DFS_SERVICE_ALL_CONNECT_MANAGER_H