VirtualBox

Ignore:
Timestamp:
Oct 21, 2010 10:46:46 AM (14 years ago)
Author:
vboxsync
Message:

Main: support aggregation of multiple event sources into one,
to allow listen on multiple event sources without heavy polling
(pretty much what select() do with fds)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r33266 r33295  
    405405    listener = console.eventSource.createListener()
    406406    registered = False
    407     sources = [console.keyboard.eventSource, console.mouse.eventSource]
     407    # we create an aggregated event source to listen for multiple event types
     408    agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource])
    408409    demo = open(file, 'w')
    409410    header="VM="+console.machine.name+"\n"
     
    413414        dur = 100000
    414415    try:
    415         for es in sources:
    416             es.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
     416        agg.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
    417417        registered = True
    418418        end = time.time() + dur
    419419        while  time.time() < end:
    420             for es in sources:
    421                 ev = es.getEvent(listener, 0)
    422                 if ev:
    423                     handleEventImpl(ev)
    424                     # keyboard/mouse events aren't waitable, so no need for eventProcessed
     420            ev = agg.getEvent(listener, 0)
     421            if ev:
     422                handleEventImpl(ev)
     423                # keyboard/mouse events aren't waitable, so no need for eventProcessed
    425424    # We need to catch all exceptions here, otherwise listener will never be unregistered
    426425    except:
     
    429428    demo.close()
    430429    if listener and registered:
    431         for es in sources:
    432             es.unregisterListener(listener)
     430        agg.unregisterListener(listener)
    433431
    434432
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