1 /* 2 * Copyright (c) 2009-2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 #include <time.h> 25 #include <stdint.h> 26 #include <dispatch/dispatch.h> 27 28 #define TIME_EVENT_NONE 0 29 #define TIME_EVENT_ONESHOT 1 30 #define TIME_EVENT_CLOCK 2 31 #define TIME_EVENT_CAL 3 32 33 /* 34 * Timer Event 35 */ 36 typedef struct 37 { 38 uint32_t type; 39 int64_t start; 40 int64_t end; 41 uint32_t freq; 42 int32_t day; 43 int64_t next; 44 void (^deactivation_handler)(); 45 dispatch_source_t src; 46 dispatch_source_t t_src; 47 dispatch_queue_t t_queue; 48 void *contextp; 49 uint32_t context32; 50 uint64_t context64; 51 } timer_event_t; 52 53 timer_event_t *timer_oneshot(time_t when, dispatch_queue_t queue); 54 timer_event_t *timer_clock(time_t first, time_t freq_sec, time_t end, dispatch_queue_t queue); 55 timer_event_t *timer_calendar(time_t first, time_t freq_mth, time_t end, int day, dispatch_queue_t queue); 56 timer_event_t *timer_calendar_long(uint32_t yf, uint32_t mf, uint32_t df, uint32_t hf, uint32_t nf, uint32_t sf, time_t fm, int d, uint32_t ye, uint32_t me, uint32_t de, uint32_t he, uint32_t ne, uint32_t se, dispatch_queue_t queue); 57 58 void timer_set_deactivation_handler(timer_event_t *t, void(^handler)()); 59 void timer_close(timer_event_t *t); 60