|
gusimplewhiteboard
|
#include <fcntl.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#include <signal.h>#include <unistd.h>#include <limits.h>#include <assert.h>#include <sys/types.h>#include <sys/param.h>#include <sys/file.h>#include <sys/mman.h>#include <sys/ipc.h>#include <sys/sem.h>#include <gu_util.h>#include "gusimplewhiteboard.h"#include "guwhiteboardtypelist_c_generated.h"Go to the source code of this file.
Macros | |
| #define | _XOPEN_SOURCE |
| #define | __block _xblock |
| #define | __block __attribute__((__blocks__(byref))) |
| #define | WHITEBOARD_MAGIC 0xfeeda11deadbeef5ULL |
| #define | SEMAPHORE_MAGIC_KEY 4242 |
| #define | SEM_ERROR -1 |
| #define | SEM_A 0200 /* alter permission */ |
| #define | SEM_R 0400 /* read permission */ |
Typedefs | |
| typedef void(* | gsw_sig_t) (int sig) |
Functions | |
| void | gsw_init_semaphores (gsw_sema_t s) |
| initialise the whiteboard semaphores More... | |
| gsw_sema_t | gsw_setup_semaphores (int key) |
| set up a semaphore array for the whiteboard More... | |
| gu_simple_whiteboard_descriptor * | gsw_new_numbered_whiteboard (const char *name, int n) |
| access a named whiteboard: this is the designated standard wb constructor for C programs that want to assign a whiteboard number (uses a different semaphore than the default) More... | |
| gu_simple_whiteboard_descriptor * | gsw_new_custom_whiteboard (const char *name, const char *message_names[], int num_messages, int semaphore_magic_key) |
| Access a named, custom whiteboard. More... | |
| gu_simple_whiteboard_descriptor * | gswr_new_whiteboard (int i) |
| access a remote named whiteboard: this is the designated constructore for C programs More... | |
| gu_simple_whiteboard_descriptor * | gsw_new_whiteboard (const char *name) |
| access a named whiteboard: this is the designated constructore for C programs More... | |
| void | gsw_free_whiteboard (gu_simple_whiteboard_descriptor *wbd) |
| free the given whiteboard descriptor More... | |
| gu_simple_whiteboard_descriptor * | get_local_singleton_whiteboard (void) |
| create a simple whiteboard for the local singleton wb pointer More... | |
| gu_simple_whiteboard * | gsw_create (const char *name, int *fdp, bool *initial) |
| create a simple whiteboard More... | |
| void | gsw_free (gu_simple_whiteboard *wb, int fd) |
| free the whiteboard More... | |
| int | gsw_procure (gsw_sema_t sem, enum gsw_semaphores s) |
| grab a whiteboard semaphore More... | |
| int | gsw_vacate (gsw_sema_t sem, enum gsw_semaphores s) |
| release a whiteboard semaphore More... | |
| int | gsw_register_message_type (gu_simple_whiteboard_descriptor *wbd, const char *name) |
| register a new whiteboard message type More... | |
| int | gsw_offset_for_message_type (gu_simple_whiteboard_descriptor *wbd, const char *name) |
| get the numerical index of a whiteboard message type More... | |
| gu_simple_message * | gsw_current_message (gu_simple_whiteboard *wb, int i) |
| get the current shared memory location for the given whiteboard message type i More... | |
| gu_simple_message * | gsw_next_message (gu_simple_whiteboard *wb, int i) |
| get the next shared memory location for the given whiteboard message type i More... | |
| void | gsw_increment (gu_simple_whiteboard *wb, int i) |
| get the next shared memory location for the given whiteboard message type i More... | |
| void | gsw_increment_event_counter (gu_simple_whiteboard *wb, int i) |
| add to a messages event counter on the wb More... | |
| void | gsw_add_process (gu_simple_whiteboard_descriptor *wbd, const pid_t proc) |
| add process for subscription signalling More... | |
| void | gsw_remove_process (gu_simple_whiteboard_descriptor *wbd, const pid_t proc) |
| remove process for subscription signalling More... | |
| void | gsw_signal_subscribers (gu_simple_whiteboard *wb) |
| signal all subscribing processes More... | |
| void | gsw_add_wbd_signal_handler (gu_simple_whiteboard_descriptor *wbd) |
| add subscription signal handler More... | |
| void | gsw_remove_wbd_signal_handler (gu_simple_whiteboard_descriptor *wbd) |
| remove subscription signal handler More... | |
| #define __block _xblock |
Definition at line 94 of file gusimplewhiteboard.c.
| #define __block __attribute__((__blocks__(byref))) |
Definition at line 94 of file gusimplewhiteboard.c.
| #define _XOPEN_SOURCE |
Definition at line 74 of file gusimplewhiteboard.c.
| #define SEM_A 0200 /* alter permission */ |
Definition at line 120 of file gusimplewhiteboard.c.
| #define SEM_ERROR -1 |
Definition at line 116 of file gusimplewhiteboard.c.
| #define SEM_R 0400 /* read permission */ |
Definition at line 121 of file gusimplewhiteboard.c.
| #define SEMAPHORE_MAGIC_KEY 4242 |
Definition at line 115 of file gusimplewhiteboard.c.
| #define WHITEBOARD_MAGIC 0xfeeda11deadbeef5ULL |
Definition at line 114 of file gusimplewhiteboard.c.
| typedef void(* gsw_sig_t) (int sig) |
Definition at line 603 of file gusimplewhiteboard.c.
| gu_simple_whiteboard_descriptor * get_local_singleton_whiteboard | ( | void | ) |
create a simple whiteboard for the local singleton wb pointer
Definition at line 281 of file gusimplewhiteboard.c.
Referenced by whiteboard_watcher::whiteboard_watcher(), generic_whiteboard_object< object_type >::init(), and SimpleWhiteboardTestPlainC::setUp.
| void gsw_add_process | ( | gu_simple_whiteboard_descriptor * | wbd, |
| const pid_t | proc | ||
| ) |
add process for subscription signalling
subscribe a new process to receive signals
Definition at line 528 of file gusimplewhiteboard.c.
References gsw_procure(), GSW_SEM_PROC, GSW_TOTAL_PROCESSES, gsw_vacate(), gsw_simple_whiteboard_s::processes, gsw_whiteboard_s::sem, gsw_simple_whiteboard_s::subscribed, u_int16_t, and gsw_whiteboard_s::wb.
Referenced by whiteboard_watcher::subscribe(), and guWhiteboard::Whiteboard::subscribeToMessage().
| void gsw_add_wbd_signal_handler | ( | gu_simple_whiteboard_descriptor * | wbd | ) |
add subscription signal handler
Definition at line 613 of file gusimplewhiteboard.c.
References gsw_procure(), GSW_SEM_PROC, and gsw_whiteboard_s::sem.
Referenced by whiteboard_watcher::subscribe(), and guWhiteboard::Whiteboard::subscribeToMessage().
| gu_simple_whiteboard * gsw_create | ( | const char * | name, |
| int * | fdp, | ||
| bool * | ini | ||
| ) |
create a simple whiteboard
| name | name of the whiteboard |
| fdp | pointer to internal file descriptor storage (NULL if not needed) |
| ini | pointer to boolean recording wb initialisation |
Definition at line 296 of file gusimplewhiteboard.c.
References GSW_DEFAULT_NAME, gsw_free(), GU_SIMPLE_WHITEBOARD_BUFSIZE, GU_SIMPLE_WHITEBOARD_VERSION, gsw_simple_whiteboard_s::magic, gsw_simple_whiteboard_s::version, and WHITEBOARD_MAGIC.
Referenced by gsw_new_custom_whiteboard().
| gu_simple_message * gsw_current_message | ( | gu_simple_whiteboard * | wb, |
| int | i | ||
| ) |
get the current shared memory location for the given whiteboard message type i
Definition at line 498 of file gusimplewhiteboard.c.
References GU_SIMPLE_WHITEBOARD_GENERATIONS, gsw_simple_whiteboard_s::indexes, gsw_simple_whiteboard_s::messages, and u_int8_t.
Referenced by generic_whiteboard_object< object_type >::get(), and guWhiteboard::Whiteboard::getMessage().
| void gsw_free | ( | gu_simple_whiteboard * | wb, |
| int | fd | ||
| ) |
free the whiteboard
| wb | whiteboard to free |
| fd | file descriptor to close (-1 to skip) |
Definition at line 351 of file gusimplewhiteboard.c.
Referenced by gsw_create().
| void gsw_free_whiteboard | ( | gu_simple_whiteboard_descriptor * | wbd | ) |
free the given whiteboard descriptor
| wbd | descriptor for the whiteboard |
Definition at line 254 of file gusimplewhiteboard.c.
Referenced by guWhiteboard::Whiteboard::~Whiteboard(), whiteboard_watcher::~whiteboard_watcher(), and gsw_new_custom_whiteboard().
| void gsw_increment | ( | gu_simple_whiteboard * | wb, |
| int | i | ||
| ) |
get the next shared memory location for the given whiteboard message type i
Definition at line 514 of file gusimplewhiteboard.c.
References GU_SIMPLE_WHITEBOARD_GENERATIONS, gsw_simple_whiteboard_s::indexes, and u_int8_t.
Referenced by guWhiteboard::Whiteboard::addMessage(), and generic_whiteboard_object< object_type >::set().
| void gsw_increment_event_counter | ( | gu_simple_whiteboard * | wb, |
| int | i | ||
| ) |
add to a messages event counter on the wb
Definition at line 521 of file gusimplewhiteboard.c.
References gsw_simple_whiteboard_s::event_counters.
Referenced by guWhiteboard::Whiteboard::addMessage(), and generic_whiteboard_object< object_type >::set().
| void gsw_init_semaphores | ( | gsw_sema_t | sem | ) |
initialise the whiteboard semaphores
| sem | whiteboard semaphore descriptor |
Definition at line 136 of file gusimplewhiteboard.c.
References GSW_NUM_SEM.
Referenced by gsw_new_custom_whiteboard(), and gsw_setup_semaphores().
| gu_simple_whiteboard_descriptor * gsw_new_custom_whiteboard | ( | const char * | name, |
| const char * | message_names[], | ||
| int | num_messages, | ||
| int | semaphore_magic_key | ||
| ) |
Access a named, custom whiteboard.
This is the designated custom wb constructor for C programs
| name | The name of the whiteboard to create/access |
| message_names | Array of char * containing the pre-defined (static) message names |
| num_messages | Number of messages in the message_names array |
| semaphore_magic_key | Semaphore magic key to use |
Definition at line 206 of file gusimplewhiteboard.c.
References gsw_whiteboard_s::callback_queue, gsw_whiteboard_s::fd, gsw_create(), gsw_free_whiteboard(), gsw_init_semaphores(), gsw_register_message_type(), gsw_setup_semaphores(), gsw_whiteboard_s::sem, SEM_ERROR, and gsw_whiteboard_s::wb.
Referenced by gsw_new_numbered_whiteboard().
| gu_simple_whiteboard_descriptor * gsw_new_numbered_whiteboard | ( | const char * | name, |
| int | num | ||
| ) |
access a named whiteboard: this is the designated standard wb constructor for C programs that want to assign a whiteboard number (uses a different semaphore than the default)
| name | name of the whiteboard |
| num | whiteboard number (0 for local, default whiteboard) |
Definition at line 181 of file gusimplewhiteboard.c.
References gsw_new_custom_whiteboard(), GSW_NUM_RESERVED, GSW_NUM_TYPES_DEFINED, gsw_register_message_type(), SEMAPHORE_MAGIC_KEY, and WBTypes_stringValues.
Referenced by guWhiteboard::Whiteboard::Whiteboard(), gsw_new_whiteboard(), and gswr_new_whiteboard().
| gu_simple_whiteboard_descriptor * gsw_new_whiteboard | ( | const char * | name | ) |
access a named whiteboard: this is the designated constructore for C programs
| name | name of the whiteboard |
Definition at line 248 of file gusimplewhiteboard.c.
References gsw_new_numbered_whiteboard().
| gu_simple_message * gsw_next_message | ( | gu_simple_whiteboard * | wb, |
| int | i | ||
| ) |
get the next shared memory location for the given whiteboard message type i
Definition at line 506 of file gusimplewhiteboard.c.
References GU_SIMPLE_WHITEBOARD_GENERATIONS, gsw_simple_whiteboard_s::indexes, gsw_simple_whiteboard_s::messages, and u_int8_t.
Referenced by guWhiteboard::Whiteboard::addMessage(), and generic_whiteboard_object< object_type >::set().
| int gsw_offset_for_message_type | ( | gu_simple_whiteboard_descriptor * | wbd, |
| const char * | name | ||
| ) |
get the numerical index of a whiteboard message type
| wbd | descriptor for the whiteboard |
| name | string to use for identification |
Definition at line 476 of file gusimplewhiteboard.c.
References gsw_whiteboard_s::wb.
| int gsw_procure | ( | gsw_sema_t | sem, |
| enum gsw_semaphores | s | ||
| ) |
grab a whiteboard semaphore
| sem | semaphore descriptor |
| s | semaphore to procure |
Definition at line 360 of file gusimplewhiteboard.c.
Referenced by guWhiteboard::Whiteboard::addMessage(), guWhiteboard::RemoteWhiteboard::getKnownTypesForMachine(), gsw_add_process(), gsw_add_wbd_signal_handler(), gsw_register_message_type(), gsw_remove_process(), whiteboard_watcher::receive_callback(), generic_whiteboard_object< object_type >::set(), whiteboard_watcher::subscribe(), guWhiteboard::Whiteboard::subscribeToMessage(), guWhiteboard::Whiteboard::subscriptionCallback(), whiteboard_watcher::unsubscribe(), and guWhiteboard::Whiteboard::unsubscribeToMessage().
| int gsw_register_message_type | ( | gu_simple_whiteboard_descriptor * | wbd, |
| const char * | name | ||
| ) |
register a new whiteboard message type
| wbd | descriptor for the whiteboard |
| name | string to use for identification |
Definition at line 432 of file gusimplewhiteboard.c.
References gsw_procure(), GSW_SEM_MSGTYPE, gsw_whiteboard_s::sem, and gsw_whiteboard_s::wb.
Referenced by gsw_new_custom_whiteboard(), and gsw_new_numbered_whiteboard().
| void gsw_remove_process | ( | gu_simple_whiteboard_descriptor * | wbd, |
| const pid_t | proc | ||
| ) |
remove process for subscription signalling
Definition at line 547 of file gusimplewhiteboard.c.
References gsw_procure(), GSW_SEM_PROC, GSW_TOTAL_PROCESSES, gsw_vacate(), gsw_simple_whiteboard_s::processes, gsw_whiteboard_s::sem, gsw_simple_whiteboard_s::subscribed, u_int16_t, and gsw_whiteboard_s::wb.
Referenced by whiteboard_watcher::unsubscribe(), and guWhiteboard::Whiteboard::unsubscribeToMessage().
| void gsw_remove_wbd_signal_handler | ( | gu_simple_whiteboard_descriptor * | wbd | ) |
remove subscription signal handler
Definition at line 630 of file gusimplewhiteboard.c.
References gsw_whiteboard_s::exit_monitor, gsw_whiteboard_s::got_monitor, and WHITEBOARD_POLL_PERIOD.
| gsw_sema_t gsw_setup_semaphores | ( | int | key | ) |
set up a semaphore array for the whiteboard
| key | semaphore key |
Definition at line 160 of file gusimplewhiteboard.c.
References gsw_init_semaphores(), GSW_NUM_SEM, SEM_A, SEM_ERROR, and SEM_R.
Referenced by gsw_new_custom_whiteboard().
| void gsw_signal_subscribers | ( | gu_simple_whiteboard * | wb | ) |
signal all subscribing processes
Definition at line 565 of file gusimplewhiteboard.c.
References gsw_simple_whiteboard_s::eventcount, gsw_simple_whiteboard_s::processes, gsw_simple_whiteboard_s::subscribed, and WHITEBOARD_SIGNAL.
Referenced by guWhiteboard::Whiteboard::addMessage(), and generic_whiteboard_object< object_type >::set().
| int gsw_vacate | ( | gsw_sema_t | sem, |
| enum gsw_semaphores | s | ||
| ) |
release a whiteboard semaphore
| sem | semaphore descriptor |
| s | semaphore to vacate |
Definition at line 380 of file gusimplewhiteboard.c.
Referenced by guWhiteboard::Whiteboard::addMessage(), guWhiteboard::RemoteWhiteboard::getKnownTypesForMachine(), gsw_add_process(), gsw_remove_process(), generic_whiteboard_object< object_type >::set(), whiteboard_watcher::subscribe(), guWhiteboard::Whiteboard::subscribeToMessage(), whiteboard_watcher::unsubscribe(), and guWhiteboard::Whiteboard::unsubscribeToMessage().
| gu_simple_whiteboard_descriptor * gswr_new_whiteboard | ( | int | i | ) |
access a remote named whiteboard: this is the designated constructore for C programs
| i | machine id of the remote whiteboard |
Definition at line 241 of file gusimplewhiteboard.c.
References gsw_new_numbered_whiteboard(), and GSWR_BASE_NAME.