Ticket #8831: 0001-input_server-use-a-generated-cookie-instead-of-point.patch

File 0001-input_server-use-a-generated-cookie-instead-of-point.patch, 5.3 KB (added by korli, 12 years ago)
  • src/servers/input/AddOnManager.cpp

    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)  
    440440            gInputServer->SetMethodReplicant(NULL);
    441441        } else if (method != NULL) {
    442442            BMessage msg(IS_REMOVE_METHOD);
    443             msg.AddInt32("cookie", (uint32)method);
     443            msg.AddInt32("cookie", method->fOwner->Cookie());
    444444            if (gInputServer->MethodReplicant())
    445445                gInputServer->MethodReplicant()->SendMessage(&msg);
    446446        }
  • src/servers/input/InputServer.cpp

    diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp
    index 685c548..45a5e0d 100644
    a b void  
    625625InputServer::HandleSetMethod(BMessage* message)
    626626{
    627627    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        }
    633641    }
    634642}
    635643
  • src/servers/input/InputServer.h

    diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h
    index 7b70b33..43f540c 100644
    a b class _BMethodAddOn_ {  
    9999        status_t SetMenu(const BMenu* menu, const BMessenger& messenger);
    100100        status_t MethodActivated(bool activate);
    101101        status_t AddMethod();
     102        int32 Cookie() { return fCookie; }
    102103
    103104    private:
    104105        BInputServerMethod* fMethod;
    class _BMethodAddOn_ {  
    106107        uchar fIcon[16*16*1];
    107108        const BMenu* fMenu;
    108109        BMessenger fMessenger;
     110        int32 fCookie;
    109111};
    110112
    111113class KeymapMethod : public BInputServerMethod {
  • src/servers/input/InputServerMethod.cpp

    diff --git a/src/servers/input/InputServerMethod.cpp b/src/servers/input/InputServerMethod.cpp
    index 06adee4..6333dc5 100644
    a b BInputServerMethod::_ReservedInputServerMethod4()  
    153153}
    154154
    155155
     156static int32 sNextMethodCookie = 1;
     157
     158
    156159_BMethodAddOn_::_BMethodAddOn_(BInputServerMethod *method, const char *name,
    157160    const uchar *icon)
    158161    : fMethod(method),
    159     fMenu(NULL)
     162    fMenu(NULL),
     163    fCookie(sNextMethodCookie++)
    160164{
    161165    fName = strdup(name);
    162166    if (icon != NULL)
    _BMethodAddOn_::SetName(const char* name)  
    183187        fName = strdup(name);
    184188
    185189    BMessage msg(IS_UPDATE_NAME);
    186     msg.AddInt32("cookie", (uint32)fMethod);
     190    msg.AddInt32("cookie", fCookie);
    187191    msg.AddString("name", name);
    188192    if (((InputServer*)be_app)->MethodReplicant())
    189193        return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
    _BMethodAddOn_::SetIcon(const uchar* icon)  
    203207        memset(fIcon, 0x1d, 16*16*1);
    204208
    205209    BMessage msg(IS_UPDATE_ICON);
    206     msg.AddInt32("cookie", (uint32)fMethod);
     210    msg.AddInt32("cookie", fCookie);
    207211    msg.AddData("icon", B_RAW_TYPE, icon, 16*16*1);
    208212    if (((InputServer*)be_app)->MethodReplicant())
    209213        return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
    _BMethodAddOn_::SetMenu(const BMenu *menu, const BMessenger &messenger)  
    220224    fMessenger = messenger;
    221225
    222226    BMessage msg(IS_UPDATE_MENU);
    223     msg.AddInt32("cookie", (uint32)fMethod);
     227    msg.AddInt32("cookie", fCookie);
    224228    BMessage menuMsg;
    225229    if (menu)
    226230        menu->Archive(&menuMsg);
    _BMethodAddOn_::MethodActivated(bool activate)  
    238242{
    239243    CALLED();
    240244    if (fMethod) {
    241         PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
     245        PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie));
    242246        if (activate && ((InputServer*)be_app)->MethodReplicant()) {
    243247            BMessage msg(IS_UPDATE_METHOD);
    244                 msg.AddInt32("cookie", (uint32)fMethod);
     248                msg.AddInt32("cookie", fCookie);
    245249                    ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
    246250        }
    247251        return fMethod->MethodActivated(activate);
    _BMethodAddOn_::MethodActivated(bool activate)  
    253257status_t
    254258_BMethodAddOn_::AddMethod()
    255259{
    256     PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
     260    PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie));
    257261    BMessage msg(IS_ADD_METHOD);
    258     msg.AddInt32("cookie", (uint32)fMethod);
     262    msg.AddInt32("cookie", fCookie);
    259263    msg.AddString("name", fName);
    260264    msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1);
    261265    if (((InputServer*)be_app)->MethodReplicant())