GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> GRBP / dev > attstream / rad750
#include <GRBP/io/ATT_stream.h>
#include <GRBP/io/ATT_dgm.h>
#include <PBI/PTR.h>
#include <PBI/Endianness.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
Classes | |
struct | _streamCloseCbp |
Structure to bind the close callback routine with a parameter. More... | |
struct | _ATT_streamHeader |
Standard header for both input and output streams. More... | |
struct | _ATT_istreamBody |
Internal structure used to control the input access to an ATT file or data section. More... | |
struct | _ATT_ostreamBody |
Context for an output event/packet stream. More... | |
union | _ATT_streamBody |
Union of all the stream types. More... | |
union | _ATT_stream |
Standard ATT stream handle. More... | |
Typedefs | |
typedef enum _ATT_STREAM_DIR_K | ATT_STREAM_DIR_K |
Typedef for enum _ATT_STREAM_DIR_K. | |
typedef enum _ATT_STREAM_DIR_K | ATT_streamDir |
Typedef for enum _ATT_STREAM_DIR_K. | |
typedef enum _ATT_STREAM_BOUNDS_K | ATT_STREAM_BOUNDS_K |
Typedef for enum _ATT_STREAM_BOUNDS_K. | |
typedef int(* | streamClose )(void *file) |
Generic stream close function signature. | |
typedef struct _streamCloseCbp | streamCloseCbp |
Typedef for struct _streamCloseCbp. | |
typedef struct _ATT_streamHeader | ATT_streamHeader |
Typedef for struct _ATT_streamHeader. | |
typedef struct _ATT_istreamBody | ATT_istreamBody |
Typedef for struct _ATT_streamFileBody. | |
typedef struct _ATT_ostreamBody | ATT_ostreamBody |
Typedef for struct _ATT_ostreamBody. | |
typedef union _ATT_streamBody | ATT_streamBody |
Typedef for union _ATT_streamBody. | |
typedef struct _ATT_stream | ATT_stream |
Typedef for struct _ATT_stream. | |
Enumerations | |
enum | _ATT_STREAM_DIR_K { ATT_STREAM_DIR_K_READ = 0, ATT_STREAM_DIR_K_WRITE = 1 } |
Enumeration of the IO direction, i.e. read or write. More... | |
enum | _ATT_STREAM_BOUNDS_K { ATT_STREAM_BOUNDS_K_MAXDGM = 1 << 16, ATT_STREAM_BOUNDS_K_LOWER = ATT_STREAM_BOUNDS_K_MAXDGM, ATT_STREAM_BOUNDS_K_UPPER = 1 << 25, ATT_STREAM_BOUNDS_K_OVERFLOW = ATT_STREAM_BOUNDS_K_MAXDGM } |
Upper and lower bounds on the segment size. More... | |
Functions | |
static ATT_stream * | fileOpen (ATT_streamType type, const char *fileName, int segment_size) |
Opens a ATT file for reading. | |
static int | fileRead (ATT_stream *stream, unsigned int *ptr, size_t nbytes) |
Reads the specified number of bytes. | |
static ATT_stream * | map (unsigned int *grb_data) |
Prepares an in memory data structure to be read. | |
static void * | mem_alloc (unsigned int nbytes) |
Wraps the 'real' allocator. | |
static void | mem_free (void *ptr) |
Wraps the 'real' deallocator. | |
static __inline void | dgm_swap (ATT_dgm *dgm) |
Byte-swap the datagram. | |
static __inline void | swap32_lclXbigN (unsigned int *w, int n) |
ATT_stream * | ATT_streamOpen (ATT_streamType type, const void *name, int segment) |
Opens a ATT file or data for reading. | |
int | ATT_streamRead (ATT_stream *stream) |
Reads the ATT file associated with the event stream handle istream. | |
const ATT_dgm * | ATT_streamLocate (ATT_stream *stream, int advance) |
Returns a pointer to the current packet and, optionally, advances the current packet to the next packet. | |
const ATT_attitude * | ATT_streamAttNext (ATT_stream *stream) |
Returns a pointer to the next attitude record or NULL if exhausted. | |
int | ATT_streamClose (ATT_stream *stream) |
Closes the file after it has been read. | |
ATT_stream * | ATT_streamCreate (ATT_streamType type, const char *name, int rsvd_mbz) |
Creates a file to receive the ATT data packets. | |
int | ATT_streamFree (ATT_stream *stream) |
Frees the memory associated with the contents of the file. | |
int | ATT_streamDgmWrite (ATT_stream *stream, const ATT_dgm *dgm) |
Writes the specified packet to the output file. |
CVS $Id: ATT_stream.c,v 1.3 2011/03/30 22:11:52 russell Exp $
Typedef for enum _ATT_STREAM_BOUNDS_K.
The lower bound must be constrained to be at least the size of the largest event.
The upper bound is really only a default used and can be easily overridden. The upper bound must be at least the size of a maximally sized event, but really is set by purely practical considerations. Since this is unit of a read, on very large files, there can be a considerable delay if this read is very large. This is annoying, particularly in the case where one working interactively and just processing the first few events. So this size is set to be something that is large enough to be accommodate most files, but small enough to keep the read latency to something tolerable on human timescales.
The overflow region is provided as an area where discontigious events may be reassembled into a contigious block of memory. As such, it must be at least the size of a maximally sized event.
enum _ATT_STREAM_BOUNDS_K |
Upper and lower bounds on the segment size.
enum _ATT_STREAM_DIR_K |
const ATT_attitude* ATT_streamAttNext | ( | ATT_stream * | stream | ) |
Returns a pointer to the next attitude record or NULL if exhausted.
stream | The attitude stream |
References ATT_streamLocate(), _ATT_stream::bdy, _ATT_streamBody::in, _ATT_istreamBody::lst_att, and _ATT_istreamBody::nxt_att.
int ATT_streamClose | ( | ATT_stream * | stream | ) |
Closes the file after it has been read.
This function only closes the file after its contents have been read into memory. To free the memory associated with the contents of the file, the user must call ATT_streamFree().
References _ATT_streamHeader::close, _ATT_stream::hdr, _streamCloseCbp::prm, and _streamCloseCbp::rtn.
ATT_stream* ATT_streamCreate | ( | ATT_streamType | type, | |
const char * | name, | |||
int | rsvd_mbz | |||
) |
Creates a file to receive the ATT data packets.
type | The type of stream to open ATT_STREAM_TYPE_K_FILE or ATT_STREAM_TYPE_K_DATA | |
name | The name of the section or file to create | |
rsvd_mbz | Reserved, must be 0 |
References ATT_STREAM_DIR_K_WRITE, ATT_STREAM_TYPE_K_DATA, ATT_STREAM_TYPE_K_FILE, _ATT_stream::bdy, _ATT_streamHeader::close, _ATT_streamHeader::dir, _ATT_ostreamBody::file, _ATT_streamHeader::free, _ATT_stream::hdr, mem_alloc(), _ATT_ostreamBody::name, _ATT_streamBody::out, _streamCloseCbp::prm, _streamCloseCbp::rtn, and _ATT_streamHeader::type.
int ATT_streamDgmWrite | ( | ATT_stream * | stream, | |
const ATT_dgm * | dgm | |||
) |
Writes the specified packet to the output file.
stream | The output stream handle | |
dgm | The datagram to write |
References _ATT_stream::bdy, _ATT_ostreamBody::file, and _ATT_streamBody::out.
int ATT_streamFree | ( | ATT_stream * | stream | ) |
Frees the memory associated with the contents of the file.
stream | The event builder stream handle |
References _ATT_streamHeader::free, _ATT_stream::hdr, and mem_free().
const ATT_dgm* ATT_streamLocate | ( | ATT_stream * | stream, | |
int | advance | |||
) |
Returns a pointer to the current packet and, optionally, advances the current packet to the next packet.
stream | The stream handle | |
advance | If non-zero, advance to the internal next packet pointer to the next packet. This is the normal way one would serially read a file of packets |
References ATT__dgmNext(), _ATT_ctbbdy::attitude, _ATT_ctb::bdy, _ATT_stream::bdy, _ATT_dgm::ctb, _ATT_istreamBody::cur_dgm, dgm_swap(), _ATT_streamBody::in, _ATT_istreamBody::lst_att, _ATT_istreamBody::lst_dgm, and _ATT_istreamBody::nxt_att.
Referenced by ATT_streamAttNext().
ATT_stream* ATT_streamOpen | ( | ATT_streamType | type, | |
const void * | name, | |||
int | segment | |||
) |
Opens a ATT file or data for reading.
type | The type of stream to open
| |
name | The name of the ATT file or the address of data section to open | |
segment | Interpretation is dependent on type. If type is
|
References ATT_STREAM_TYPE_K_DATA, ATT_STREAM_TYPE_K_FILE, ATT_STREAM_TYPE_K_FILESEG, fileOpen(), and map().
int ATT_streamRead | ( | ATT_stream * | stream | ) |
Reads the ATT file associated with the event stream handle istream.
stream | A previously opened event builder stream handle |
0,if | successful | |
-1,if | not |
References ATT_STREAM_TYPE_K_FILE, _ATT_stream::bdy, _ATT_istreamBody::buf, _ATT_istreamBody::cur_dgm, fileRead(), _ATT_stream::hdr, _ATT_streamBody::in, _ATT_istreamBody::lst_dgm, _ATT_istreamBody::seg_size, and _ATT_streamHeader::type.
static __inline void dgm_swap | ( | ATT_dgm * | dgm | ) | [static] |
static ATT_stream * fileOpen | ( | ATT_streamType | type, | |
const char * | fileName, | |||
int | segmentSize | |||
) | [static] |
Opens a ATT file for reading.
type | The stream type, must be either
| |
fileName | The name of the ATT file to open | |
segmentSize | The largest portion of the file that will be buffered on a read.
|
References ATT_STREAM_BOUNDS_K_LOWER, ATT_STREAM_BOUNDS_K_OVERFLOW, ATT_STREAM_BOUNDS_K_UPPER, ATT_STREAM_DIR_K_READ, ATT_STREAM_TYPE_K_FILE, _ATT_stream::bdy, _ATT_istreamBody::buf, _ATT_streamHeader::close, _ATT_istreamBody::cur_dgm, _ATT_istreamBody::cur_size, _ATT_streamHeader::dir, _ATT_istreamBody::fate, _ATT_istreamBody::fd, _ATT_streamHeader::free, _ATT_stream::hdr, _ATT_streamBody::in, mem_alloc(), _ATT_istreamBody::name, _ATT_istreamBody::nprocess, _streamCloseCbp::prm, _streamCloseCbp::rtn, _ATT_istreamBody::seg_size, _ATT_istreamBody::tot_left, _ATT_istreamBody::tot_size, _ATT_streamHeader::type, and _ATT_istreamBody::which.
Referenced by ATT_streamOpen().
static int fileRead | ( | ATT_stream * | stream, | |
unsigned int * | ptr, | |||
size_t | nbytes | |||
) | [static] |
Reads the specified number of bytes.
References _ATT_stream::bdy, _ATT_istreamBody::fd, _ATT_streamBody::in, and _ATT_istreamBody::name.
Referenced by ATT_streamRead().
static ATT_stream * map | ( | unsigned int * | data | ) | [static] |
Prepares an in memory data structure to be read.
data | Pointer to the in memory data structure. |
References ATT_STREAM_DIR_K_READ, ATT_STREAM_TYPE_K_DATA, _ATT_streamHeader::close, _ATT_streamHeader::dir, _ATT_streamHeader::free, _ATT_stream::hdr, mem_alloc(), _streamCloseCbp::prm, _streamCloseCbp::rtn, and _ATT_streamHeader::type.
Referenced by ATT_streamOpen().
static void * mem_alloc | ( | unsigned int | nbytes | ) | [static] |
Wraps the 'real' allocator.
nbytes | The number of bytes |
Referenced by ATT_streamCreate(), fileOpen(), and map().
static void mem_free | ( | void * | ptr | ) | [static] |
Wraps the 'real' deallocator.
ptr | Pointer to the memory to free |
Referenced by ATT_streamFree().