一直在努力
分类:
2010-09-08 19:24:28
CFRunLoopAddSource
,CFRunLoopAddTimer
, or CFRunLoopAddObserver
. CFRunLoopRunInMode函数。它类似一个容器可以将多个mode添加到common mode中使用
CFRunLoopAddCommonModekCFRunLoopCommonModes
for the run loop mode.kCFRunLoopRunFinished = 1, //没有sources或者timers需要处理 kCFRunLoopRunStopped = 2, //CFRunloopStop在run loop中调用 kCFRunLoopRunTimedOut = 3, //超时终止,固定的时间间隔已经过去了 kCFRunLoopRunHandledSource = 4//sources已经被处理了,这个值返回的情况仅仅是当前run loop用于处理这个返回值只有当运行循环被告知只能运行到一个源进行处理。 };
CFRunLoopAddSource
CFRunLoopContainsSource
CFRunLoopRemoveSource
CFAllocatorRef allocator, CFIndex order, CFRunLoopSourceContext *context );
order是优先级索引,对version1无效,一般情况为0;
CFRunLoopSource’s behavior.
struct CFRunLoopSourceContext {
CFIndex version; 0
void *info;
CFAllocatorRetainCallBack retain;
CFAllocatorReleaseCallBack release;
CFAllocatorCopyDescriptionCallBack copyDescription;
CFRunLoopEqualCallBack equal;
CFRunLoopHashCallBack hash;
CFRunLoopScheduleCallBack schedule;
CFRunLoopCancelCallBack cancel;
CFRunLoopPerformCallBack perform;
};
CFRunLoopSourceContext1
A structure that contains program-defined data and callbacks with which you can configure a version 1 CFRunLoopSource’s behavior.
struct CFRunLoopSourceContext1 {
CFIndex version; 1
void *info;
CFAllocatorRetainCallBack retain;
CFAllocatorReleaseCallBack release;
CFAllocatorCopyDescriptionCallBack copyDescription;
CFRunLoopEqualCallBack equal;
CFRunLoopHashCallBack hash;
CFRunLoopGetPortCallBack getPort;
CFRunLoopMachPerformCallBack perform;
};
7。Managing Observers
CFRunLoopAddObserver
CFRunLoopContainsObserver
CFRunLoopRemoveObserver
Each run loop observer can be registered in only one run loop at a time, although it can be added to multiple run loop modes within that run loop.
Creates a CFRunLoopObserver object.
CFRunLoopObserverRef CFRunLoopObserverCreate (
CFAllocatorRef allocator,
CFOptionFlags activities,
Boolean repeats,
CFIndex order,
CFRunLoopObserverCallBack callout,
CFRunLoopObserverContext *context
);
- activities
Set of flags identifying the activity stages of the run loop during which the observer should be called. See Run Loop Activitiesfor the list of stages. To have the observer called at multiple stages in the run loop, combine theRun Loop Activities values using the bitwise-OR operator.
- repeats
A flag identifying whether the observer should be called only once or every time through the run loop. If repeatsis false
, the observer is invalidated after it is called once, even if the observer was scheduled to be called at multiple stages within the run loop.
struct CFRunLoopObserverContext {
CFIndex version;
void *info;
CFAllocatorRetainCallBack retain;
CFAllocatorReleaseCallBack release;
CFAllocatorCopyDescriptionCallBack copyDescription;
};
typedef struct CFRunLoopObserverContext CFRunLoopObserverContext;
enum CFRunLoopActivity {
kCFRunLoopEntry = (1 << 0),
kCFRunLoopBeforeTimers = (1 << 1),
kCFRunLoopBeforeSources = (1 << 2),
kCFRunLoopBeforeWaiting = (1 << 5),
kCFRunLoopAfterWaiting = (1 << 6),
kCFRunLoopExit = (1 << 7),
kCFRunLoopAllActivities = 0x0FFFFFFFU
};
typedef enum CFRunLoopActivity CFRunLoopActivity;
- 8。Managing Timers
CFRunLoopAddTimer
CFRunLoopGetNextTimerFireDate
CFRunLoopRemoveTimer
CFRunLoopContainsTimer
- 9。A CFRunLoopObserver provides a general means to receive callbacks at different points within a running run loop. In contrast to sources, which fire when an asynchronous event occurs, and timers, which fire when a particular time passes, observers fire at special locations within the execution of the run loop, such as before sources are processed or before the run loop goes to sleep, waiting for an event to occur. Observers can be either one-time events or repeated every time through the run loop’s loop.
- observer是监控run loop运行期间的某个特殊的时间点儿或者事件发生的触发回调函数,sources是等待的资源到位之后触发,timer是在特定时间段结束触发。
- observer可以是在sources处理前,sleep前,
- Each run loop observer can be registered in only one run loop at a time, although it can be added to multiple run loop modes within that run loop.
- 更多信息参考相关文档
- 所谓get 原则就是只CFRetain保留所有权的那一方