objective c - What's the modern equivalent of GetNextEvent in Cocoa? -
i'm porting archaic c++/carbon program obj-c , cocoa. current version uses asynchronous usb reads , getnextevent read data.
when try compile in objective c, getnextevent isn't found because it's in carbon framework.
searching apple support yields nothing of use.
edit add:
ok, i'm trying run document scanner through usb. have set usbdeviceinterface , usbinterfaceinterface (who came that name???) , call (*usbinterfaceinterface)->writepipeto()
ask scanner scan. believe works. @ least flatbed light moves across page...
then try use *(usbinterfaceinterface))->readpipeasyncto()
read data. give function callback function, usbdoneproc()
.
the general structure is:
startscan() waitforscan()
startscan()
calls writepipeto
, readpipeasyncto
waitforscan()
has this:
while (deviceactive) { eventrecord event; getnextevent(0,&event); if (gdataptr != savedataptr) { // more data timeout timeoutticks = tickcount() + 60 * 60; savedataptr = gdataptr; } if (tickcount() > timeoutticks) { deviceactive = false; } }
meanwhile, usbdoneproc
incrementing gdataptr end of data we've read far. gets called several times during asynchronous read, called automatically callback, far can tell.
if cake out getnextevent()
call in working code usbdoneproc
doesn't called until asynchronous readpipe timesout.
so looks me need give control event handler usbread interrupts can interrupt , make usbdoneproc
get called...
does make sense?
thanks.
i suppose nearest thing cocoa equivalent -[nsapplication nexteventmatchingmask:untildate:inmode:dequeue:]
. bear in mind getnextevent
archaic carbon. preferred way of handing events "don't call us, we'll call you" scheme, app calls nsapplicationmain
or runapplicationeventloop
, events dispatched you.
edit add: app have normal event loop? if so, maybe waitforscan start carbon timer , return event loop. each time timer fires, did in waitforscan loop.
Comments
Post a Comment