views:

39

answers:

2

I'm porting an archaic C++/Carbon program to Obj-C and Cocoa. The current version uses asynchronous usb reads and GetNextEvent to read the data.

When I try to compile this in Objective C, GetNextEvent isn't found because it's in the Carbon framework.

Searching Apple support yields nothing of use.

EDIT TO ADD:

Ok, so what I'm trying to do is run a document scanner through USB. I have set up the USBDeviceInterface and the USBInterfaceInterface (who came up with THAT name???) and I call (*usbInterfaceInterface)->WritePipeTO() to ask the scanner to scan. I believe this works. AT least the flatbed light moves across the page...

Then I try to use *(usbInterfaceInterface))->ReadPipeAsyncTO() to read data. I give this function a callback function, USBDoneProc().

The general structure is:

StartScan()
WaitForScan()

StartScan() calls the WritePipeTO and the ReadPipeAsyncTO

WaitForScan() has this:

while (deviceActive) {
    EventRecord event;
    GetNextEvent(0,&event);
    if (gDataPtr != saveDataPtr) { // more data up the timeout    
        timeoutTicks = TickCount() + 60 * 60;
        saveDataPtr = gDataPtr;
    }
    if (TickCount() > timeoutTicks) {
        deviceActive = false;
    }
}

Meanwhile, USBDoneProc incrementing gDataPtr to be the end of the data that we've read so far. It gets called several times during the asynchronous read, called automatically by the callback, as far as I can tell.

If I cake out the GetNextEvent() call in the WORKING code the USBDoneProc doesn't get called until the asynchronous readpipe timesout.

So it looks to me that I need something to give control back to the event handler so that the USBRead interrupts can actually interrupt and make the USBDoneProcget called...

Does that make any sense?

thanks.
A: 

I suppose the nearest thing to a Cocoa equivalent would be -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]. But bear in mind that GetNextEvent is archaic even for Carbon. The preferred way of handing events is the "don't call us, we'll call you" scheme, where the app calls NSApplicationMain or RunApplicationEventLoop and events are dispatched to you.

EDIT to add: Does you app have a normal event loop? If so, maybe WaitForScan could start a Carbon timer and return to the event loop. Each time the timer fires, do what you did in the WaitForScan loop.

JWWalker
yeah, I'm working with 15 year old code. I don't know what's from os9, and what's just deprecated from 10.1 or whatis actually not deprecated.... I'll put more details into the question to explainwhat I'm trying to do.
Brian Postow
I know SO will notify you of new answers and comments, but I'm not sure if it notifies you of edited answers... so, check out my edited answer. :-)
JWWalker
A: 

Have you considered throwing the whole thing out and using Image Kit's new-in-10.6 scanner support instead? Even if it's custom, writing a TWAIN driver for it might be easier (and is certainly better) than trying to twist Cocoa into a GetNextEvent shape.

Peter Hosey
the program I'm writing has to support 10.5 systems, maybe even 10.4. Trust me I'm just over joyed that I don't have to support 10.3
Brian Postow