1f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. 2f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * 3f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * Redistribution and use in source and binary forms, with or without 4f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * modification, are permitted provided that the following conditions are 5f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * met: 6f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * * Redistributions of source code must retain the above copyright 7f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * notice, this list of conditions and the following disclaimer. 8f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * * Redistributions in binary form must reproduce the above 9f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * copyright notice, this list of conditions and the following 10f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * disclaimer in the documentation and/or other materials provided 11f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * with the distribution. 12f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * * Neither the name of Code Aurora Forum, Inc. nor the names of its 13f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * contributors may be used to endorse or promote products derived 14f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * from this software without specific prior written permission. 15f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * 16f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani */ 28f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 29f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifndef __MSG_Q_H__ 30f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#define __MSG_Q_H__ 31f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 32f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifdef __cplusplus 33f77c85bb51137f5ba854184e5e9194197027438aAjay Dudaniextern "C" { 34f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif /* __cplusplus */ 35f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 36f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#include <stdlib.h> 37f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 38f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/** Linked List Return Codes */ 39f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanitypedef enum 40f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani{ 41f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_SUCCESS = 0, 42f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Request was successful. */ 43f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_FAILURE_GENERAL = -1, 44f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Failed because of a general failure. */ 45f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_INVALID_PARAMETER = -2, 46f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Failed because the request contained invalid parameters. */ 47f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_INVALID_HANDLE = -3, 48f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Failed because an invalid handle was specified. */ 49f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_UNAVAILABLE_RESOURCE = -4, 50f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Failed because an there were not enough resources. */ 51f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani eMSG_Q_INSUFFICIENT_BUFFER = -5, 52f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani /**< Failed because an the supplied buffer was too small. */ 53f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani}msq_q_err_type; 54f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 55f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 56f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_init 57f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 58f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 59f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Initializes internal structures for message queue. 60f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 61f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: State of message queue to be initialized. 62f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 63f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 64f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 65f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 66f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 67f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 68f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 69f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 70f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 71f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 72f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 73f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_init(void** msg_q_data); 74f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 75f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 76f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_destroy 77f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 78f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 79f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Releases internal structures for message queue. 80f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 81f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: State of message queue to be released. 82f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 83f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 84f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 85f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 86f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 87f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 88f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 89f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 90f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 91f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 92f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 93f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_destroy(void** msg_q_data); 94f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 95f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 96f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_snd 97f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 98f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 99f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Sends data to the message queue. The passed in data pointer 100f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani is not modified or freed. Passed in msg_obj is expected to live throughout 101f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani the use of the msg_q (i.e. data is not allocated internally) 102f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 103f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: Message Queue to add the element to. 104f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msgp: Pointer to data to add into message queue. 105f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani dealloc: Function used to deallocate memory for this element. Pass NULL 106f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani if you do not want data deallocated during a flush operation 107f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 108f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 109f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 110f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 111f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 112f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 113f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 114f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 115f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 116f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 117f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 118f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*)); 119f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 120f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 121f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_rcv 122f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 123f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 124f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Retrieves data from the message queue. msg_obj is the oldest message received 125f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani and pointer is simply removed from message queue. 126f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 127f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: Message Queue to copy data from into msgp. 128f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_obj: Pointer to space to copy msg_q contents to. 129f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 130f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 131f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 132f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 133f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 134f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 135f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 136f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 137f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 138f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 139f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 140f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj); 141f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 142f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 143f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_flush 144f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 145f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 146f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Function removes all elements from the message queue. 147f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 148f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: Message Queue to remove elements from. 149f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 150f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 151f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 152f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 153f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 154f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 155f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 156f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 157f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 158f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 159f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 160f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_flush(void* msg_q_data); 161f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 162f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=========================================================================== 163f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniFUNCTION msg_q_unblock 164f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 165f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDESCRIPTION 166f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani This function will stop use of the message queue. All waiters will wake up 167f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani and likely receive nothing from the queue resulting in a negative return 168f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani value. The message queue can no longer be used until it is destroyed 169f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani and initialized again after calling this function. 170f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 171f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani msg_q_data: Message queue to unblock. 172f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 173f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniDEPENDENCIES 174f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 175f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 176f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniRETURN VALUE 177f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani Look at error codes above. 178f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 179f77c85bb51137f5ba854184e5e9194197027438aAjay DudaniSIDE EFFECTS 180f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani N/A 181f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 182f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani===========================================================================*/ 183f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanimsq_q_err_type msg_q_unblock(void* msg_q_data); 184f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 185f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifdef __cplusplus 186f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani} 187f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif /* __cplusplus */ 188f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani 189f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif /* __MSG_Q_H__ */ 190