Adding models for NSTimer and NSRunLoop

Reviewed By: @dulmarod

Differential Revision: D2502606

fb-gh-sync-id: 9c26103
master
Dino Distefano 9 years ago committed by facebook-github-bot-7
parent aa1951cad4
commit e6625c9e37

@ -0,0 +1,45 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSDate.h>
@class NSTimer;
@interface NSRunLoop : NSObject
+ (NSRunLoop*) currentRunLoop;
+ (NSRunLoop*) mainRunLoop;
- (void) acceptInputForMode: (NSString*)mode
beforeDate: (NSDate*)limit_date;
- (void) addTimer: (NSTimer*)timer
forMode: (NSString*)mode;
- (NSString*) currentMode;
- (NSDate*) limitDateForMode: (NSString*)mode;
- (void) run;
- (BOOL) runMode: (NSString*)mode
beforeDate: (NSDate*)date;
- (void) runUntilDate: (NSDate*)date;
@end

@ -0,0 +1,56 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "NSRunLoop.h"
@implementation NSRunLoop
+ (NSRunLoop*) currentRunLoop {
return [NSRunLoop alloc];
};
+ (NSRunLoop*) mainRunLoop {
return [NSRunLoop alloc];
};
- (void) acceptInputForMode: (NSString*)mode
beforeDate: (NSDate*)limit_date {
};
- (void) addTimer: (NSTimer*)timer
forMode: (NSString*)mode {
};
- (NSString*) currentMode {
return @"";
};
- (NSDate*) limitDateForMode: (NSString*)mode {
return [NSDate alloc];
};
- (void) run {};
- (BOOL) runMode: (NSString*)mode
beforeDate: (NSDate*)date {
int res;
return res;
};
- (void) runUntilDate: (NSDate*)date {};
@end

@ -0,0 +1,59 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <Foundation/NSDate.h>
@class NSInvocation;
@interface NSTimer : NSObject
{
NSTimeInterval _interval;
id _info;
id _target;
SEL _selector;
unsigned _repeats:2;
unsigned _timer_filler:6;
@public
NSDate *_fireDate;
BOOL _is_valid;
}
+ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval) ti
invocation:(NSInvocation *) invocation
repeats:(BOOL) f;
+ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval) ti
target:(id) object
selector:(SEL) selector
userInfo:(id) info
repeats:(BOOL) f;
+ (NSTimer *) timerWithTimeInterval:(NSTimeInterval) ti
invocation:(NSInvocation *) invocation
repeats:(BOOL) f;
+ (NSTimer *) timerWithTimeInterval:(NSTimeInterval) ti
target:(id) object
selector:(SEL) selector
userInfo:(id) info
repeats:(BOOL) f;
- (void) fire;
- (NSDate *) fireDate;
- (id) initWithFireDate:(NSDate *) date
interval:(NSTimeInterval) seconds
target:(id) target
selector:(SEL) aSelector
userInfo:(id) userInfo
repeats:(BOOL) repeats;
- (void) invalidate;
- (BOOL) isValid;
- (void) setFireDate:(NSDate *) date;
- (NSTimeInterval) timeInterval;
- (id) userInfo;
@end

@ -0,0 +1,144 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "NSTimer.h"
#import <Foundation/NSDate.h>
// Note: we do not link timers to NSRunLoop as this is irrelevant for
// our models. If at some point becomes important it needs to be changed.
void free(void *ptr);
@implementation NSTimer
+ (NSTimer*) timerWithTimeInterval:(NSTimeInterval)seconds
invocation:(NSInvocation *)invocation
repeats:(BOOL)f
{
NSTimer *t = [self alloc];
if(t)
{
t->_interval = seconds;
t->_fireDate = [NSDate alloc];
t->_is_valid = YES;
t->_target = invocation;
t->_repeats = f;
}
return t;
}
+ (NSTimer*) timerWithTimeInterval:(NSTimeInterval)seconds
target:(id)object
selector:(SEL)selector
userInfo:(id)info
repeats:(BOOL)f
{
NSDate *d = [NSDate alloc];
return [[self alloc] initWithFireDate:d
interval:seconds
target:object
selector:selector
userInfo:info
repeats:f];
}
+ (NSTimer*) scheduledTimerWithTimeInterval:(NSTimeInterval)ti
invocation:(NSInvocation *)invocation
repeats:(BOOL)f
{
NSTimer *t = [self timerWithTimeInterval:ti invocation:invocation repeats:f];
return t;
}
+ (NSTimer*) scheduledTimerWithTimeInterval:(NSTimeInterval)ti
target:(id)object
selector:(SEL)selector
userInfo:(id)info
repeats:(BOOL)f
{
NSTimer *t = [self timerWithTimeInterval: ti
target: object
selector: selector
userInfo: info
repeats: f];
return t;
}
- (id) initWithFireDate:(NSDate *) date
interval:(NSTimeInterval)seconds
target:(id)object
selector:(SEL)selector
userInfo:(id)info
repeats:(BOOL)f
{
_interval = seconds;
_fireDate = date;
_is_valid = YES;
_selector = selector;
_target = object;
_info = info;
_repeats = f;
return self;
}
- (void) dealloc
{
_fireDate=nil;
free(self);
}
- (NSString *) description;
{
return [NSString alloc];
}
// Abstract everything except making the timer invalid if
// cannot repeat
- (void) fire
{
if(!_repeats)
_is_valid = NO;
}
- (void) invalidate
{
_is_valid = NO;
}
- (BOOL) isValid {
return _is_valid;
}
- (NSDate *) fireDate {
return _fireDate;
}
- (NSTimeInterval) timeInterval {
return _interval;
}
- (id) userInfo {
return _info;
}
- (void) setFireDate:(NSDate *)date;
{
_fireDate =date;
}
- (int) compare:(NSTimer*)anotherTimer
{
int res;
return res;
}
@end
Loading…
Cancel
Save