Skip to content

Commit 8457dbd

Browse files
robamuyashi
authored andcommitted
Make pointer arguments const where mutation is not required
Some pointer arguments were updated to `const` to indicate immutability when no modification is necessary. Signed-off-by: Robin Mueller <[email protected]> Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent 9c02134 commit 8457dbd

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

include/csp/csp.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const csp_conf_t * csp_get_conf(void);
7171
/**
7272
* Copy csp id fields from source to target object
7373
*/
74-
void csp_id_copy(csp_id_t * target, csp_id_t * source);
74+
void csp_id_copy(csp_id_t * target, const csp_id_t * source);
7575

7676
/**
7777
* Clear csp id fields after creating new buffer
@@ -135,7 +135,7 @@ void csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet);
135135
* Returns:
136136
* int: 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout)
137137
*/
138-
int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen, uint32_t opts);
138+
int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, const void *outbuf, int outlen, void *inbuf, int inlen, uint32_t opts);
139139

140140
/**
141141
* Perform an entire request & reply transaction.
@@ -151,7 +151,7 @@ int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_
151151
* @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply.
152152
* @return 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout)
153153
*/
154-
static inline int csp_transaction(uint8_t prio, uint16_t dest, uint8_t port, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen) {
154+
static inline int csp_transaction(uint8_t prio, uint16_t dest, uint8_t port, uint32_t timeout, const void * outbuf, int outlen, void * inbuf, int inlen) {
155155
return csp_transaction_w_opts(prio, dest, port, timeout, outbuf, outlen, inbuf, inlen, 0);
156156
}
157157

@@ -167,7 +167,7 @@ static inline int csp_transaction(uint8_t prio, uint16_t dest, uint8_t port, uin
167167
* @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply.
168168
* @return 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout)
169169
*/
170-
int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
170+
int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, const void *outbuf, int outlen, void *inbuf, int inlen);
171171

172172
/**
173173
* Read data from a connection-less server socket.
@@ -238,39 +238,39 @@ int csp_socket_close(csp_socket_t* sock);
238238
* @param[in] conn connection
239239
* @return destination port of an incoming connection
240240
*/
241-
int csp_conn_dport(csp_conn_t *conn);
241+
int csp_conn_dport(const csp_conn_t *conn);
242242

243243
/**
244244
* Return source port of connection.
245245
*
246246
* @param[in] conn connection
247247
* @return source port of an incoming connection
248248
*/
249-
int csp_conn_sport(csp_conn_t *conn);
249+
int csp_conn_sport(const csp_conn_t *conn);
250250

251251
/**
252252
* Return destination address of connection.
253253
*
254254
* @param[in] conn connection
255255
* @return destination address of an incoming connection
256256
*/
257-
int csp_conn_dst(csp_conn_t *conn);
257+
int csp_conn_dst(const csp_conn_t *conn);
258258

259259
/**
260260
* Return source address of connection.
261261
*
262262
* @param[in] conn connection
263263
* @return source address of an incoming connection
264264
*/
265-
int csp_conn_src(csp_conn_t *conn);
265+
int csp_conn_src(const csp_conn_t *conn);
266266

267267
/**
268268
* Return flags of connection.
269269
*
270270
* @param[in] conn connection
271271
* @return flags of an incoming connection, see @ref CSP_HEADER_FLAGS
272272
*/
273-
int csp_conn_flags(csp_conn_t *conn);
273+
int csp_conn_flags(const csp_conn_t *conn);
274274

275275
/**
276276
* Return if the CSP connection is active
@@ -500,7 +500,7 @@ void csp_conn_print_table(void);
500500
* @param[in] len number of bytes to dump, starting from \a addr.
501501
*
502502
*/
503-
void csp_hex_dump(const char *desc, void *addr, int len);
503+
void csp_hex_dump(const char *desc, const void *addr, int len);
504504

505505
#else
506506

src/csp_conn.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,27 +331,27 @@ csp_conn_t * csp_connect(uint8_t prio, uint16_t dest, uint8_t dport, uint32_t ti
331331
return conn;
332332
}
333333

