mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 05:31:44 +00:00
added (joke) alarm_speech plugin for OSX
This commit is contained in:
+37
-1
@@ -68,6 +68,10 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) {
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (uor->buf) {
|
||||
free(uor->buf);
|
||||
}
|
||||
|
||||
free(uor);
|
||||
}
|
||||
|
||||
@@ -139,8 +143,40 @@ static void uwsgi_offload_loop(struct uwsgi_thread *ut) {
|
||||
if (errno == EAGAIN) continue;
|
||||
uwsgi_error("sendfile()");
|
||||
}
|
||||
uwsgi_offload_close(uor);
|
||||
#else
|
||||
if (!uor->buf) {
|
||||
uor->buf = uwsgi_malloc(32768);
|
||||
}
|
||||
if (uor->to_write == 0) {
|
||||
ssize_t len = read(uor->fd, uor->buf, 32768);
|
||||
if (len > 0) {
|
||||
uor->to_write = len;
|
||||
uor->buf_pos = 0;
|
||||
continue;
|
||||
}
|
||||
else if (len < 0) {
|
||||
uwsgi_error("read()");
|
||||
}
|
||||
uwsgi_offload_close(uor);
|
||||
continue;
|
||||
}
|
||||
ssize_t len = write(uor->s, uor->buf + uor->buf_pos, uor->to_write - uor->buf_pos);
|
||||
if (len > 0) {
|
||||
uor->written += len;
|
||||
uor->to_write -= len;
|
||||
uor->buf_pos += len;
|
||||
if (uor->written >= uor->len) {
|
||||
uwsgi_offload_close(uor);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (len < 0) {
|
||||
if (errno == EAGAIN) continue;
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
|
||||
#endif
|
||||
uwsgi_offload_close(uor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "../../uwsgi.h"
|
||||
#import "Foundation/NSString.h"
|
||||
#import "AppKit/NSSpeechSynthesizer.h"
|
||||
|
||||
@interface uWSGIAlarmSpeaker : NSObject {
|
||||
NSSpeechSynthesizer *synth;
|
||||
}
|
||||
|
||||
-(void)speak: (NSString *)phrase;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation uWSGIAlarmSpeaker
|
||||
|
||||
- (uWSGIAlarmSpeaker *) init {
|
||||
self = [super init];
|
||||
synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)speak:(NSString *)phrase {
|
||||
[synth startSpeakingString:phrase];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// generate a uwsgi signal on alarm
|
||||
void uwsgi_alarm_speech_init(struct uwsgi_alarm_instance *uai) {
|
||||
uai->data_ptr = [[uWSGIAlarmSpeaker alloc] init];
|
||||
}
|
||||
|
||||
void uwsgi_alarm_speech_func(struct uwsgi_alarm_instance *uai, char *msg, size_t len) {
|
||||
uWSGIAlarmSpeaker *say = (uWSGIAlarmSpeaker *) uai->data_ptr;
|
||||
NSString *phrase = [[NSString alloc] initWithBytes:msg
|
||||
length:len
|
||||
encoding:NSUTF8StringEncoding];
|
||||
|
||||
[say speak:phrase];
|
||||
[phrase release];
|
||||
|
||||
}
|
||||
|
||||
static void uwsgi_alarm_speech_load(void) {
|
||||
uwsgi_register_alarm("speech", uwsgi_alarm_speech_init, uwsgi_alarm_speech_func);
|
||||
}
|
||||
|
||||
struct uwsgi_plugin alarm_speech_plugin = {
|
||||
.name = "alarm_speech",
|
||||
.on_load = uwsgi_alarm_speech_load,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME='alarm_speech'
|
||||
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = ['-framework appkit']
|
||||
GCC_LIST = ['alarm_speech.m']
|
||||
Reference in New Issue
Block a user