Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.accessibility/windows/native/libwindowsaccessbridge/AccessBridgeMessageQueue.cpp
40957 views
1
/*
2
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
* A class to manage queueing of messages for IPC
28
*/
29
30
#include "AccessBridgeDebug.h"
31
#include "AccessBridgeMessageQueue.h"
32
#include "AccessBridgePackages.h" // for debugging only
33
#include <windows.h>
34
#include <malloc.h>
35
#include <new>
36
37
DEBUG_CODE(extern HWND theDialogWindow);
38
extern "C" {
39
DEBUG_CODE(void AppendToCallInfo(char *s));
40
}
41
42
// -------------------
43
44
45
AccessBridgeQueueElement::AccessBridgeQueueElement(char *buf, int size) {
46
bufsize = size;
47
next = (AccessBridgeQueueElement *) 0;
48
previous = (AccessBridgeQueueElement *) 0;
49
buffer = (char *) malloc(bufsize);
50
if (buffer == NULL) {
51
throw std::bad_alloc();
52
}
53
memcpy(buffer, buf, bufsize);
54
}
55
56
AccessBridgeQueueElement::~AccessBridgeQueueElement() {
57
// delete buffer;
58
free(buffer);
59
}
60
61
62
// -------------------
63
64
65
AccessBridgeMessageQueue::AccessBridgeMessageQueue() {
66
queueLocked = FALSE;
67
queueRemoveLocked = FALSE;
68
start = (AccessBridgeQueueElement *) 0;
69
end = (AccessBridgeQueueElement *) 0;
70
size = 0;
71
}
72
73
AccessBridgeMessageQueue::~AccessBridgeMessageQueue() {
74
// empty queue, then exit
75
}
76
77
/**
78
* getEventsWaiting - gets the number of events waiting to fire
79
*/
80
int
81
AccessBridgeMessageQueue::getEventsWaiting() {
82
return size;
83
}
84
85
/**
86
* add - add an element to the queue, which is locked with semaphores
87
*
88
*/
89
QueueReturns
90
AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) {
91
PrintDebugString("[INFO]: in AccessBridgeMessageQueue::add()");
92
PrintDebugString("[INFO]: queue size = %d", size);
93
94
QueueReturns returnVal = cElementPushedOK;
95
if (queueLocked) {
96
PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!");
97
return cQueueInUse;
98
}
99
queueLocked = TRUE;
100
{
101
PrintDebugString("[INFO]: adding element to queue!");
102
if (end == (AccessBridgeQueueElement *) 0) {
103
if (start == (AccessBridgeQueueElement *) 0 && size == 0) {
104
start = element;
105
end = element;
106
element->previous = (AccessBridgeQueueElement *) 0;
107
element->next = (AccessBridgeQueueElement *) 0;
108
size++;
109
} else {
110
returnVal = cQueueBroken; // bad voodo!
111
}
112
} else {
113
element->previous = end;
114
element->next = (AccessBridgeQueueElement *) 0;
115
end->next = element;
116
end = element;
117
size++;
118
}
119
}
120
queueLocked = FALSE;
121
PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::add()");
122
return returnVal;
123
}
124
125
126
/**
127
* remove - remove an element from the queue, which is locked with semaphores
128
*
129
*/
130
QueueReturns
131
AccessBridgeMessageQueue::remove(AccessBridgeQueueElement **element) {
132
PrintDebugString("[INFO]: in AccessBridgeMessageQueue::remove()");
133
PrintDebugString("[INFO]: queue size = %d", size);
134
135
QueueReturns returnVal = cMoreMessages;
136
if (queueLocked) {
137
PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!");
138
return cQueueInUse;
139
}
140
queueLocked = TRUE;
141
{
142
PrintDebugString("[INFO]: removing element from queue!");
143
if (size > 0) {
144
if (start != (AccessBridgeQueueElement *) 0) {
145
*element = start;
146
start = start->next;
147
if (start != (AccessBridgeQueueElement *) 0) {
148
start->previous = (AccessBridgeQueueElement *) 0;
149
} else {
150
end = (AccessBridgeQueueElement *) 0;
151
if (size != 1) {
152
returnVal = cQueueBroken; // bad voodo, should only be 1 in this situation
153
}
154
}
155
size--;
156
} else {
157
returnVal = cQueueBroken; // bad voodo!
158
}
159
} else {
160
returnVal = cQueueEmpty;
161
}
162
}
163
queueLocked = FALSE;
164
PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::remove()");
165
return returnVal;
166
}
167
168
169
/**
170
* setRemoveLock - set the state of the removeLock (TRUE or FALSE)
171
*
172
*/
173
QueueReturns
174
AccessBridgeMessageQueue::setRemoveLock(BOOL removeLockSetting) {
175
if (queueLocked) {
176
return cQueueInUse;
177
}
178
queueRemoveLocked = removeLockSetting;
179
180
return cQueueOK;
181
}
182
183
/**
184
* setRemoveLock - set the state of the removeLock (TRUE or FALSE)
185
*
186
*/
187
BOOL
188
AccessBridgeMessageQueue::getRemoveLockSetting() {
189
return queueRemoveLocked;
190
}
191
192