/usr/include/x86_64-linux-gnu/aj_bufio.h is in liballjoyntcl-dev-1504 15.04b-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #ifndef _AJ_BUFIO_H
#define _AJ_BUFIO_H
/**
* @file aj_bufio.h
* @defgroup aj_bufio Buffer Input/Output
* @{
*/
/******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************************/
#include "aj_target.h"
#include "aj_status.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Forward declaration
*/
struct _AJ_IOBuffer;
/**
* Function pointer type for an abstracted transmit function
*/
typedef AJ_Status (*AJ_TxFunc)(struct _AJ_IOBuffer* buf);
/**
* Function pointer type for an abstracted receive function
*
* @param buf The buffer to read into
* @param len The requested number of bytes to read. More or fewer bytes may actually be read into
* the buffer.
* @param timeout A timeout in milliseconds after which the read will return with an error status if
* there is not data to read.
*
* @return
* - AJ_OK if some data was read
* - AJ_ERR_TIMEOUT if the read timedout
* - AJ_ERR_RESOURCES if there isn't enough room in the buffer to read len bytes. The buffer
* will contain the bytes actually read so this is not a fatal error.
* - AJ_ERR_READ the read failed irrecoverably
* - AJ_ERR_LINK_DEAD the network link is dead
*/
typedef AJ_Status (*AJ_RxFunc)(struct _AJ_IOBuffer* buf, uint32_t len, uint32_t timeout);
#define AJ_IO_BUF_RX 1 /**< I/O direction is receive */
#define AJ_IO_BUF_TX 2 /**< I/O direction is send */
#define AJ_IO_BUF_AJ 1 /**< send/receive data to/from AJ */
#define AJ_IO_BUF_MDNS 2 /**< send/receive data to/from mDNS */
/**
* A type for managing a receive or transmit buffer
*/
typedef struct _AJ_IOBuffer {
uint8_t direction; /**< I/O buffer is either a Tx buffer or an Rx buffer */
uint8_t flags; /**< ports to send to or receive on */
uint16_t bufSize; /**< Size of the data buffer */
uint8_t* bufStart; /**< Start for the data buffer */
uint8_t* readPtr; /**< Current position in buf for reading data */
uint8_t* writePtr; /**< Current position in buf for writing data */
/*
* Function pointer to send or recv function
*/
union {
AJ_TxFunc send;
AJ_RxFunc recv;
};
void* context; /**< Abstracted context for managing I/O */
} AJ_IOBuffer;
/**
* How much data is available to read from the buffer
*/
#define AJ_IO_BUF_AVAIL(iobuf) (uint32_t)(((iobuf)->writePtr - (iobuf)->readPtr))
/**
* How much space is available to write to the buffer
*/
#define AJ_IO_BUF_SPACE(iobuf) ((uint32_t)((iobuf)->bufSize - ((iobuf)->writePtr - (iobuf)->bufStart)))
/**
* How much data has been consumed from the buffer
*/
#define AJ_IO_BUF_CONSUMED(iobuf) (uint32_t)(((iobuf)->readPtr - (iobuf)->bufStart))
/**
* Reset and IO buffer
*/
#define AJ_IO_BUF_RESET(iobuf) \
do { \
(iobuf)->readPtr = (iobuf)->bufStart; \
(iobuf)->writePtr = (iobuf)->bufStart; \
(iobuf)->flags = 0; \
} while (0)
/**
* Initialize an I/O Buffer.
*
* @param ioBuf The I/O buffer to initialize
* @param buffer The data buffer to use
* @param bufLen The size of the data buffer
* @param direction Indicates if the buffer is being used for sending or receiving data
* @param context Abstracted context for managing I/O
*/
void AJ_IOBufInit(AJ_IOBuffer* ioBuf, uint8_t* buffer, uint32_t bufLen, uint8_t direction, void* context);
/**
* Move any unconsumed data to the start of the buffer.
*
* @param ioBuf An RX I/O buf that may contain unconsumed data
* @param preserve Data (if any) at front of buffer that must be preserved
*/
void AJ_IOBufRebase(AJ_IOBuffer* ioBuf, size_t preserve);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif
|