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 EXTENSION_C_API_H 17 #define EXTENSION_C_API_H 18 19 #include <cstdint> 20 #include <cstdio> 21 22 #ifdef __cplusplus 23 namespace OHOS::uitest { 24 extern "C" { 25 #endif 26 27 typedef int32_t RetCode; 28 #define RETCODE_SUCCESS 0 29 #define RETCODE_FAIL (-1) 30 31 struct Text { 32 const char *data; 33 size_t size; 34 }; 35 36 struct ReceiveBuffer { 37 uint8_t *data; 38 size_t capacity; 39 size_t *size; 40 }; 41 42 // enum LogLevel : int32_t { DEBUG = 3, INFO = 4, WARN = 5, ERROR = 6 }; 43 44 typedef void (*DataCallback)(Text bytes); 45 46 struct LowLevelFunctions { 47 RetCode (*callThroughMessage)(Text in, ReceiveBuffer out, bool *fatalError); 48 RetCode (*setCallbackMessageHandler)(DataCallback handler); 49 RetCode (*atomicTouch)(int32_t stage, int32_t px, int32_t py); 50 RetCode (*startCapture)(Text name, DataCallback callback, Text optJson); 51 RetCode (*stopCapture)(Text name); 52 }; 53 54 struct UiTestPort { 55 RetCode (*getUiTestVersion)(ReceiveBuffer out); 56 RetCode (*printLog)(int32_t level, Text tag, Text format, va_list ap); 57 RetCode (*getAndClearLastError)(int32_t *codeOut, ReceiveBuffer msgOut); 58 RetCode (*initLowLevelFunctions)(LowLevelFunctions *out); 59 }; 60 61 // hook function names of UiTestExtension library 62 #define UITEST_EXTENSION_CALLBACK_ONINIT "UiTestExtension_OnInit" 63 #define UITEST_EXTENSION_CALLBACK_ONRUN "UiTestExtension_OnRun" 64 // proto of UiTestExtensionOnInitCallback: void (UiTestPort port, size_t argc, char **argv) 65 typedef RetCode (*UiTestExtensionOnInitCallback)(UiTestPort port, size_t argc, char **argv); 66 // proto of UiTestExtensionOnRun 67 typedef RetCode (*UiTestExtensionOnRunCallback)(void); 68 69 #ifdef __cplusplus 70 } 71 } 72 #endif 73 74 #endif