Skip to content

Commit 9605140

Browse files
dsward2dsward2
dsward2
authored and
dsward2
committed
In TaskPipelineManager, a periodic NSTimer was added to check the isRunning status of each NSTask in the pipeline. If a NSTask with isRunning = NO is found, all tasks in the pipeline are terminated and purged from the pipeline array.
In AppDelegate, a type error was fixed in an empty NSTimer callback function.
1 parent 6da64f8 commit 9605140

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

LocalRadio/AppDelegate.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
126126
[self updateViews:self];
127127

128128
self.periodicUpdateTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(periodicUpdateTimerFired:) userInfo:self repeats:YES];
129+
130+
[[NSRunLoop mainRunLoop] addTimer:self.periodicUpdateTimer forMode:NSDefaultRunLoopMode];
129131

130132
NSNumber * statusPortNumber = [self.localRadioAppSettings integerForKey:@"StatusPort"];
131133
[self.udpStatusListenerController runServerOnPort:statusPortNumber.integerValue];
@@ -147,7 +149,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
147149
// periodicUpdateTimerFired:
148150
//==================================================================================
149151

150-
- (void)periodicUpdateTimerFired:(NSNotification *)aNotification
152+
- (void)periodicUpdateTimerFired:(NSTimer *)timer
151153
{
152154

153155
}

LocalRadio/TaskPipelineManager.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
@property (strong) NSMutableArray * taskItemsArray;
2020
@property (assign) NSInteger taskPipelineStatus;
2121

22+
@property (strong) NSTimer * periodicTaskPipelineCheckTimer;
23+
2224
- (TaskItem *) makeTaskItemWithExecutable:(NSString *)executableName functionName:(NSString *)functionName;
2325

2426
- (void) addTaskItem:(TaskItem *)taskItem;

LocalRadio/TaskPipelineManager.m

+54
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,31 @@
88

99
#import "TaskPipelineManager.h"
1010
#import "TaskItem.h"
11+
#import "AppDelegate.h"
1112

1213
@implementation TaskPipelineManager
1314

1415

16+
- (void) dealloc
17+
{
18+
[self.periodicTaskPipelineCheckTimer invalidate];
19+
self.periodicTaskPipelineCheckTimer = NULL;
20+
}
21+
22+
23+
24+
1525
- (instancetype)init
1626
{
1727
self = [super init];
1828
if (self) {
1929
self.taskItemsArray = [NSMutableArray array];
2030

2131
self.taskPipelineStatus = kTaskPipelineStatusIdle;
32+
33+
self.periodicTaskPipelineCheckTimer = [NSTimer timerWithTimeInterval:5.0f target:self selector:@selector(periodicTaskPipelineCheckTimerFired:) userInfo:self repeats:YES];
34+
35+
[[NSRunLoop mainRunLoop] addTimer:self.periodicTaskPipelineCheckTimer forMode:NSDefaultRunLoopMode];
2236
}
2337
return self;
2438
}
@@ -40,13 +54,16 @@ - (TaskItem *) makeTaskItemWithExecutable:(NSString *)executableName functionNam
4054
}
4155

4256

57+
58+
4359
- (void) addTaskItem:(TaskItem *)taskItem
4460
{
4561
[self.taskItemsArray addObject:taskItem];
4662
}
4763

4864

4965

66+
5067
- (void) configureTaskPipes
5168
{
5269
TaskItem * firstTaskItem = [self.taskItemsArray firstObject];
@@ -90,6 +107,8 @@ - (void) configureTaskPipes
90107
}
91108

92109

110+
111+
93112
- (void) startTasks
94113
{
95114
for (TaskItem * taskItem in self.taskItemsArray)
@@ -113,6 +132,8 @@ - (void) startTasks
113132
}
114133

115134

135+
136+
116137
- (void) terminateTasks
117138
{
118139
//NSArray * reversedTaskItemsArray = [[self.taskItemsArray reverseObjectEnumerator] allObjects];
@@ -131,6 +152,39 @@ - (void) terminateTasks
131152
}
132153

133154

155+
156+
- (void) periodicTaskPipelineCheckTimerFired:(NSTimer *)timer
157+
{
158+
BOOL failedTaskFound = NO;
159+
TaskItem * failedTaskItem = NULL;
160+
161+
for (TaskItem * taskItem in self.taskItemsArray)
162+
{
163+
if (taskItem.task.isRunning == NO)
164+
{
165+
failedTaskFound = YES;
166+
failedTaskItem = taskItem;
167+
break;
168+
}
169+
}
170+
171+
if (failedTaskFound == YES)
172+
{
173+
NSLog(@"TaskPipelineManager - TaskPipelineFailed - %@ - %@", failedTaskItem, self.taskItemsArray);
174+
175+
[[NSNotificationCenter defaultCenter] postNotificationName:@"TaskPipelineFailedNotification" object:self];
176+
177+
[self terminateTasks];
178+
179+
AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
180+
181+
[appDelegate updateCurrentTasksText];
182+
}
183+
}
184+
185+
186+
187+
134188
- (NSString *)tasksInfoString
135189
{
136190
NSMutableString * tasksInfoString = [NSMutableString stringWithString:@"\n\n"];

rtl_fm_localradio/rtl_fm_localradio/rtl_fm_localradio.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,8 @@ int main(int argc, char **argv)
20432043
status_cleanup(&status);
20442044

20452045
if (output.file != stdout) {
2046-
fclose(output.file);}
2046+
fclose(output.file);
2047+
}
20472048

20482049
//fprintf(stderr, "\nrtlsdr_close\n");
20492050
//NSLog(@"rtlsdr_close");

0 commit comments

Comments
 (0)