1 2 /* 3 * Copyright (c) 2024 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "unified_record_ffi.h" 18 #include "unified_record_impl.h" 19 20 using namespace OHOS::FFI; 21 using namespace OHOS::UDMF; 22 23 namespace OHOS { 24 namespace UDMF { 25 extern "C" { 26 FfiUDMFUnifiedRecordConstructor()27 int64_t FfiUDMFUnifiedRecordConstructor() 28 { 29 auto nativeCJUnifiedRecord = FFIData::Create<CUnifiedRecord>(); 30 if (nativeCJUnifiedRecord == nullptr) { 31 return -1; 32 } 33 return nativeCJUnifiedRecord->GetID(); 34 } 35 FfiUDMFUnifiedRecordConstructorwithType(const char * type,CJValueType value)36 int64_t FfiUDMFUnifiedRecordConstructorwithType(const char *type, CJValueType value) 37 { 38 auto nativeCJUnifiedRecord = FFIData::Create<CUnifiedRecord>(type, value); 39 if (nativeCJUnifiedRecord == nullptr) { 40 return -1; 41 } 42 return nativeCJUnifiedRecord->GetID(); 43 } 44 FfiUDMFUnifiedRecordGetType(int64_t unifiedId)45 char *FfiUDMFUnifiedRecordGetType(int64_t unifiedId) 46 { 47 auto instance = FFIData::GetData<CUnifiedRecord>(unifiedId); 48 if (instance == nullptr) { 49 return nullptr; 50 } 51 return instance->GetType(); 52 } 53 FfiUDMFUnifiedRecordGetValue(int64_t unifiedId)54 CJValueType FfiUDMFUnifiedRecordGetValue(int64_t unifiedId) 55 { 56 auto instance = FFIData::GetData<CUnifiedRecord>(unifiedId); 57 if (instance == nullptr) { 58 return CJValueType{}; 59 } 60 return instance->GetValue(); 61 } 62 } 63 } 64 } 65