VirtualBox

Ignore:
Timestamp:
Aug 11, 2010 5:21:27 PM (14 years ago)
Author:
vboxsync
Message:

EventQueue: Fix losing messages, use the right queue type on XPCOM (the fact that event handling in VBoxSVC worked was mainly luck), big code cleanup. VBoxHeadless and VirtualBoxImpl now use the only remaining event processing style. Eliminated redundant custom StateChange event in VBoxHeadless.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r31539 r31579  
    8383static EventQueue *gEventQ = NULL;
    8484
     85/* flag whether frontend should terminate */
     86static volatile bool g_fTerminateFE = false;
     87
    8588#ifdef VBOX_WITH_VNC
    8689static VNCFB *g_pFramebufferVNC;
     
    8992
    9093////////////////////////////////////////////////////////////////////////////////
    91 
    92 /**
    93  *  State change event.
    94  */
    95 class StateChangeEvent : public Event
    96 {
    97 public:
    98     StateChangeEvent(MachineState_T state) : mState(state) {}
    99 protected:
    100     void *handler()
    101     {
    102         LogFlow(("VBoxHeadless: StateChangeEvent: %d\n", mState));
    103         /* post the termination event if the machine has been PoweredDown/Saved/Aborted */
    104         if (mState < MachineState_Running)
    105             gEventQ->postEvent(NULL);
    106         return 0;
    107     }
    108 private:
    109     MachineState_T mState;
    110 };
    11194
    11295/**
     
    319302                scev->COMGETTER(State)(&machineState);
    320303
    321                 gEventQ->postEvent(new StateChangeEvent(machineState));
     304                /* Terminate any event wait operation if the machine has been
     305                 * PoweredDown/Saved/Aborted. */
     306                if (machineState < MachineState_Running)
     307                {
     308                    g_fTerminateFE = true;
     309                    gEventQ->interruptEventQueueProcessing();
     310                }
     311
    322312                break;
    323313            }
     
    10881078                break;
    10891079
    1090             /* Process pending events, then wait for new ones. */
     1080            /* Process pending events, then wait for new ones. Note, this
     1081             * processes NULL events signalling event loop termination. */
    10911082            gEventQ->processEventQueue(0);
    1092             gEventQ->processEventQueue(500);
    1093         }
    1094 
    1095         /** @todo The error handling here is kind of peculiar, anyone care
    1096          *        to comment why this works just fine? (this is old the code) */
     1083            if (!g_fTerminateFE)
     1084                gEventQ->processEventQueue(500);
     1085        }
     1086
    10971087        if (SUCCEEDED(progress->WaitForCompletion(-1)))
    10981088        {
     1089            /* Figure out if the operation completed with a failed status
     1090             * and print the error message. Terminate immediately, and let
     1091             * the cleanup code take care of potentially pending events. */
    10991092            LONG progressRc;
    11001093            progress->COMGETTER(ResultCode)(&progressRc);
    11011094            rc = progressRc;
    1102             if (FAILED(progressRc))
     1095            if (FAILED(rc))
    11031096            {
    11041097                com::ProgressErrorInfo info(progress);
     
    11111104                    RTPrintf("Error: failed to start machine. No error message available!\n");
    11121105                }
     1106                break;
    11131107            }
    11141108        }
     
    11321126        Log(("VBoxHeadless: Waiting for PowerDown...\n"));
    11331127
    1134         Event *e;
    1135 
    1136         while (gEventQ->waitForEvent(&e) && e)
    1137           gEventQ->handleEvent(e);
     1128        while (   !g_fTerminateFE
     1129               && RT_SUCCESS(gEventQ->processEventQueue(RT_INDEFINITE_WAIT)))
     1130            /* nothing */ ;
    11381131
    11391132        Log(("VBoxHeadless: event loop has terminated...\n"));
Note: See TracChangeset for help on using the changeset viewer.

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