idlize

Форк
0
/
library_template.cc 
73 строки · 2.5 Кб
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
#include "arkoala_api_generated.h"
17
#include "load-library.h"
18
#include "arkoala-logging.h"
19
#include "library.h"
20

21
static %CPP_PREFIX%ArkUIAnyAPI* impls[%CPP_PREFIX%Ark_APIVariantKind::%CPP_PREFIX%COUNT] = { 0 };
22
const char* getArkAnyAPIFuncName = "%CPP_PREFIX%GetArkAnyAPI";
23

24
const ArkUIAnyAPI* GetAnyImpl(ArkUIAPIVariantKind kind, int version, std::string* result) {
25
    if (!impls[kind]) {
26
        %CPP_PREFIX%ArkUIAnyAPI* impl = nullptr;
27
        typedef %CPP_PREFIX%ArkUIAnyAPI* (*GetAPI_t)(int, int);
28
        GetAPI_t getAPI = nullptr;
29

30
        void* module = FindModule();
31
        if (!module) {
32
            if (result)
33
                *result = "Cannot find dynamic module";
34
            else
35
                LOGE("Cannot find dynamic module");
36
            return nullptr;
37
        }
38

39
        if (getAPI == nullptr) {
40
            getAPI = reinterpret_cast<GetAPI_t>(FindFunction(module, getArkAnyAPIFuncName));
41
            if (!getAPI) {
42
                if (result)
43
                    *result = std::string("Cannot find ") + getArkAnyAPIFuncName;
44
                else
45
                    LOGE("Cannot find %s", getArkAnyAPIFuncName);
46
                return nullptr;
47
            }
48
        }
49

50
        impl = (*getAPI)(kind, version);
51
        if (!impl) {
52
            if (result)
53
                *result = "getAPI() returned null";
54
            else
55
                LOGE("getAPI() returned null")
56
            return nullptr;
57
        }
58

59
        if (impl->version != version) {
60
            if (result) {
61
                char buffer[256];
62
                snprintf(buffer, sizeof(buffer), "FATAL: API version mismatch, expected %d got %d",
63
                    version, impl->version);
64
                *result = buffer;
65
            } else {
66
                LOGE("API version mismatch for API %d: expected %d got %d", kind, version, impl->version);
67
            }
68
            return nullptr;
69
        }
70
        impls[kind] = impl;
71
    }
72
    return reinterpret_cast<ArkUIAnyAPI*>(impls[kind]);
73
}
74

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.