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 16 #ifndef OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H 17 #define OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H 18 19 #include "extension_base.h" 20 21 namespace OHOS { 22 namespace AbilityRuntime { 23 class DriverExtensionContext; 24 class Runtime; 25 class DriverExtension; 26 using CreatorDriverFunc = std::function<DriverExtension* (const std::unique_ptr<Runtime>& runtime)>; 27 /** 28 * @brief Basic driver components. 29 */ 30 class DriverExtension : public ExtensionBase<DriverExtensionContext>, 31 public std::enable_shared_from_this<DriverExtension> { 32 public: 33 DriverExtension() = default; 34 virtual ~DriverExtension() = default; 35 36 /** 37 * @brief Create and init context. 38 * 39 * @param record the extension record. 40 * @param application the application info. 41 * @param handler the extension handler. 42 * @param token the remote token. 43 * @return The created context. 44 */ 45 virtual std::shared_ptr<DriverExtensionContext> CreateAndInitContext( 46 const std::shared_ptr<AbilityLocalRecord> &record, 47 const std::shared_ptr<OHOSApplication> &application, 48 std::shared_ptr<AbilityHandler> &handler, 49 const sptr<IRemoteObject> &token) override; 50 51 /**DRIVER 52 * @brief Init the extension. 53 * 54 * @param record the extension record. 55 * @param application the application info. 56 * @param handler the extension handler. 57 * @param token the remote token. 58 */ 59 virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record, 60 const std::shared_ptr<OHOSApplication> &application, 61 std::shared_ptr<AbilityHandler> &handler, 62 const sptr<IRemoteObject> &token) override; 63 64 /** 65 * @brief Create Extension. 66 * 67 * @param runtime The runtime. 68 * @return The DriverExtension instance. 69 */ 70 static DriverExtension* Create(const std::unique_ptr<Runtime>& runtime); 71 72 /** 73 * @brief Set a creator function. 74 * 75 * @param creator The function for create a driver-extension ability. 76 */ 77 static void SetCreator(const CreatorDriverFunc& creator); 78 79 private: 80 static CreatorDriverFunc creator_; 81 }; 82 } // namespace AbilityRuntime 83 } // namespace OHOS 84 #endif // OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H 85