123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ADAPTER_OHOS_CPP_PA_CONTAINER_H
1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_OHOS_CPP_PA_CONTAINER_H
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#include <memory>
2023b3eb3cSopenharmony_ci
2123b3eb3cSopenharmony_ci#include "abs_shared_result_set.h"
2223b3eb3cSopenharmony_ci#include "data_ability_predicates.h"
2323b3eb3cSopenharmony_ci#include "form_provider_info.h"
2423b3eb3cSopenharmony_ci#include "iremote_object.h"
2523b3eb3cSopenharmony_ci#include "pac_map.h"
2623b3eb3cSopenharmony_ci#include "values_bucket.h"
2723b3eb3cSopenharmony_ci#include "want.h"
2823b3eb3cSopenharmony_ci
2923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/platform_event_callback.h"
3023b3eb3cSopenharmony_ci#include "base/resource/asset_manager.h"
3123b3eb3cSopenharmony_ci#include "base/thread/task_executor.h"
3223b3eb3cSopenharmony_ci#include "base/utils/noncopyable.h"
3323b3eb3cSopenharmony_ci#include "core/common/ace_view.h"
3423b3eb3cSopenharmony_ci#include "core/common/container.h"
3523b3eb3cSopenharmony_ci#include "core/common/js_message_dispatcher.h"
3623b3eb3cSopenharmony_ci#include "frameworks/core/common/backend.h"
3723b3eb3cSopenharmony_ci
3823b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform {
3923b3eb3cSopenharmony_ci
4023b3eb3cSopenharmony_cistruct WorkerPath {
4123b3eb3cSopenharmony_ci    std::string packagePathStr;
4223b3eb3cSopenharmony_ci    std::vector<std::string> assetBasePathStr;
4323b3eb3cSopenharmony_ci};
4423b3eb3cSopenharmony_ci
4523b3eb3cSopenharmony_cistruct PaContainerOptions {
4623b3eb3cSopenharmony_ci    BackendType type;
4723b3eb3cSopenharmony_ci    SrcLanguage language = SrcLanguage::ETS;
4823b3eb3cSopenharmony_ci    std::string hapPath = "";
4923b3eb3cSopenharmony_ci    std::shared_ptr<WorkerPath> workerPath = nullptr;
5023b3eb3cSopenharmony_ci};
5123b3eb3cSopenharmony_ci
5223b3eb3cSopenharmony_ciclass PaContainer : public Container {
5323b3eb3cSopenharmony_ci    DECLARE_ACE_TYPE(PaContainer, Container);
5423b3eb3cSopenharmony_ci
5523b3eb3cSopenharmony_cipublic:
5623b3eb3cSopenharmony_ci    PaContainer(int32_t instanceId, void* paAbility, const PaContainerOptions& options,
5723b3eb3cSopenharmony_ci        std::unique_ptr<PlatformEventCallback> callback);
5823b3eb3cSopenharmony_ci    ~PaContainer() override = default;
5923b3eb3cSopenharmony_ci
6023b3eb3cSopenharmony_ci    void Initialize() override {}
6123b3eb3cSopenharmony_ci
6223b3eb3cSopenharmony_ci    void Destroy() override;
6323b3eb3cSopenharmony_ci
6423b3eb3cSopenharmony_ci    int32_t GetInstanceId() const override
6523b3eb3cSopenharmony_ci    {
6623b3eb3cSopenharmony_ci        return instanceId_;
6723b3eb3cSopenharmony_ci    }
6823b3eb3cSopenharmony_ci
6923b3eb3cSopenharmony_ci    RefPtr<AssetManager> GetAssetManager() const override
7023b3eb3cSopenharmony_ci    {
7123b3eb3cSopenharmony_ci        return assetManager_;
7223b3eb3cSopenharmony_ci    }
7323b3eb3cSopenharmony_ci
7423b3eb3cSopenharmony_ci    RefPtr<Frontend> GetFrontend() const override
7523b3eb3cSopenharmony_ci    {
7623b3eb3cSopenharmony_ci        return nullptr;
7723b3eb3cSopenharmony_ci    }
7823b3eb3cSopenharmony_ci
7923b3eb3cSopenharmony_ci    RefPtr<PlatformResRegister> GetPlatformResRegister() const override
8023b3eb3cSopenharmony_ci    {
8123b3eb3cSopenharmony_ci        return nullptr;
8223b3eb3cSopenharmony_ci    }
8323b3eb3cSopenharmony_ci
8423b3eb3cSopenharmony_ci    RefPtr<PipelineBase> GetPipelineContext() const override
8523b3eb3cSopenharmony_ci    {
8623b3eb3cSopenharmony_ci        return nullptr;
8723b3eb3cSopenharmony_ci    }
8823b3eb3cSopenharmony_ci
8923b3eb3cSopenharmony_ci    int32_t GetViewWidth() const override
9023b3eb3cSopenharmony_ci    {
9123b3eb3cSopenharmony_ci        return 0;
9223b3eb3cSopenharmony_ci    }
9323b3eb3cSopenharmony_ci
9423b3eb3cSopenharmony_ci    int32_t GetViewHeight() const override
9523b3eb3cSopenharmony_ci    {
9623b3eb3cSopenharmony_ci        return 0;
9723b3eb3cSopenharmony_ci    }
9823b3eb3cSopenharmony_ci
9923b3eb3cSopenharmony_ci    int32_t GetViewPosX() const override
10023b3eb3cSopenharmony_ci    {
10123b3eb3cSopenharmony_ci        return 0;
10223b3eb3cSopenharmony_ci    }
10323b3eb3cSopenharmony_ci
10423b3eb3cSopenharmony_ci    int32_t GetViewPosY() const override
10523b3eb3cSopenharmony_ci    {
10623b3eb3cSopenharmony_ci        return 0;
10723b3eb3cSopenharmony_ci    }
10823b3eb3cSopenharmony_ci
10923b3eb3cSopenharmony_ci    uint32_t GetWindowId() const override
11023b3eb3cSopenharmony_ci    {
11123b3eb3cSopenharmony_ci        return 0;
11223b3eb3cSopenharmony_ci    }
11323b3eb3cSopenharmony_ci
11423b3eb3cSopenharmony_ci    void SetWindowId(uint32_t windowId) override {}
11523b3eb3cSopenharmony_ci
11623b3eb3cSopenharmony_ci    RefPtr<AceView> GetAceView() const override
11723b3eb3cSopenharmony_ci    {
11823b3eb3cSopenharmony_ci        return nullptr;
11923b3eb3cSopenharmony_ci    }
12023b3eb3cSopenharmony_ci
12123b3eb3cSopenharmony_ci    void* GetView() const override
12223b3eb3cSopenharmony_ci    {
12323b3eb3cSopenharmony_ci        return nullptr;
12423b3eb3cSopenharmony_ci    }
12523b3eb3cSopenharmony_ci
12623b3eb3cSopenharmony_ci    RefPtr<Backend> GetBackend() const
12723b3eb3cSopenharmony_ci    {
12823b3eb3cSopenharmony_ci        return backend_;
12923b3eb3cSopenharmony_ci    }
13023b3eb3cSopenharmony_ci
13123b3eb3cSopenharmony_ci    RefPtr<TaskExecutor> GetTaskExecutor() const override
13223b3eb3cSopenharmony_ci    {
13323b3eb3cSopenharmony_ci        return nullptr;
13423b3eb3cSopenharmony_ci    }
13523b3eb3cSopenharmony_ci
13623b3eb3cSopenharmony_ci    void OnFinish()
13723b3eb3cSopenharmony_ci    {
13823b3eb3cSopenharmony_ci        if (platformEventCallback_) {
13923b3eb3cSopenharmony_ci            platformEventCallback_->OnFinish();
14023b3eb3cSopenharmony_ci        }
14123b3eb3cSopenharmony_ci    }
14223b3eb3cSopenharmony_ci
14323b3eb3cSopenharmony_ci    std::string GetHostClassName() const override
14423b3eb3cSopenharmony_ci    {
14523b3eb3cSopenharmony_ci        return "";
14623b3eb3cSopenharmony_ci    }
14723b3eb3cSopenharmony_ci
14823b3eb3cSopenharmony_ci    static bool Register();
14923b3eb3cSopenharmony_ci    static void CreateContainer(int32_t instanceId, void* paAbility, const PaContainerOptions& options,
15023b3eb3cSopenharmony_ci        std::unique_ptr<PlatformEventCallback> callback);
15123b3eb3cSopenharmony_ci    static void DestroyContainer(int32_t instanceId);
15223b3eb3cSopenharmony_ci    static RefPtr<PaContainer> GetContainer(int32_t instanceId);
15323b3eb3cSopenharmony_ci    static bool RunPa(int32_t instanceId, const std::string& content, const OHOS::AAFwk::Want& want);
15423b3eb3cSopenharmony_ci    static void AddAssetPath(int32_t instanceId, const std::string& packagePath, const std::string& hapPath,
15523b3eb3cSopenharmony_ci        const std::vector<std::string>& paths);
15623b3eb3cSopenharmony_ci    static void AddLibPath(int32_t instanceId, const std::vector<std::string>& libPath);
15723b3eb3cSopenharmony_ci    static bool OnCreate(int32_t instanceId, const OHOS::AAFwk::Want& want);
15823b3eb3cSopenharmony_ci    static bool OnDelete(int32_t instanceId, int64_t formId);
15923b3eb3cSopenharmony_ci    static bool OnTriggerEvent(int32_t instanceId, int64_t formId, const std::string& message);
16023b3eb3cSopenharmony_ci    static int32_t OnAcquireFormState(int32_t instanceId, const OHOS::AAFwk::Want& want);
16123b3eb3cSopenharmony_ci    static bool OnUpdate(int32_t instanceId, int64_t formId);
16223b3eb3cSopenharmony_ci    static bool OnCastTemptoNormal(int32_t instanceId, int64_t formId);
16323b3eb3cSopenharmony_ci    static bool OnVisibilityChanged(int32_t instanceId, const std::map<int64_t, int32_t>& formEventsMap);
16423b3eb3cSopenharmony_ci    static AppExecFwk::FormProviderData GetFormData(int32_t instanceId);
16523b3eb3cSopenharmony_ci    static int32_t Insert(int32_t instanceId, const Uri& uri, const OHOS::NativeRdb::ValuesBucket& value);
16623b3eb3cSopenharmony_ci    static std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(int32_t instanceId, const Uri& uri,
16723b3eb3cSopenharmony_ci        const std::vector<std::string>& columns, const OHOS::NativeRdb::DataAbilityPredicates& predicates);
16823b3eb3cSopenharmony_ci    static int32_t Update(int32_t instanceId, const Uri& uri, const OHOS::NativeRdb::ValuesBucket& value,
16923b3eb3cSopenharmony_ci        const OHOS::NativeRdb::DataAbilityPredicates& predicates);
17023b3eb3cSopenharmony_ci    static int32_t Delete(int32_t instanceId, const Uri& uri, const OHOS::NativeRdb::DataAbilityPredicates& predicates);
17123b3eb3cSopenharmony_ci
17223b3eb3cSopenharmony_ci    static int32_t BatchInsert(
17323b3eb3cSopenharmony_ci        int32_t instanceId, const Uri& uri, const std::vector<OHOS::NativeRdb::ValuesBucket>& values);
17423b3eb3cSopenharmony_ci    static std::string GetType(int32_t instanceId, const Uri& uri);
17523b3eb3cSopenharmony_ci    static std::vector<std::string> GetFileTypes(int32_t instanceId, const Uri& uri, const std::string& mimeTypeFilter);
17623b3eb3cSopenharmony_ci    static int32_t OpenFile(int32_t instanceId, const Uri& uri, const std::string& mode);
17723b3eb3cSopenharmony_ci    static int32_t OpenRawFile(int32_t instanceId, const Uri& uri, const std::string& mode);
17823b3eb3cSopenharmony_ci    static Uri NormalizeUri(int32_t instanceId, const Uri& uri);
17923b3eb3cSopenharmony_ci    static Uri DenormalizeUri(int32_t instanceId, const Uri& uri);
18023b3eb3cSopenharmony_ci    static sptr<IRemoteObject> OnConnect(int32_t instanceId, const OHOS::AAFwk::Want& want);
18123b3eb3cSopenharmony_ci    static void OnDisConnect(int32_t instanceId, const OHOS::AAFwk::Want& want);
18223b3eb3cSopenharmony_ci    static void OnCommand(const OHOS::AAFwk::Want &want, int startId, int32_t instanceId);
18323b3eb3cSopenharmony_ci    static bool OnShare(int32_t instanceId, int64_t formId, OHOS::AAFwk::WantParams &wantParams);
18423b3eb3cSopenharmony_ci    static std::shared_ptr<AppExecFwk::PacMap> Call(int32_t instanceId, const Uri& uri,
18523b3eb3cSopenharmony_ci        const std::string& method, const std::string& arg, const AppExecFwk::PacMap& pacMap);
18623b3eb3cSopenharmony_ci
18723b3eb3cSopenharmony_ciprivate:
18823b3eb3cSopenharmony_ci    void InitializeBackend(SrcLanguage language);
18923b3eb3cSopenharmony_ci    void InitializeCallback();
19023b3eb3cSopenharmony_ci
19123b3eb3cSopenharmony_ci    RefPtr<AssetManager> assetManager_;
19223b3eb3cSopenharmony_ci    RefPtr<Backend> backend_;
19323b3eb3cSopenharmony_ci
19423b3eb3cSopenharmony_ci    int32_t instanceId_ = 0;
19523b3eb3cSopenharmony_ci    BackendType type_ = BackendType::SERVICE;
19623b3eb3cSopenharmony_ci    std::unique_ptr<PlatformEventCallback> platformEventCallback_;
19723b3eb3cSopenharmony_ci    void* paAbility_ = nullptr;
19823b3eb3cSopenharmony_ci    std::string hapPath_;
19923b3eb3cSopenharmony_ci    std::shared_ptr<WorkerPath> workerPath_;
20023b3eb3cSopenharmony_ci    ACE_DISALLOW_COPY_AND_MOVE(PaContainer);
20123b3eb3cSopenharmony_ci};
20223b3eb3cSopenharmony_ci
20323b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform
20423b3eb3cSopenharmony_ci
20523b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_PA_CONTAINER_H
206