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///Uncomment this macro to debug the message queue implementation
26//#define DEBUG_LOG
27
28///Camera HAL Logging Functions
29#ifndef DEBUG_LOG
30
31#define MSGQ_LOGDA(str)
32#define MSGQ_LOGDB(str, ...)
33
34#undef LOG_FUNCTION_NAME
35#undef LOG_FUNCTION_NAME_EXIT
36#define LOG_FUNCTION_NAME
37#define LOG_FUNCTION_NAME_EXIT
38
39#else
40
41#define MSGQ_LOGDA DBGUTILS_LOGDA
42#define MSGQ_LOGDB DBGUTILS_LOGDB
43
44#endif
45
46#define MSGQ_LOGEA DBGUTILS_LOGEA
47#define MSGQ_LOGEB DBGUTILS_LOGEB
48
49
50namespace TIUTILS {
51
52///Message type
53struct Message
54{
55    unsigned int command;
56    void*        arg1;
57    void*        arg2;
58    void*        arg3;
59    void*        arg4;
60    int64_t     id;
61};
62
63///Message queue implementation
64class MessageQueue
65{
66public:
67
68    MessageQueue();
69    ~MessageQueue();
70
71    ///Get a message from the queue
72    android::status_t get(Message*);
73
74    ///Get the input file descriptor of the message queue
75    int getInFd();
76
77    ///Set the input file descriptor for the message queue
78    void setInFd(int fd);
79
80    ///Queue a message
81    android::status_t put(Message*);
82
83    ///Returns if the message queue is empty or not
84    bool isEmpty();
85
86    void clear();
87
88    ///Force whether the message queue has message or not
89    void setMsg(bool hasMsg=false);
90
91    ///Wait for message in maximum three different queues with a timeout
92    static int waitForMsg(MessageQueue *queue1, MessageQueue *queue2=0, MessageQueue *queue3=0, int timeout = 0);
93
94    bool hasMsg()
95    {
96      return mHasMsg;
97    }
98
99private:
100    int fd_read;
101    int fd_write;
102    bool mHasMsg;
103};
104
105};
106
107#endif
108