Retain connection.

This commit is contained in:
Gregory John Casamento 2020-02-08 03:58:13 -05:00
parent 60cf308471
commit eda8259f53
3 changed files with 2 additions and 122 deletions

View file

@ -24,7 +24,6 @@
#import "GSSpeechRecognitionServer.h"
#import "GSSpeechRecognitionEngine.h"
#import "GSSpeechRecognizer.h"
#import <Foundation/Foundation.h>
static GSSpeechRecognitionServer *_sharedInstance;
@ -40,11 +39,12 @@ static GSSpeechRecognitionServer *_sharedInstance;
{
NSConnection *connection = [NSConnection defaultConnection];
[connection setRootObject: _sharedInstance];
RETAIN(connection);
if (NO == [connection registerName: @"GSSpeechRecognitionServer"])
{
return;
}
// [[NSRunLoop currentRunLoop] run];
[[NSRunLoop currentRunLoop] run];
}
+ (id)sharedServer

View file

@ -1,29 +0,0 @@
/* Interface of class GSSpeechRecognizer
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: Fri Dec 6 04:55:59 EST 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#import "GSSpeechRecognitionServer.h"
#import <AppKit/NSSpeechRecognizer.h>
@interface GSSpeechRecognizer : NSSpeechRecognizer
@end

View file

@ -1,91 +0,0 @@
/* Implementation of class GSSpeechRecognizer
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: Fri Dec 6 04:55:59 EST 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#import "GSSpeechRecognizer.h"
static GSSpeechRecognitionServer *server;
@interface GSSpeechRecognizer (Private)
+ (void)connectionDied: (NSNotification*)aNotification;
@end
@implementation GSSpeechRecognizer
/**
* If no clients have been active for some time, kill the speech server to
* conserve resources.
*/
+ (void)exitIfUnneeded: (NSTimer*)sender
{
if (clients == 0)
{
exit(0);
}
}
- (id)init
{
self = [super init];
if (self != nil)
{
clients++;
NSLog(@"self = %@",self);
}
return self;
}
- (void)dealloc
{
NSLog(@"Deallocating recognizer....");
clients--;
if (clients == 0)
{
[NSTimer scheduledTimerWithTimeInterval: 600
target: object_getClass(self)
selector: @selector(exitIfUnneeded:)
userInfo: nil
repeats: NO];
}
[super dealloc];
}
- (void) startListening
{
NSLog(@"Start Listening");
if (server != nil)
{
[server startListening];
}
}
- (void) stopListening
{
NSLog(@"Stop Listening");
if (server != nil)
{
[server stopListening];
}
}
@end