[Hardware OS Message Queue Interface] Functionality for keeping message queue identifiers. More...
Go to the source code of this file.
Enumerations | |
enum | hmqueue_mode { HMQ_CREATE, HMQ_CONNECT } |
Types of modes when creating a message queue. | |
Functions | |
struct hmqueue * | hmqueue_get_prev (struct hmqueue *element) |
Get previous element in list. | |
struct hmqueue * | hmqueue_get_next (struct hmqueue *element) |
Get next element in list. | |
int | hmqueue_get_key (struct hmqueue *element) |
Get key of a given message queue. | |
int | hmqueue_get_id (struct hmqueue *element) |
Get ID of message queue. | |
int | hmqueue_size () |
Get size of elements in message queue list. | |
int | hmqueue_get_id_by_key (int key) |
Get ID of message queue identified by key. | |
struct hmqueue * | hmqueue_get (int key) |
Get message queue element identified by key. | |
struct hmqueue * | hmqueue_add (int key, enum hmqueue_mode mode) |
Adds a message queue and returns the queue identifier. | |
int | hmqueue_remove (struct hmqueue *element) |
Remove the given list element. | |
int | hmqueue_remove_by_key (int key) |
Remove the given message queue by key. | |
int | hmqueue_remove_all () |
Remove all message queues in list. | |
struct hmqueue * | hmqueue_get_first () |
Get first element in list. | |
struct hmqueue * | hmqueue_get_last () |
Get last element in list. | |
int | hmqueue_get_daemonkey () |
Get the key of the message servers message queue. |
[Hardware OS Message Queue Interface] Functionality for keeping message queue identifiers.
This is simply a double linked list of System V message queues. This module should probably be rewritten so it uses hlist internally.
Original author (2010): Vegard Endresen
Modified (2011): Sindre Hansen
Definition in file hmqueue.h.
struct hmqueue* hmqueue_add | ( | int | key, | |
enum hmqueue_mode | mode | |||
) | [read] |
Adds a message queue and returns the queue identifier.
Based on "mode" this function either connects to an exisiting message queue or creates an new message queue.
key | Unique key for the new queue. | |
mode | Mode for adding a message queue to the list. |
Definition at line 184 of file hmqueue.c.
{ // Remove any existing queues (should be none or just one). int nr_removed = 0; while (hmqueue_remove_by_key(key) == 0) { nr_removed += 1; if (nr_removed > 10) return NULL; } int msgflg = -1; if (mode == HMQ_CREATE) msgflg = IPC_CREAT | 0666; else if (mode == HMQ_CONNECT) msgflg = 0666; else return NULL; struct hmqueue* queue = calloc(1, sizeof(*queue)); int msqid = create_mqueue_(key, msgflg); set_key_(queue, key); set_id_(queue, msqid); set_next_(queue, NULL); set_prev_(queue, NULL); if(hmqueue_size() == 0) { // This is first element. firstq = queue; lastq = queue; } else { // There is element(s) in list already. set_next_(hmqueue_get_last(), queue); set_prev_(queue, hmqueue_get_last()); lastq = queue; } queue_cnt++; return queue; }
struct hmqueue* hmqueue_get | ( | int | key | ) | [read] |
Get message queue element identified by key.
key | A key that identifies the message queue. |
Definition at line 144 of file hmqueue.c.
{ if (hmqueue_size() == 0) return NULL; struct hmqueue* queue; queue = hmqueue_get_first(); if (hmqueue_get_key(queue) == key) return queue; while (hmqueue_get_next(queue) != NULL) { queue = hmqueue_get_next(queue); if (hmqueue_get_key(queue) == key) return queue; } return NULL; }
int hmqueue_get_daemonkey | ( | ) |
struct hmqueue* hmqueue_get_first | ( | ) | [read] |
int hmqueue_get_id | ( | struct hmqueue * | element | ) |
int hmqueue_get_id_by_key | ( | int | key | ) |
Get ID of message queue identified by key.
key | A key that identifies the message queue. |
Definition at line 163 of file hmqueue.c.
{ if(hmqueue_size() == 0) return -1; struct hmqueue *it; it = hmqueue_get_first(); if (hmqueue_get_key(it) == key) return hmqueue_get_id(it); while(1) { //last item if(hmqueue_get_next(it) == NULL) return -1; it = hmqueue_get_next(it); if (hmqueue_get_key(it) == key) return hmqueue_get_id(it); } }
int hmqueue_get_key | ( | struct hmqueue * | element | ) |
struct hmqueue* hmqueue_get_last | ( | ) | [read] |
int hmqueue_remove | ( | struct hmqueue * | element | ) |
Remove the given list element.
element | Pointer to list element that has the message queue. |
List is invalid.
Connect next and previous element together.
Definition at line 227 of file hmqueue.c.
{ if (element == NULL) return -1; hlog_write(HLOG_DEBUG, "hmqueue_remove: Removing queue with id="); hlog_write_integer(hmqueue_get_id(element)); hlog_write_text("\n"); // Remove the actual message queue. if (hmqueue_get_id(element) > 0) msgctl(hmqueue_get_id(element), IPC_RMID, NULL); if (hmqueue_size() < 1) { hlog_write(HLOG_ERROR, "hmqueue_remove: Invalid list structure (-2).\n"); return -2; } else if (hmqueue_size() == 1) { // Only one element. free(element); firstq = NULL; lastq = NULL; queue_cnt = 0; } else { // More than one element. struct hmqueue* element_prev = hmqueue_get_prev(element); struct hmqueue* element_next = hmqueue_get_next(element); if (element_prev == NULL && element_next != NULL) { // This is first element. firstq = element_next; set_prev_( element_next, NULL ); } else if (element_next == NULL && element_prev != NULL) { // This is last element. lastq = element_prev; set_next_( element_prev, NULL); } else if (element_next != NULL && element_prev != NULL) { // Element is in-between. set_prev_( element_next, element_prev ); set_next_( element_prev, element_next ); } else { // List is invalid. hlog_write(HLOG_ERROR, "hmqueue_remove: Invalid list structure (-3).\n"); return -3; } free(element); queue_cnt--; } return 0; }
int hmqueue_remove_all | ( | ) |
Remove all message queues in list.
int hmqueue_remove_by_key | ( | int | key | ) |