//// BXSystemEventNotifier.m// BaseTen//// Copyright (C) 2010 Marko Karppinen & Co. LLC.//// Before using this software, please review the available licensing options// by visiting http://www.karppinen.fi/baseten/licensing/ or by contacting// us at sales@karppinen.fi. Without an additional license, this software// may be distributed only in compliance with the GNU General Public License.////// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License, version 2.0,// as published by the Free Software Foundation.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA//// $Id$//#import "BXSystemEventNotifier.h"#import "BXIOKitSystemEventNotifier.h"#import "BXProbes.h"#import "BXValidationLock.h"#import "../BaseTenAppKit/Sources/BXAppKitSystemEventNotifier.h"ClassBXAppKitSystemEventNotifierClass=Nil;NSString*constkBXSystemEventNotifierProcessWillExitNotification=@"kBXSystemEventNotifierProcessWillExitNotification";NSString*constkBXSystemEventNotifierSystemWillSleepNotification=@"kBXSystemEventNotifierSystemWillSleepNotification";NSString*constkBXSystemEventNotifierSystemDidWakeNotification=@"kBXSystemEventNotifierSystemDidWakeNotification";@implementationBXSystemEventNotifier+(void)initialize{staticBOOLtooLate=NO;if(!tooLate){tooLate=YES;BXAppKitSystemEventNotifierClass=NSClassFromString(@"BXAppKitSystemEventNotifier");}}+(id)copyNotifier{idretval=nil;if(BXAppKitSystemEventNotifierClass)retval=[BXAppKitSystemEventNotifierClasscopyNotifier];elseretval=[BXIOKitSystemEventNotifiercopyNotifier];returnretval;}-(id)init{if([selfclass]==[BXSystemEventNotifierclass])[selfdoesNotRecognizeSelector:_cmd];if((self=[superinit])){mValidationLock=[[BXValidationLockalloc]init];}returnself;}-(void)dealloc{[selfinvalidate];[mValidationLockrelease];[superdealloc];}-(void)install{}-(void)invalidate{[mValidationLockinvalidate];}-(void)processWillExit{if([mValidationLocklockIfValid]){BASETEN_BEGIN_EXIT_PREPARATION();NSNotificationCenter*nc=[NSNotificationCenterdefaultCenter];[ncpostNotificationName:kBXSystemEventNotifierProcessWillExitNotificationobject:self];BASETEN_END_EXIT_PREPARATION();[mValidationLockunlock];}}-(void)systemWillSleep{if([mValidationLocklockIfValid]){BASETEN_BEGIN_SLEEP_PREPARATION();NSNotificationCenter*nc=[NSNotificationCenterdefaultCenter];[ncpostNotificationName:kBXSystemEventNotifierSystemWillSleepNotificationobject:self];BASETEN_END_SLEEP_PREPARATION();[mValidationLockunlock];}}-(void)systemDidWake{if([mValidationLocklockIfValid]){BASETEN_BEGIN_WAKE_PREPARATION();NSNotificationCenter*nc=[NSNotificationCenterdefaultCenter];[ncpostNotificationName:kBXSystemEventNotifierSystemDidWakeNotificationobject:self];BASETEN_END_WAKE_PREPARATION();[mValidationLockunlock];}}@end