isolationserver/messagequeue/src/msgqcreate.c
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /** 
       
     2  *  @file MsgQCreate.cpp
       
     3  *  Description: Source file for MsgQLib's MsgQCreate API
       
     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 #include <errno.h>
       
    27 #include <sys/msg.h>
       
    28 #include <sys/sem.h>
       
    29 #include <msgqinternal.h>
       
    30 #include <msgliterals.h>
       
    31 
       
    32 
       
    33 /********************************************************************************
       
    34 * MsgQCreate
       
    35 * Description: Creates a message queue
       
    36 * Inputs:
       
    37 *  qName   : ULONG that represents the queue name
       
    38 *  maxMsgs : ULONG that represents maximum size of messages 
       
    39 *********************************************************************************/
       
    40 EXPORT_C int MsgQCreate(ULONG qName, ULONG maxMsgs, ULONG qOptions, int* err) {
       
    41 	
       
    42 
       
    43 	    UNUSED_FORMAL_PARAM(qName);
       
    44 	    UNUSED_FORMAL_PARAM(maxMsgs);
       
    45 	    UNUSED_FORMAL_PARAM(err);
       
    46 		if((qOptions == MSG_Q_FIFO) || (qOptions == MSG_Q_PRIORITY)) {
       
    47 			// Set msg queue options to  FIFO and create the message queue
       
    48 			qOptions= MSG_Q_FIFO ;
       
    49 			
       
    50 		if((msgget((key_t) qName ,IPC_CREAT | 0666 | IPC_EXCL )) == -1 ) {
       
    51 			if ( errno == 17 ){
       
    52 			// message queue already exists
       
    53 			// now just get the hanlde to it
       
    54 			// no need to leave over here;
       
    55 			}
       
    56 		}
       
    57 			
       
    58 			if((msgget((key_t) qName ,IPC_CREAT | 0666 )) >=0 ) {
       
    59 				
       
    60 				    //  set msg queue parameter max # bytes in queue
       
    61 				
       
    62 					/* if( msgctl(qId,IPC_STAT,&qStatus) == 0  ) 
       
    63 					
       
    64 					if( qStatus.msg_qbytes > (maxMsgs * MAX_MSG_LEN) ) {
       
    65 						qStatus.msg_qbytes = maxMsgs * MAX_MSG_LEN ;              
       
    66 						if( msgctl(qId,IPC_SET,&qStatus) < 0) {
       
    67 							// delete message queue on error 
       
    68 							msgctl(qId,IPC_RMID,0);
       
    69 							*err = errno;
       
    70 							return(ERROR);
       
    71 						}
       
    72 					} 
       
    73 					
       
    74 					*/
       
    75 				
       
    76 				*err = OK;                
       
    77 				return (OK);
       
    78 					
       
    79 				
       
    80 			}
       
    81 			else {
       
    82 				*err = errno;
       
    83 			}       
       
    84 		}
       
    85 		else {
       
    86 			*err = KMsgQLibParamErr;
       
    87 		}
       
    88 		
       
    89 		return(ERROR);
       
    90 }
       
    91