1 /*
2  * Copyright (C) 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 OHOS_ABILITY_RUNTIME_FENCE_EXTENSION_H
17 #define OHOS_ABILITY_RUNTIME_FENCE_EXTENSION_H
18 
19 #include "extension_base.h"
20 #include "fence_extension_context.h"
21 #include "constant_definition.h"
22 #include <map>
23 
24 namespace OHOS {
25 namespace Location {
26 using namespace AbilityRuntime;
27 
28 class FenceExtensionContext;
29 
30 class FenceExtension;
31 
32 using CreatorFunc = std::function<FenceExtension *(const std::unique_ptr<Runtime> &runtime)>;
33 
34 /**
35  * @brief Basic vpn components.
36  */
37 class FenceExtension : public ExtensionBase<FenceExtensionContext> {
38 public:
39     FenceExtension() = default;
40 
41     virtual ~FenceExtension() = default;
42 
43     /**
44      * @brief Create and init fence context.
45      *
46      * @param record the fence extension record.
47      * @param application the application info.
48      * @param handler the fence extension handler.
49      * @param token the remote token.
50      * @return The created fence context.
51      */
52     virtual std::shared_ptr<FenceExtensionContext> CreateAndInitContext(
53         const std::shared_ptr<AbilityLocalRecord> &record, const std::shared_ptr<OHOSApplication> &application,
54         std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
55 
56     /**
57      * @brief Init the fence extension.
58      *
59      * @param record the fence extension record.
60      * @param application the application info.
61      * @param handler the extension handler.
62      * @param token the remote token.
63      */
64     virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record,
65         const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
66         const sptr<IRemoteObject> &token) override;
67 
68     /**
69      * @brief Create Extension.
70      *
71      * @param runtime The runtime.
72      * @return The VpnExtension instance.
73      */
74     static FenceExtension *Create(const std::unique_ptr<OHOS::AbilityRuntime::Runtime> &runtime);
75 
76     /**
77      * @brief Set a creator function.
78      *
79      * @param creator The function for create a vpn-extension ability.
80      */
81     static void SetCreator(const CreatorFunc &creator);
82 
83     /**
84      * @brief called back when geofence status is change.
85      *
86      * @param fenceId enter fence id
87      * @param fenceType enter fence type
88      * @param extraData other extra data
89      */
90     FenceExtensionErrCode OnFenceStatusChange(std::map<std::string, std::string> extraData);
91 
92     /**
93      * @brief destroy this extension
94      */
95     void OnDestroy();
96 };
97 }  // namespace Location
98 }  // namespace OHOS
99 
100 #endif  // OHOS_ABILITY_RUNTIME_FENCE_EXTENSION_H
101