opensrv_plat/messagequeue_api/inc/msgqlib.h
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /** 
       
     2  *  @file MsgQLib.h
       
     3  *  Description: Header file for MsgQLib
       
     4  *  Copyright (c) 2007 Nokia Corporation.
       
     5 *  All rights reserved.
       
     6 *  Redistribution and use in source and binary forms, with or without modification, 
       
     7 *  are permitted provided that the following conditions are met:
       
     8 *  Redistributions of source code must retain the above copyright notice, this list 
       
     9 *  of conditions and the following disclaimer.Redistributions in binary form must 
       
    10 *  reproduce the above copyright notice, this list of conditions and the following 
       
    11 *  disclaimer in the documentation and/or other materials provided with the distribution.
       
    12 *  Neither the name of the Nokia Corporation nor the names of its contributors may be used 
       
    13 *  to endorse or promote products derived from this software without specific prior written 
       
    14 *  permission.
       
    15 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
       
    16 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
       
    17 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
       
    18 *  SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
       
    19 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
       
    20 *  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
       
    21 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
       
    22 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
       
    23 *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    24 */
       
    25 
       
    26 #ifndef __MSGQLIB_H__
       
    27 #define __MSGQLIB_H__
       
    28 
       
    29 #include <_ansi.h>
       
    30 
       
    31 #ifdef __cplusplus
       
    32 extern "C" {
       
    33 #endif
       
    34 
       
    35 /* MsgQLib sizes */
       
    36 #define  MAX_MSG_LEN	   2048 
       
    37 
       
    38 /* hash table parameters - table size must be a prime number  */
       
    39 #define  MSGQ_TBL_SZ	   101
       
    40 
       
    41 /* message send states */
       
    42 #define MSG_Q_READY        0
       
    43 #define MSG_Q_CLEANING	   1
       
    44 
       
    45 
       
    46 #define NO_WAIT 			0
       
    47 #define WAIT_FOREVER 		0xFFFF
       
    48 
       
    49 #ifndef NULL
       
    50 #define NULL 				0
       
    51 #endif /* NULL */
       
    52 
       
    53 /* errors */
       
    54 #define KMsgQLibErr			 	0x100
       
    55 #define KMsgQLibNoMemoryErr 	(KMsgQLibErr | 1) /* out of memory */
       
    56 #define KMsgQLibQIdErr 			(KMsgQLibErr | 2) /* queue already in use or invalid */
       
    57 #define KMsgQLibParamErr    	(KMsgQLibErr | 3) /* illegal parm(s)/val(s) */
       
    58 #define KMsgQLibQFlushErr   	(KMsgQLibErr | 4) /* queue being flushed */
       
    59 #define KMsgQLibQShortErr   	(KMsgQLibErr | 5) /* internal error:  inconsistency between #of msgs*/
       
    60 
       
    61 #define  MSG_Q_FIFO       1
       
    62 #define  MSG_Q_PRIORITY   2
       
    63 #define  MSG_PRI_NORMAL   3
       
    64 #define  MSG_PRI_URGENT   4
       
    65 #define  SEM_Q_FIFO       5
       
    66 #define  SEM_Q_PRIORITY   6
       
    67 
       
    68 #define  OK               0
       
    69 #define  ERROR           -1  
       
    70 
       
    71 typedef  unsigned long    ULONG ;
       
    72 typedef  unsigned short   ushort_t;
       
    73 
       
    74 
       
    75 /**
       
    76  *
       
    77  * Creates a message queue with the argument passed
       
    78  *
       
    79  * @param qName   - queue name
       
    80  * @param maxMsgs - max messages in the queue
       
    81  * @param qOptions - message queue options
       
    82  *                        MSG_Q_FIFO
       
    83  *                        MSG_Q_PRIORITY
       
    84  * @param err - error code to be returned
       
    85  *
       
    86  * @return Returns status and error code
       
    87  */
       
    88 IMPORT_C int MsgQCreate (ULONG qName, ULONG maxMsgs, ULONG qOptions, int* err);
       
    89 
       
    90 /**
       
    91  *
       
    92  * This function deletes a message queue
       
    93  *
       
    94  * @param qName - queue name
       
    95  * @param err - error code to be returned
       
    96  *
       
    97  * @return Returns status and error code
       
    98  **/
       
    99 IMPORT_C int MsgQDelete (ULONG qName, int* err);
       
   100 
       
   101 /**
       
   102  *
       
   103  * This function sends a message with internal copy
       
   104  *
       
   105  * @param qName - queue name
       
   106  * @param msg - message to send
       
   107  * @param nBytes - length of message
       
   108  * @param priority - message priority
       
   109  * @param timeout - milliseconds to wait
       
   110  * @param err - error code to be returned
       
   111  *
       
   112  * @return Returns status and error code
       
   113  **/
       
   114 
       
   115 IMPORT_C int MsgQSend (ULONG qName, char* msg, ULONG nBytes, ULONG priority, int timeout, int* err);
       
   116 
       
   117 /**
       
   118  *
       
   119  * This function receives a message with internal copy
       
   120  *
       
   121  * @param qName - queue name
       
   122  * @param msg - buffer for received message
       
   123  * @param maxNBytes - length of buffer
       
   124  * @param timeout - milliseconds to wait
       
   125  * @param err - error code to be returned
       
   126  *
       
   127  * @return Returns status and error code
       
   128  **/
       
   129 
       
   130 IMPORT_C int MsgQReceive (ULONG qName, char* msg, ULONG maxNBytes, int timeout, int* err);
       
   131 
       
   132 /**
       
   133  *
       
   134  * This function checks how many messages are in a queue
       
   135  *
       
   136  * @param qName - queue name
       
   137  * @param err - error code to be returned
       
   138  *
       
   139  * @return Returns status and error code
       
   140  **/
       
   141 IMPORT_C int MsgQCheck (ULONG qName, int* err);
       
   142 
       
   143 /**
       
   144  * This function checks the maximum number of messages in a queue
       
   145  *
       
   146  * @param qName - queue name
       
   147  * @param err - error code to be returned
       
   148  *
       
   149  * @return Returns status and error code
       
   150  **/
       
   151 IMPORT_C int MsgQMaxCheck (ULONG qName, int* err);
       
   152 
       
   153 /**
       
   154  *
       
   155  * This function empties the specified queue
       
   156  *
       
   157  * @param qName - queue name
       
   158  * @param err - error code to be returned
       
   159  *
       
   160  * @return Returns status and error code
       
   161  **/
       
   162 IMPORT_C int MsgQClean (ULONG qName, int* err);
       
   163 
       
   164 #ifdef __cplusplus
       
   165 }
       
   166 #endif
       
   167 
       
   168 #endif // __MSGQLIB_H__