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