// Copyright 1997-2000 Omni Development, Inc.  All rights reserved.
//
// This software may only be used and reproduced according to the
// terms in the file OmniSourceLicense.html, which should be
// distributed with this project and can also be found at
// http://www.omnigroup.com/DeveloperResources/OmniSourceLicense.html.
//
// $Header: /Network/Source/CVS/OmniGroup/Frameworks/OmniFoundation/Scheduling.subproj/OFScheduler.h,v 1.11 2000/08/09 06:46:59 bungi Exp $

#import <OmniFoundation/OFObject.h>

@class NSDate, NSRecursiveLock, NSMutableArray;
@class OFDedicatedThreadScheduler, OFInvocation, OFScheduledEvent;

#import <Foundation/NSDate.h> // For NSTimeInterval

@interface OFScheduler : OFObject
{
    NSMutableArray *scheduleQueue;
    NSRecursiveLock *scheduleLock;
    BOOL terminationSignaled;
}

+ (OFScheduler *)mainScheduler;
+ (OFDedicatedThreadScheduler *)dedicatedThreadScheduler;

- (void)scheduleEvent: (OFScheduledEvent *) event;
- (BOOL)abortEvent:(OFScheduledEvent *)anEvent;
- (void)abortSchedule;
- (OFScheduler *)subscheduler;
- (NSDate *)dateOfFirstEvent;

@end

@interface OFScheduler (OFConvenienceMethods)
- (OFScheduledEvent *)scheduleInvocation:(OFInvocation *)anInvocation atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleInvocation:(OFInvocation *)anInvocation afterTime:(NSTimeInterval)time;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id)anObject withObject:(id)anArgument atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id)anObject withObject:(id)anArgument afterTime:(NSTimeInterval)time;
@end

@interface OFScheduler (SubclassesOnly)
- (void)invokeScheduledEvents;
    // Subclasses call this method to invoke all events scheduled to happen up to the current time
- (void)scheduleEvents;
    // Subclasses override this method to schedule their events
- (void)cancelScheduledEvents;
    // Subclasses override this method to cancel their previously scheduled events.
@end

#import <OmniFoundation/FrameworkDefines.h>

OmniFoundation_EXTERN BOOL OFSchedulerDebug;
