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 "i18n_struct.h"
17 #include "ffi_remote_data.h"
18 #include "i18n_entity_ffi.h"
19 #include "i18n_entity_impl.h"
20 #include "i18n_hilog.h"
21
22 namespace OHOS {
23 namespace Global {
24 namespace I18n {
25 using namespace OHOS::FFI;
26 extern "C" {
FfiOHOSEntityImplConstructor(char * locale,int32_t * errcode)27 int64_t FfiOHOSEntityImplConstructor(char* locale, int32_t* errcode)
28 {
29 std::string localeStr(locale);
30 auto instance = FFIData::Create<CEntity>(localeStr);
31 if (!instance->InitSuccess()) {
32 *errcode = I18N_NOT_VALID;
33 HILOG_ERROR_I18N("Create CEntity fail");
34 return -1;
35 }
36 return instance->GetID();
37 }
38
FfiOHOSEntityFindEntityInfo(int64_t id,char * text)39 CEntityInfoItemArr FfiOHOSEntityFindEntityInfo(int64_t id, char* text)
40 {
41 auto instance = FFIData::GetData<CEntity>(id);
42 if (!instance) {
43 HILOG_ERROR_I18N("The CEntity instance is nullptr");
44 return { 0, nullptr };
45 }
46 return instance->FindEntityInfo(std::string(text));
47 }
48 }
49 } // namespace I18n
50 } // namespace Global
51 } // namespace OHOS
52