aboutsummaryrefslogtreecommitdiffstats
path: root/lcmtype/eventlog.h
diff options
context:
space:
mode:
Diffstat (limited to 'lcmtype/eventlog.h')
-rw-r--r--lcmtype/eventlog.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/lcmtype/eventlog.h b/lcmtype/eventlog.h
new file mode 100644
index 0000000..8999b1c
--- /dev/null
+++ b/lcmtype/eventlog.h
@@ -0,0 +1,150 @@
1#ifndef _LCM_EVENTLOG_H_
2#define _LCM_EVENTLOG_H_
3
4#include <stdint.h>
5#include <stdio.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#ifndef LCM_API_FUNCTION
12#ifdef WIN32
13#define LCM_API_FUNCTION __declspec(dllexport)
14#else
15#define LCM_API_FUNCTION
16#endif // WIN32
17#endif // LCM_API_FUNCTION
18
19/**
20 * @defgroup LcmC_lcm_eventlog_t lcm_eventlog_t
21 * @ingroup LcmC
22 * @brief Read and write %LCM log files
23 *
24 * <tt> #include <lcm.h> </tt>
25 *
26 * Linking: <tt> `pkg-config --libs lcm` </tt>
27 *
28 * @{
29 */
30
31typedef struct _lcm_eventlog_t lcm_eventlog_t;
32struct _lcm_eventlog_t {
33 /**
34 * The underlying file handle. Use this at your own risk. Example use
35 * cases include implementing your own seek routine for read-mode logs, or
36 * rewinding the file pointer to the beginning of the log file.
37 */
38 FILE *f;
39 /**
40 * Do not use.
41 */
42 int64_t eventcount;
43};
44
45/**
46 * Represents a single event (message) in a log file.
47 */
48typedef struct _lcm_eventlog_event_t lcm_eventlog_event_t;
49struct _lcm_eventlog_event_t {
50 /**
51 * A monotonically increasing number assigned to the message to identify it
52 * in the log file.
53 */
54 int64_t eventnum;
55 /**
56 * Time that the message was received, in microseconds since the UNIX
57 * epoch
58 */
59 int64_t timestamp;
60 /**
61 * Length of @c channel, in bytes
62 */
63 int32_t channellen;
64 /**
65 * Length of @c data, in bytes
66 */
67 int32_t datalen;
68
69 /**
70 * Channel that the message was received on
71 */
72 char *channel;
73 /**
74 * Raw byte buffer containing the message payload.
75 */
76 void *data;
77};
78
79/**
80 * Open a log file for reading or writing.
81 *
82 * @param path Log file to open
83 * @param mode "r" (read mode) or "w" (write mode)
84 *
85 * @return a newly allocated lcm_eventlog_t, or NULL on failure.
86 */
87LCM_API_FUNCTION
88lcm_eventlog_t *lcm_eventlog_create(const char *path, const char *mode);
89
90/**
91 * Read the next event in the log file. Valid in read mode only. Free the
92 * returned structure with lcm_eventlog_free_event() after use.
93 *
94 * @param eventlog The log file object
95 *
96 * @return the next event in the log file, or NULL when the end of the file has
97 * been reached.
98 */
99LCM_API_FUNCTION
100lcm_eventlog_event_t *lcm_eventlog_read_next_event(lcm_eventlog_t *eventlog);
101
102/**
103 * Free a structure returned by lcm_eventlog_read_next_event().
104 *
105 * @param event A structure returned by lcm_eventlog_read_next_event()
106 */
107LCM_API_FUNCTION
108void lcm_eventlog_free_event(lcm_eventlog_event_t *event);
109
110/**
111 * Seek (approximately) to a particular timestamp.
112 *
113 * @param eventlog The log file object
114 * @param ts Timestamp of the target event in the log file.
115 *
116 * @return 0 on success, -1 on failure
117 */
118LCM_API_FUNCTION
119int lcm_eventlog_seek_to_timestamp(lcm_eventlog_t *eventlog, int64_t ts);
120
121/**
122 * Write an event into a log file. Valid in write mode only.
123 *
124 * @param eventlog The log file object
125 * @param event The event to write to the file. On return, the eventnum field
126 * will be filled in for you.
127 *
128 * @return 0 on success, -1 on failure.
129 */
130LCM_API_FUNCTION
131int lcm_eventlog_write_event(lcm_eventlog_t *eventlog,
132 lcm_eventlog_event_t *event);
133
134/**
135 * Close a log file and release allocated resources.
136 *
137 * @param eventlog The log file object
138 */
139LCM_API_FUNCTION
140void lcm_eventlog_destroy(lcm_eventlog_t *eventlog);
141
142/**
143 * @}
144 */
145
146#ifdef __cplusplus
147}
148#endif
149
150#endif