Professional Web Applications Themes

Using Run Loops - Blocking User Input? - Mac Programming

I've been working for a few weeks on an application to write data to a USB device and receive input from that device. This has been a very confusing and compicated endeavor, but I think I'm making some progress. One thing that is really confusing me, however, is the use of Run Loops. The sample code I am modifying sets up a run loop and adds a notification port to it in order that notification events from the USB IO device will be received. To do this it calls: IONotificationPortCreate(); IONotificationPortGetRunLoopSource(); CFRunLoopGetCurrent(); CFRunLoopAddSource(); Then it makes a call to IOServiceAddMatchingNotification() ...

  1. #1

    Default Using Run Loops - Blocking User Input?

    I've been working for a few weeks on an application to write data to a
    USB device and receive input from that device. This has been a very
    confusing and compicated endeavor, but I think I'm making some progress.

    One thing that is really confusing me, however, is the use of Run Loops.

    The sample code I am modifying sets up a run loop and adds a
    notification port to it in order that notification events from the USB
    IO device will be received. To do this it calls:

    IONotificationPortCreate();
    IONotificationPortGetRunLoopSource();
    CFRunLoopGetCurrent();
    CFRunLoopAddSource();

    Then it makes a call to IOServiceAddMatchingNotification() and passes it
    the NotificationPortRef which was obtained by the call to
    IONotificationPortCreate().

    All is fine and dandy, and my application receives notifications of when
    matching USB devices are plugged in or unplugged.

    The problem is that this run loop seems to block all other application
    activities from happening. All user input is ignored until the run loop
    is terminated, at which point the user input is re-enabled.

    My question is: How can I have this run loop looking for I/O
    notifications without blocking all the other tasks that the application
    has to do (e.g. obtaining and processing user input, updating the GUI,
    etc.)?

    I feel that I have somehow unwittingly created a premptive thread and
    what I'd like is a thread that shares time with the main application
    event thread.

    Any help on this or pointers to doents which explain run loops better
    would be appreciated. I've read TONS of doents on Apple.Com in the
    last few weeks, but nothing addresses this specific issue.

    Thanks!
    Charles Guest

  2. #2

    Default Re: Using Run Loops - Blocking User Input?

    In article <doit.wisc.edu>,
    Charles Thomas <facstaff.wisc.edu> wrote:
     

    How is your application doing the UI? Are you old style polling ala
    WaitNextEvent() or are you calling RunApplicationEventLoop()?

    If you are calling RunApplicationEventLoop(), that is equivalent to
    CFRunLoopRun() with some extra stuff thrown in behind your back. So,
    you can set everything up as you've outlined above and when you call
    RunApplicationEventLoop() both the UI and notifications should run.

    A run loop is basically an infinite loop (infinite state machine) that
    schedules everything on your main thread.

    Hope this helped.

    Cheers,
    H.

    --
    To reply via email, replace "LastNameHere" with my last name.
    Herb Guest

  3. #3

    Default Re: Using Run Loops - Blocking User Input?

    In article <cg.shawcable.net>,
    Herb Petschauer <com> wrote:
     

    This is an older application that was converted to carbon but still uses
    WaitNextEvent().

    CT
    Charles Guest

  4. #4

    Default Re: Using Run Loops - Blocking User Input?

    In article <doit.wisc.edu>,
    Charles Thomas <facstaff.wisc.edu> wrote:
     
    >
    > This is an older application that was converted to carbon but still uses
    > WaitNextEvent().
    >
    > CT[/ref]

    Have you tried not calling CFRunLoopRun()? I seem to recall that I've
    subscribed to various CarbonEvents using PowerPlant (not PP X) and that
    definitely did old style polling. I even subscribed to power
    notifications and that requires a call to CFRunLoopAddSource().

    H.

    --
    To reply via email, replace "LastNameHere" with my last name.
    Herb Guest

Similar Threads

  1. Saving user input to xml
    By Beatie3 in forum Macromedia Flash Data Integration
    Replies: 2
    Last Post: May 23rd, 10:51 PM
  2. Remembering User input
    By Lamptey in forum Macromedia Director Basics
    Replies: 2
    Last Post: May 9th, 11:59 AM
  3. Getting User Input via Email
    By Tim M in forum ASP
    Replies: 2
    Last Post: September 25th, 05:14 PM
  4. Will Thread blocking in read() leads to process blocking?
    By Loic Domaigne in forum UNIX Programming
    Replies: 4
    Last Post: July 23rd, 12:36 PM
  5. Blocking user sharing router
    By Jason in forum Windows Networking
    Replies: 3
    Last Post: July 3rd, 04:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139