/* * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #include #include #include #include #include #include #include "RepeatingAutoWake.h" /* // These are the days of the week as provided by // CFAbslouteTimeGetDayOfWeek() enum { kCFMonday = 1, kCFTuesday = 2, kCFWednesday = 3, kCFThursday = 4, kCFFriday = 5, kCFSaturday = 6, kCFSunday = 7 }; // In the "days of the week" bitmask, this is the key... enum { kBitMaskMonday = 0, kBitMaskTuesday = 1, kBitMaskWednesday = 2, kBitMaskThursday = 3, kBitMaskFriday = 4, kBitMaskSaturday = 5, kBitMaskSunday = 6 }; */ static CFDictionaryRef currentRepeatingEvents = 0; static CFDictionaryRef newRepeatingEvents = 0; static CFDictionaryRef repeatingPowerOff = 0; static CFDictionaryRef repeatingPowerOn = 0; //**************************** // CANCEL PRE-SCHEDULED EVENTS static IOReturn cancelAllRepeatingEvents(void) { CFArrayRef list = 0; CFDictionaryRef scheduled_event; CFDateRef scheduled_time; CFStringRef scheduled_scheduler; CFStringRef scheduled_type; IOReturn ret = kIOReturnSuccess; int i, count; list = IOPMCopyScheduledPowerEvents(); if(!list || (0==CFArrayGetCount(list))) { // It's possible that IOPMCopyScheduledPowerEvents wasn't successful (like if we're not running as root) and it // just returned NULL, since it can't return error codes. Oh well. As far as we can tell we're successful. ret = kIOReturnSuccess; goto exit; } // scan the list of power events and remove each one scheduled by type "Repeating" count = CFArrayGetCount(list); for(i=0; i= (minutes_now+2)) return true; else return false; } // daysUntil // returns 0 if the event is upcoming today // otherwise returns days until next repeating event, in range 1-7 static int daysUntil(CFDictionaryRef event, int today_cf_day_of_week) { int days_mask = getRepeatingDictionaryDayMask(event); int check = today_cf_day_of_week % 7; if(0 == days_mask) return -1; if(upcomingToday(event)) return 0; // Note: CF days start counting at 1, the bit mask starts counting at 0. // Therefore, since we're tossing the CF day of week into a variable (check) // that we're checking the bitmask with, "check" effectively refers // to tomorrow, whlie today_cf_day_of_week refers to today. while(!(days_mask & (1<