Skip to content

Commit d8a5739

Browse files
authored
Merge pull request #35 from SpringQL/docs/header-file-doc
docs: update doc comments on functions and structures
2 parents 260b343 + f689bf1 commit d8a5739

6 files changed

Lines changed: 246 additions & 176 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "springql-client-c"
3-
version = "0.9.0"
3+
version = "0.9.0+2"
44

55
authors = ["Sho Nakatani <lay.sakura@gmail.com>"]
66
license = "MIT OR Apache-2.0"

springql.h

Lines changed: 121 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* Errno (error number) to be returned erroneous functions.
10-
*
11-
* See springql_core::api::error::SpringError for details of each error reason.
1210
*/
1311
typedef enum SpringErrno {
1412
Ok = 0,
@@ -37,210 +35,253 @@ typedef enum SpringErrno {
3735
CNull = -127,
3836
} SpringErrno;
3937

38+
/**
39+
* Configuration.
40+
*/
4041
typedef void *SpringConfig;
4142

43+
/**
44+
* Pipeline (dataflow definition) in SpringQL.
45+
*/
4246
typedef void *SpringPipeline;
4347

48+
/**
49+
* Row object from an in memory queue.
50+
*/
4451
typedef void *SpringRow;
4552

4653
/**
47-
* See: springql_core::api::spring_config_default
54+
* Returns default configuration.
4855
*
4956
* Returned value is not modifiable (it is just a void pointer).
5057
* If you would like to change the default configuration, use `spring_config_toml()` instead.
5158
*/
5259
SpringConfig *spring_config_default(void);
5360

5461
/**
55-
* See: springql_core::api::spring_config_default
62+
* Configuration by TOML format string.
5663
*
5764
* Returned value is not modifiable (it is just a void pointer).
58-
* If you would like to change the default configuration, use `spring_config_toml()` instead.
5965
*
60-
* # Safety
66+
* # Parameters
6167
*
62-
* This function is unsafe because it uses raw pointer.
68+
* - `overwrite_config_toml`: TOML format configuration to overwrite default.
69+
* See https://springql.github.io/deployment/configuration for TOML format and configuration values.
70+
*
71+
* # Panics
72+
*
73+
* Currently, the process aborts when:
74+
*
75+
* - `overwrite_config_toml` includes invalid key and/or value.
76+
* - `overwrite_config_toml` is not valid as TOML.
6377
*/
6478
SpringConfig *spring_config_toml(const char *overwrite_config_toml);
6579

6680
/**
67-
* # Returns
68-
*
69-
* - `0`: if there are no recent errors.
70-
* - `< 0`: SpringErrno
81+
* Frees heap occupied by a `SpringConfig`.
7182
*
72-
* # Safety
83+
* # Returns
7384
*
74-
* This function is unsafe because it uses raw pointer.
85+
* - `Ok`: on success.
86+
* - `CNull`: `config` is a NULL pointer.
7587
*/
7688
enum SpringErrno spring_config_close(SpringConfig *config);
7789

7890
/**
79-
* See: springql_core::api::spring_open
91+
* Creates and open an in-process stream pipeline.
8092
*
8193
* # Returns
8294
*
8395
* - non-NULL: on success
8496
* - NULL: on failure. Check spring_last_err() for details.
8597
*
86-
* # Safety
98+
* # Errors
8799
*
88-
* This function is unsafe because it uses raw pointer.
100+
* No errors are expected currently.
89101
*/
90102
SpringPipeline *spring_open(const SpringConfig *config);
91103

92104
/**
93-
* # Returns
94-
*
95-
* - `0`: if there are no recent errors.
96-
* - `< 0`: SpringErrno
105+
* Frees heap occupied by a `SpringPipeline`.
97106
*
98-
* # Safety
107+
* # Returns
99108
*
100-
* This function is unsafe because it uses raw pointer.
109+
* - `Ok`: on success.
110+
* - `CNull`: `pipeline` is a NULL pointer.
101111
*/
102112
enum SpringErrno spring_close(SpringPipeline *pipeline);
103113

104114
/**
105-
* See: springql_core::api::spring_command
115+
* Execute commands (DDL) to modify the pipeline.
106116
*
107117
* # Returns
108118
*
109-
* - `0`: if there are no recent errors.
110-
* - `< 0`: SpringErrno
111-
*
112-
* # Safety
113-
*
114-
* This function is unsafe because it uses raw pointer.
119+
* - `Ok`: on success.
120+
* - `Sql`:
121+
* - Invalid SQL syntax.
122+
* - Refers to undefined objects (streams, pumps, etc)
123+
* - Other semantic errors.
124+
* - `InvalidOption`:
125+
* - `OPTIONS` in `CREATE` statement includes invalid key or value.
115126
*/
116127
enum SpringErrno spring_command(const SpringPipeline *pipeline, const char *sql);
117128

118129
/**
119-
* See: springql_core::api::spring_pop
130+
* Pop a row from an in memory queue. This is a blocking function.
131+
*
132+
* Do not call this function from threads.
133+
* If you need to pop from multiple in-memory queues using threads, use `spring_pop_non_blocking()`.
134+
* See: https://github.com/SpringQL/SpringQL/issues/125
120135
*
121136
* # Returns
122137
*
123138
* - non-NULL: on success
124139
* - NULL: on failure. Check spring_last_err() for details.
125140
*
126-
* # Safety
141+
* # Errors
127142
*
128-
* This function is unsafe because it uses raw pointer.
143+
* - `Unavailable`: queue named `queue` does not exist.
129144
*/
130145
SpringRow *spring_pop(const SpringPipeline *pipeline, const char *queue);
131146

132147
/**
133-
* See: springql_core::api::spring_pop_non_blocking
148+
* Pop a row from an in memory queue. This is a non-blocking function.
134149
*
135150
* # Returns
136151
*
137152
* - non-NULL: Successfully get a row.
138153
* - NULL: Error occurred if `is_err` is true (check spring_last_err() for details). Otherwise, any row is not in the queue.
139154
*
140-
* # Safety
155+
* # Errors
141156
*
142-
* This function is unsafe because it uses raw pointer.
157+
* - `Unavailable`: queue named `queue` does not exist.
143158
*/
144159
SpringRow *spring_pop_non_blocking(const SpringPipeline *pipeline,
145160
const char *queue,
146161
bool *is_err);
147162

148163
/**
149-
* # Returns
150-
*
151-
* - `0`: if there are no recent errors.
152-
* - `< 0`: SpringErrno
164+
* Frees heap occupied by a `SpringRow`.
153165
*
154-
* # Safety
166+
* # Returns
155167
*
156-
* This function is unsafe because it uses raw pointer.
168+
* - `Ok`: on success.
169+
* - `CNull`: `pipeline` is a NULL pointer.
157170
*/
158171
enum SpringErrno spring_row_close(SpringRow *row);
159172

160173
/**
161-
* See: springql_core::api::spring_column_i16
174+
* Get a 2-byte integer column.
162175
*
163-
* # Returns
176+
* # Parameters
164177
*
165-
* - `0`: if there are no recent errors.
166-
* - `< 0`: SpringErrno
178+
* - `row`: A `SpringRow` pointer to get a column value from.
179+
* - `i_col`: The column index to get a value from.
180+
* - `out`: A pointer to a buffer to store the column value.
167181
*
168-
* # Safety
182+
* # Returns
169183
*
170-
* This function is unsafe because it uses raw pointer.
184+
* - `Ok`: On success.
185+
* - `Unavailable`:
186+
* - Column pointed by `i_col` is already fetched.
187+
* - `i_col` is out of range.
188+
* - `CNull`: Column value is NULL.
171189
*/
172190
enum SpringErrno spring_column_short(const SpringRow *row, uint16_t i_col, short *out);
173191

174192
/**
175-
* See: springql_core::api::spring_column_i32
193+
* Get a 4-byte integer column.
176194
*
177-
* # Returns
195+
* # Parameters
178196
*
179-
* - `0`: if there are no recent errors.
180-
* - `< 0`: SpringErrno
197+
* - `row`: A `SpringRow` pointer to get a column value from.
198+
* - `i_col`: The column index to get a value from.
199+
* - `out`: A pointer to a buffer to store the column value.
181200
*
182-
* # Safety
201+
* # Returns
183202
*
184-
* This function is unsafe because it uses raw pointer.
203+
* - `Ok`: On success.
204+
* - `Unavailable`:
205+
* - Column pointed by `i_col` is already fetched.
206+
* - `i_col` is out of range.
207+
* - `CNull`: Column value is NULL.
185208
*/
186209
enum SpringErrno spring_column_int(const SpringRow *row, uint16_t i_col, int *out);
187210

188211
/**
189-
* See: springql_core::api::spring_column_i64
212+
* Get an 8-byte integer column.
190213
*
191-
* # Returns
214+
* # Parameters
192215
*
193-
* - `0`: if there are no recent errors.
194-
* - `< 0`: SpringErrno
216+
* - `row`: A `SpringRow` pointer to get a column value from.
217+
* - `i_col`: The column index to get a value from.
218+
* - `out`: A pointer to a buffer to store the column value.
195219
*
196-
* # Safety
220+
* # Returns
197221
*
198-
* This function is unsafe because it uses raw pointer.
222+
* - `Ok`: On success.
223+
* - `Unavailable`:
224+
* - Column pointed by `i_col` is already fetched.
225+
* - `i_col` is out of range.
226+
* - `CNull`: Column value is NULL.
199227
*/
200228
enum SpringErrno spring_column_long(const SpringRow *row, uint16_t i_col, long *out);
201229

202230
/**
203-
* See: springql_core::api::spring_column_text
231+
* Get a text column.
204232
*
205-
* This returns UTF-8 string into `out`.
233+
* # Parameters
206234
*
207-
* # Returns
235+
* - `row`: A `SpringRow` pointer to get a column value from.
236+
* - `i_col`: The column index to get a value from.
237+
* - `out`: A pointer to a buffer to store the column value.
238+
* - `out_len`: The length of the buffer pointed by `out`.
208239
*
209-
* - `0`: if there are no recent errors.
210-
* - `> 0`: the length of the recent error message.
211-
* - `< 0`: SpringErrno
212-
*
213-
* # Safety
240+
* # Returns
214241
*
215-
* This function is unsafe because it uses raw pointer.
242+
* - `> 0`: Length of the text.
243+
* - `Unavailable`:
244+
* - Column pointed by `i_col` is already fetched.
245+
* - `i_col` is out of range.
246+
* - `CNull`: Column value is NULL.
216247
*/
217248
int spring_column_text(const SpringRow *row, uint16_t i_col, char *out, int out_len);
218249

219250
/**
220-
* See: springql_core::api::spring_column_bool
251+
* Get a bool column.
221252
*
222-
* # Returns
253+
* # Parameters
223254
*
224-
* - `0`: if there are no recent errors.
225-
* - `< 0`: SpringErrno
255+
* - `row`: A `SpringRow` pointer to get a column value from.
256+
* - `i_col`: The column index to get a value from.
257+
* - `out`: A pointer to a buffer to store the column value.
226258
*
227-
* # Safety
259+
* # Returns
228260
*
229-
* This function is unsafe because it uses raw pointer.
261+
* - `Ok`: On success.
262+
* - `Unavailable`:
263+
* - Column pointed by `i_col` is already fetched.
264+
* - `i_col` is out of range.
265+
* - `CNull`: Column value is NULL.
230266
*/
231267
enum SpringErrno spring_column_bool(const SpringRow *row, uint16_t i_col, bool *out);
232268

233269
/**
234-
* See: springql_core::api::spring_column_f32
270+
* Get a 4-byte floating point column.
235271
*
236-
* # Returns
272+
* # Parameters
237273
*
238-
* - `0`: if there are no recent errors.
239-
* - `< 0`: SpringErrno
274+
* - `row`: A `SpringRow` pointer to get a column value from.
275+
* - `i_col`: The column index to get a value from.
276+
* - `out`: A pointer to a buffer to store the column value.
240277
*
241-
* # Safety
278+
* # Returns
242279
*
243-
* This function is unsafe because it uses raw pointer.
280+
* - `Ok`: On success.
281+
* - `Unavailable`:
282+
* - Column pointed by `i_col` is already fetched.
283+
* - `i_col` is out of range.
284+
* - `CNull`: Column value is NULL.
244285
*/
245286
enum SpringErrno spring_column_float(const SpringRow *row, uint16_t i_col, float *out);
246287

@@ -262,10 +303,6 @@ enum SpringErrno spring_column_float(const SpringRow *row, uint16_t i_col, float
262303
* - `0`: if there are no recent errors.
263304
* - `> 0`: the length of the recent error message.
264305
* - `< 0`: SpringErrno
265-
*
266-
* # Safety
267-
*
268-
* This function is unsafe because it writes into a caller-provided buffer.
269306
*/
270307
int spring_last_err(enum SpringErrno *errno,
271308
char *errmsg,

src/cstr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::spring_errno::SpringErrno;
1111

1212
/// # Returns
1313
///
14-
/// - `> 0`: the length of the recent error message.
14+
/// - `> 0`: the length of `src`.
1515
/// - `< 0`: SpringErrno
1616
pub(super) fn strcpy(src: &str, dest_buf: *mut c_char, dest_len: c_int) -> c_int {
1717
if src.len() >= dest_len as usize {

0 commit comments

Comments
 (0)