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 #ifndef OHOS_FFI_CJ_COMMON_FFI_H 17 #define OHOS_FFI_CJ_COMMON_FFI_H 18 19 #include <cstdint> 20 #include <string> 21 22 #define FFI_EXPORT __attribute__((visibility("default"))) 23 24 extern "C" { 25 const int32_t SUCCESS_CODE = 0; 26 const int32_t ERR_INVALID_INSTANCE_CODE = -1; 27 const int32_t ERR_CODE_PARAM_INVALID = -2; 28 const int64_t INVALID_DATA_ID = -100; 29 30 int64_t FFI_EXPORT FfiGeneralSizeOfPointer(); 31 32 typedef int RetCode; 33 34 struct RetDataCString { 35 int32_t code; 36 char* data; 37 }; 38 39 struct RetDataUI { 40 int32_t code; 41 size_t data; 42 }; 43 44 struct RetDataI64 { 45 int32_t code; 46 int64_t data; 47 }; 48 49 struct RetDataI32 { 50 int32_t code; 51 int32_t data; 52 }; 53 54 struct RetDataI64U32 { 55 uint32_t code; 56 int64_t data; 57 }; 58 59 struct RetDataUI32 { 60 uint32_t code; 61 uint32_t data; 62 }; 63 64 struct RetDataBool { 65 int32_t code; 66 bool data; 67 }; 68 69 struct CArrI64 { 70 int64_t* head; 71 int64_t size; 72 }; 73 74 struct CArrI32 { 75 int32_t* head; 76 int64_t size; 77 }; 78 79 struct RetDataCArrI32 { 80 int32_t code; 81 CArrI32 data; 82 }; 83 84 struct CArrUI32 { 85 unsigned int* head; 86 int64_t size; 87 }; 88 89 struct RetDataCArrI64 { 90 int32_t code; 91 CArrI64 data; 92 }; 93 94 struct CArrUI8 { 95 uint8_t* head; 96 int64_t size; 97 }; 98 99 struct RetDataCArrUI8 { 100 int32_t code; 101 CArrUI8 data; 102 }; 103 104 struct CArrString { 105 char** head; 106 int64_t size; 107 }; 108 109 struct RetDataCArrString { 110 int32_t code; 111 CArrString data; 112 }; 113 114 struct CArrUnit { 115 void* head; 116 int64_t size; 117 }; 118 119 struct RetDataCArrUnit { 120 int32_t code; 121 CArrUnit data; 122 }; 123 } 124 #endif