1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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_SHARING_CONTEXT_MANAGER_H 17 #define OHOS_SHARING_CONTEXT_MANAGER_H 18 19 #include <unordered_map> 20 #include "context/context.h" 21 #include "event/handle_event_base.h" 22 #include "singleton.h" 23 24 namespace OHOS { 25 namespace Sharing { 26 27 class ContextManager : public EventEmitter, 28 public Singleton<ContextManager>, 29 public HandleEventBase { 30 friend class Singleton<ContextManager>; 31 32 public: 33 virtual ~ContextManager(); 34 35 void Init(); 36 int32_t HandleEvent(SharingEvent &event) override; 37 38 protected: GetAgentSrcLimit()39 uint32_t GetAgentSrcLimit() 40 { 41 return maxSrcAgent_; 42 } 43 GetAgentSinkLimit()44 uint32_t GetAgentSinkLimit() 45 { 46 return maxSinkAgent_; 47 } 48 49 protected: 50 uint32_t HandleContextCreate(); 51 void DestroyContext(uint32_t contextId); 52 Context::Ptr GetContextById(uint32_t contextId); 53 54 private: 55 bool CheckAgentSize(AgentType agentType); 56 57 void HandleAgentCreate(SharingEvent &event); 58 void HandleContextEvent(SharingEvent &event); 59 void HandleConfiguration(SharingEvent &event); 60 void HandleMediachannelDestroy(SharingEvent &event); 61 62 private: 63 uint32_t maxContext_ = MAX_CONTEXT_NUM; 64 uint32_t maxSrcAgent_ = MAX_SRC_AGENT_NUM; 65 uint32_t maxSinkAgent_ = MAX_SINK_AGENT_NUM; 66 67 std::mutex mutex_; 68 std::unordered_map<int32_t, Context::Ptr> contexts_; 69 }; 70 71 } // namespace Sharing 72 } // namespace OHOS 73 #endif