das2C
das core C utilities (v3)
stream.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2024 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * Adapted from:
4  * Copyright (C) 2006 Jeremy Faden <jeremy-faden@uiowa.edu>
5  *
6  * This file is part of das2C, the Core Das2 C Library.
7  *
8  * das2C is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 2.1 as published
10  * by the Free Software Foundation.
11  *
12  * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
23 #ifndef _das_stream_h_
24 #define _das_stream_h_
25 
26 #include <stdbool.h>
27 #include <das2/packet.h>
28 #include <das2/dataset.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define STREAM_MODEL_MIXED -1
35 #define STREAM_MODEL_V2 2
36 #define STREAM_MODEL_V3 3
37 
38 #define STREAMDESC_CMP_SZ 48
39 #define STREAMDESC_VER_SZ 48
40 #define STREAMDESC_TYPE_SZ 48
41 
42 #define MAX_PKTIDS 100
43 #define MAX_FRAMES 12
44 
45 
92 typedef struct das_stream{
95 
96  /* TODO: Replace this with a sorted array of structures of the type
97 
98  {int id, DasDesc* pDesc}
99 
100  and use sorted insert and binary search to retrieve packet IDs
101  if greater then say 10. For 10 or less the "small vector"
102  assumption applies and we just an embedded 10-element array
103  and loops.
104  */
105  DasDesc* descriptors[MAX_PKTIDS];
106 
108  DasFrame* frames[MAX_FRAMES];
109 
110  /* Common properties */
111  char compression[STREAMDESC_CMP_SZ];
112  char type[STREAMDESC_TYPE_SZ];
113  char version[STREAMDESC_VER_SZ];
114  bool bDescriptorSent;
115 
123  void* pUser;
124 } DasStream;
125 
132 #define StreamDesc DasStream
133 
140 DAS_API DasStream* new_DasStream(void);
141 
142 #define new_StreamDesc new_DasStream
143 
144 DAS_API DasStream* new_DasStream_str(DasBuf* pBuf, int nModel);
145 
146 #define new_StreamDesc_str new_DasStream_str
147 
153 DAS_API char* DasStream_info(const DasStream* pSd, char* sBuf, int nLen);
154 
155 #define StreamDesc_info DasStream_info
156 
170 DAS_API DasStream* DasStream_copy(const DasStream* pThis);
171 
172 #define StreamDesc_copy DasStream_copy
173 
181 DAS_API void del_DasStream(DasStream* pThis);
182 
183 #define del_StreamDesc del_DasStream
184 
201 DAS_API size_t DasStream_getNPktDesc(const DasStream* pThis);
202 
203 #define StreamDesc_getNPktDesc DasStream_getNPktDesc
204 
228 DAS_API DasDesc* DasStream_nextPktDesc(const DasStream* pThis, int* pPrevPktId);
229 
230 #define StreamDesc_nextPktDesc DasStream_nextPktDesc
231 
248 DAS_API DasErrCode DasStream_addPktDesc(DasStream* pThis, DasDesc* pDesc, int nPktId);
249 
250 #define StreamDesc_addPktDesc DasStream_addPktDesc
251 
256 DAS_API void DasStream_setMonotonic(DasStream* pThis, bool isMonotonic );
257 
258 #define StreamDesc_setMonotonic DasStream_setMonotonic
259 
265 DAS_API void DasStream_addStdProps(DasStream* pThis);
266 
267 #define StreamDesc_addStdProps DasStream_addStdProps
268 
273 DAS_API void DasStream_addCmdLineProp(DasStream* pThis, int argc, char* argv[] );
274 
275 #define StreamDesc_addCmdLineProp DasStream_addCmdLineProp
276 
301  DasStream* pThis, DasEncoding* pXEncoder, das_units xUnits
302 );
303 
304 #define StreamDesc_createPktDesc DasStream_createPktDesc
305 
316  DasStream* pThis, ubyte id, const char* sName, const char* sType
317 );
318 
319 #define StreamDesc_createFrame DasStream_createFrame
320 
325 DAS_API int DasStream_nextFrameId(const DasStream* pThis);
326 
327 #define StreamDesc_nextFrameId DasStream_nextFrameId
328 
340 DAS_API PktDesc* DasStream_clonePktDesc(DasStream* pThis, const PktDesc* pd);
341 
342 #define StreamDesc_clonePktDesc DasStream_clonePktDesc
343 
357  DasStream* pThis, const DasStream* pOther, int nPktId
358 );
359 
360 #define StreamDesc_clonePktDescById DasStream_clonePktDescById
361 
369 DAS_API bool DasStream_isValidId(const DasStream* pThis, int nPktId);
370 
371 #define StreamDesc_isValidId DasStream_isValidId
372 
382 DAS_API PktDesc* DasStream_getPktDesc(const DasStream* pThis, int id);
383 
384 #define StreamDesc_getPktDesc DasStream_getPktDesc
385 
386 
397 DAS_API const DasFrame* DasStream_getFrame(const DasStream* pThis, int idx);
398 
399 #define StreamDesc_getFrame DasStream_getFrame
400 
402 DAS_API int8_t DasStream_getNumFrames(const DasStream* pThis);
403 
404 #define StreamDesc_getNumFrames DasStream_getNumFrames
405 
410 DAS_API int8_t DasStream_getFrameId(const DasStream* pThis, const char* sFrame);
411 
412 #define StreamDesc_getFrameId DasStream_getFrameId
413 
422  const DasStream* pThis, const char* sFrame
423 );
424 
425 #define StreamDesc_getFrameByName DasStream_getFrameByName
426 
434 const DasFrame* DasStream_getFrameById(const DasStream* pThis, ubyte id);
435 
436 #define StreamDesc_getFrameById DasStream_getFrameById
437 
442 DAS_API DasErrCode DasStream_freeSubDesc(DasStream* pThis, int nPktId);
443 
444 #define StreamDesc_freeDesc DasStream_freeSubDesc
445 
449 DAS_API int DasStream_getOffset(DasStream* pThis);
450 
451 #define StreamDesc_getOffset DasStream_getOffset
452 
461 
462 #define StreamDesc_encode DasStream_encode
463 
479  DasBuf* pBuf, DasStream* pSd, int nPktId, int nModel
480 );
481 
482 
483 #ifdef __cplusplus
484 }
485 #endif
486 
487 #endif /* _das_stream_h_ */
Objects which define a iteration space.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: defs.h:164
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
DAS_API bool DasStream_isValidId(const DasStream *pThis, int nPktId)
Check to see if an packet ID has been defined for the stream.
DAS_API DasDesc * DasDesc_decode(DasBuf *pBuf, DasStream *pSd, int nPktId, int nModel)
Packtized Stream Descriptor Factory Function.
DAS_API int DasStream_nextFrameId(const DasStream *pThis)
Get the next open frame ID.
DAS_API int8_t DasStream_getNumFrames(const DasStream *pThis)
Return the number of frames defined in the stream.
DAS_API int8_t DasStream_getFrameId(const DasStream *pThis, const char *sFrame)
Get a frame index given it's name.
Buffer class to handle accumulating byte streams.
Definition: buffer.h:47
Base structure for Stream Header Items.
Definition: descriptor.h:74
Reading and writing values to buffers.
Definition: encoding.h:108
Stores the definitions for a directional coordinate frame.
Definition: frame.h:57
Describes the stream itself, in particular the compression used, current packetDescriptors,...
Definition: stream.h:92
DAS_API PktDesc * DasStream_createPktDesc(DasStream *pThis, DasEncoding *pXEncoder, das_units xUnits)
Creates a descriptor structure that for a stream packet type.
DAS_API PktDesc * DasStream_getPktDesc(const DasStream *pThis, int id)
Get the packet descriptor associated with an ID.
DAS_API DasErrCode DasStream_freeSubDesc(DasStream *pThis, int nPktId)
Free any resources associated with this PacketDescriptor, and release it's id number for use with a n...
DAS_API void del_DasStream(DasStream *pThis)
Delete a stream descriptor and all it's sub objects.
DAS_API int DasStream_getOffset(DasStream *pThis)
An I/O function that makes sense to use for either operation.
DAS_API DasStream * new_DasStream(void)
Creates a new blank StreamDesc.
DAS_API char * DasStream_info(const DasStream *pSd, char *sBuf, int nLen)
Print a short description of the stream to a string buffer, This is not a serialization,...
DAS_API DasDesc * DasStream_nextPktDesc(const DasStream *pThis, int *pPrevPktId)
Iterate over packet descriptiors.
DAS_API void DasStream_setMonotonic(DasStream *pThis, bool isMonotonic)
Indicates if the xtags on the stream are monotonic, in which case there might be optimal ways of proc...
DAS_API void DasStream_addStdProps(DasStream *pThis)
Adds metadata into the property set of the DasStream.
DAS_API DasErrCode DasStream_encode(DasStream *pThis, DasBuf *pBuf)
Encode a DasStream to an XML string.
const DasFrame * DasStream_getFrameById(const DasStream *pThis, ubyte id)
Get a frame pointer by it's id.
DAS_API PktDesc * DasStream_clonePktDescById(DasStream *pThis, const DasStream *pOther, int nPktId)
Deepcopy a PacketDescriptor from one stream to another.
DAS_API void DasStream_addCmdLineProp(DasStream *pThis, int argc, char *argv[])
Adds the command line into the property set of the DasStream.
DasDesc base
The base structure.
Definition: stream.h:94
DAS_API const DasFrame * DasStream_getFrameByName(const DasStream *pThis, const char *sFrame)
Get a frame pointer by it's name.
DAS_API DasErrCode DasStream_addPktDesc(DasStream *pThis, DasDesc *pDesc, int nPktId)
Attach a packet descriptor to this stream.
DAS_API DasFrame * DasStream_createFrame(DasStream *pThis, ubyte id, const char *sName, const char *sType)
Define a new vector direction frame for the stream.
DAS_API DasStream * DasStream_copy(const DasStream *pThis)
Creates a deep-copy of an existing DasStream object.
DAS_API const DasFrame * DasStream_getFrame(const DasStream *pThis, int idx)
Get a frame pointer by it's index.
DAS_API size_t DasStream_getNPktDesc(const DasStream *pThis)
Get the number of packet descriptors defined for this stream.
DAS_API PktDesc * DasStream_clonePktDesc(DasStream *pThis, const PktDesc *pd)
Make a deep copy of a PacketDescriptor on a new stream.
void * pUser
User data pointer.
Definition: stream.h:123
Holds information for a single packet type in a Das2 stream.
Definition: packet.h:138