added (joke) alarm_speech plugin for OSX

This commit is contained in:
Unbit
2012-10-09 18:43:02 +02:00
parent adcbc061b1
commit 1015ef9611
4 changed files with 98 additions and 1 deletions
+37 -1
View File
@@ -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);
}
}
}
+52
View File
@@ -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,
};
+6
View File
@@ -0,0 +1,6 @@
NAME='alarm_speech'
CFLAGS = []
LDFLAGS = []
LIBS = ['-framework appkit']
GCC_LIST = ['alarm_speech.m']
+3
View File
@@ -3333,6 +3333,9 @@ struct uwsgi_offload_request {
int s;
int fd;
off_t pos;
char *buf;
off_t buf_pos;
size_t to_write;
size_t len;
size_t written;
struct uwsgi_offload_request *prev;