334-
int csp_conn_dport(csp_conn_t * conn) {
334+
int csp_conn_dport(const csp_conn_t * conn) {
335335

336336
return conn->idin.dport;
337337
}
338338

339-
int csp_conn_sport(csp_conn_t * conn) {
339+
int csp_conn_sport(const csp_conn_t * conn) {
340340

341341
return conn->idin.sport;
342342
}
343343

344-
int csp_conn_dst(csp_conn_t * conn) {
344+
int csp_conn_dst(const csp_conn_t * conn) {
345345

346346
return conn->idin.dst;
347347
}
348348

349-
int csp_conn_src(csp_conn_t * conn) {
349+
int csp_conn_src(const csp_conn_t * conn) {
350350

351351
return conn->idin.src;
352352
}
353353

354-
int csp_conn_flags(csp_conn_t * conn) {
354+
int csp_conn_flags(const csp_conn_t * conn) {
355355

356356
return conn->idin.flags;
357357
}

src/csp_hex_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <csp/csp_debug.h>
55
#include <stddef.h>
66

7-
void csp_hex_dump_format(const char * desc, void * addr, int len, int format) {
7+
void csp_hex_dump_format(const char * desc, const void * addr, int len, int format) {
88
int i;
99
unsigned char buff[17];
1010
unsigned char * pc = (unsigned char *)addr;
@@ -54,6 +54,6 @@ void csp_hex_dump_format(const char * desc, void * addr, int len, int format) {
5454
csp_print(" %s\n", buff);
5555
}
5656

57-
void csp_hex_dump(const char * desc, void * addr, int len) {
57+
void csp_hex_dump(const char * desc, const void * addr, int len) {
5858
csp_hex_dump_format(desc, addr, len, 0);
5959
}

src/csp_io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ csp_packet_t * csp_read(csp_conn_t * conn, uint32_t timeout) {
6666
}
6767

6868
/* Provide a safe method to copy type safe, between two csp ids */
69-
void csp_id_copy(csp_id_t * target, csp_id_t * source) {
69+
void csp_id_copy(csp_id_t * target, const csp_id_t * source) {
7070
target->pri = source->pri;
7171
target->dst = source->dst;
7272
target->src = source->src;
@@ -216,13 +216,13 @@ void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * route
216216

217217
}
218218

219-
__weak void csp_output_hook(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) {
219+
__weak void csp_output_hook(const csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) {
220220
csp_print_packet("OUT: S %u, D %u, Dp %u, Sp %u, Pr %u, Fl 0x%02X, Sz %u VIA: %s (%u), Tms %u\n",
221221
idout->src, idout->dst, idout->dport, idout->sport, idout->pri, idout->flags, packet->length, iface->name, (via != CSP_NO_VIA_ADDRESS) ? via : idout->dst, csp_get_ms());
222222
return;
223223
}
224224

225-
void csp_send_direct_iface(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) {
225+
void csp_send_direct_iface(const csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) {
226226

227227
csp_output_hook(idout, packet, iface, via, from_me);
228228

@@ -311,7 +311,7 @@ void csp_send_prio(uint8_t prio, csp_conn_t * conn, csp_packet_t * packet) {
311311
csp_send(conn, packet);
312312
}
313313

314-
int csp_transaction_persistent(csp_conn_t * conn, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen) {
314+
int csp_transaction_persistent(csp_conn_t * conn, uint32_t timeout, const void * outbuf, int outlen, void * inbuf, int inlen) {
315315

316316
if(outlen > CSP_BUFFER_SIZE){
317317
return 0;
@@ -348,7 +348,7 @@ int csp_transaction_persistent(csp_conn_t * conn, uint32_t timeout, void * outbu
348348
return length;
349349
}
350350

351-
int csp_transaction_w_opts(uint8_t prio, uint16_t dest, uint8_t port, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen, uint32_t opts) {
351+
int csp_transaction_w_opts(uint8_t prio, uint16_t dest, uint8_t port, uint32_t timeout, const void * outbuf, int outlen, void * inbuf, int inlen, uint32_t opts) {
352352

353353
csp_conn_t * conn = csp_connect(prio, dest, port, 0, opts);
354354
if (conn == NULL)

src/csp_io.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <csp/csp.h>
66

77
/**
8-
*
8+
*
99
* @param packet packet to send - this may not be freed if error code is returned
1010
* @param from_me 1 if from me, 0 if routed message
1111
* @return #CSP_ERR_NONE on success, otherwise an error code.
12-
*
12+
*
1313
*/
1414

1515
void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * routed_from);
16-
void csp_send_direct_iface(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me);
16+
void csp_send_direct_iface(const csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me);

0 commit comments

Comments
 (0)