Skip to content

Commit d6eff5c

Browse files
author
Arto Kinnunen
committed
Clarify function signature
Use coap_msg_process_cb typedef to clarify function signature
1 parent 587e8de commit d6eff5c

File tree

7 files changed

+29
-18
lines changed

7 files changed

+29
-18
lines changed

source/coap_message_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr,
294294
}
295295

296296
int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t recv_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
297-
uint8_t *data_ptr, uint16_t data_len, int16_t (msg_process_callback)(int8_t, int8_t, sn_coap_hdr_s *, coap_transaction_t *, const uint8_t *))
297+
uint8_t *data_ptr, uint16_t data_len, coap_msg_process_cb *msg_process_callback)
298298
{
299299
sn_nsdl_addr_s src_addr;
300300
sn_coap_hdr_s *coap_message;

source/include/coap_message_handler.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ typedef int coap_message_handler_response_recv(int8_t service_id, uint8_t source
4949
typedef struct coap_msg_handler_s {
5050
void *(*sn_coap_service_malloc)(uint16_t);
5151
void (*sn_coap_service_free)(void *);
52-
5352
uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *);
54-
5553
struct coap_s *coap;
5654
} coap_msg_handler_t;
5755

@@ -74,6 +72,20 @@ typedef struct coap_transaction {
7472
ns_list_link_t link;
7573
} coap_transaction_t;
7674

75+
/**
76+
* \brief Service message processing callback.
77+
*
78+
* Function that processes CoAP service message
79+
*
80+
* \param socket_id Socket that receives the message.
81+
* \param recv_if_id Interface where message is received.
82+
* \param coap_message Actual CoAP message.
83+
* \param transaction_ptr Message transaction.
84+
* \param local_addr Address where message is received.
85+
*
86+
* \return 0 for success / -1 for failure
87+
*/
88+
typedef int16_t coap_msg_process_cb(int8_t socket_id, int8_t recv_if_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr, const uint8_t * local_addr);
7789

7890
extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
7991
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *));
@@ -84,9 +96,8 @@ extern coap_transaction_t *coap_message_handler_transaction_valid(coap_transacti
8496

8597
extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port);
8698

87-
extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t source_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port,
88-
const uint8_t dst_addr_ptr[static 16], uint8_t *data_ptr, uint16_t data_len,
89-
int16_t (msg_process_callback)(int8_t, int8_t, sn_coap_hdr_s *, coap_transaction_t *, const uint8_t *));
99+
extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t recv_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port,
100+
const uint8_t dst_addr_ptr[static 16], uint8_t *data_ptr, uint16_t data_len, coap_msg_process_cb *msg_process_callback);
90101

91102
extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16],
92103
uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, sn_coap_content_format_e cont_type,

test/coap-service/unittest/coap_service_api/test_coap_service_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ bool test_conn_handler_callbacks()
417417

418418
//This could be moved to own test function,
419419
//but thread_conn_handler_stub.receive_from_sock_cb must be called successfully
420-
if (coap_message_handler_stub.cb) {
421-
if (-1 != coap_message_handler_stub.cb(1, 1, NULL, NULL, local_addr)) {
420+
if (coap_message_handler_stub.msg_process_cb) {
421+
if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, NULL, NULL, local_addr)) {
422422
return false;
423423
}
424424

@@ -429,7 +429,7 @@ bool test_conn_handler_callbacks()
429429
coap->uri_path_ptr = &uri;
430430
coap->uri_path_len = 2;
431431

432-
if (-1 != coap_message_handler_stub.cb(1, 1, coap, NULL, local_addr)) {
432+
if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, NULL, local_addr)) {
433433
return false;
434434
}
435435

@@ -439,7 +439,7 @@ bool test_conn_handler_callbacks()
439439
return false;
440440
}
441441

442-
if (-1 != coap_message_handler_stub.cb(1, 1, coap, NULL, local_addr)) {
442+
if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, NULL, local_addr)) {
443443
return false;
444444
}
445445

@@ -451,15 +451,15 @@ bool test_conn_handler_callbacks()
451451
return false;
452452
}
453453

454-
if (-1 != coap_message_handler_stub.cb(1, 1, coap, tr, local_addr)) {
454+
if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, tr, local_addr)) {
455455
return false;
456456
}
457457

458458
if (0 != coap_service_msg_prevalidate_callback_set(2, NULL)) {
459459
return false;
460460
}
461461

462-
if (2 != coap_message_handler_stub.cb(1, 1, coap, tr, local_addr)) {
462+
if (2 != coap_message_handler_stub.msg_process_cb(1, 1, coap, tr, local_addr)) {
463463
return false;
464464
}
465465

test/coap-service/unittest/stub/coap_connection_handler_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
3333
return thread_conn_handler_stub.int_value;
3434
}
3535

36-
coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, int8_t source_if_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int),
36+
coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, int8_t recv_if_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int),
3737
int (*send_cb)(int8_t socket_id, uint8_t const address[static 16], uint16_t port, const void *, int),
3838
int (*pw_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr),
3939
void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]))

test/coap-service/unittest/stub/coap_connection_handler_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct {
3333
cch_func_cb *cch_function_callback;
3434

3535
int (*send_to_sock_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, const void *, int);
36-
int (*receive_from_sock_cb)(int8_t socket_id, int8_t source_if_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int);
36+
int (*receive_from_sock_cb)(int8_t socket_id, int8_t recv_if_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int);
3737
int (*get_passwd_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr);
3838
void (*sec_done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]);
3939

test/coap-service/unittest/stub/coap_message_handler_stub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr,
5555
return coap_message_handler_stub.coap_tx_ptr;
5656
}
5757

58-
int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t source_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
59-
uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, int8_t, sn_coap_hdr_s *, coap_transaction_t *, const uint8_t *))
58+
extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t recv_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port,
59+
const uint8_t dst_addr_ptr[static 16], uint8_t *data_ptr, uint16_t data_len, coap_msg_process_cb *msg_process_callback)
6060
{
61-
coap_message_handler_stub.cb = cb;
61+
coap_message_handler_stub.msg_process_cb = msg_process_callback;
6262
return coap_message_handler_stub.int16_value;
6363
}
6464

test/coap-service/unittest/stub/coap_message_handler_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct {
3131
uint16_t uint16_value;
3232
coap_msg_handler_t *coap_ptr;
3333
coap_transaction_t *coap_tx_ptr;
34-
int16_t (*cb)(int8_t, int8_t, sn_coap_hdr_s *, coap_transaction_t *, const uint8_t *);
34+
coap_msg_process_cb *msg_process_cb;
3535
} coap_message_handler_stub_def;
3636

3737
extern coap_message_handler_stub_def coap_message_handler_stub;

0 commit comments

Comments
 (0)