Skip to content

Commit

Permalink
examples/gcoap_fileserver: make use of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Nov 10, 2022
1 parent b2c931e commit fd87b0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/gcoap_fileserver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ USEMODULE += shell_commands

# enable the fileserver module
USEMODULE += gcoap_fileserver
USEMODULE += gcoap_fileserver_callback
USEMODULE += gcoap_fileserver_delete
USEMODULE += gcoap_fileserver_put

Expand Down
25 changes: 25 additions & 0 deletions examples/gcoap_fileserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,36 @@ static gcoap_listener_t _listener = {
.resources_len = ARRAY_SIZE(_resources),
};

static void _event_cb(gcoap_fileserver_event_t event, gcoap_fileserver_event_ctx_t *ctx)
{
switch (event) {
case GCOAP_FILESERVER_GET_START:
printf("gcoap fileserver: Download started: %s\n", ctx->file);
break;
case GCOAP_FILESERVER_GET_END:
printf("gcoap fileserver: Download finished: %s\n", ctx->file);
break;
case GCOAP_FILESERVER_PUT_START:
printf("gcoap fileserver: Upload started: %s\n", ctx->file);
break;
case GCOAP_FILESERVER_PUT_END:
printf("gcoap fileserver: Upload finished: %s\n", ctx->file);
break;
case GCOAP_FILESERVER_DELETE:
printf("gcoap fileserver: Delete %s\n", ctx->file);
break;
}
}

int main(void)
{
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
gcoap_register_listener(&_listener);

if (IS_USED(MODULE_GCOAP_FILESERVER_CALLBACK)) {
gcoap_fileserver_set_event_cb(_event_cb, NULL);
}

char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);

Expand Down

0 comments on commit fd87b0f

Please sign in to comment.