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 "type_descriptor_ffi.h" 18 #include "type_descriptor_impl.h" 19 #include "cj_common_ffi.h" 20 #include "type_descriptor.h" 21 22 #include <string> 23 #include <vector> 24 25 #include "ffi_remote_data.h" 26 27 #include "utils.h" 28 29 using namespace OHOS::FFI; 30 using namespace OHOS::UDMF; 31 32 namespace OHOS { 33 namespace UDMF { CTypeDescriptor(std::shared_ptr<UDMF::TypeDescriptor> typeDescriptor)34 CTypeDescriptor::CTypeDescriptor(std::shared_ptr<UDMF::TypeDescriptor> typeDescriptor) 35 { 36 typeDescriptor_ = typeDescriptor; 37 } 38 GetTypeId()39 char *CTypeDescriptor::GetTypeId() 40 { 41 std::string ret = typeDescriptor_->GetTypeId(); 42 return Utils::MallocCString(ret); 43 } 44 GetBelongingToTypes()45 CArrString CTypeDescriptor::GetBelongingToTypes() 46 { 47 std::vector<std::string> types = typeDescriptor_->GetBelongingToTypes(); 48 return Utils::StringVectorToArray(types); 49 } 50 GetDescription()51 char *CTypeDescriptor::GetDescription() 52 { 53 std::string ret = typeDescriptor_->GetDescription(); 54 return Utils::MallocCString(ret); 55 } 56 GetIconFile()57 char *CTypeDescriptor::GetIconFile() 58 { 59 std::string ret = typeDescriptor_->GetIconFile(); 60 return Utils::MallocCString(ret); 61 } 62 GetReferenceURL()63 char *CTypeDescriptor::GetReferenceURL() 64 { 65 std::string ret = typeDescriptor_->GetReferenceURL(); 66 return Utils::MallocCString(ret); 67 } 68 GetFilenameExtensions()69 CArrString CTypeDescriptor::GetFilenameExtensions() 70 { 71 std::vector<std::string> types = typeDescriptor_->GetFilenameExtensions(); 72 return Utils::StringVectorToArray(types); 73 } 74 GetMimeTypes()75 CArrString CTypeDescriptor::GetMimeTypes() 76 { 77 std::vector<std::string> types = typeDescriptor_->GetMimeTypes(); 78 return Utils::StringVectorToArray(types); 79 } 80 81 BelongsTo(const char * type)82 bool CTypeDescriptor::BelongsTo(const char *type) 83 { 84 bool result = false; 85 typeDescriptor_->BelongsTo(type, result); 86 return result; 87 } 88 IsLowerLevelType(const char * type)89 bool CTypeDescriptor::IsLowerLevelType(const char *type) 90 { 91 bool result = false; 92 typeDescriptor_->IsLowerLevelType(type, result); 93 return result; 94 } 95 IsHigherLevelType(const char * type)96 bool CTypeDescriptor::IsHigherLevelType(const char *type) 97 { 98 bool result = false; 99 typeDescriptor_->IsHigherLevelType(type, result); 100 return result; 101 } 102 GetTypeDescriptor() const103 const std::shared_ptr<UDMF::TypeDescriptor> &CTypeDescriptor::GetTypeDescriptor() const 104 { 105 return typeDescriptor_; 106 } 107 Equals(CTypeDescriptor * thatCTypeDescriptor)108 bool CTypeDescriptor::Equals(CTypeDescriptor* thatCTypeDescriptor) 109 { 110 return typeDescriptor_->Equals(thatCTypeDescriptor->GetTypeDescriptor()); 111 } 112 113 } 114 } 115