Queue Struct Reference


Public Methods

struct MessageQueue_peek_message (struct Queue *ptr_queue, bool remove, int min, int max)
struct MessageQueue_get_message (struct Queue *ptr_queue, long timeout, int min, int max)
void Queue_put_message (struct Queue *ptr_queue, struct Message *ptr_message)


Detailed Description

Queues can peek at and/or remove messages from a specified range. They have names and are targets for messages; in particular, all processes have queues and thus can get messages.

See also:
Processes and Modules


Member Function Documentation

struct Message * Queue_get_message ( struct Queue * ptr_queue,
long timeout,
int min,
int max )
 

Returns the message from the specified interval.
The calling thread waits until the first message appears in the queue. Be careful not to overload, the queue. Delete the message when you are finished with it.

Parameters:
ptr_queue   A pointer to the initialized Queue object
timeout   Timeout value(in milliseconds)
min   deprecated
max   deprecated
Returns:
A pointer to the Message if one is in the queue, or 0 if a timeout occurs
       #include <cybiko.h>
       ...
       struct module_t main_module;
       struct Message* ptr_message;
       ...
       init_module( &main_module );
       ...
       ptr_message = Queue_get_message( main_module.m_process, 
                                        0, 
                                        1, 
                                        MSG_USER );
       if( ptr_message->msgid == MSG_KEYDOWN )
       {
         if( Message_get_key_param( ptr_message )->scancode == KEY_ESC )
         {
           //  Processes key 'Esc'.
         }
       }
       ...
       Message_delete( ptr_message );
       ...
See also:
Queue_peek_message.

struct Message * Queue_peek_message ( struct Queue * ptr_queue,
bool remove,
int min,
int max )
 

Peeks at or gets a message from the queue.
If remove is TRUE, the message will be removed. It does not wait for a message to be available; it returns 0 immediately if there are no messages in the specified range. Don't use this function unless really need to.

Parameters:
ptr_queue   A pointer to the initialized Queue object
remove   If TRUE, the message will be removed from the message queue
min   Specifies the lowest message value to be retrieved, as an integer
max   Specifies the highest message value to be retrieved, as an integer
Returns:
A pointer to the Message if one is in the queue, otherwise 0
       #include <cybiko.h>
       ...
       struct module_t main_module;
       struct Message* ptr_message;
       ...
       init_module( &main_module );
       ...
       //  Removes all keyboard messages from the queue.
       while( ptr_message = Queue_peek_message( main_module.m_process, 
                                                TRUE, 
                                                MSG_KEYDOWN, 
                                                MSG_KEYDOWN ) )
       {
         Message_delete( ptr_message );
       }
       ...
See also:
Queue_get_message.

void Queue_put_message ( struct Queue * ptr_queue,
struct Message * ptr_message )
 

Puts a Message in the Queue.

Parameters:
ptr_queue   A pointer to the initialized Queue object
ptr_message   A pointer to the specified message to put
Returns:
None
       #include <cybiko.h>
       #define MSG_MAKE_TASK  MSG_USER + 1
       ...
       struct module_t main_module;
       struct Message* ptr_message;
       ...
       init_module( &main_module );
       ...
       ptr_message = Queue_get_message( main_module.m_process, 
                                        0, 
                                        1, 
                                        MSG_MAKE_TASK );
       if( ptr_message->msgid == MSG_MAKE_TASK )
       {
         ...
         //  Performs some periodical calculation.
         ...
         sleep( 250 );
         Queue_put_message( main_module.m_process, ptr_message );
       }
       else
       {
         Message_delete( ptr_message );
       }
       ...
See also:
Queue_get_message , Queue_peek_message.