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
7
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
#include "arkoala_api_generated.h"
17
#include "load-library.h"
18
#include "arkoala-logging.h"
21
static %CPP_PREFIX%ArkUIAnyAPI* impls[%CPP_PREFIX%Ark_APIVariantKind::%CPP_PREFIX%COUNT] = { 0 };
22
const char* getArkAnyAPIFuncName = "%CPP_PREFIX%GetArkAnyAPI";
24
const ArkUIAnyAPI* GetAnyImpl(ArkUIAPIVariantKind kind, int version, std::string* result) {
26
%CPP_PREFIX%ArkUIAnyAPI* impl = nullptr;
27
typedef %CPP_PREFIX%ArkUIAnyAPI* (*GetAPI_t)(int, int);
28
GetAPI_t getAPI = nullptr;
30
void* module = FindModule();
33
*result = "Cannot find dynamic module";
35
LOGE("Cannot find dynamic module");
39
if (getAPI == nullptr) {
40
getAPI = reinterpret_cast<GetAPI_t>(FindFunction(module, getArkAnyAPIFuncName));
43
*result = std::string("Cannot find ") + getArkAnyAPIFuncName;
45
LOGE("Cannot find %s", getArkAnyAPIFuncName);
50
impl = (*getAPI)(kind, version);
53
*result = "getAPI() returned null";
55
LOGE("getAPI() returned null")
59
if (impl->version != version) {
62
snprintf(buffer, sizeof(buffer), "FATAL: API version mismatch, expected %d got %d",
63
version, impl->version);
66
LOGE("API version mismatch for API %d: expected %d got %d", kind, version, impl->version);
72
return reinterpret_cast<ArkUIAnyAPI*>(impls[kind]);