• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H
17 #define FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H
18 
19 #include <string>
20 
21 #include "ability_local_record.h"
22 #include "extension.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class OHOSApplication;
27 class AbilityHandler;
28 }
29 namespace AbilityRuntime {
30 using namespace OHOS::AppExecFwk;
31 class ExtensionContext;
32 /**
33  * @brief The ExtensionBase class for all extensions.
34  */
35 template<class C = ExtensionContext>
36 class ExtensionBase : public Extension {
37 public:
38     ExtensionBase() = default;
39     virtual ~ExtensionBase() = default;
40 
41     /**
42      * @brief Init the extension.
43      *
44      * @param record the extension record.
45      * @param application the application info.
46      * @param handler the extension handler.
47      * @param token the remote token.
48      */
49     virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record,
50         const std::shared_ptr<OHOSApplication> &application,
51         std::shared_ptr<AbilityHandler> &handler,
52         const sptr<IRemoteObject> &token);
53 
54     /**
55      * @brief Create and init context.
56      *
57      * @param record the extension record.
58      * @param application the application info.
59      * @param handler the extension handler.
60      * @param token the remote token.
61      * @return The created context.
62      */
63     virtual std::shared_ptr<C> CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> &record,
64         const std::shared_ptr<OHOSApplication> &application,
65         std::shared_ptr<AbilityHandler> &handler,
66         const sptr<IRemoteObject> &token);
67 
68     /**
69      * @brief Get context.
70      *
71      * @return The context object.
72      */
73     virtual std::shared_ptr<C> GetContext();
74 private:
75     std::shared_ptr<C> context_ = nullptr;
76 };
77 } // namespace AbilityRuntime
78 } // namespace OHOS
79 #include "extension_base.inl"
80 #endif  // FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H