1/* 2 * Copyright (C) Texas Instruments - http://www.ti.com/ 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 19#ifndef __MESSAGEQUEUE_H__ 20#define __MESSAGEQUEUE_H__ 21 22#include "DebugUtils.h" 23#include <stdint.h> 24 25#ifdef MSGQ_DEBUG 26# define MSGQ_LOGDA DBGUTILS_LOGDA 27# define MSGQ_LOGDB DBGUTILS_LOGDB 28#else 29# define MSGQ_LOGDA(str) 30# define MSGQ_LOGDB(str, ...) 31#endif 32 33#define MSGQ_LOGEA DBGUTILS_LOGEA 34#define MSGQ_LOGEB DBGUTILS_LOGEB 35 36namespace Ti { 37namespace Utils { 38 39///Message type 40struct Message 41{ 42 unsigned int command; 43 void* arg1; 44 void* arg2; 45 void* arg3; 46 void* arg4; 47 int64_t id; 48}; 49 50///Message queue implementation 51class MessageQueue 52{ 53public: 54 55 MessageQueue(); 56 ~MessageQueue(); 57 58 ///Get a message from the queue 59 android::status_t get(Message*); 60 61 ///Get the input file descriptor of the message queue 62 int getInFd(); 63 64 ///Set the input file descriptor for the message queue 65 void setInFd(int fd); 66 67 ///Queue a message 68 android::status_t put(Message*); 69 70 ///Returns if the message queue is empty or not 71 bool isEmpty(); 72 73 void clear(); 74 75 ///Force whether the message queue has message or not 76 void setMsg(bool hasMsg=false); 77 78 ///Wait for message in maximum three different queues with a timeout 79 static int waitForMsg(MessageQueue *queue1, MessageQueue *queue2=0, MessageQueue *queue3=0, int timeout = 0); 80 81 bool hasMsg() 82 { 83 return mHasMsg; 84 } 85 86private: 87 int fd_read; 88 int fd_write; 89 bool mHasMsg; 90}; 91 92} // namespace Utils 93} // namespace Ti 94 95 96 97 98#endif 99