Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force notifications which touch GUI elements onto main thread #504

Closed
wants to merge 9 commits into from
3 changes: 2 additions & 1 deletion Source/Objects/Custom Hardware/SNO+/ELLIE/ELLIEController.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
- (IBAction)telliePing:(id)sender;
- (IBAction)smelliePing:(id)sender;
- (IBAction)interlockPing:(id)sender;
- (IBAction)tubiiPing:(id)sender;
- (void)tubiiPing;
- (IBAction)tubiiPingAction:(id)sender;
- (IBAction)tubiiRestart:(id)sender;
- (IBAction)serverSettingsChanged:(id)sender;
-(void)killInterlock:(NSNotification *)aNote;
Expand Down
24 changes: 12 additions & 12 deletions Source/Objects/Custom Hardware/SNO+/ELLIE/ELLIEController.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ -(IBAction)tellieGeneralFireAction:(id)sender

[tellieGeneralFireButton setEnabled:NO];
[tellieGeneralStopButton setEnabled:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:ORTELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:ORTELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are IBAction methods which means they are called when someone clicks a button right? If so, they are guaranteed to be on the main thread so you don't need to change this.

[tellieGeneralValidationStatusTf setStringValue:@""];
}

Expand All @@ -328,7 +328,7 @@ -(IBAction)tellieExpertFireAction:(id)sender
}

[tellieExpertStopButton setEnabled:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:ORTELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:ORTELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

[tellieExpertFireButton setEnabled:NO];
[tellieExpertValidationStatusTf setStringValue:@""];
}
Expand Down Expand Up @@ -548,7 +548,7 @@ - (IBAction)amellieFireAction:(id)sender {

[amellieFireButton setEnabled:NO];
[amellieStopButton setEnabled:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:ORAMELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:ORAMELLIERunStartNotification object:nil userInfo:[self guiFireSettings]];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

[amellieValidationStatusTf setStringValue:@""];
}

Expand Down Expand Up @@ -1585,22 +1585,18 @@ - (IBAction)tubiiRestart:(id)sender {
}
TUBiiModel* theTubiiModel = [tubiiModels objectAtIndex:0];
if([[theTubiiModel keepAliveThread] isExecuting]){
NSString* response = @"TUBii keep alive thread is already active, restarting.\n";
NSString* response = @"TUBii keep alive thread is already active.\n";
[tubiiThreadResponseTf setStringValue:response];
// This method will cancel the thread, causing a break statement to
// be called, ending a while loop. Once outside the loop the memory
// is tidied up and the user is promped (via a pop-up box) to
// re-activate the thread.
[theTubiiModel killKeepAlive:nil];
} else {
NSString* response = @"TUBii keep alive thread is getting a cold start.\n";
[tubiiThreadResponseTf setStringValue:response];
[theTubiiModel activateKeepAlive];
// Send a ping after a short delay
[self performSelector:@selector(tubiiPing) withObject:self afterDelay:1];
}
[self tubiiPing:self];
}

