• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 IMAGE_EMBEDDING_NAPI_H
17 #define IMAGE_EMBEDDING_NAPI_H
18 
19 #include <uv.h>
20 #include <refbase.h>
21 
22 #include "i_aip_core_manager.h"
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 
26 namespace OHOS {
27 namespace DataIntelligence {
28 class ImageEmbeddingNapi {
29 public:
30     ImageEmbeddingNapi();
31     ~ImageEmbeddingNapi();
32 
33     static napi_value Init(napi_env env, napi_value exports);
34     static napi_value LoadModel(napi_env env, napi_callback_info info);
35     static napi_value ReleaseModel(napi_env env, napi_callback_info info);
36     static napi_value GetEmbedding(napi_env env, napi_callback_info info);
37     static napi_value GetImageEmbeddingModel(napi_env env, napi_callback_info info);
38     static napi_value Constructor(napi_env env, napi_callback_info info);
39     static void Destructor(napi_env env, void *nativeObject, void *finalize);
40 
41     struct AsyncGetImageEmbeddingModelData {
42         napi_async_work asyncWork;
43         napi_deferred deferred;
44         ModelConfigData config;
45         napi_value res;
46         int32_t ret;
47     };
48 
49 private:
50     static bool LoadAsyncExecution(napi_env env, napi_deferred deferred);
51     static bool ReleaseAsyncExecution(napi_env env, napi_deferred deferred);
52     static bool GetEmbeddingAsyncExecution(napi_env env, napi_deferred deferred, std::string str);
53     static bool CreateAsyncImgModelExecution(napi_env env, AsyncGetImageEmbeddingModelData *asyncModelData);
54     static void GetImgEmbeddingModelExecutionCB(napi_env env, void *data);
55     static void GetImgEmbeddingModelCompleteCB(napi_env env, napi_status status, void *data);
56     static bool ParseModelConfig(napi_env env, napi_value *args, size_t argc, ModelConfigData *textModelConfig);
57     static void LoadExecuteCB(napi_env env, void *data);
58     static void LoadCompleteCB(napi_env env, napi_status status, void *data);
59     static void ReleaseExecuteCB(napi_env env, void *data);
60     static void ReleaseCompleteCB(napi_env env, napi_status status, void *data);
61     static void GetEmbeddingExecuteCB(napi_env env, void *data);
62     static void GetEmbeddingCompleteCB(napi_env env, napi_status status, void *data);
63     napi_env env_;
64     static thread_local napi_ref sConstructor_;
65     static AipCoreManagerHandle imgAipCoreMgrHandle_;
66     static IAipCoreManager *imageAipCoreManager_;
67 };
68 } // namespace DataIntelligence
69 } // namespace OHOS
70 #endif // IMAGE_EMBEDDING_NAPI_H
71