1 /* 2 * Copyright (c) 2022 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 AUTH_TCP_CONNECTION_H 17 #define AUTH_TCP_CONNECTION_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "auth_connection.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 #define AUTH_INVALID_FD (-1) 30 31 typedef struct { 32 void (*onConnected)(int32_t fd, bool isClient); 33 void (*onDisconnected)(int32_t fd); 34 void (*onDataReceived)(int32_t fd, const AuthDataHead *head, const uint8_t *data); 35 } SocketCallback; 36 int32_t SetSocketCallback(const SocketCallback *cb); 37 void UnsetSocketCallback(void); 38 39 // connect succ, return fd; otherwise, return -1. 40 int32_t SocketConnectDevice(const char *ip, int32_t port, bool isBlockMode); 41 void SocketDisconnectDevice(int32_t fd); 42 43 int32_t SocketPostBytes(int32_t fd, const AuthDataHead *head, const uint8_t *data); 44 int32_t SocketGetConnInfo(int32_t fd, AuthConnInfo *connInfo, bool *isServer); 45 46 int32_t StartSocketListening(const char *ip, int32_t port); 47 void StopSocketListening(void); 48 49 #ifdef __cplusplus 50 #if __cplusplus 51 } 52 #endif 53 #endif 54 #endif /* AUTH_TCP_CONNECTION_H */ 55