- (IBAction)tubiiPing:(id)sender {
-(void)tubiiPing{
//////////////
//Get a Tubii object
NSArray* tubiiModels = [[(ORAppDelegate*)[NSApp delegate] document] collectObjectsOfClass:NSClassFromString(@"TUBiiModel")];
Expand All @@ -1609,7 +1605,7 @@ - (IBAction)tubiiPing:(id)sender {
return;
}
TUBiiModel* theTubiiModel = [tubiiModels objectAtIndex:0];

// If ping was requested by note, wait to see if keep alive inits OK.
if([[theTubiiModel keepAliveThread] isExecuting]){
NSString* response = @"TUBii keep alive thread is active.\n";
Expand All @@ -1620,6 +1616,10 @@ - (IBAction)tubiiPing:(id)sender {
}
}

- (IBAction)tubiiPingAction:(id)sender {
[self tubiiPing];
}

-(void)tubiiDied:(NSNotification*)note{
NSString* response = @"TUBii keep alive thread is not executing. Please try a restart";
[tubiiThreadResponseTf setStringValue:response];
Expand Down
17 changes: 14 additions & 3 deletions Source/Objects/Custom Hardware/SNO+/ELLIE/ELLIEModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -980,11 +980,15 @@ -(void) startTellieRun:(NSDictionary*)fireCommands forTELLIE:(BOOL)forTELLIE
}
}

////////////////////////
// Check keep alive is running.
if(![[theTubiiModel keepAliveThread] isExecuting]){
NSLog(@"The keep alive thread between ORCA and TUBii was inactive. Relaunching.\n");
[theTubiiModel activateKeepAlive];
}

///////////////////////
// Check trigger is being sent to asyncronus port of the MTC/D (EXT_A)
if([[theTubiiModel keepAliveThread] isCancelled]){
[theTubiiModel restartKeepAlive:nil];
}
NSUInteger asyncTrigMask;
@try{
asyncTrigMask = [theTubiiModel asyncTrigMask];
Expand Down Expand Up @@ -1990,6 +1994,13 @@ -(void)startSmellieRun:(NSDictionary*)smellieSettings
goto err;
}

////////////////////////
// Check keep alive is running.
if(![[theTubiiModel keepAliveThread] isExecuting]){
NSLog(@"The keep alive thread between ORCA and TUBii was inactive. Relaunching.\n");
[theTubiiModel activateKeepAlive];
}

///////////////////////
// Check trigger is being sent to asyncronus port (EXT_A)
NSUInteger asyncTrigMask;
Expand Down
4 changes: 2 additions & 2 deletions Source/Objects/Custom Hardware/SNO+/ELLIE/ellie.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="15G1004" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="13F1603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1060" identifier="macosx"/>
<development version="5100" identifier="xcode"/>
Expand Down Expand Up @@ -2142,7 +2142,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="tubiiPing:" target="-2" id="UBr-wE-SJ0"/>
<action selector="tubiiPingAction:" target="-2" id="DVB-bt-JFD"/>
</connections>
</button>
</subviews>
Expand Down
3 changes: 3 additions & 0 deletions Source/Objects/Custom Hardware/SNO+/RedisClient/RedisClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ @implementation RedisClient

- (void) setTimeout: (long) _timeout
{
/*
Timeout should be specified in ms using a long unsigned integer
*/
@synchronized(self) {
timeout = _timeout;
if (context) {
Expand Down
1 change: 0 additions & 1 deletion Source/Objects/Custom Hardware/SNO+/TUBii/TUBiiModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ struct TUBiiState { //A struct that allows users of TUBiiModel to get/set all of
CounterInhibitOn: (bool) Inhibit;
-(void)activateKeepAlive;
-(void)pulseKeepAlive:(id)passed;
-(void)restartKeepAlive:(NSNotification*)aNote;
-(void)killKeepAlive:(NSNotification*)aNote;
@end

Expand Down
29 changes: 8 additions & 21 deletions Source/Objects/Custom Hardware/SNO+/TUBii/TUBiiModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ - (id) init {
connection = [[RedisClient alloc] init]; // Connection must be allocated before port and host name are set
portNumber = TUBII_DEFAULT_PORT;
strHostName = [[NSString alloc]initWithUTF8String:TUBII_DEFAULT_IP];
// This is being extended in an attempt to resolve the issues with ORPHANs
// from missing TUBii information at run rollovers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't resolve the orphan issue right? If so, can you delete this comment. Not sure if we want to keep the timeout extended or not. Presumably that was what was causing the run modal issue to be raised, so it could still help for remote institutions, so maybe you can just update the comment to say that the latency from remote shift stations is big enough that we are increasing it in an attempt to prevent timeouts from remote shift stations.

[connection setTimeout:2000];
}
return self;
}
Expand Down Expand Up @@ -141,6 +144,9 @@ - (id) initWithCoder:(NSCoder *)aCoder {

//Connection must be made before port and host name are set.
connection = [[RedisClient alloc] initWithHostName:strHostName withPort:portNumber];
// This is being extended in an attempt to resolve the issues with ORPHANs
// from missing TUBii information at run rollovers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

[connection setTimeout:2000];
}
return self;
}
Expand All @@ -166,11 +172,6 @@ - (void) registerNotificationObservers{
name : ORRunAboutToStartNotification
object : nil];

[notifyCenter addObserver : self
selector : @selector(restartKeepAlive:)
name : @"TUBiiKeepAliveDied"
object : nil];

[notifyCenter addObserver : self
selector : @selector(killKeepAlive:)
name : @"TELLIEEmergencyStop"
Expand Down Expand Up @@ -962,27 +963,13 @@ -(void)pulseKeepAlive:(id)passed
counter = counter + 1;
}

NSLog(@"[TUBii]: Stopped sending keep-alive to TUBii - ELLIE pulses will be shut off\n");

// This thread should always be running. If it's died, post a note to get it automatically restarted.
[[NSNotificationCenter defaultCenter] postNotificationName:@"TUBiiKeepAliveDied" object:nil];
NSLogColor([NSColor redColor],@"[TUBii]: Stopped sending keep-alive to TUBii\n");
NSLogColor([NSColor redColor],@"[TUBii]: Unless you restart this process the ELLIE systems will not be able to trigger through TUBii. If you'd like to restart at a later time please do so from the servers tab of the ELLIE gui\n");

// release memory
[pool release];
}

-(void)restartKeepAlive:(NSNotification*)aNote{
/*
If the keep alive has died, as a user to re-start it.
*/
BOOL restart = ORRunAlertPanel(@"The keep alive pulse to TUBii has died.",
@"Unless you restart this process the ELLIE systems will not be able to trigger through TUBii. If you'd like to restart at a later time please do so from the servers tab of the ELLIE gui",
@"Restart",
@"Cancel",nil);
if(restart){
[self activateKeepAlive];
}
}

-(void)killKeepAlive:(NSNotification*)aNote
{
Expand Down