Skip to content

Commit

Permalink
Switch to stdint types.
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <Timothy.Rule@de.bosch.com>
  • Loading branch information
timrulebosch committed Feb 27, 2024
1 parent a47887a commit 0335ed0
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 90 deletions.
26 changes: 23 additions & 3 deletions doc/content/apis/ncodec/examples/ncodec_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
#include <dse/ncodec/codec.h>


#define MIMETYPE "application/x-codec-example"
#define MIMETYPE "application/x-codec-example"
#define UNUSED(x) ((void)x)


extern NCodecStreamVTable example_stream;
extern int stream_seek(NCODEC* nc, size_t pos, int op);


static void trace_read(NCODEC* nc, NCodecMessage* m)
{
UNUSED(nc);
NCodecCanMessage* msg = m;
printf("TRACE RX: %02d (length=%lu)\n", msg->frame_id, msg->len);
}

static void trace_write(NCODEC* nc, NCodecMessage* m)
{
UNUSED(nc);
NCodecCanMessage* msg = m;
printf("TRACE TX: %02d (length=%lu)\n", msg->frame_id, msg->len);
}


int main(int argc, char* argv[])
Expand All @@ -37,6 +52,11 @@ int main(int argc, char* argv[])
ncodec_config(nc, (struct NCodecConfigItem){
.name = "name", .value = "simple network codec" });

/* Install trace functions. */
NCodecInstance* _nc = (NCodecInstance*)nc;
_nc->trace.read = trace_read;
_nc->trace.write = trace_write;

