• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_ACE_FRAMEWORKS_CORE_COMMON_BACKEND_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_BACKEND_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/resource/asset_manager.h"
21 #include "base/thread/task_executor.h"
22 #include "core/common/js_message_dispatcher.h"
23 
24 namespace OHOS::Ace {
25 
26 enum class BackendType { SERVICE, DATA, FORM };
27 
28 class ACE_EXPORT Backend : public AceType {
29     DECLARE_ACE_TYPE(Backend, AceType);
30 
31 public:
32     Backend() = default;
33     ~Backend() override = default;
34 
35     enum class State { ON_CREATE, ON_DESTROY };
36 
37     static RefPtr<Backend> Create();
38 
39     virtual bool Initialize(BackendType type, const RefPtr<TaskExecutor>& taskExecutor) = 0;
40 
41     virtual void LoadEngine(const char* libName, int32_t instanceId) = 0;
42 
43     virtual void MethodChannel(const std::string& methodName, std::string& jsonStr) = 0;
44 
45     virtual void RunPa(const std::string &url) = 0;
46 
47     virtual void OnCommand(const std::string& intent, int startId) = 0;
48 
49     virtual void SetAssetManager(const RefPtr<AssetManager> &assetManager) = 0;
50 
51     virtual void SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher> &transfer) const = 0;
52 
53     virtual void TransferJsResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const = 0;
54 
55     virtual void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const = 0;
56 
57     virtual void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const = 0;
58 
59     virtual void LoadPluginJsCode(std::string&& jsCode) const = 0;
60 
61     virtual void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const = 0;
62 
63     virtual BackendType GetType() = 0;
64 
65     // inform the frontend that onCreate or onDestroy
66     virtual void UpdateState(State) = 0;
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_BACKEND_H