discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheduling functions to be run all the time in runloop


From: Dr. H. Nikolaus Schaller
Subject: Re: Scheduling functions to be run all the time in runloop
Date: Tue, 10 Jul 2012 07:20:12 +0200

Am 09.07.2012 um 23:13 schrieb Ivan Vučica:

> On 9. 7. 2012., at 22:52, Dr. H. Nikolaus Schaller wrote:
> 
>>> Please note that Core Animation is not in GUI either :-)
>> 
>> Yes, but you can't guarantee that there is a runloop at all if you don't 
>> have GUI... And I don't know if CA is useful if you don't have any GUI.
> 
> Apple's documentation explicitly says that if there is no run loop, one must 
> manually run -[CATransaction flush] when needed. :-)
> 
> You may be creating the user interface in some other way: I presume Apple 
> refers to a person integrating Core Animation in a Carbon application, or in 
> an X11 application. (And it's easy to envision similar scenario under 
> GNUstep, too. I have an X11 window manager that I hope to keep working on 
> once Core Animation is featureful enough to provide some graphical effects.)
> 
> Even with NSRunLoop, gnustep-gui/AppKit is not the only target GUI under 
> GNUstep that will make use of Core Animation; UIKit heavily depends on it, 
> uses NSRunLoop, and does not implement AppKit.

It could be integrated by the same or similar hooks into AppKit and UIKit 
without being integrated into NSRunLoop.

> 
> All in all, a solution that depends on integration with AppKit is, sadly, not 
> a solution. :-)

I do not propose to make CA depend on AppKit - rather, it could make AppKit 
depend on CA.

> 
>> 
>>> Is there no API in NSRunLoop for scheduling additional functions to be run 
>>> in the situations I described that would be available to applications?
>> 
>> Yes, there are some idle and other hooks. Maybe you can also achieve what 
>> you intend by NSNotificationQueue.
>> 
>> But it is not clear to me what you really want to achieve. On one hand it 
>> looks like you want to intercept user events. On the other hand I assume 
>> that it is more related to keeping the display updated in time (flushing).
>> 
>> And you mention "every time runloop calls user code and whenever user code 
>> is done running". Can you please better specify (examples) what "user code" 
>> means for you? Are notifications "user code"? Are timers "user code"? Are 
>> file handle/socket events "user code"? All these are handled by the runloop, 
>> and GUI events are only a variant of them.
> 
> Sorry for using a completely unclear term. By "user code" I meant anything 
> that drops out of run loop and processes events.

This is still unclear. Which type of events? AppKit NSEvent and UIKit UIEvent 
only or anything else that drops out of the runloop?

> It turned out that I quickly managed to find how Apple integrates Core 
> Animation with the run loop -- far more quickly than I expected I would, 
> considering my needs are pretty obscure. So to better explain what I would 
> want to use, I'd like to mention CFRunLoopObservers. 
> 
> http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFRunLoopObserverRef/Reference/reference.html
> 
> They seem to be triggered whenever a "source is processed" and "before the 
> run loop goes to sleep" - which sounds exactly like what I need. However, 
> based on their name and the location inside Core Foundation framework, I 
> presume that they are not implemented in this form in GNUstep.
> 
> So, is there an alternative way to insert my functions whenever a source is 
> processed and before the run loop goes to sleep that works with GNUstep?

AFAIK, this is not available in GNUstep.

> 
> On 9. 7. 2012., at 22:58, Dr. H. Nikolaus Schaller wrote:
> 
>> Another thought: if you want to integrate that into handling of all 
>> NSEvents, then add it to -[NSApplication sendEvent:] (but this also does 
>> only handle top-level events and not mouse tracking within e.g. NSCell).
>> 
>> So to me it is not at all clear on which level of abstraction you need to 
>> call these methods. Maybe, you can explain what they are intended to do. 
>> Then it may be easier to recommend a location where to call them.
> 
> Unfortunately, this again depends on AppKit. Not only that - considering that 
> Core Animation is currently implemented as an "additional" library not in 
> AppKit, but distributed separately in "quartzcore" directory, and considering 
> that it intentionally uses Objective-C 2.0 features, it would be very 
> irresponsible if I added Core Animation-specific calls to AppKit :-)

It still depends on what you want to achieve. There might be notification hooks 
in GUI/AppKit that do exactly what you need. Then, you just have to register 
NSNotification observers. They *may* do the same as the CFRunLoopObserver - but 
on a higher level. But for helping I still would like to understand what these 
actions should do and why CA needs to know if the run loop is running or not. 
BTW: what should happen if the application has multiple run loops?

I think you refer to: "...are committed automatically when the thread's 
run-loop next iterates." and "Flush is typically called automatically at then 
end of the current runloop, regardless of the runloop mode. If your application 
does not have a runloop, you must call this method explicitly." in the 
CATransaction documentation.

But compare to NSWindow: "You rarely need to invoke this method. NSWindow 
objects normally record which of their views need display and display them 
automatically on each pass through the event loop." Which I read to be the same.

From this I would assume that it can be implemented by a CFRunLoopObserver, but 
it is not necessarily so. It could also be called before/after each call to 
[runloop runMode:beforeDate:]. In GUI and UIKit and whereever important. I.e.

[CATransaction flush];
[runloop runMode:... beforeDate:...];
[CATransaction flush];

So IMHO there are different implementation options. One by installing a 
CFRunLoopObserver and another by calling flush at the right time.

> 
> However, since you suggest patching the code so often, I guess that if there 
> is no equivalent to CFRunLoopObservers with GNUstep, I may dig in and 
> implement them. I'd do so directly in base (despite the name implying Core 
> Foundation and GNUstep's corebase). If I do so, I would definitely first ask 
> for review of the patch, considering that I don't feel confident enough to 
> dig deep into such an essential component of the system like run loops.

BR,
Nikolaus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]