From 61c148b084a9bb1a3fe75131aae0b14b86eb7e08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= <jerome.duval@gmail.com>
Date: Tue, 28 Aug 2012 20:32:46 +0200
Subject: [PATCH] input_server: use a generated cookie instead of pointer
* fixed #8831
---
src/servers/input/AddOnManager.cpp | 2 +-
src/servers/input/InputServer.cpp | 18 +++++++++++++-----
src/servers/input/InputServer.h | 2 ++
src/servers/input/InputServerMethod.cpp | 20 ++++++++++++--------
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/servers/input/AddOnManager.cpp b/src/servers/input/AddOnManager.cpp
index 0d75e6a..867903c 100644
a
|
b
|
AddOnManager::_UnregisterAddOn(BEntry& entry)
|
440 | 440 | gInputServer->SetMethodReplicant(NULL); |
441 | 441 | } else if (method != NULL) { |
442 | 442 | BMessage msg(IS_REMOVE_METHOD); |
443 | | msg.AddInt32("cookie", (uint32)method); |
| 443 | msg.AddInt32("cookie", method->fOwner->Cookie()); |
444 | 444 | if (gInputServer->MethodReplicant()) |
445 | 445 | gInputServer->MethodReplicant()->SendMessage(&msg); |
446 | 446 | } |
diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp
index 685c548..45a5e0d 100644
a
|
b
|
void
|
625 | 625 | InputServer::HandleSetMethod(BMessage* message) |
626 | 626 | { |
627 | 627 | CALLED(); |
628 | | uint32 cookie; |
629 | | if (message->FindInt32("cookie", (int32*)&cookie) == B_OK) { |
630 | | BInputServerMethod *method = (BInputServerMethod*)cookie; |
631 | | PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, method)); |
632 | | SetActiveMethod(method); |
| 628 | int32 cookie; |
| 629 | if (message->FindInt32("cookie", &cookie) == B_OK) { |
| 630 | BAutolock lock(InputServer::gInputMethodListLocker); |
| 631 | for (int32 i = 0; i < gInputMethodList.CountItems(); i++) { |
| 632 | BInputServerMethod* method |
| 633 | = (BInputServerMethod*)InputServer::gInputMethodList.ItemAt(i); |
| 634 | if (method->fOwner->Cookie() == cookie) { |
| 635 | PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, |
| 636 | cookie)); |
| 637 | SetActiveMethod(method); |
| 638 | break; |
| 639 | } |
| 640 | } |
633 | 641 | } |
634 | 642 | } |
635 | 643 | |
diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h
index 7b70b33..43f540c 100644
a
|
b
|
class _BMethodAddOn_ {
|
99 | 99 | status_t SetMenu(const BMenu* menu, const BMessenger& messenger); |
100 | 100 | status_t MethodActivated(bool activate); |
101 | 101 | status_t AddMethod(); |
| 102 | int32 Cookie() { return fCookie; } |
102 | 103 | |
103 | 104 | private: |
104 | 105 | BInputServerMethod* fMethod; |
… |
… |
class _BMethodAddOn_ {
|
106 | 107 | uchar fIcon[16*16*1]; |
107 | 108 | const BMenu* fMenu; |
108 | 109 | BMessenger fMessenger; |
| 110 | int32 fCookie; |
109 | 111 | }; |
110 | 112 | |
111 | 113 | class KeymapMethod : public BInputServerMethod { |
diff --git a/src/servers/input/InputServerMethod.cpp b/src/servers/input/InputServerMethod.cpp
index 06adee4..6333dc5 100644
a
|
b
|
BInputServerMethod::_ReservedInputServerMethod4()
|
153 | 153 | } |
154 | 154 | |
155 | 155 | |
| 156 | static int32 sNextMethodCookie = 1; |
| 157 | |
| 158 | |
156 | 159 | _BMethodAddOn_::_BMethodAddOn_(BInputServerMethod *method, const char *name, |
157 | 160 | const uchar *icon) |
158 | 161 | : fMethod(method), |
159 | | fMenu(NULL) |
| 162 | fMenu(NULL), |
| 163 | fCookie(sNextMethodCookie++) |
160 | 164 | { |
161 | 165 | fName = strdup(name); |
162 | 166 | if (icon != NULL) |
… |
… |
_BMethodAddOn_::SetName(const char* name)
|
183 | 187 | fName = strdup(name); |
184 | 188 | |
185 | 189 | BMessage msg(IS_UPDATE_NAME); |
186 | | msg.AddInt32("cookie", (uint32)fMethod); |
| 190 | msg.AddInt32("cookie", fCookie); |
187 | 191 | msg.AddString("name", name); |
188 | 192 | if (((InputServer*)be_app)->MethodReplicant()) |
189 | 193 | return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); |
… |
… |
_BMethodAddOn_::SetIcon(const uchar* icon)
|
203 | 207 | memset(fIcon, 0x1d, 16*16*1); |
204 | 208 | |
205 | 209 | BMessage msg(IS_UPDATE_ICON); |
206 | | msg.AddInt32("cookie", (uint32)fMethod); |
| 210 | msg.AddInt32("cookie", fCookie); |
207 | 211 | msg.AddData("icon", B_RAW_TYPE, icon, 16*16*1); |
208 | 212 | if (((InputServer*)be_app)->MethodReplicant()) |
209 | 213 | return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); |
… |
… |
_BMethodAddOn_::SetMenu(const BMenu *menu, const BMessenger &messenger)
|
220 | 224 | fMessenger = messenger; |
221 | 225 | |
222 | 226 | BMessage msg(IS_UPDATE_MENU); |
223 | | msg.AddInt32("cookie", (uint32)fMethod); |
| 227 | msg.AddInt32("cookie", fCookie); |
224 | 228 | BMessage menuMsg; |
225 | 229 | if (menu) |
226 | 230 | menu->Archive(&menuMsg); |
… |
… |
_BMethodAddOn_::MethodActivated(bool activate)
|
238 | 242 | { |
239 | 243 | CALLED(); |
240 | 244 | if (fMethod) { |
241 | | PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod)); |
| 245 | PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie)); |
242 | 246 | if (activate && ((InputServer*)be_app)->MethodReplicant()) { |
243 | 247 | BMessage msg(IS_UPDATE_METHOD); |
244 | | msg.AddInt32("cookie", (uint32)fMethod); |
| 248 | msg.AddInt32("cookie", fCookie); |
245 | 249 | ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); |
246 | 250 | } |
247 | 251 | return fMethod->MethodActivated(activate); |
… |
… |
_BMethodAddOn_::MethodActivated(bool activate)
|
253 | 257 | status_t |
254 | 258 | _BMethodAddOn_::AddMethod() |
255 | 259 | { |
256 | | PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod)); |
| 260 | PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie)); |
257 | 261 | BMessage msg(IS_ADD_METHOD); |
258 | | msg.AddInt32("cookie", (uint32)fMethod); |
| 262 | msg.AddInt32("cookie", fCookie); |
259 | 263 | msg.AddString("name", fName); |
260 | 264 | msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1); |
261 | 265 | if (((InputServer*)be_app)->MethodReplicant()) |