Collapse server into normal instance

This commit is contained in:
Gregory John Casamento 2020-02-08 02:45:40 -05:00
parent 3468a92539
commit 60cf308471
4 changed files with 36 additions and 72 deletions

View file

@ -14,7 +14,6 @@ GSSpeechRecognitionServer_LANGUAGES = English
GSSpeechRecognitionServer_OBJC_FILES = \
GSSpeechRecognitionEngine.m \
GSSpeechRecognitionServer.m \
GSSpeechRecognizer.m \
main.m

View file

@ -27,29 +27,29 @@
#import "GSSpeechRecognizer.h"
#import <Foundation/Foundation.h>
static GSSpeechRecognitionServer *sharedInstance;
static GSSpeechRecognitionServer *_sharedInstance;
@implementation GSSpeechRecognitionServer
+ (void)initialize
{
sharedInstance = [self new];
_sharedInstance = [[self alloc] init];
}
+ (void)start
{
NSConnection *connection = [NSConnection defaultConnection];
[connection setRootObject: sharedInstance];
[connection setRootObject: _sharedInstance];
if (NO == [connection registerName: @"GSSpeechRecognitionServer"])
{
return;
}
[[NSRunLoop currentRunLoop] run];
// [[NSRunLoop currentRunLoop] run];
}
+ (id)sharedServer
{
return sharedInstance;
return _sharedInstance;
}
- (id)init
@ -74,13 +74,6 @@ static GSSpeechRecognitionServer *sharedInstance;
return self;
}
- (id)newRecognizer
{
GSSpeechRecognizer *r = [[GSSpeechRecognizer alloc] init];
RETAIN(r);
return r;
}
- (void) startListening
{
[_engine startListening];

View file

@ -25,44 +25,12 @@
#import "GSSpeechRecognizer.h"
static GSSpeechRecognitionServer *server;
static int clients;
@interface GSSpeechRecognizer (Private)
+ (void)connectionDied: (NSNotification*)aNotification;
@end
@implementation GSSpeechRecognizer
+ (void)initialize
{
if (self == [GSSpeechRecognizer class])
{
server = [GSSpeechRecognitionServer sharedServer];
RETAIN(server);
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(connectionDied:)
name: NSConnectionDidDieNotification
object: nil];
}
}
/**
* If the remote end exits before freeing the GSSpeechRecognizer then we need
* to send it a -release message to make sure it dies.
*/
+ (void)connectionDied: (NSNotification*)aNotification
{
NSEnumerator *e = [[[aNotification object] localObjects] objectEnumerator];
NSObject *o = nil;
for (o = [e nextObject] ; nil != o ; o = [e nextObject])
{
if ([o isKindOfClass: self])
{
[o release];
}
}
}
/**
* If no clients have been active for some time, kill the speech server to