/* Write a message to the Network Codec. */
ncodec_write(nc, &(struct NCodecCanMessage){ .frame_id = 42,
.frame_type = CAN_EXTENDED_FRAME,
Expand All @@ -45,7 +65,7 @@ int main(int argc, char* argv[])
ncodec_flush(nc);

/* Reposition to start of stream. */
stream_seek(nc, 0, NCODEC_SEEK_SET);
ncodec_seek(nc, 0, NCODEC_SEEK_SET);

/* Read the response from the Network Codec. */
NCodecCanMessage msg = {};
Expand Down
75 changes: 66 additions & 9 deletions doc/content/apis/ncodec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ typedef struct NCodecInstance {
const char* mime_type;
NCodecVTable codec;
NCodecStreamVTable* stream;
NCodecTraceVTable trace;
void* private;
}
```

Expand All @@ -116,6 +118,15 @@ typedef struct NCodecStreamVTable {
}
```

### NCodecTraceVTable

```c
typedef struct NCodecTraceVTable {
NCodecTraceWrite write;
NCodecTraceRead read;
}
```

### NCodecVTable

```c
Expand Down Expand Up @@ -279,22 +290,48 @@ implementation.

#### Returns

<int>
<int32_t>
: The number of bytes read from the Network Codec. Will be identical to the
value returned in `msg.len`.
Additional messages may remain on the Network Codec, after processing this
message, repeat calls to `ncodec_read` until -ENOMSG is returned.

-ENOMSG
-ENOMSG (-42)
: No message is available from the Network Codec.

-ENOSTR
-ENOSTR (-60)
: The object represented by `nc` does not represent a valid stream.

-ENOSR
-ENOSR (-63)
: No stream resource has been configured.

-EINVAL
-EINVAL (-22)
: Bad `msg` argument.



### ncodec_seek

#### Parameters

nc (NCODEC*)
: Network Codec object.

pos (size_t)
: Seek position relative to the seek operation.

op (int32_t)
: Seek operation (NCodecStreamSeekOperation).

#### Returns

+ve
: The position in the underlying stream object after the seek operation.

-ENOSTR (-60)
: The object represented by `nc` does not represent a valid stream.

-EINVAL (-22)
: Bad `msg` argument.


Expand All @@ -306,7 +343,7 @@ implementation.
nc (NCODEC*)
: Network Codec object.

index (int*)
index (int32_t*)
: (out) Index of the config item returned by this call. When there are no more
config items to be returned, this value is set to -1 and an empty
NetworkConfigItem object is returned.
Expand All @@ -318,6 +355,26 @@ NetworkConfigItem



### ncodec_tell

#### Parameters

nc (NCODEC*)
: Network Codec object.

#### Returns

+ve
: The current position in the underlying stream object.

-ENOSTR (-60)
: The object represented by `nc` does not represent a valid stream.

-ENOSR (-63)
: No stream resource has been configured.



### ncodec_truncate

#### Parameters
Expand Down Expand Up @@ -357,14 +414,14 @@ msg (NCodecMessage*)

#### Returns

+VE (int)
+VE (int32_t)
: The number of bytes written to the Network Codec. Will be identical to the
value provided in `msg.len`.

-ENOSTR
-ENOSTR (-60)
: The object represented by `nc` does not represent a valid stream.

-EINVAL
-EINVAL (-22)
: Bad `msg` argument.


Expand Down
28 changes: 14 additions & 14 deletions dse/ncodec/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Returns
: The Network Codec library could not be loaded. Inspect `errno` for more
details.
*/
extern int ncodec_load(const char* filename, const char* hint);
extern int32_t ncodec_load(const char* filename, const char* hint);


/**
Expand Down Expand Up @@ -129,7 +129,7 @@ Parameters
nc (NCODEC*)
: Network Codec object.
index (int*)
index (int32_t*)
: (out) Index of the config item returned by this call. When there are no more
config items to be returned, this value is set to -1 and an empty
NetworkConfigItem object is returned.
Expand All @@ -139,7 +139,7 @@ Returns
NetworkConfigItem
: A config item.
*/
inline NCodecConfigItem ncodec_stat(NCODEC* nc, int* index)
inline NCodecConfigItem ncodec_stat(NCODEC* nc, int32_t* index)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->codec.stat) {
Expand Down Expand Up @@ -172,7 +172,7 @@ msg (NCodecMessage*)
Returns
-------
+VE (int)
+VE (int32_t)
: The number of bytes written to the Network Codec. Will be identical to the
value provided in `msg.len`.
Expand All @@ -182,11 +182,11 @@ Returns
-EINVAL (-22)
: Bad `msg` argument.
*/
inline int ncodec_write(NCODEC* nc, NCodecMessage* msg)
inline int32_t ncodec_write(NCODEC* nc, NCodecMessage* msg)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->codec.write) {
int rc = _nc->codec.write(nc, msg);
int32_t rc = _nc->codec.write(nc, msg);
if (_nc->trace.write && (rc > 0)) _nc->trace.write(nc, msg);
return rc;
} else {
Expand Down Expand Up @@ -218,7 +218,7 @@ implementation.
Returns
-------
<int>
<int32_t>
: The number of bytes read from the Network Codec. Will be identical to the
value returned in `msg.len`.
Additional messages may remain on the Network Codec, after processing this
Expand All @@ -236,11 +236,11 @@ Returns
-EINVAL (-22)
: Bad `msg` argument.
*/
inline int ncodec_read(NCODEC* nc, NCodecMessage* msg)
inline int32_t ncodec_read(NCODEC* nc, NCodecMessage* msg)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->codec.read) {
int rc = _nc->codec.read(nc, msg);
int32_t rc = _nc->codec.read(nc, msg);
if (_nc->trace.read && (rc > 0)) _nc->trace.read(nc, msg);
return rc;
} else {
Expand Down Expand Up @@ -270,7 +270,7 @@ Returns
-ENOSR
: No stream resource has been configured.
*/
inline int ncodec_flush(NCODEC* nc)
inline int32_t ncodec_flush(NCODEC* nc)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->codec.flush) {
Expand Down Expand Up @@ -301,7 +301,7 @@ Returns
-ENOSR
: No stream resource has been configured.
*/
inline int ncodec_truncate(NCODEC* nc)
inline int32_t ncodec_truncate(NCODEC* nc)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->codec.truncate) {
Expand All @@ -324,7 +324,7 @@ nc (NCODEC*)
pos (size_t)
: Seek position relative to the seek operation.
op (int)
op (int32_t)
: Seek operation (NCodecStreamSeekOperation).
Returns
Expand All @@ -338,7 +338,7 @@ Returns
-EINVAL (-22)
: Bad `msg` argument.
*/
inline long ncodec_seek(NCODEC* nc, size_t pos, int op)
inline int64_t ncodec_seek(NCODEC* nc, size_t pos, int32_t op)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->stream && _nc->stream->seek) {
Expand Down Expand Up @@ -369,7 +369,7 @@ Returns
-ENOSR (-63)
: No stream resource has been configured.
*/
inline long ncodec_tell(NCODEC* nc)
inline int64_t ncodec_tell(NCODEC* nc)
{
NCodecInstance* _nc = (NCodecInstance*)nc;
if (_nc && _nc->stream && _nc->stream->tell) {
Expand Down
42 changes: 21 additions & 21 deletions dse/ncodec/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ typedef enum NCodecStreamPosOperation {
} NCodecStreamPosOperation;

typedef size_t (*NCodecStreamRead)(
NCODEC* nc, uint8_t** data, size_t* len, int pos_op);
NCODEC* nc, uint8_t** data, size_t* len, int32_t pos_op);
typedef size_t (*NCodecStreamWrite)(NCODEC* nc, uint8_t* data, size_t len);
typedef long (*NCodecStreamSeek)(NCODEC* nc, size_t pos, int op);
typedef long (*NCodecStreamTell)(NCODEC* nc);
typedef int (*NCodecStreamEof)(NCODEC* nc);
typedef int (*NCodecStreamClose)(NCODEC* nc);
typedef int64_t (*NCodecStreamSeek)(NCODEC* nc, size_t pos, int32_t op);
typedef int64_t (*NCodecStreamTell)(NCODEC* nc);
typedef int32_t (*NCodecStreamEof)(NCODEC* nc);
typedef int32_t (*NCodecStreamClose)(NCODEC* nc);

typedef struct NCodecStreamVTable {
NCodecStreamRead read;
Expand All @@ -142,16 +142,16 @@ typedef struct NCodecConfigItem {
typedef void NCodecMessage; /* Generic message container. */


typedef int NCodecLoad(const char* filename, const char* hint);
typedef int32_t NCodecLoad(const char* filename, const char* hint);
typedef NCODEC* NCodecOpen(const char* mime_type, NCodecStreamVTable* stream);
typedef NCODEC* NCodecCreate(const char* mime_type);

typedef int (*NCodecConfig)(NCODEC* nc, NCodecConfigItem item);
typedef NCodecConfigItem (*NCodecStat)(NCODEC* nc, int* index);
typedef int (*NCodecWrite)(NCODEC* nc, NCodecMessage* msg);
typedef int (*NCodecRead)(NCODEC* nc, NCodecMessage* msg);
typedef int (*NCodecFlush)(NCODEC* nc);
typedef int (*NCodecTruncate)(NCODEC* nc);
typedef int32_t (*NCodecConfig)(NCODEC* nc, NCodecConfigItem item);
typedef NCodecConfigItem (*NCodecStat)(NCODEC* nc, int32_t* index);
typedef int32_t (*NCodecWrite)(NCODEC* nc, NCodecMessage* msg);
typedef int32_t (*NCodecRead)(NCODEC* nc, NCodecMessage* msg);
typedef int32_t (*NCodecFlush)(NCODEC* nc);
typedef int32_t (*NCodecTruncate)(NCODEC* nc);
typedef void (*NCodecClose)(NCODEC* nc);

typedef struct NCodecVTable {
Expand Down Expand Up @@ -180,7 +180,7 @@ typedef struct NCodecInstance {
/* Trace interface (optional). */
NCodecTraceVTable trace;
/* Private reference data from API user (optional). */
void* private;
void* private;
} NCodecInstance;


Expand All @@ -205,19 +205,19 @@ typedef struct NCodecCanMessage {
DLL_PUBLIC NCodecCreate ncodec_create;

/* Implemented by integrator. */
DLL_PUBLIC int ncodec_load(const char* filename, const char* hint);
DLL_PUBLIC int32_t ncodec_load(const char* filename, const char* hint);
DLL_PUBLIC NCODEC* ncodec_open(
const char* mime_type, NCodecStreamVTable* stream);

/* Provided by codec.c (in this package). */
DLL_PUBLIC void ncodec_config(NCODEC* nc, NCodecConfigItem item);
DLL_PUBLIC NCodecConfigItem ncodec_stat(NCODEC* nc, int* index);
DLL_PUBLIC int ncodec_write(NCODEC* nc, NCodecMessage* msg);
DLL_PUBLIC int ncodec_read(NCODEC* nc, NCodecMessage* msg);
DLL_PUBLIC int ncodec_flush(NCODEC* nc);
DLL_PUBLIC int ncodec_truncate(NCODEC* nc);
DLL_PUBLIC NCodecConfigItem ncodec_stat(NCODEC* nc, int32_t* index);
DLL_PUBLIC int32_t ncodec_write(NCODEC* nc, NCodecMessage* msg);
DLL_PUBLIC int32_t ncodec_read(NCODEC* nc, NCodecMessage* msg);
DLL_PUBLIC int32_t ncodec_flush(NCODEC* nc);
DLL_PUBLIC int32_t ncodec_truncate(NCODEC* nc);
DLL_PUBLIC void ncodec_close(NCODEC* nc);
DLL_PUBLIC long ncodec_seek(NCODEC* nc, size_t pos, int op);
DLL_PUBLIC long ncodec_tell(NCODEC* nc);
DLL_PUBLIC int64_t ncodec_seek(NCODEC* nc, size_t pos, int32_t op);
DLL_PUBLIC int64_t ncodec_tell(NCODEC* nc);

#endif // DSE_NCODEC_CODEC_H_
Loading

0 comments on commit 0335ed0

Please sign in to comment.