| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2007-2010, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bioatom.h $ |
|---|
| 11 | * $brcm_Revision: 33 $ |
|---|
| 12 | * $brcm_Date: 12/6/10 6:23p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Scatter gatther unit |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /BSEAV/lib/utils/bioatom.h $ |
|---|
| 21 | * |
|---|
| 22 | * 33 12/6/10 6:23p vsilyaev |
|---|
| 23 | * SW35230-1953: Added function to return vector array and size |
|---|
| 24 | * |
|---|
| 25 | * 32 8/5/10 1:15p vsilyaev |
|---|
| 26 | * SW7405-4681: Added function to return position in the bitstream |
|---|
| 27 | * |
|---|
| 28 | * 31 2/2/10 3:52p vsilyaev |
|---|
| 29 | * SW7468-69: Added function to help switch between bitstream and |
|---|
| 30 | * bytestream |
|---|
| 31 | * |
|---|
| 32 | * 30 12/2/09 12:04p vsilyaev |
|---|
| 33 | * SW7405-3368: Removed unnecessary const |
|---|
| 34 | * |
|---|
| 35 | * 29 12/2/09 11:53a vsilyaev |
|---|
| 36 | * SW7405-3368: Fixed implementation of batom_cursor_compare |
|---|
| 37 | * |
|---|
| 38 | * 28 12/2/09 11:28a vsilyaev |
|---|
| 39 | * SW7405-3368: Added batom_cursor_compare function |
|---|
| 40 | * |
|---|
| 41 | * dev_bdvd_v3.0_issue15380/1 12/2/09 11:22a gooslin |
|---|
| 42 | * Add cursor compare function |
|---|
| 43 | * |
|---|
| 44 | * 27 11/4/08 9:57a vsilyaev |
|---|
| 45 | * PR 48608: Merged code that alligns audio/video streams after seek. |
|---|
| 46 | * |
|---|
| 47 | * bdvd_v1.4/bdvd_v1.42/fix_bdvd_v1.42_pr11402/1 11/1/08 7:43p gooslin |
|---|
| 48 | * Cleanup A/V sync modifications |
|---|
| 49 | * |
|---|
| 50 | * 26 8/6/08 2:01p vsilyaev |
|---|
| 51 | * PR 45133: Annotate that flag member is unused |
|---|
| 52 | * |
|---|
| 53 | * 25 7/22/08 10:03a jtna |
|---|
| 54 | * PR44493: Compiler warning |
|---|
| 55 | * |
|---|
| 56 | * 24 3/3/08 12:28p vsilyaev |
|---|
| 57 | * PR 39818: Fixed cursor update after accum_trim, imporved diagnostic and |
|---|
| 58 | * comments |
|---|
| 59 | * |
|---|
| 60 | * 23 8/10/07 12:27p vsilyaev |
|---|
| 61 | * PR 32813: Added functions to return pointer to the cursor's continuous |
|---|
| 62 | * buffer |
|---|
| 63 | * |
|---|
| 64 | * 22 7/26/07 2:48p vsilyaev |
|---|
| 65 | * PR 32813: One more function inlined |
|---|
| 66 | * |
|---|
| 67 | * 21 7/26/07 2:01p vsilyaev |
|---|
| 68 | * PR 32813: Added inline versions of some cursor functions |
|---|
| 69 | * |
|---|
| 70 | * 20 7/12/07 3:41p vsilyaev |
|---|
| 71 | * PR 32846: Added function to return atom's vector array |
|---|
| 72 | * |
|---|
| 73 | * 19 6/14/07 1:53p vsilyaev |
|---|
| 74 | * PR 31887: Added function to directly copy data between accumulators |
|---|
| 75 | * |
|---|
| 76 | * 18 5/29/07 4:27p vsilyaev |
|---|
| 77 | * PR 25701: Added documentation |
|---|
| 78 | * |
|---|
| 79 | * 17 5/25/07 7:17p vsilyaev |
|---|
| 80 | * PR 25701: Added documentation |
|---|
| 81 | * |
|---|
| 82 | * 16 5/24/07 6:46p vsilyaev |
|---|
| 83 | * PR 25701: Added documentation |
|---|
| 84 | * |
|---|
| 85 | * 15 5/24/07 10:26a vsilyaev |
|---|
| 86 | * PR 29815: Added function batom_empty to create empty atom (e.g. without |
|---|
| 87 | * payload), fixed b_atom_refill, improved debug output |
|---|
| 88 | * |
|---|
| 89 | * 14 5/23/07 9:14p vsilyaev |
|---|
| 90 | * PR 29815: By default mark atoms as dirty, so cache would be flushed |
|---|
| 91 | * |
|---|
| 92 | * 13 5/21/07 5:53p vsilyaev |
|---|
| 93 | * PR 29815: Fixed improper use of assert, when partioning accumulator |
|---|
| 94 | * with anonymous data |
|---|
| 95 | * |
|---|
| 96 | * 12 5/18/07 5:11p vsilyaev |
|---|
| 97 | * PR 28631: Optimized (reduced code size) of batom_cursor_next and |
|---|
| 98 | * b_atom_cursor_refill |
|---|
| 99 | * |
|---|
| 100 | * 11 5/18/07 12:36a vsilyaev |
|---|
| 101 | * PR 31188: Added functions to read 24 bit integers |
|---|
| 102 | * |
|---|
| 103 | * 10 5/1/07 11:16a vsilyaev |
|---|
| 104 | * PR 28631: Added functions to dump content of accumulator, atom and |
|---|
| 105 | * cursor |
|---|
| 106 | * |
|---|
| 107 | * 9 3/27/07 7:25p vsilyaev |
|---|
| 108 | * PR 29125: Added bit reader |
|---|
| 109 | * |
|---|
| 110 | * 8 3/2/07 5:31p vsilyaev |
|---|
| 111 | * PR 25701: Added support to splitting range in multiple vectors |
|---|
| 112 | * |
|---|
| 113 | * 7 3/1/07 7:05p vsilyaev |
|---|
| 114 | * PR 25701: Added function to return number of vectors in the atom |
|---|
| 115 | * |
|---|
| 116 | * 6 2/20/07 10:18a vsilyaev |
|---|
| 117 | * PR 25701: Added batom_extract |
|---|
| 118 | * |
|---|
| 119 | * 5 2/15/07 3:12p vsilyaev |
|---|
| 120 | * PR 25701: Added code to handle parsing during resource starvation |
|---|
| 121 | * |
|---|
| 122 | * 4 2/14/07 5:46p vsilyaev |
|---|
| 123 | * PR 25701: Added code to dump content/status of allocator |
|---|
| 124 | * |
|---|
| 125 | * 3 2/9/07 7:28p vsilyaev |
|---|
| 126 | * PR 25701: Added new function to combine range and pipe (frequent case |
|---|
| 127 | * when PES header appended to the payload) |
|---|
| 128 | * |
|---|
| 129 | * 2 2/6/07 6:47p vsilyaev |
|---|
| 130 | * PR 25701: Added batom_accum_trim and batom_accum_extract to manipulate |
|---|
| 131 | * acccumulators based on cursors |
|---|
| 132 | * |
|---|
| 133 | * 1 2/5/07 5:28p vsilyaev |
|---|
| 134 | * PR 25701:Portions of stackable parsing framework |
|---|
| 135 | * |
|---|
| 136 | *******************************************************************************/ |
|---|
| 137 | #ifndef __BATOM_H__ |
|---|
| 138 | #define __BATOM_H__ |
|---|
| 139 | |
|---|
| 140 | #include "balloc.h" |
|---|
| 141 | #include "bpool.h" |
|---|
| 142 | #ifdef __cplusplus |
|---|
| 143 | extern "C" |
|---|
| 144 | { |
|---|
| 145 | #endif |
|---|
| 146 | |
|---|
| 147 | /*================== Module Overview ===================================== |
|---|
| 148 | This module defines basic elements which are used to build stackable stream |
|---|
| 149 | parsers or processors. These processors obey the following rules: |
|---|
| 150 | 1. In-place parsing (e.g. zero memory copy parsing), where stream is separated in pieces and rejoined into a new stream format |
|---|
| 151 | 2. Symmetric input and outputs |
|---|
| 152 | 3. Asynchronous non-blocking model of operation |
|---|
| 153 | |
|---|
| 154 | First rule is the key for high performance, actual data is not copied, instead all parsers and processors |
|---|
| 155 | operate with the same data, thus significantly reducing memory traffic and increasing performance. |
|---|
| 156 | with compile-time and run-time control. Second rule allows arbitrary connection between processors and |
|---|
| 157 | third rule provides flexibility in partioning the system, since neither of calls block, arbitrary complex |
|---|
| 158 | system could be build in a single execution context, i.e. it doesn't require separate thread for each |
|---|
| 159 | processing element |
|---|
| 160 | |
|---|
| 161 | Below is a sample interconnection scheme for the network of system processors. |
|---|
| 162 | |
|---|
| 163 | +----------+ |
|---|
| 164 | +---------+ +---------+ +--------)->[PIPE]->) | +-------------+ |
|---|
| 165 | | Source )->[PIPE]->( Filter1 )->[PIPE]->( Parser | | Filter2 )->[PIPE]->( Destination | |
|---|
| 166 | +---------+ +---------+ +--------)->[PIPE}->) | +-------------+ |
|---|
| 167 | +----------+ |
|---|
| 168 | |
|---|
| 169 | Each stream processor is independent module, that has one or more inputs and one or more outputs. Each input |
|---|
| 170 | is a pipe, the software abstraction which is used to accumulated data elements. |
|---|
| 171 | |
|---|
| 172 | This modules provides the following basic elements: |
|---|
| 173 | o batom_t - basic data element, in corresponds to single data element, it could be single network packet, single video or audio packet. |
|---|
| 174 | o batom_pipe_t - FIFO of basics data elements |
|---|
| 175 | o batom_cursor - means of representing seqeuence of memory blocks as continous sequence of bytes |
|---|
| 176 | o batom_accum_t - instrument to merge and slice batom_t |
|---|
| 177 | |
|---|
| 178 | ========================================================================*/ |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | /** |
|---|
| 182 | Summary: |
|---|
| 183 | batom_t is a basic element of the stream processing |
|---|
| 184 | Description: |
|---|
| 185 | batom_t is immutable representation of one or more regions in the memory (called atom payload). There are operations that could be used to split batom_t into |
|---|
| 186 | multiple batom_t, data could be appended into the batom_t or removed. However because batom_t is immutable in order to modify batom_t users |
|---|
| 187 | create new batom_t which shares all or some payload of source batom)t. Each batom_t is a reference counted object and when batom_t payload is used to create new batom_t, its reference |
|---|
| 188 | counter incremented. When b_atom_t first created it's reference counter is set to 1, batom_lock increments reference counter and batom_release decrements reference counter. |
|---|
| 189 | When reference counter goes through zero, then batom_t is recycled, and if it uses payload from other atoms their reference counter recursively decremented. |
|---|
| 190 | **/ |
|---|
| 191 | typedef struct batom *batom_t; |
|---|
| 192 | |
|---|
| 193 | /** |
|---|
| 194 | Summary: |
|---|
| 195 | batom_pipe_t is FIFO of batom_t |
|---|
| 196 | Description: |
|---|
| 197 | batom_pipe_t is used to group atoms into the FIFO sequence, there is no limit to number of elements queued in the pipe, however given atom could participate only |
|---|
| 198 | at one pipe at the time. |
|---|
| 199 | **/ |
|---|
| 200 | typedef struct batom_pipe *batom_pipe_t; |
|---|
| 201 | |
|---|
| 202 | /** |
|---|
| 203 | Summary: |
|---|
| 204 | batom_accum_t a slicing/cutting board to construct atoms |
|---|
| 205 | Description: |
|---|
| 206 | batom_accum_t is used to combins atoms and memory regions into the single object, and then to extract atom. |
|---|
| 207 | **/ |
|---|
| 208 | typedef struct batom_accum *batom_accum_t; |
|---|
| 209 | |
|---|
| 210 | /** |
|---|
| 211 | Summary: |
|---|
| 212 | batom_factory_t is used to manage resources need by batom_t |
|---|
| 213 | **/ |
|---|
| 214 | typedef struct batom_factory *batom_factory_t; |
|---|
| 215 | |
|---|
| 216 | /** |
|---|
| 217 | Summary: |
|---|
| 218 | batom_vec structure is a lowest-level building block of batom_t, it desribes continious block of memory |
|---|
| 219 | **/ |
|---|
| 220 | typedef struct batom_vec { |
|---|
| 221 | /* members are arranged in a way that they would be packed and structure occupyis 2x32 bits */ |
|---|
| 222 | void *base; /* pointer to the vectors start address */ |
|---|
| 223 | uint16_t len; /* size is 16 bit field, to there are 16 bit spare */ |
|---|
| 224 | bool dirty; /* set to true if block was modified, e.g. need to flush a cache */ |
|---|
| 225 | uint8_t unused_flags; /* misc flags */ |
|---|
| 226 | } batom_vec; |
|---|
| 227 | #define BATOM_VEC_INITIALIZER(base, len) {(base), (len), false, 0} |
|---|
| 228 | |
|---|
| 229 | /** |
|---|
| 230 | Summary: |
|---|
| 231 | batom_user_free type of function pointer is called when batom_t is recycled |
|---|
| 232 | **/ |
|---|
| 233 | typedef void (*batom_user_free)( |
|---|
| 234 | batom_t atom, /* instance of batom_t */ |
|---|
| 235 | void *user /* pointer to the user supplied data */ |
|---|
| 236 | ); |
|---|
| 237 | |
|---|
| 238 | /** |
|---|
| 239 | Summary: |
|---|
| 240 | batom_user structure describes user supplied data that associated with the batom_t |
|---|
| 241 | Description: |
|---|
| 242 | This structure is used to associate user specified descriptor with batom_t. |
|---|
| 243 | When pointer to the user supplied data is passed to one of functions that create batom_t, |
|---|
| 244 | user data copied into the batom_t private storage, number of bytes copied specified |
|---|
| 245 | by the user_size structure member. When atom recycled and user_free function called |
|---|
| 246 | it receives pointer to the batom private copy of user data. |
|---|
| 247 | **/ |
|---|
| 248 | typedef struct batom_user { |
|---|
| 249 | batom_user_free user_free; /* this function called when atom is recycled */ |
|---|
| 250 | size_t user_size; /* size of the user data */ |
|---|
| 251 | } batom_user; |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | /** |
|---|
| 255 | Summary: |
|---|
| 256 | This type allows read-only navigation over sequence of batom_vec |
|---|
| 257 | Description: |
|---|
| 258 | To access data stored in the batom_t or batom_accum_t, user shall use batom_cursor family of functions. |
|---|
| 259 | This structure is used for internal book-keeping by forementioned functions. Memebers of this structure |
|---|
| 260 | shall not be accesses directly. Use of batom_cursor functions have benefit that it seamlessly handles |
|---|
| 261 | discontinuity in the data. |
|---|
| 262 | **/ |
|---|
| 263 | typedef struct batom_cursor { |
|---|
| 264 | const uint8_t *cursor; /* pointer to the current read pointer */ |
|---|
| 265 | int left; /* number of bytes left in the cursor, -1 if cursor have reached last data in the vector array */ |
|---|
| 266 | uint16_t pos; /* current position in the vector array */ |
|---|
| 267 | uint16_t count; /* number of entries in the vector array */ |
|---|
| 268 | const batom_vec *vec; /* pointer to the vector array */ |
|---|
| 269 | } batom_cursor; |
|---|
| 270 | |
|---|
| 271 | /** |
|---|
| 272 | Summary: |
|---|
| 273 | This structure is used to retrieve accumulated statistics from the batom_factory_t instance |
|---|
| 274 | **/ |
|---|
| 275 | typedef struct batom_factory_stats { |
|---|
| 276 | unsigned atom_live; /* number of not recycled atoms */ |
|---|
| 277 | unsigned atom_allocated; /* number of allocated atoms */ |
|---|
| 278 | unsigned atom_freed; /* number of recycled atoms */ |
|---|
| 279 | unsigned alloc_pool; /* number of atoms allocated from the pool allocator */ |
|---|
| 280 | unsigned alloc_arena; /* number of atoms allocated from the arena allocator */ |
|---|
| 281 | unsigned alloc_alloc; /* number of atoms allocated from the standard allocator */ |
|---|
| 282 | unsigned free_pool; /* number of atoms freed from the pool allocator */ |
|---|
| 283 | unsigned free_arena; /* number of atoms freed from the arena allocator */ |
|---|
| 284 | unsigned free_alloc; /* number of atoms freed from the standard allocator */ |
|---|
| 285 | unsigned full_pool; /* number of times when poll allocator was exhausted */ |
|---|
| 286 | unsigned full_arena; /* number of times when arena allocator was exhausted */ |
|---|
| 287 | bpool_status pool_status; /* status of the pool allocator */ |
|---|
| 288 | } batom_factory_stats; |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | /** |
|---|
| 292 | Summary: |
|---|
| 293 | This structure is used to save batom_cursor position |
|---|
| 294 | **/ |
|---|
| 295 | typedef struct batom_checkpoint { |
|---|
| 296 | int cp_left; /* copy of left from the batom_cursor */ |
|---|
| 297 | unsigned cp_pos; /* copy of pos from the batom_cursor */ |
|---|
| 298 | } batom_checkpoint; |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | /** |
|---|
| 303 | Summary: |
|---|
| 304 | This constant is used by batom_cursor functions to signal end of data condition |
|---|
| 305 | **/ |
|---|
| 306 | #define BATOM_EOF (-1) |
|---|
| 307 | /** |
|---|
| 308 | Summary: |
|---|
| 309 | This constant defined maximum number of vectors that could be saved in the single atom |
|---|
| 310 | **/ |
|---|
| 311 | #define BATOM_VEC_MAX_SIZE (65535) |
|---|
| 312 | |
|---|
| 313 | /** |
|---|
| 314 | Summary: |
|---|
| 315 | Creates atom factory |
|---|
| 316 | **/ |
|---|
| 317 | batom_factory_t batom_factory_create( |
|---|
| 318 | balloc_iface_t alloc, /* memory allocator for the factory */ |
|---|
| 319 | size_t natoms /* number of preallocated atoms */ |
|---|
| 320 | ); |
|---|
| 321 | |
|---|
| 322 | /** |
|---|
| 323 | Summary: |
|---|
| 324 | Releases resources allocated by factory. |
|---|
| 325 | Note: |
|---|
| 326 | When this function called all atoms shall be already recycled. |
|---|
| 327 | **/ |
|---|
| 328 | void batom_factory_destroy( |
|---|
| 329 | batom_factory_t factory /* factory instance */ |
|---|
| 330 | ); |
|---|
| 331 | /** |
|---|
| 332 | Summary: |
|---|
| 333 | This function returns statistics for the factory |
|---|
| 334 | **/ |
|---|
| 335 | void batom_factory_get_stats(batom_factory_t factory, batom_factory_stats *stats); |
|---|
| 336 | |
|---|
| 337 | /** |
|---|
| 338 | Summary: |
|---|
| 339 | This function dumps active objects in the factory |
|---|
| 340 | **/ |
|---|
| 341 | void batom_factory_dump(batom_factory_t factory); |
|---|
| 342 | |
|---|
| 343 | /** |
|---|
| 344 | Summary: |
|---|
| 345 | This function creates accumulator object |
|---|
| 346 | **/ |
|---|
| 347 | batom_accum_t batom_accum_create( |
|---|
| 348 | batom_factory_t factory /* instance of factory */ |
|---|
| 349 | ); |
|---|
| 350 | |
|---|
| 351 | /** |
|---|
| 352 | Summary: |
|---|
| 353 | This function creates contents of accumulator |
|---|
| 354 | Description: |
|---|
| 355 | Function batom_accum_clear would recycle all accumulated atoms |
|---|
| 356 | **/ |
|---|
| 357 | void batom_accum_clear( |
|---|
| 358 | batom_accum_t acc /* instance of accumulator */ |
|---|
| 359 | ); |
|---|
| 360 | |
|---|
| 361 | /** |
|---|
| 362 | Summary: |
|---|
| 363 | This function releases resources associated with accumulator |
|---|
| 364 | **/ |
|---|
| 365 | void batom_accum_destroy( |
|---|
| 366 | batom_accum_t acc /* instance of accumulator */ |
|---|
| 367 | ); |
|---|
| 368 | |
|---|
| 369 | /** |
|---|
| 370 | Summary: |
|---|
| 371 | This function returns number of bytes accumulated in accumulator |
|---|
| 372 | **/ |
|---|
| 373 | size_t batom_accum_len( |
|---|
| 374 | batom_accum_t acc /* instance of accumulator */ |
|---|
| 375 | ); |
|---|
| 376 | |
|---|
| 377 | /** |
|---|
| 378 | Summary: |
|---|
| 379 | This function returns vector array from accumulator |
|---|
| 380 | Description: |
|---|
| 381 | Accumulator is collection of vectors, this function provides direct access to all vectors. |
|---|
| 382 | Note: |
|---|
| 383 | Function returns read only pointer to the atom, therefore accumulatora shall not be modified, also modification of memory that vector points to is discouraged as well. |
|---|
| 384 | **/ |
|---|
| 385 | const batom_vec * |
|---|
| 386 | batom_accum_get_vectors( |
|---|
| 387 | batom_accum_t acc, /* accumulatora */ |
|---|
| 388 | unsigned *nvecs /* number of vectors in the atom */ |
|---|
| 389 | ); |
|---|
| 390 | |
|---|
| 391 | /** |
|---|
| 392 | Summary: |
|---|
| 393 | This function dumps data accumulated in the accumulator |
|---|
| 394 | **/ |
|---|
| 395 | void batom_accum_dump( |
|---|
| 396 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 397 | const char *name /* name printed in the dump */ |
|---|
| 398 | ); |
|---|
| 399 | |
|---|
| 400 | /** |
|---|
| 401 | Summary: |
|---|
| 402 | This function adds vector into the accumulator |
|---|
| 403 | **/ |
|---|
| 404 | void batom_accum_add_vec( |
|---|
| 405 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 406 | const batom_vec *vec /* pointer to the vector */ |
|---|
| 407 | ); |
|---|
| 408 | |
|---|
| 409 | /** |
|---|
| 410 | Summary: |
|---|
| 411 | This function adds memory range into accumulator |
|---|
| 412 | **/ |
|---|
| 413 | void batom_accum_add_range( |
|---|
| 414 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 415 | const void *base, /* start address */ |
|---|
| 416 | size_t len /* length */ |
|---|
| 417 | ); |
|---|
| 418 | |
|---|
| 419 | /** |
|---|
| 420 | Summary: |
|---|
| 421 | This function adds atom into accumulator |
|---|
| 422 | Note: |
|---|
| 423 | The same atom could be added multiple time into the same or different accumulators |
|---|
| 424 | **/ |
|---|
| 425 | void batom_accum_add_atom( |
|---|
| 426 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 427 | batom_t atom /* atom */ |
|---|
| 428 | ); |
|---|
| 429 | |
|---|
| 430 | /** |
|---|
| 431 | Summary: |
|---|
| 432 | This function 'trims' data from accumulator |
|---|
| 433 | Description: |
|---|
| 434 | The batom_accum_trim removes data stored in accumulator started from beginning of accumulator and uptto cursor. |
|---|
| 435 | Cursor shall be created from the accumulator. Atoms from recycled region would be recycled. |
|---|
| 436 | After completion of function cursors still points into the same data. |
|---|
| 437 | **/ |
|---|
| 438 | void batom_accum_trim( |
|---|
| 439 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 440 | batom_cursor *cursor /* cursor which marks trimming point */ |
|---|
| 441 | ); |
|---|
| 442 | |
|---|
| 443 | /** |
|---|
| 444 | Summary: |
|---|
| 445 | This function creates atom from slice of accumulator |
|---|
| 446 | Description: |
|---|
| 447 | The batom_accum_extract functions produces new atom with content copied from the accumulator |
|---|
| 448 | Both cursors shall be created from the accumulator. |
|---|
| 449 | **/ |
|---|
| 450 | batom_t batom_accum_extract( |
|---|
| 451 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 452 | const batom_cursor *first, /* cursor that marks start of range */ |
|---|
| 453 | const batom_cursor *last, /* cursor that marks end of range */ |
|---|
| 454 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 455 | const void *udata /* pointer to the user data */ |
|---|
| 456 | ); |
|---|
| 457 | |
|---|
| 458 | /** |
|---|
| 459 | Summary: |
|---|
| 460 | This function appends data from one accumulator to another |
|---|
| 461 | Description: |
|---|
| 462 | The batom_accum_append functions appends data to the destination accumulator, from the source accumulator bounded by two cursors. |
|---|
| 463 | Both cursors shall be created from the source accumulator. |
|---|
| 464 | This function returns false if resources were exhausted and append has failed. |
|---|
| 465 | **/ |
|---|
| 466 | bool batom_accum_append( |
|---|
| 467 | batom_accum_t dst, /* destination accumulator */ |
|---|
| 468 | batom_accum_t src, /* source accumulator */ |
|---|
| 469 | const batom_cursor *first, /* cursor that marks start of range */ |
|---|
| 470 | const batom_cursor *last /* cursor that marks end of range */ |
|---|
| 471 | ); |
|---|
| 472 | |
|---|
| 473 | /** |
|---|
| 474 | Summary: |
|---|
| 475 | This function creates atom from single vector |
|---|
| 476 | **/ |
|---|
| 477 | batom_t batom_from_vector( |
|---|
| 478 | batom_factory_t factory, /* instance of factory */ |
|---|
| 479 | const batom_vec *vec, /* vector that describes memory region */ |
|---|
| 480 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 481 | const void *udata /* pointer to the user data */ |
|---|
| 482 | ); |
|---|
| 483 | |
|---|
| 484 | /** |
|---|
| 485 | Summary: |
|---|
| 486 | This function creates atom from array of vectors |
|---|
| 487 | **/ |
|---|
| 488 | batom_t batom_from_vectors( |
|---|
| 489 | batom_factory_t factory, /* instance of factory */ |
|---|
| 490 | const batom_vec *vecs, /* array of vectors that describes in memory object */ |
|---|
| 491 | unsigned nvecs, /* number of entries in the vector array */ |
|---|
| 492 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 493 | const void *udata /* pointer to the user data */ |
|---|
| 494 | ); |
|---|
| 495 | |
|---|
| 496 | /** |
|---|
| 497 | Summary: |
|---|
| 498 | This function creates atom from consecutive memory range |
|---|
| 499 | **/ |
|---|
| 500 | batom_t batom_from_range( |
|---|
| 501 | batom_factory_t factory, /* instance of factory */ |
|---|
| 502 | const void *base, /* first address of memory region */ |
|---|
| 503 | size_t len, /* length of memory region */ |
|---|
| 504 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 505 | const void *udata /* pointer to the user data */ |
|---|
| 506 | ); |
|---|
| 507 | |
|---|
| 508 | /** |
|---|
| 509 | Summary: |
|---|
| 510 | This function creates atom from accumulator |
|---|
| 511 | Description: |
|---|
| 512 | This function creates atom from accumulator content and then clears accumulator. |
|---|
| 513 | **/ |
|---|
| 514 | batom_t batom_from_accum( |
|---|
| 515 | batom_accum_t acc, /* instance of accumulator */ |
|---|
| 516 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 517 | const void *udata /* pointer to the user data */ |
|---|
| 518 | ); |
|---|
| 519 | |
|---|
| 520 | /** |
|---|
| 521 | Summary: |
|---|
| 522 | This function creates clone of atom |
|---|
| 523 | Description: |
|---|
| 524 | This function creates atom with exactly the same contant, but with different user data |
|---|
| 525 | **/ |
|---|
| 526 | batom_t batom_clone( |
|---|
| 527 | batom_t atom, /* instance of accumulator */ |
|---|
| 528 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 529 | const void *udata /* pointer to the user data */ |
|---|
| 530 | ); |
|---|
| 531 | |
|---|
| 532 | /** |
|---|
| 533 | Summary: |
|---|
| 534 | This function creates of atom from concatenation of memory range and atom |
|---|
| 535 | **/ |
|---|
| 536 | batom_t batom_from_range_and_atom( |
|---|
| 537 | const void *base, /* first address of memory region */ |
|---|
| 538 | size_t len, /* length of memory region */ |
|---|
| 539 | batom_t atom, /* atom */ |
|---|
| 540 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 541 | const void *udata /* pointer to the user data */ |
|---|
| 542 | ); |
|---|
| 543 | |
|---|
| 544 | /** |
|---|
| 545 | Summary: |
|---|
| 546 | This function creates of atom from concatenation of vector and atom |
|---|
| 547 | **/ |
|---|
| 548 | batom_t batom_from_vec_and_atom( |
|---|
| 549 | const batom_vec *vec, /* vector that describes memory region */ |
|---|
| 550 | batom_t atom, /* atom */ |
|---|
| 551 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 552 | const void *udata /* pointer to the user data */ |
|---|
| 553 | ); |
|---|
| 554 | |
|---|
| 555 | /** |
|---|
| 556 | Summary: |
|---|
| 557 | This function creates of empty atom, e.g. atom without associated data |
|---|
| 558 | **/ |
|---|
| 559 | batom_t batom_empty( |
|---|
| 560 | batom_factory_t factory, /* instance of factory */ |
|---|
| 561 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 562 | const void *udata /* pointer to the user data */ |
|---|
| 563 | ); |
|---|
| 564 | |
|---|
| 565 | /** |
|---|
| 566 | Summary: |
|---|
| 567 | This function increments reference counter of atom |
|---|
| 568 | **/ |
|---|
| 569 | void batom_lock( |
|---|
| 570 | batom_t atom /* atom */ |
|---|
| 571 | ); |
|---|
| 572 | |
|---|
| 573 | /** |
|---|
| 574 | Summary: |
|---|
| 575 | This function decrements reference counter of atom |
|---|
| 576 | Description: |
|---|
| 577 | If reference counter passes through zero, memory occupied by atom is recycles and, |
|---|
| 578 | if applicable, user supplied free function called. |
|---|
| 579 | **/ |
|---|
| 580 | void batom_release( |
|---|
| 581 | batom_t atom /* atom */ |
|---|
| 582 | ); |
|---|
| 583 | |
|---|
| 584 | /** |
|---|
| 585 | Summary: |
|---|
| 586 | This function returns size (in bytes) of atom payload |
|---|
| 587 | **/ |
|---|
| 588 | size_t batom_len( |
|---|
| 589 | batom_t atom /* atom */ |
|---|
| 590 | ); |
|---|
| 591 | |
|---|
| 592 | /** |
|---|
| 593 | Summary: |
|---|
| 594 | This function returns vector from atom |
|---|
| 595 | Description: |
|---|
| 596 | Atom is collection of vectors, this function provides direct access to the vectors. |
|---|
| 597 | Note: |
|---|
| 598 | Function returns read only pointer to the atom, therefore atom shall not be modified, also modification of memory that vector points to is discouraged as well. |
|---|
| 599 | **/ |
|---|
| 600 | const batom_vec *batom_get_vec( |
|---|
| 601 | batom_t atom, /* atom */ |
|---|
| 602 | unsigned vecno /* request element */ |
|---|
| 603 | ); |
|---|
| 604 | /** |
|---|
| 605 | Summary: |
|---|
| 606 | This function returns size of the atom's vector array |
|---|
| 607 | **/ |
|---|
| 608 | unsigned batom_get_nvecs( |
|---|
| 609 | batom_t atom /* atom */ |
|---|
| 610 | ); |
|---|
| 611 | |
|---|
| 612 | /** |
|---|
| 613 | Summary: |
|---|
| 614 | This function returns vector array from atom |
|---|
| 615 | Description: |
|---|
| 616 | Atom is collection of vectors, this function provides direct access to all vectors. |
|---|
| 617 | Note: |
|---|
| 618 | Function returns read only pointer to the atom, therefore atom shall not be modified, also modification of memory that vector points to is discouraged as well. |
|---|
| 619 | **/ |
|---|
| 620 | const batom_vec * |
|---|
| 621 | batom_get_vectors( |
|---|
| 622 | batom_t atom, /* atom */ |
|---|
| 623 | unsigned *nvecs /* number of vectors in the atom */ |
|---|
| 624 | ); |
|---|
| 625 | |
|---|
| 626 | /** |
|---|
| 627 | Summary: |
|---|
| 628 | This function returns pointer to the user data saved in the atom |
|---|
| 629 | **/ |
|---|
| 630 | void *batom_userdata( |
|---|
| 631 | batom_t atom /* atom */ |
|---|
| 632 | ); |
|---|
| 633 | |
|---|
| 634 | /** |
|---|
| 635 | Summary: |
|---|
| 636 | This function extracts content from atom as specified by two cursors |
|---|
| 637 | **/ |
|---|
| 638 | batom_t batom_extract( |
|---|
| 639 | batom_t src, /* source atom */ |
|---|
| 640 | const batom_cursor *first, /* cursor that marks start of range */ |
|---|
| 641 | const batom_cursor *last, /* cursor that marks end of range */ |
|---|
| 642 | const batom_user *user, /* pointer to the user data descriptor */ |
|---|
| 643 | const void *udata /* pointer to the user data */ |
|---|
| 644 | ); |
|---|
| 645 | |
|---|
| 646 | /** |
|---|
| 647 | Summary: |
|---|
| 648 | This function prints content of the atom |
|---|
| 649 | **/ |
|---|
| 650 | void batom_dump( |
|---|
| 651 | batom_t atom, /* atom */ |
|---|
| 652 | const char *name /* name of atom printed in the dump */ |
|---|
| 653 | ); |
|---|
| 654 | |
|---|
| 655 | /** |
|---|
| 656 | Summary: |
|---|
| 657 | This function creates cursor from the vector array |
|---|
| 658 | **/ |
|---|
| 659 | void batom_cursor_from_vec( |
|---|
| 660 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 661 | const batom_vec *vec, /* vector array */ |
|---|
| 662 | unsigned count /* size of the vector array */ |
|---|
| 663 | ); |
|---|
| 664 | |
|---|
| 665 | /** |
|---|
| 666 | Summary: |
|---|
| 667 | This function creates cursor from atom |
|---|
| 668 | **/ |
|---|
| 669 | void batom_cursor_from_atom( |
|---|
| 670 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 671 | batom_t atom /* atom */ |
|---|
| 672 | ); |
|---|
| 673 | |
|---|
| 674 | /** |
|---|
| 675 | Summary: |
|---|
| 676 | This function creates cursor from accumulator |
|---|
| 677 | **/ |
|---|
| 678 | void batom_cursor_from_accum( |
|---|
| 679 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 680 | batom_accum_t acc /* accumulator */ |
|---|
| 681 | ); |
|---|
| 682 | |
|---|
| 683 | /** |
|---|
| 684 | Summary: |
|---|
| 685 | This function creates cursor from accumulator |
|---|
| 686 | **/ |
|---|
| 687 | void batom_cursor_empty( |
|---|
| 688 | batom_cursor *cursor /* pointer to the cursor */ |
|---|
| 689 | ); |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | /** |
|---|
| 694 | Summary: |
|---|
| 695 | This function returns next byte from the cursor |
|---|
| 696 | Result: |
|---|
| 697 | Function returns either byte fetched from the cursor, or BATOM_EOF if cursor advanced past end of data |
|---|
| 698 | **/ |
|---|
| 699 | int batom_cursor_next( |
|---|
| 700 | batom_cursor *cursor /* pointer to the cursor */ |
|---|
| 701 | ); |
|---|
| 702 | |
|---|
| 703 | /** |
|---|
| 704 | Summary: |
|---|
| 705 | This function tests whether cursor advanced past end of data |
|---|
| 706 | **/ |
|---|
| 707 | bool batom_cursor_eof( |
|---|
| 708 | const batom_cursor *cursor /* pointer to the cursor */ |
|---|
| 709 | ); |
|---|
| 710 | |
|---|
| 711 | /** |
|---|
| 712 | Summary: |
|---|
| 713 | This function advances cursor by specified number of bytes |
|---|
| 714 | Result: |
|---|
| 715 | Function returns number of bytes advanced, it could be smaller than requested number if cursor advanced past end of data |
|---|
| 716 | **/ |
|---|
| 717 | size_t batom_cursor_skip( |
|---|
| 718 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 719 | size_t count /* number of bytes to skip */ |
|---|
| 720 | ); |
|---|
| 721 | |
|---|
| 722 | /** |
|---|
| 723 | Summary: |
|---|
| 724 | This function copies data from cursor |
|---|
| 725 | Result: |
|---|
| 726 | Function returns number of bytes copied, it could be smaller than requested number if cursor advanced past end of data |
|---|
| 727 | **/ |
|---|
| 728 | size_t batom_cursor_copy( |
|---|
| 729 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 730 | void *dest, /* address of the destination buffer */ |
|---|
| 731 | size_t count /* number of bytes to copy */ |
|---|
| 732 | ); |
|---|
| 733 | |
|---|
| 734 | /** |
|---|
| 735 | Summary: |
|---|
| 736 | This function returns distance between two cursors, cursors shall be created for the same underlying object |
|---|
| 737 | **/ |
|---|
| 738 | size_t batom_cursor_distance( |
|---|
| 739 | const batom_cursor *from, /* pointer to the first cursor */ |
|---|
| 740 | const batom_cursor *to /* pointer to the second cursor */ |
|---|
| 741 | ); |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | /** |
|---|
| 745 | Summary: |
|---|
| 746 | This function saves position of cursor |
|---|
| 747 | Description: |
|---|
| 748 | Position of cursor is saved into tbe batom_checkpoint data structure. |
|---|
| 749 | **/ |
|---|
| 750 | void batom_cursor_save( |
|---|
| 751 | const batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 752 | batom_checkpoint *checkpoint /* pointer to checkpoint */ |
|---|
| 753 | ); |
|---|
| 754 | /** |
|---|
| 755 | Summary: |
|---|
| 756 | This function restores position of cursor |
|---|
| 757 | Description: |
|---|
| 758 | Position of cursor restored based on checkpoint. The same rollback pointer could be used multiple times as long as |
|---|
| 759 | underlying element (atom,accumulator or vector) didn't change. |
|---|
| 760 | If changes have occured in the underlying element, behaviour is undefined. |
|---|
| 761 | **/ |
|---|
| 762 | void batom_cursor_rollback( |
|---|
| 763 | batom_cursor *cursor, /* pointer to the cursor */ |
|---|
| 764 | const batom_checkpoint *checkpoint /* pointer to checkpoint */ |
|---|
| 765 | ); |
|---|
| 766 | |
|---|
| 767 | /** |
|---|
| 768 | Summary: |
|---|
| 769 | This function makes an indentical copy of cursor |
|---|
| 770 | **/ |
|---|
| 771 | void batom_cursor_clone( |
|---|
| 772 | batom_cursor *dst, /* pointer to the destination cursor */ |
|---|
| 773 | const batom_cursor *src /* pointer to the source cursor */ |
|---|
| 774 | ); |
|---|
| 775 | |
|---|
| 776 | /** |
|---|
| 777 | Summary: |
|---|
| 778 | This function returns current position of cursor |
|---|
| 779 | **/ |
|---|
| 780 | size_t batom_cursor_pos( |
|---|
| 781 | const batom_cursor *cursor /* pointer to cursor */ |
|---|
| 782 | ); |
|---|
| 783 | |
|---|
| 784 | /** |
|---|
| 785 | Summary: |
|---|
| 786 | This function returns cursor's size, e.g. number of bytes addressable by cursor |
|---|
| 787 | **/ |
|---|
| 788 | size_t batom_cursor_size( |
|---|
| 789 | const batom_cursor *cursor /* pointer to cursor */ |
|---|
| 790 | ); |
|---|
| 791 | |
|---|
| 792 | /** |
|---|
| 793 | Summary: |
|---|
| 794 | This function validates number of bytes avaliable in the cursor |
|---|
| 795 | Description: |
|---|
| 796 | This function is identical to batom_cursor_skip, with exeption that cursor poisition doesn't change |
|---|
| 797 | **/ |
|---|
| 798 | size_t batom_cursor_reserve( |
|---|
| 799 | const batom_cursor *cursor, /* pointer to cursor */ |
|---|
| 800 | size_t count /* number of bytes to reserve */ |
|---|
| 801 | ); |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | /** |
|---|
| 805 | Summary: |
|---|
| 806 | This function compares the contents of a cursor with the contents of a buff. It doesn't change cursor/ |
|---|
| 807 | Result: |
|---|
| 808 | Function returns 0 if the buffers are identical |
|---|
| 809 | **/ |
|---|
| 810 | int batom_cursor_compare( |
|---|
| 811 | const batom_cursor *cursor, |
|---|
| 812 | const void *buff, /* address of the compare buffer */ |
|---|
| 813 | size_t bytes /* number of bytes to compare */ |
|---|
| 814 | ); |
|---|
| 815 | |
|---|
| 816 | /** |
|---|
| 817 | Summary: |
|---|
| 818 | This function prints content of the cursor, starting from current position |
|---|
| 819 | **/ |
|---|
| 820 | void batom_cursor_dump( |
|---|
| 821 | const batom_cursor *c, /* pointer to cursor */ |
|---|
| 822 | const char *name /* name to be displayed in the dump */ |
|---|
| 823 | ); |
|---|
| 824 | |
|---|
| 825 | /** |
|---|
| 826 | Summary: |
|---|
| 827 | This function returns next byte from the cursor |
|---|
| 828 | Description: |
|---|
| 829 | Function would return undefined data if end of data reached. |
|---|
| 830 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 831 | **/ |
|---|
| 832 | uint8_t batom_cursor_byte( |
|---|
| 833 | batom_cursor *c /* pointer to cursor */ |
|---|
| 834 | ); |
|---|
| 835 | |
|---|
| 836 | /** |
|---|
| 837 | Summary: |
|---|
| 838 | This function returns next 16-bit little endian number from the cursor |
|---|
| 839 | Description: |
|---|
| 840 | Function would return undefined data if end of data reached. |
|---|
| 841 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 842 | If cursor has content of 0x11 0x22, then this function would return 0x2211 |
|---|
| 843 | **/ |
|---|
| 844 | uint16_t batom_cursor_uint16_le( |
|---|
| 845 | batom_cursor *c /* pointer to cursor */ |
|---|
| 846 | ); |
|---|
| 847 | |
|---|
| 848 | /** |
|---|
| 849 | Summary: |
|---|
| 850 | This function returns next 16-bit big endian number from the cursor |
|---|
| 851 | Description: |
|---|
| 852 | Function would return undefined data if end of data reached. |
|---|
| 853 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 854 | If cursor has content of 0x11 0x22, then this function would return 0x1122 |
|---|
| 855 | **/ |
|---|
| 856 | uint16_t batom_cursor_uint16_be( |
|---|
| 857 | batom_cursor *c /* pointer to cursor */ |
|---|
| 858 | ); |
|---|
| 859 | |
|---|
| 860 | /** |
|---|
| 861 | Summary: |
|---|
| 862 | This function returns next 32-bit little endian number from the cursor |
|---|
| 863 | Description: |
|---|
| 864 | Function would return undefined data if end of data reached. |
|---|
| 865 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 866 | If cursor has content of 0x11 0x22 0x33 0x44, then this function would return 0x44332211 |
|---|
| 867 | **/ |
|---|
| 868 | uint32_t batom_cursor_uint32_le( |
|---|
| 869 | batom_cursor *c /* pointer to cursor */ |
|---|
| 870 | ); |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | /** |
|---|
| 874 | Summary: |
|---|
| 875 | This function returns next 32-bit big endian number from the cursor |
|---|
| 876 | Description: |
|---|
| 877 | Function would return undefined data if end of data reached. |
|---|
| 878 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 879 | If cursor has content of 0x11 0x22 0x33 0x44, then this function would return 0x11223344 |
|---|
| 880 | **/ |
|---|
| 881 | uint32_t batom_cursor_uint32_be( |
|---|
| 882 | batom_cursor *c /* pointer to cursor */ |
|---|
| 883 | ); |
|---|
| 884 | |
|---|
| 885 | /** |
|---|
| 886 | Summary: |
|---|
| 887 | This function returns next 64-bit little endian number from the cursor |
|---|
| 888 | Description: |
|---|
| 889 | Function would return undefined data if end of data reached. |
|---|
| 890 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 891 | If cursor has content of 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88, then this function would return 0x8877665544332211 |
|---|
| 892 | **/ |
|---|
| 893 | uint64_t batom_cursor_uint64_le( |
|---|
| 894 | batom_cursor *c /* pointer to cursor */ |
|---|
| 895 | ); |
|---|
| 896 | |
|---|
| 897 | /** |
|---|
| 898 | Summary: |
|---|
| 899 | This function returns next 64-bit big endian number from the cursor |
|---|
| 900 | Description: |
|---|
| 901 | Function would return undefined data if end of data reached. |
|---|
| 902 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 903 | If cursor has content of 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88, then this function would return 0x1122334455667788 |
|---|
| 904 | **/ |
|---|
| 905 | uint64_t batom_cursor_uint64_be( |
|---|
| 906 | batom_cursor *c /* pointer to cursor */ |
|---|
| 907 | ); |
|---|
| 908 | |
|---|
| 909 | /** |
|---|
| 910 | Summary: |
|---|
| 911 | This function returns next 24-bit little endian number from the cursor |
|---|
| 912 | Description: |
|---|
| 913 | Function would return undefined data if end of data reached. |
|---|
| 914 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 915 | If cursor has content of 0x11 0x22 0x33, then this function would return 0x332211 |
|---|
| 916 | **/ |
|---|
| 917 | uint32_t batom_cursor_uint24_le(batom_cursor *c); |
|---|
| 918 | |
|---|
| 919 | /** |
|---|
| 920 | Summary: |
|---|
| 921 | This function returns next 24-bit big endian number from the cursor |
|---|
| 922 | Description: |
|---|
| 923 | Function would return undefined data if end of data reached. |
|---|
| 924 | however it's safe to call this function when end of data reached as many times as required. |
|---|
| 925 | If cursor has content of 0x11 0x22 0x33, then this function would return 0x112233 |
|---|
| 926 | **/ |
|---|
| 927 | uint32_t batom_cursor_uint24_be( |
|---|
| 928 | batom_cursor *c /* pointer to cursor */ |
|---|
| 929 | ); |
|---|
| 930 | |
|---|
| 931 | /** |
|---|
| 932 | Summary: |
|---|
| 933 | This function returns next 1,2,3 or 4 bytes combined as little endian number |
|---|
| 934 | **/ |
|---|
| 935 | uint32_t batom_cursor_vword_le( |
|---|
| 936 | batom_cursor *c, /* pointer to cursor */ |
|---|
| 937 | unsigned bytes /* number of bytes to read */ |
|---|
| 938 | ); |
|---|
| 939 | |
|---|
| 940 | /** |
|---|
| 941 | Summary: |
|---|
| 942 | This function returns next 1,2,3 or 4 bytes combined as big endian number |
|---|
| 943 | **/ |
|---|
| 944 | uint32_t batom_cursor_vword_be( |
|---|
| 945 | batom_cursor *c, /* pointer to cursor */ |
|---|
| 946 | unsigned bytes /* number of bytes to read */ |
|---|
| 947 | ); |
|---|
| 948 | |
|---|
| 949 | /** |
|---|
| 950 | Summary: |
|---|
| 951 | This function returns continuous buffer of specified length. |
|---|
| 952 | Description: |
|---|
| 953 | The batom_cursor_continuous would return pointer to the current read loacation |
|---|
| 954 | if cursor points to the continious buffer of specified length, otherwise function |
|---|
| 955 | will return NULL. |
|---|
| 956 | It would return NULL, in either case if size of cursor is smaller then specified size |
|---|
| 957 | or cursor passes through fragmented data. |
|---|
| 958 | **/ |
|---|
| 959 | const void *batom_cursor_continuous( |
|---|
| 960 | const batom_cursor *c, /* pointer to cursor */ |
|---|
| 961 | size_t bytes /* number of continuous bytes requested */ |
|---|
| 962 | ); |
|---|
| 963 | /** |
|---|
| 964 | Summary: |
|---|
| 965 | This function creates pipe |
|---|
| 966 | **/ |
|---|
| 967 | batom_pipe_t batom_pipe_create( |
|---|
| 968 | batom_factory_t factory /* factory instance */ |
|---|
| 969 | ); |
|---|
| 970 | |
|---|
| 971 | /** |
|---|
| 972 | Summary: |
|---|
| 973 | This function releases resources allocated by a pipe |
|---|
| 974 | **/ |
|---|
| 975 | void batom_pipe_destroy( |
|---|
| 976 | batom_pipe_t pipe /* pipe instance */ |
|---|
| 977 | ); |
|---|
| 978 | |
|---|
| 979 | /** |
|---|
| 980 | Summary: |
|---|
| 981 | This function removes all atoms from the pipe. |
|---|
| 982 | Description: |
|---|
| 983 | For evert atom removed from the pipe, batom_release function called |
|---|
| 984 | **/ |
|---|
| 985 | void batom_pipe_flush( |
|---|
| 986 | batom_pipe_t pipe /* pipe instance */ |
|---|
| 987 | ); |
|---|
| 988 | |
|---|
| 989 | /** |
|---|
| 990 | Summary: |
|---|
| 991 | This function addes atom into head of pipe |
|---|
| 992 | Description: |
|---|
| 993 | One atom could be added only to single pipe. |
|---|
| 994 | If one atom shall be added to several pipes, the batom_clone function could be used to create a new atom |
|---|
| 995 | **/ |
|---|
| 996 | void batom_pipe_push( |
|---|
| 997 | batom_pipe_t pipe, /* pipe instance */ |
|---|
| 998 | batom_t atom /* atom */ |
|---|
| 999 | ); |
|---|
| 1000 | /** |
|---|
| 1001 | Summary: |
|---|
| 1002 | This function returns first atom from the tail of pipe |
|---|
| 1003 | Result: |
|---|
| 1004 | atom or NULL if pipe is empty |
|---|
| 1005 | **/ |
|---|
| 1006 | batom_t batom_pipe_peek( |
|---|
| 1007 | batom_pipe_t pipe /* pipe instance */ |
|---|
| 1008 | ); |
|---|
| 1009 | |
|---|
| 1010 | /** |
|---|
| 1011 | Summary: |
|---|
| 1012 | This function extracts first atom from the tail of pipe |
|---|
| 1013 | Result: |
|---|
| 1014 | atom or NULL if pipe is empty |
|---|
| 1015 | **/ |
|---|
| 1016 | batom_t batom_pipe_pop( |
|---|
| 1017 | batom_pipe_t pipe /* pipe instance */ |
|---|
| 1018 | ); |
|---|
| 1019 | |
|---|
| 1020 | /** |
|---|
| 1021 | Summary: |
|---|
| 1022 | This function drops first atom from the tail of pipe |
|---|
| 1023 | **/ |
|---|
| 1024 | void batom_pipe_drop(batom_pipe_t pipe); |
|---|
| 1025 | |
|---|
| 1026 | /** |
|---|
| 1027 | Summary: |
|---|
| 1028 | This function to initializes batom_vec structure |
|---|
| 1029 | **/ |
|---|
| 1030 | void batom_vec_init( |
|---|
| 1031 | batom_vec *vec, /* pointer to the batom_vec */ |
|---|
| 1032 | const void *base, /* start of the memory region */ |
|---|
| 1033 | size_t len /* length of memory region */ |
|---|
| 1034 | ); |
|---|
| 1035 | |
|---|
| 1036 | /** |
|---|
| 1037 | Summary: |
|---|
| 1038 | This function defines bit parser based on batom_cursor |
|---|
| 1039 | Description: |
|---|
| 1040 | This structure is used for internal book-keeping by batom_bitstream functions and |
|---|
| 1041 | shall not be accesses directly. |
|---|
| 1042 | **/ |
|---|
| 1043 | typedef struct batom_bitstream { |
|---|
| 1044 | batom_cursor *cursor; /* pointer to batom_cursor */ |
|---|
| 1045 | uint32_t cache; /* 32 bits prefetched from the cursor */ |
|---|
| 1046 | int cache_pos; /* number of bits left in the cache */ |
|---|
| 1047 | } batom_bitstream; |
|---|
| 1048 | |
|---|
| 1049 | /** |
|---|
| 1050 | Summary: |
|---|
| 1051 | This function initializes batom_bitstream structur |
|---|
| 1052 | **/ |
|---|
| 1053 | void batom_bitstream_init( |
|---|
| 1054 | batom_bitstream *bs, /* pointer to the batom_bitstream */ |
|---|
| 1055 | batom_cursor *cursor /* pointer to the batom_cursor which is used as a data source */ |
|---|
| 1056 | ); |
|---|
| 1057 | |
|---|
| 1058 | /** |
|---|
| 1059 | Summary: |
|---|
| 1060 | This function detects whether last bit was read from th batom_bitstream |
|---|
| 1061 | **/ |
|---|
| 1062 | bool batom_bitstream_eof( |
|---|
| 1063 | batom_bitstream *bs /* pointer to the batom_bitstream */ |
|---|
| 1064 | ); |
|---|
| 1065 | |
|---|
| 1066 | /** |
|---|
| 1067 | Summary: |
|---|
| 1068 | This function shows (peeks) current bit in the bitstream, but it doesn't advances to the next bit |
|---|
| 1069 | Result: |
|---|
| 1070 | BATOM_EOF if no bits left in the bitstream |
|---|
| 1071 | 0 or 1 otherwise |
|---|
| 1072 | **/ |
|---|
| 1073 | int batom_bitstream_show( |
|---|
| 1074 | batom_bitstream *bs /* pointer to the batom_bitstream */ |
|---|
| 1075 | ); |
|---|
| 1076 | |
|---|
| 1077 | /** |
|---|
| 1078 | Summary: |
|---|
| 1079 | This function returns current bit in the bitstream and advances to the next bit |
|---|
| 1080 | Result: |
|---|
| 1081 | BATOM_EOF if no bits left in the bitstream |
|---|
| 1082 | 0 or 1 otherwise |
|---|
| 1083 | **/ |
|---|
| 1084 | int batom_bitstream_bit( |
|---|
| 1085 | batom_bitstream *bs /* pointer to the batom_bitstream */ |
|---|
| 1086 | ); |
|---|
| 1087 | |
|---|
| 1088 | /** |
|---|
| 1089 | Summary: |
|---|
| 1090 | This function advances to the next bite |
|---|
| 1091 | Result: |
|---|
| 1092 | BATOM_EOF if no bits left in the bitstream |
|---|
| 1093 | **/ |
|---|
| 1094 | int batom_bitstream_drop( |
|---|
| 1095 | batom_bitstream *bs /* pointer to the batom_bitstream */ |
|---|
| 1096 | ); |
|---|
| 1097 | |
|---|
| 1098 | /** |
|---|
| 1099 | Summary: |
|---|
| 1100 | This function returns specified number of bits from the bitstream |
|---|
| 1101 | **/ |
|---|
| 1102 | unsigned batom_bitstream_bits( |
|---|
| 1103 | batom_bitstream *bs, /* pointer to the batom_bitstream */ |
|---|
| 1104 | unsigned nbits /* number of bits to read */ |
|---|
| 1105 | ); |
|---|
| 1106 | |
|---|
| 1107 | /** |
|---|
| 1108 | Summary: |
|---|
| 1109 | This function skips specified number of bits from the bitstream |
|---|
| 1110 | **/ |
|---|
| 1111 | void batom_bitstream_drop_bits( |
|---|
| 1112 | batom_bitstream *bs, /* pointer to the batom_bitstream */ |
|---|
| 1113 | unsigned nbits /* number of bits to skip */ |
|---|
| 1114 | ); |
|---|
| 1115 | |
|---|
| 1116 | /** |
|---|
| 1117 | Summary: |
|---|
| 1118 | This function prints out status of bitstream |
|---|
| 1119 | **/ |
|---|
| 1120 | void batom_bitstream_dump( |
|---|
| 1121 | const batom_bitstream *bs /* pointer to bitstream */ |
|---|
| 1122 | ); |
|---|
| 1123 | |
|---|
| 1124 | /** |
|---|
| 1125 | Summary: |
|---|
| 1126 | This function returns position in the cursor, if bitstream was only reading from cursor byte at the time. This function should be used to help implement switch from bitstream back to the bytstream. |
|---|
| 1127 | **/ |
|---|
| 1128 | size_t batom_bitstream_position( |
|---|
| 1129 | const batom_bitstream *bs /* pointer to bitstream */ |
|---|
| 1130 | ); |
|---|
| 1131 | |
|---|
| 1132 | /** |
|---|
| 1133 | Summary: |
|---|
| 1134 | This function returns position in the bitstream (in bits) |
|---|
| 1135 | **/ |
|---|
| 1136 | size_t batom_bitstream_bit_position( |
|---|
| 1137 | const batom_bitstream *bs /* pointer to bitstream */ |
|---|
| 1138 | ); |
|---|
| 1139 | |
|---|
| 1140 | |
|---|
| 1141 | |
|---|
| 1142 | |
|---|
| 1143 | #ifndef B_ATOM_FAST |
|---|
| 1144 | #define B_ATOM_FAST 1 |
|---|
| 1145 | #endif |
|---|
| 1146 | |
|---|
| 1147 | |
|---|
| 1148 | #if B_ATOM_FAST |
|---|
| 1149 | /** |
|---|
| 1150 | Summary: |
|---|
| 1151 | This macro reads next byte from the batom_cursor |
|---|
| 1152 | See also: |
|---|
| 1153 | batom_cursor_next |
|---|
| 1154 | **/ |
|---|
| 1155 | #define BATOM_NEXT(d,c) do {if((c)->left>0) {(c)->left--;d=*(c)->cursor++;} else {d=batom_cursor_next(c);}}while(0) |
|---|
| 1156 | /** |
|---|
| 1157 | Summary: |
|---|
| 1158 | This macro tests whether last byte was read from the batom_cursor |
|---|
| 1159 | **/ |
|---|
| 1160 | #define BATOM_IS_EOF(c) ((c)->left<0) |
|---|
| 1161 | /** |
|---|
| 1162 | Summary: |
|---|
| 1163 | This macro saves current position of the batom_cursor |
|---|
| 1164 | See also: |
|---|
| 1165 | batom_cursor_save |
|---|
| 1166 | **/ |
|---|
| 1167 | #define BATOM_SAVE(cur,check) do {(check)->cp_left=(cur)->left;(check)->cp_pos=(cur)->pos;}while(0) |
|---|
| 1168 | /** |
|---|
| 1169 | Summary: |
|---|
| 1170 | This macro makes an indentical copy of cursor |
|---|
| 1171 | See also: |
|---|
| 1172 | batom_cursor_clone |
|---|
| 1173 | **/ |
|---|
| 1174 | #define BATOM_CLONE(dst,src) *(dst)=*(src) |
|---|
| 1175 | /** |
|---|
| 1176 | Summary: |
|---|
| 1177 | This macro initializes batom_vec structure |
|---|
| 1178 | See also: |
|---|
| 1179 | batom_vec_init |
|---|
| 1180 | **/ |
|---|
| 1181 | #define BATOM_VEC_INIT(vec, vec_base, vec_len) B_ATOM_VEC_INIT(vec, vec_base, vec_len) |
|---|
| 1182 | |
|---|
| 1183 | /** |
|---|
| 1184 | Summary: |
|---|
| 1185 | This macro returns number of bytes avaliable in the cursor |
|---|
| 1186 | See also: |
|---|
| 1187 | batom_cursor_reserve |
|---|
| 1188 | **/ |
|---|
| 1189 | #define BATOM_RESERVE(cur,bytes) ((cur)->left >= (int)(bytes) ? (bytes):batom_cursor_reserve((cur),(bytes))) |
|---|
| 1190 | |
|---|
| 1191 | /** |
|---|
| 1192 | Summary: |
|---|
| 1193 | This macro reads 32-bit big endian number from cursor |
|---|
| 1194 | See also: |
|---|
| 1195 | batom_cursor_uint32_be |
|---|
| 1196 | **/ |
|---|
| 1197 | #define BATOM_UINT32_BE(cur) (((cur)->left >= 4) ? ( \ |
|---|
| 1198 | (cur)->left -= 4, (cur)->cursor+=4, \ |
|---|
| 1199 | ((((uint32_t)(cur)->cursor[0-4])<<24) | \ |
|---|
| 1200 | (((uint32_t)(cur)->cursor[1-4])<<16) | \ |
|---|
| 1201 | (((uint32_t)(cur)->cursor[2-4])<<8) | \ |
|---|
| 1202 | (cur)->cursor[3-4])) \ |
|---|
| 1203 | : batom_cursor_vword_be((cur), 4)) |
|---|
| 1204 | |
|---|
| 1205 | /** |
|---|
| 1206 | Summary: |
|---|
| 1207 | This macro advances cursor's read pointer |
|---|
| 1208 | See also: |
|---|
| 1209 | batom_cursor_skip |
|---|
| 1210 | **/ |
|---|
| 1211 | #define BATOM_SKIP(cur,bytes) do{ if((cur)->left >= (bytes)) { (cur)->left-=(bytes);(cur)->cursor+=(bytes);} else {batom_cursor_skip((cur),(bytes));}} while(0) |
|---|
| 1212 | /** |
|---|
| 1213 | * |
|---|
| 1214 | Summary: |
|---|
| 1215 | This macro returns pointer to the cursor continuous buffer or NULL |
|---|
| 1216 | See also: |
|---|
| 1217 | batom_cursor_continuous |
|---|
| 1218 | **/ |
|---|
| 1219 | #define BATOM_CONTINUOUS(cur,bytes) ((cur)->left >= (int)(bytes) ? (cur)->cursor ? batom_cursor_continuous((cur),(bytes)) |
|---|
| 1220 | |
|---|
| 1221 | /** |
|---|
| 1222 | Summary: |
|---|
| 1223 | This macro restores state of cursor |
|---|
| 1224 | See also: |
|---|
| 1225 | batom_cursor_rollback |
|---|
| 1226 | **/ |
|---|
| 1227 | #define BATOM_ROLLBACK(cur, chk) do { if( (cur)->left>=0 && (cur)->pos == (chk)->cp_pos ) { (cur)->cursor -= (chk)->cp_left - (cur)->left; (cur)->left=(chk)->cp_left;} else {batom_cursor_rollback((cur), (chk));}}while(0) |
|---|
| 1228 | |
|---|
| 1229 | |
|---|
| 1230 | #else /* B_ATOM_FAST */ |
|---|
| 1231 | #define BATOM_NEXT(d,c) ((d)=batom_cursor_next(c)) |
|---|
| 1232 | #define BATOM_IS_EOF(c) batom_cursor_eof(c) |
|---|
| 1233 | #define BATOM_SAVE(cur,check) batom_cursor_save((cur),(check)) |
|---|
| 1234 | #define BATOM_CLONE(dst,src) batom_cursor_clone((dst),(src)) |
|---|
| 1235 | #define BATOM_VEC_INIT(vec, vec_base, vec_len) batom_vec_init((vec), (vec_base), (vec_len)) |
|---|
| 1236 | #define BATOM_RESERVE(cur,bytes) batom_cursor_reserve((cur), (bytes)) |
|---|
| 1237 | #define BATOM_UINT32_BE(cur) batom_cursor_uint32_be(cur) |
|---|
| 1238 | #define BATOM_SKIP(cur, bytes) batom_cursor_skip((cur),(bytes() |
|---|
| 1239 | #define BATOM_ROLLBACK(cur, chk) batom_cursor_rollback((cur), (chk)) |
|---|
| 1240 | #endif /* B_ATOM_FAST */ |
|---|
| 1241 | |
|---|
| 1242 | #define B_ATOM_VEC_INIT(vec, vec_base, vec_len) do { (vec)->base=(void *)(vec_base);(vec)->len = (vec_len);(vec)->dirty = true; (vec)->unused_flags = 0;} while(0) |
|---|
| 1243 | |
|---|
| 1244 | #ifdef __cplusplus |
|---|
| 1245 | } |
|---|
| 1246 | #endif |
|---|
| 1247 | |
|---|
| 1248 | #endif /* __BATOM_H__ */ |
|---|
| 1249 | |
|---|