VirtualBox

Ignore:
Timestamp:
Sep 20, 2012 12:12:09 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
80828
Message:

Haiku Additions: cleanup.

Location:
trunk/src/VBox/Additions/haiku/VBoxMouse
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp

    r43363 r43364  
    6363
    6464/* Export as global symbol with C linkage, RTDECL is necessary. */
    65 RTDECL(BInputServerDevice*)
     65RTDECL(BInputServerDevice *)
    6666instantiate_input_device()
    6767{
     
    6969}
    7070
     71
    7172VBoxMouse::VBoxMouse()
    72         : BInputServerDevice(),
    73         fDriverFD(-1),
    74         fServiceThreadID(-1),
    75         fExiting(false)
    76 {
    77 }
     73     : BInputServerDevice(),
     74       fDriverFD(-1),
     75       fServiceThreadID(-1),
     76       fExiting(false)
     77{
     78}
     79
    7880
    7981VBoxMouse::~VBoxMouse()
    8082{
    8183}
     84
    8285
    8386status_t VBoxMouse::InitCheck()
     
    8588    int rc = VbglR3Init();
    8689    if (!RT_SUCCESS(rc))
    87                 return ENXIO;
    88 
    89         //// Start() will *not* Init() again
     90        return ENXIO;
     91
     92    //// Start() will *not* Init() again
    9093    //VbglR3Term();
    9194
    92 //              return B_DEVICE_NOT_FOUND;
    93 
    94         input_device_ref device = { (char *)"VBoxMouse",
    95                 B_POINTING_DEVICE, (void*)this };
    96         input_device_ref* deviceList[2] = { &device, NULL };
    97         RegisterDevices(deviceList);
    98 
    99         return B_OK;
    100 }
     95//        return B_DEVICE_NOT_FOUND;
     96
     97    input_device_ref device = { (char *)"VBoxMouse",
     98        B_POINTING_DEVICE, (void *)this };
     99    input_device_ref *deviceList[2] = { &device, NULL };
     100    RegisterDevices(deviceList);
     101
     102    return B_OK;
     103}
     104
    101105
    102106status_t VBoxMouse::SystemShuttingDown()
     
    104108    VbglR3Term();
    105109
    106         return B_OK;
    107 }
    108 
    109 status_t VBoxMouse::Start(const char* device, void* cookie)
    110 {
    111         status_t err;
    112         int rc;
     110    return B_OK;
     111}
     112
     113
     114status_t VBoxMouse::Start(const char *device, void *cookie)
     115{
     116    status_t err;
     117    int rc;
    113118    uint32_t fFeatures = 0;
    114119    Log(("VBoxMouse::%s()\n", __FUNCTION__));
     
    116121    rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
    117122    if (RT_SUCCESS(rc))
    118         rc = VbglR3SetMouseStatus(  fFeatures
     123        rc = VbglR3SetMouseStatus(fFeatures
    119124                                  | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
    120125                                  | VMMDEV_MOUSE_NEW_PROTOCOL);
    121     if (!RT_SUCCESS(rc)) {
    122                 LogRel(("VBoxMouse: Error switching guest mouse into absolute mode: %d\n", rc));
     126    if (!RT_SUCCESS(rc))
     127    {
     128        LogRel(("VBoxMouse: Error switching guest mouse into absolute mode: %d\n", rc));
    123129        return B_DEVICE_NOT_FOUND;
    124130    }
    125131
    126         err = fServiceThreadID = spawn_thread(_ServiceThreadNub,
    127                         "VBoxMouse", B_NORMAL_PRIORITY, this);
    128         if (err >= B_OK) {
    129                 resume_thread(fServiceThreadID);
    130                 return B_OK;
    131         } else
     132    err = fServiceThreadID = spawn_thread(_ServiceThreadNub,
     133                                          "VBoxMouse", B_NORMAL_PRIORITY, this);
     134    if (err >= B_OK)
     135    {
     136        resume_thread(fServiceThreadID);
     137        return B_OK;
     138    }
     139    else
    132140        LogRel(("VBoxMouse: Error starting service thread: 0x%08lx\n",
    133                 err));
    134 
    135         // release the mouse
     141                err));
     142
     143    // release the mouse
    136144    rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
    137145    if (RT_SUCCESS(rc))
    138         rc = VbglR3SetMouseStatus(  fFeatures
     146        rc = VbglR3SetMouseStatus(fFeatures
    139147                                  & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
    140148                                  & ~VMMDEV_MOUSE_NEW_PROTOCOL);
    141149
    142          return B_ERROR;
    143 }
    144 
    145 status_t VBoxMouse::Stop(const char* device, void* cookie)
    146 {
    147         status_t status;
    148         int rc;
     150    return B_ERROR;
     151}
     152
     153
     154status_t VBoxMouse::Stop(const char *device, void *cookie)
     155{
     156    status_t status;
     157    int rc;
    149158    uint32_t fFeatures = 0;
    150159    Log(("VBoxMouse::%s()\n", __FUNCTION__));
    151160
    152         fExiting = true;
     161    fExiting = true;
    153162
    154163
    155164    rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
    156165    if (RT_SUCCESS(rc))
    157         rc = VbglR3SetMouseStatus(  fFeatures
     166        rc = VbglR3SetMouseStatus(fFeatures
    158167                                  & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
    159168                                  & ~VMMDEV_MOUSE_NEW_PROTOCOL);
    160169
    161170
    162         close(fDriverFD);
    163         fDriverFD = -1;
    164         //XXX WTF ?
    165         suspend_thread(fServiceThreadID);
    166         resume_thread(fServiceThreadID);
    167         wait_for_thread(fServiceThreadID, &status);
    168         fServiceThreadID = -1;
    169         fExiting = false;
    170     return B_OK;
    171 }
    172 
    173 status_t VBoxMouse::Control(const char  *device,
    174                                                 void            *cookie,
    175                                                 uint32          code,
    176                                                 BMessage        *message)
    177 {
    178         // respond to changes in the system
    179         switch (code) {
    180                 case B_MOUSE_SPEED_CHANGED:
    181                 case B_CLICK_SPEED_CHANGED:
    182                 case B_MOUSE_ACCELERATION_CHANGED:
    183                 default:
    184                         return BInputServerDevice::Control(device, cookie, code, message);
    185         }
    186         return B_OK;
    187 }
     171    close(fDriverFD);
     172    fDriverFD = -1;
     173    //XXX WTF ?
     174    suspend_thread(fServiceThreadID);
     175    resume_thread(fServiceThreadID);
     176    wait_for_thread(fServiceThreadID, &status);
     177    fServiceThreadID = -1;
     178    fExiting = false;
     179    return B_OK;
     180}
     181
     182
     183status_t VBoxMouse::Control(const char *device, void *cookie, uint32 code, BMessage *message)
     184{
     185    // respond to changes in the system
     186    switch (code)
     187    {
     188        case B_MOUSE_SPEED_CHANGED:
     189        case B_CLICK_SPEED_CHANGED:
     190        case B_MOUSE_ACCELERATION_CHANGED:
     191        default:
     192            return BInputServerDevice::Control(device, cookie, code, message);
     193    }
     194    return B_OK;
     195}
     196
    188197
    189198status_t VBoxMouse::_ServiceThreadNub(void *_this)
    190199{
    191         VBoxMouse *service = (VBoxMouse *)_this;
    192         return service->_ServiceThread();
    193 }
     200    VBoxMouse *service = (VBoxMouse *)_this;
     201    return service->_ServiceThread();
     202}
     203
    194204
    195205status_t VBoxMouse::_ServiceThread()
     
    197207    Log(("VBoxMouse::%s()\n", __FUNCTION__));
    198208
    199         fDriverFD = open(VBOXGUEST_DEVICE_NAME, O_RDWR);
    200         if (fDriverFD < 0)
    201                 return ENXIO;
     209    fDriverFD = open(VBOXGUEST_DEVICE_NAME, O_RDWR);
     210    if (fDriverFD < 0)
     211        return ENXIO;
    202212
    203213    /* The thread waits for incoming messages from the host. */
    204214    while (!fExiting)
    205215    {
    206             uint32_t cx, cy, fFeatures;
    207         int rc;
    208 
    209 
    210                 fd_set readSet, writeSet, errorSet;
    211                 FD_ZERO(&readSet);
    212                 FD_ZERO(&writeSet);
    213                 FD_ZERO(&errorSet);
    214                 FD_SET(fDriverFD, &readSet);
    215                 if (fDriverFD < 0)
    216                         break;
    217                 rc = select(fDriverFD + 1, &readSet, &writeSet, &errorSet, NULL);
    218                 if (rc < 0) {
    219                         if (errno == EINTR || errno == EAGAIN)
    220                                 continue;
    221                         break;
    222                 }
    223 
    224             if (RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy))
    225             && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE))
    226         {
    227                 float x = cx * 1.0 / 65535;
    228                 float y = cy * 1.0 / 65535;
    229 
    230                 _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y);
    231 
    232                 /* send absolute movement */
    233 
    234                         bigtime_t now = system_time();
    235                         BMessage* event = new BMessage(B_MOUSE_MOVED);
    236                         event->AddInt64("when", now);
    237                         event->AddFloat("x", x);
    238                         event->AddFloat("y", y);
    239                         event->AddFloat("be:tablet_x", x);
    240                         event->AddFloat("be:tablet_y", y);
    241                         //event->PrintToStream();
    242                         EnqueueMessage(event);
    243 
    244                 //LogRelFlow(("processed host event rc = %d\n", rc));
    245         }
    246     }
    247         return 0;
    248 }
    249 
    250 
     216        uint32_t cx, cy, fFeatures;
     217        int rc;
     218
     219
     220        fd_set readSet, writeSet, errorSet;
     221        FD_ZERO(&readSet);
     222        FD_ZERO(&writeSet);
     223        FD_ZERO(&errorSet);
     224        FD_SET(fDriverFD, &readSet);
     225        if (fDriverFD < 0)
     226            break;
     227        rc = select(fDriverFD + 1, &readSet, &writeSet, &errorSet, NULL);
     228        if (rc < 0)
     229        {
     230            if (errno == EINTR || errno == EAGAIN)
     231                continue;
     232            break;
     233        }
     234
     235        if (RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy))
     236            && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE))
     237        {
     238            float x = cx * 1.0 / 65535;
     239            float y = cy * 1.0 / 65535;
     240
     241            _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y);
     242
     243            /* send absolute movement */
     244
     245            bigtime_t now = system_time();
     246            BMessage *event = new BMessage(B_MOUSE_MOVED);
     247            event->AddInt64("when", now);
     248            event->AddFloat("x", x);
     249            event->AddFloat("y", y);
     250            event->AddFloat("be:tablet_x", x);
     251            event->AddFloat("be:tablet_y", y);
     252            //event->PrintToStream();
     253            EnqueueMessage(event);
     254
     255            //LogRelFlow(("processed host event rc = %d\n", rc));
     256        }
     257    }
     258    return 0;
     259}
     260
  • trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h

    r43363 r43364  
    5050#include <InputServerDevice.h>
    5151
    52 extern "C" _EXPORT BInputServerDevice* instantiate_input_device();
     52extern "C"
     53_EXPORT BInputServerDevice* instantiate_input_device();
    5354
    54 class VBoxMouse : public BInputServerDevice {
    55 public:
    56         VBoxMouse();
    57         virtual ~VBoxMouse();
     55class VBoxMouse : public BInputServerDevice
     56{
     57    public:
     58        VBoxMouse();
     59        virtual ~VBoxMouse();
    5860
    59         virtual status_t                InitCheck();
    60         virtual status_t                SystemShuttingDown();
     61        virtual status_t                InitCheck();
     62        virtual status_t                SystemShuttingDown();
    6163
    62         virtual status_t                Start(const char* device, void* cookie);
    63         virtual status_t                Stop(const char* device, void* cookie);
    64         virtual status_t                Control(const char      *device,
    65                                                                         void            *cookie,
    66                                                                         uint32          code,
    67                                                                         BMessage        *message);
     64        virtual status_t                Start(const char *device, void *cookie);
     65        virtual status_t                Stop(const char *device, void *cookie);
     66        virtual status_t                Control(const char      *device,
     67                                  void          *cookie,
     68                                  uint32                code,
     69                                  BMessage      *message);
    6870
    69 private:
     71    private:
    7072
    71 static status_t _ServiceThreadNub(void *_this);
    72         status_t        _ServiceThread();
     73        static status_t _ServiceThreadNub(void *_this);
     74        status_t        _ServiceThread();
    7375
    74         int                     fDriverFD;
    75         thread_id       fServiceThreadID;
    76         bool            fExiting;
     76        int                     fDriverFD;
     77        thread_id       fServiceThreadID;
     78        bool            fExiting;
    7779
    7880};
     
    8082
    8183#endif /* __VBOXMOUSE__H */
     84
  • trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp

    r43363 r43364  
    6464// TODO can this be merged with VBoxMouse?
    6565
    66 RTDECL(BInputServerFilter*)
     66RTDECL(BInputServerFilter *)
    6767instantiate_input_filter()
    6868{
    69         return new VBoxMouseFilter();
     69    return new VBoxMouseFilter();
    7070}
    7171
    7272VBoxMouseFilter::VBoxMouseFilter()
    73         : BInputServerFilter(),
    74         fDriverFD(-1),
    75         fServiceThreadID(-1),
    76         fExiting(false),
    77         fCurrentButtons(0)
     73     : BInputServerFilter(),
     74       fDriverFD(-1),
     75       fServiceThreadID(-1),
     76       fExiting(false),
     77       fCurrentButtons(0)
    7878{
    7979}
     
    8383}
    8484
    85 filter_result VBoxMouseFilter::Filter(BMessage* message, BList* outList)
     85filter_result VBoxMouseFilter::Filter(BMessage *message, BList *outList)
    8686{
    87         switch(message->what) {
    88                 case B_MOUSE_UP:
    89                 case B_MOUSE_DOWN:
    90                 {
    91                         printf("click|release\n");
    92                         message->FindInt32("buttons", &fCurrentButtons);
    93                 }
    94                 case B_MOUSE_MOVED:
    95                 {
    96                         printf("mouse moved\n");
    97                         message->ReplaceInt32("buttons", fCurrentButtons);
    98                 }
    99         }
     87    switch (message->what)
     88    {
     89        case B_MOUSE_UP:
     90        case B_MOUSE_DOWN:
     91        {
     92            printf("click|release\n");
     93            message->FindInt32("buttons", &fCurrentButtons);
     94        }
     95        case B_MOUSE_MOVED:
     96        {
     97            printf("mouse moved\n");
     98            message->ReplaceInt32("buttons", fCurrentButtons);
     99        }
     100    }
    100101
    101         return B_DISPATCH_MESSAGE;
     102    return B_DISPATCH_MESSAGE;
    102103}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette