Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtock/ipc: add custom IPC service callback type with buffer pointer #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/rot13_service/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ struct rot13_buf {
char buf[31];
};

static void rot13_callback(int pid, int len, int buf, __attribute__ ((unused)) void* ud) {
struct rot13_buf *rb = (struct rot13_buf*)buf;
static void rot13_callback(int pid, int len, void *buf, __attribute__ ((unused)) void* ud) {
struct rot13_buf *rb = buf;
int length = rb->length;
if (length > len - 1) {
length = len - 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/services/ble-env-sense/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ typedef struct {
} sensor_update_t;


static void ipc_callback(int pid, int len, int buf, __attribute__ ((unused)) void* ud) {
static void ipc_callback(int pid, int len, void *buf, __attribute__ ((unused)) void* ud) {
if (len < (int) sizeof(sensor_update_t)) {
printf("Error! IPC message too short.\n");
ipc_notify_client(pid);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/05_ipc/led/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

uint8_t _number_of_leds = 0;

static void ipc_callback(int pid, int len, int buf, __attribute__ ((unused)) void* ud) {
static void ipc_callback(int pid, int len, void *buf, __attribute__ ((unused)) void* ud) {
uint8_t* buffer = (uint8_t*) buf;

if (len < 1) {
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/05_ipc/rng/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// If the buffer is not long enough to hold the number of requested bytes
// the service will stop processing the request and not notify the client.

static void ipc_callback(int pid, int len, int buf, __attribute__ ((unused)) void* ud) {
static void ipc_callback(int pid, int len, void *buf, __attribute__ ((unused)) void* ud) {
uint8_t* buffer = (uint8_t*) buf;
uint8_t* rng;

Expand Down
6 changes: 3 additions & 3 deletions libtock-sync/services/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ static void timeout_callback(__attribute__ ((unused)) uint32_t now,
*/
static void unit_test_service_callback(int pid,
__attribute__ ((unused)) int len,
int buf,
void* buf,
__attribute__ ((unused)) void *ud) {
if (buf == 0) {
return;
}

unit_test_t *test = (unit_test_t *)buf;
linked_list_t *pending = (linked_list_t *)ud;
unit_test_t *test = buf;
linked_list_t *pending = ud;

switch (test->cmd) {
case TestInit:
Expand Down
4 changes: 2 additions & 2 deletions libtock/kernel/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ int ipc_discover(const char* pkg_name, size_t* svc_id) {
}

int ipc_register_service_callback(const char *pkg_name,
subscribe_upcall callback, void *ud) {
ipc_service_upcall callback, void *ud) {
size_t svc_id;

// Look up the service id so we can subscribe as the service
int ret = ipc_discover(pkg_name, &svc_id);
if (ret < 0) return ret;

subscribe_return_t sval = subscribe(IPC_DRIVER_NUM, svc_id, callback, ud);
subscribe_return_t sval = subscribe(IPC_DRIVER_NUM, svc_id, *((subscribe_upcall*) &callback), ud);
return tock_subscribe_return_to_returncode(sval);
}

Expand Down
7 changes: 6 additions & 1 deletion libtock/kernel/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ extern "C" {

#define IPC_DRIVER_NUM 0x10000

// Specific upcall type used for IPC service callbacks. This upcall
// has a pointer as its third argument, which contains the address to
// the buffer that an app has shared.
typedef void (ipc_service_upcall)(int, int, void*, void*);

// Performs service discovery
//
// Retrieves the process identifier of the process with the given package name,
Expand All @@ -26,7 +31,7 @@ int ipc_discover(const char* pkg_name, size_t* svc_id);
// callback - the address callback function to execute when clients notify
// void* ud - `userdata`. data passed to callback function
int ipc_register_service_callback(const char *pkg_name,
subscribe_upcall callback, void *ud);
ipc_service_upcall callback, void *ud);

// Registers a client callback for a particular service.
//
Expand Down
Loading