dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / Input / InputQueue.cpp
blob327854124c88d02851c1489caed5b801476e9d42
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "InputQueue.hpp"
25 #include "InputEvents.hpp"
26 #include "Protection.hpp"
27 #include "Thread/Mutex.hpp"
28 #include "Thread/Debug.hpp"
30 #include <algorithm>
32 static Mutex mutexEventQueue;
34 #define MAX_GCE_QUEUE 10
35 static int GCE_Queue[MAX_GCE_QUEUE];
36 #define MAX_NMEA_QUEUE 10
37 static int NMEA_Queue[MAX_NMEA_QUEUE];
39 void
40 InputEvents::ClearQueues()
42 ScopeLock protect(mutexEventQueue);
44 std::fill(GCE_Queue, GCE_Queue + MAX_GCE_QUEUE, -1);
45 std::fill(NMEA_Queue, NMEA_Queue + MAX_NMEA_QUEUE, -1);
48 bool
49 InputEvents::processNmea(unsigned ne_id)
51 assert(InMainThread());
53 // add an event to the bottom of the queue
54 for (int i = 0; i < MAX_NMEA_QUEUE; i++) {
55 if (NMEA_Queue[i] == -1) {
56 NMEA_Queue[i] = ne_id;
57 break;
61 return true; // ok.
65 void
66 InputEvents::DoQueuedEvents()
68 assert(InMainThread());
70 int GCE_Queue_copy[MAX_GCE_QUEUE];
71 int i;
73 // copy the queue first, blocking
74 mutexEventQueue.Lock();
75 std::copy(GCE_Queue, GCE_Queue + MAX_GCE_QUEUE, GCE_Queue_copy);
76 std::fill(GCE_Queue, GCE_Queue + MAX_GCE_QUEUE, -1);
77 mutexEventQueue.Unlock();
79 // process each item in the queue
80 for (i = 0; i < MAX_GCE_QUEUE; i++) {
81 if (GCE_Queue_copy[i] != -1) {
82 processGlideComputer_real(GCE_Queue_copy[i]);
85 for (i = 0; i < MAX_NMEA_QUEUE; i++) {
86 if (NMEA_Queue[i] != -1)
87 processNmea_real(NMEA_Queue[i]);
91 bool
92 InputEvents::processGlideComputer(unsigned gce_id)
94 // add an event to the bottom of the queue
95 mutexEventQueue.Lock();
96 for (int i = 0; i < MAX_GCE_QUEUE; i++) {
97 if (GCE_Queue[i] == -1) {
98 GCE_Queue[i] = gce_id;
99 break;
102 mutexEventQueue.Unlock();
103 return true;