1 /* 2 * Copyright (c) 2021-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 SOFTBUS_SESSION_DISPATCHER_H 17 #define SOFTBUS_SESSION_DISPATCHER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <utility> 24 #include "transport/socket.h" 25 #include "transport/trans_type.h" 26 27 namespace OHOS { 28 namespace Storage { 29 namespace DistributedFile { 30 class SoftbusAgent; 31 class SoftbusSessionDispatcher final { 32 public: 33 SoftbusSessionDispatcher() = delete; 34 ~SoftbusSessionDispatcher() = delete; 35 static void RegisterSessionListener(const std::string busName, std::weak_ptr<SoftbusAgent>); 36 static void UnregisterSessionListener(const std::string busName); 37 static std::weak_ptr<SoftbusAgent> GetAgent(int32_t sessionId, std::string peerSessionName); 38 static void OnSessionOpened(int32_t sessionId, PeerSocketInfo info); 39 static void OnSessionClosed(int32_t sessionId, ShutdownReason reason); 40 41 private: 42 static std::mutex idMapMutex_; 43 static std::map<int32_t, std::pair<std::string, std::string>> idMap_; 44 static std::mutex softbusAgentMutex_; 45 static std::map<std::string, std::weak_ptr<SoftbusAgent>> busNameToAgent_; 46 }; 47 } // namespace DistributedFile 48 } // namespace Storage 49 } // namespace OHOS 50 #endif // SOFTBUS_SESSION_DISPATCHER_H