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 #ifndef BUS_EXTENSION_CORE_H 16 #define BUS_EXTENSION_CORE_H 17 18 #include <memory> 19 #include <unordered_map> 20 #include "ext_object.h" 21 #include "idev_change_callback.h" 22 #include "single_instance.h" 23 #include "ibus_extension.h" 24 25 namespace OHOS { 26 namespace ExternalDeviceManager { 27 class BusExtensionCore { 28 DECLARE_SINGLE_INSTANCE_BASE(BusExtensionCore); 29 30 public: 31 ~BusExtensionCore() = default; 32 int32_t Init(std::shared_ptr<IDevChangeCallback> callback); 33 int32_t Register(BusType busType, std::shared_ptr<IBusExtension> busExtension); 34 std::shared_ptr<IBusExtension> GetBusExtensionByName(std::string busName); 35 void LoadBusExtensionLibs(); 36 37 private: 38 BusExtensionCore() = default; 39 std::unordered_map<BusType, std::shared_ptr<IBusExtension>> busExtensions_; 40 const uint32_t MAX_BUS_EXTENSIONS = 100; 41 }; 42 43 // bus extension should register by __attribute__ ((constructor)) when loading so 44 template <typename BusExtension> RegisterBusExtension(BusType busType)45void RegisterBusExtension(BusType busType) 46 { 47 BusExtensionCore::GetInstance().Register(busType, std::make_shared<BusExtension>()); 48 } 49 } // namespace ExternalDeviceManager 50 } // namespace OHOS 51 #endif // BUS_EXTENSION_CORE_H