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_data_ffi.h" 18 #include "unified_data_impl.h" 19 #include "unified_record_impl.h" 20 #include "cj_common_ffi.h" 21 22 using namespace OHOS::FFI; 23 using namespace OHOS::UDMF; 24 25 namespace OHOS { 26 namespace UDMF { 27 extern "C" { 28 FfiUDMFUnifiedDataConstructor()29 int64_t FfiUDMFUnifiedDataConstructor() 30 { 31 auto nativeCJUnifiedData = FFIData::Create<CUnifiedData>(); 32 if (nativeCJUnifiedData == nullptr) { 33 return -1; 34 } 35 return nativeCJUnifiedData->GetID(); 36 } 37 FfiUDMFUnifiedDataConstructorWithRecord(int64_t unifiedRecordId)38 int64_t FfiUDMFUnifiedDataConstructorWithRecord(int64_t unifiedRecordId) 39 { 40 auto record = FFIData::GetData<CUnifiedRecord>(unifiedRecordId); 41 if (record == nullptr) { 42 return -1; 43 } 44 45 auto nativeCJUnifiedData = FFIData::Create<CUnifiedData>(record); 46 if (nativeCJUnifiedData == nullptr) { 47 return -1; 48 } 49 return nativeCJUnifiedData->GetID(); 50 } 51 FfiUDMFUnifiedDataAddRecord(int64_t unifiedDataId, int64_t unifiedRecordId)52 void FfiUDMFUnifiedDataAddRecord(int64_t unifiedDataId, int64_t unifiedRecordId) 53 { 54 auto record = FFIData::GetData<CUnifiedRecord>(unifiedRecordId); 55 if (record == nullptr) { 56 return; 57 } 58 59 auto data = FFIData::GetData<CUnifiedData>(unifiedDataId); 60 if (data == nullptr) { 61 return; 62 } 63 64 data->AddRecord(record); 65 } 66 FfiUDMFUnifiedDataGetRecords(int64_t unifiedDataId)67 CArrUnifiedRecord FfiUDMFUnifiedDataGetRecords(int64_t unifiedDataId) 68 { 69 auto data = FFIData::GetData<CUnifiedData>(unifiedDataId); 70 if (data == nullptr) { 71 return CArrUnifiedRecord{}; 72 } 73 74 return data->GetRecords(); 75 } 76 FfiUDMFUnifiedDataHasType(int64_t unifiedDataId, const char *type)77 bool FfiUDMFUnifiedDataHasType(int64_t unifiedDataId, const char *type) 78 { 79 auto data = FFIData::GetData<CUnifiedData>(unifiedDataId); 80 if (data == nullptr) { 81 return false; 82 } 83 84 return data->HasType(type); 85 } 86 FfiUDMFUnifiedDataGetTypes(int64_t unifiedDataId)87 CArrString FfiUDMFUnifiedDataGetTypes(int64_t unifiedDataId) 88 { 89 auto data = FFIData::GetData<CUnifiedData>(unifiedDataId); 90 if (data == nullptr) { 91 return CArrString{}; 92 } 93 94 return data->GetTypes(); 95 } 96 } 97 } 98 } 99