input_server: use a generated cookie instead of pointer

* fixed #8831
This commit is contained in:
Jérôme Duval 2012-08-28 20:32:46 +02:00
parent 61cb4d8c6d
commit c618b6ccb1
4 changed files with 32 additions and 14 deletions

View File

@ -440,7 +440,7 @@ AddOnManager::_UnregisterAddOn(BEntry& entry)
gInputServer->SetMethodReplicant(NULL);
} else if (method != NULL) {
BMessage msg(IS_REMOVE_METHOD);
msg.AddInt32("cookie", (uint32)method);
msg.AddInt32("cookie", method->fOwner->Cookie());
if (gInputServer->MethodReplicant())
gInputServer->MethodReplicant()->SendMessage(&msg);
}

View File

@ -625,11 +625,23 @@ void
InputServer::HandleSetMethod(BMessage* message)
{
CALLED();
uint32 cookie;
if (message->FindInt32("cookie", (int32*)&cookie) == B_OK) {
BInputServerMethod *method = (BInputServerMethod*)cookie;
PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, method));
SetActiveMethod(method);
int32 cookie;
if (message->FindInt32("cookie", &cookie) != B_OK)
return;
if (cookie == gKeymapMethod.fOwner->Cookie()) {
SetActiveMethod(&gKeymapMethod);
} else {
BAutolock lock(InputServer::gInputMethodListLocker);
for (int32 i = 0; i < gInputMethodList.CountItems(); i++) {
BInputServerMethod* method
= (BInputServerMethod*)InputServer::gInputMethodList.ItemAt(i);
if (method->fOwner->Cookie() == cookie) {
PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__,
cookie));
SetActiveMethod(method);
break;
}
}
}
}

View File

@ -99,6 +99,7 @@ class _BMethodAddOn_ {
status_t SetMenu(const BMenu* menu, const BMessenger& messenger);
status_t MethodActivated(bool activate);
status_t AddMethod();
int32 Cookie() { return fCookie; }
private:
BInputServerMethod* fMethod;
@ -106,6 +107,7 @@ class _BMethodAddOn_ {
uchar fIcon[16*16*1];
const BMenu* fMenu;
BMessenger fMessenger;
int32 fCookie;
};
class KeymapMethod : public BInputServerMethod {

View File

@ -153,10 +153,14 @@ BInputServerMethod::_ReservedInputServerMethod4()
}
static int32 sNextMethodCookie = 1;
_BMethodAddOn_::_BMethodAddOn_(BInputServerMethod *method, const char *name,
const uchar *icon)
: fMethod(method),
fMenu(NULL)
fMenu(NULL),
fCookie(sNextMethodCookie++)
{
fName = strdup(name);
if (icon != NULL)
@ -183,7 +187,7 @@ _BMethodAddOn_::SetName(const char* name)
fName = strdup(name);
BMessage msg(IS_UPDATE_NAME);
msg.AddInt32("cookie", (uint32)fMethod);
msg.AddInt32("cookie", fCookie);
msg.AddString("name", name);
if (((InputServer*)be_app)->MethodReplicant())
return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
@ -203,7 +207,7 @@ _BMethodAddOn_::SetIcon(const uchar* icon)
memset(fIcon, 0x1d, 16*16*1);
BMessage msg(IS_UPDATE_ICON);
msg.AddInt32("cookie", (uint32)fMethod);
msg.AddInt32("cookie", fCookie);
msg.AddData("icon", B_RAW_TYPE, icon, 16*16*1);
if (((InputServer*)be_app)->MethodReplicant())
return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
@ -220,7 +224,7 @@ _BMethodAddOn_::SetMenu(const BMenu *menu, const BMessenger &messenger)
fMessenger = messenger;
BMessage msg(IS_UPDATE_MENU);
msg.AddInt32("cookie", (uint32)fMethod);
msg.AddInt32("cookie", fCookie);
BMessage menuMsg;
if (menu)
menu->Archive(&menuMsg);
@ -238,10 +242,10 @@ _BMethodAddOn_::MethodActivated(bool activate)
{
CALLED();
if (fMethod) {
PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie));
if (activate && ((InputServer*)be_app)->MethodReplicant()) {
BMessage msg(IS_UPDATE_METHOD);
msg.AddInt32("cookie", (uint32)fMethod);
msg.AddInt32("cookie", fCookie);
((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
}
return fMethod->MethodActivated(activate);
@ -253,9 +257,9 @@ _BMethodAddOn_::MethodActivated(bool activate)
status_t
_BMethodAddOn_::AddMethod()
{
PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie));
BMessage msg(IS_ADD_METHOD);
msg.AddInt32("cookie", (uint32)fMethod);
msg.AddInt32("cookie", fCookie);
msg.AddString("name", fName);
msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1);
if (((InputServer*)be_app)->MethodReplicant())