mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Start implementing scheduler
This commit is contained in:
parent
873e4edc47
commit
6ef18c3ec3
3 changed files with 67 additions and 15 deletions
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
|
||||
#include <Foundation/NSBackgroundActivityScheduler.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSTimer.h>
|
||||
|
||||
@implementation NSBackgroundActivityScheduler
|
||||
|
||||
|
@ -38,10 +40,21 @@
|
|||
_tolerance = 0;
|
||||
_shouldDefer = NO;
|
||||
_timer = nil;
|
||||
_opts = 0;
|
||||
_token = nil;
|
||||
_reason = [NSString stringWithFormat: @"Reason-%@", self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_identifier);
|
||||
RELEASE(_token);
|
||||
RELEASE(_reason);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) identifier
|
||||
{
|
||||
return _identifier;
|
||||
|
@ -102,36 +115,61 @@
|
|||
_shouldDefer = flag;
|
||||
}
|
||||
|
||||
- (void) _performActivity
|
||||
{
|
||||
NSProcessInfo *pinfo = [NSProcessInfo processInfo];
|
||||
|
||||
# if __has_feature(blocks)
|
||||
[pinfo performActivityWithOptions: _opts
|
||||
reason: _reason
|
||||
usingBlock: ^{
|
||||
// CALL_BLOCK(_block);
|
||||
}];
|
||||
# else
|
||||
NSLog(@"No block support, so not running background activity....");
|
||||
# endif
|
||||
}
|
||||
|
||||
- (void) scheduleWithBlock: (GSScheduledBlock)block
|
||||
{
|
||||
NSProcessInfo *pinfo = [NSProcessInfo processInfo];
|
||||
id token = nil;
|
||||
NSActivityOptions opts = 0;
|
||||
|
||||
switch(qualityOfService)
|
||||
|
||||
ASSIGN(_block, block);
|
||||
switch(_qualityOfService)
|
||||
{
|
||||
case NSQualityOfServiceUserInteractive:
|
||||
opts = NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled;
|
||||
_opts = NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled;
|
||||
break;
|
||||
case NSQualityOfServiceUserInitiated:
|
||||
opts = NSActivityUserInitiated;
|
||||
_opts = NSActivityUserInitiated;
|
||||
break;
|
||||
case NSQualityOfServiceUtility:
|
||||
opts = NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled;
|
||||
_opts = NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled;
|
||||
break;
|
||||
case NSQualityOfServiceBackground:
|
||||
opts = NSActivityBackground;
|
||||
_opts = NSActivityBackground;
|
||||
break;
|
||||
case NSQualityOfServiceDefault:
|
||||
opts = NSActivityLatencyCritical;
|
||||
_opts = NSActivityLatencyCritical;
|
||||
break;
|
||||
}
|
||||
|
||||
token = [pinfo beginActivityWithOptions:
|
||||
_token = [pinfo beginActivityWithOptions: _opts
|
||||
reason: _reason];
|
||||
|
||||
_timer = [NSTimer scheduledTimerWithTimeInterval: _interval
|
||||
target: self
|
||||
selector: @selector(_performActivity)
|
||||
userInfo: nil
|
||||
repeats: _repeats];
|
||||
|
||||
}
|
||||
|
||||
- (void) invalidate
|
||||
{
|
||||
NSProcessInfo *pinfo = [NSProcessInfo processInfo];
|
||||
[_timer invalidate];
|
||||
[pinfo endActivity: _token];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue