request meta

master
Jordan Orelli 8 years ago
parent 848c56099e
commit c623b59b08

@ -28,7 +28,9 @@ func (s *server) setRoot(path string) {
} }
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.out <- events.BeginRequestEvent{} s.out <- events.BeginRequestEvent{
Path: r.URL.Path,
}
if s.root == "" { if s.root == "" {
writeNotInitializedResponse(w) writeNotInitializedResponse(w)
return return

@ -17,6 +17,7 @@ type SetRootEvent struct {
} }
type BeginRequestEvent struct { type BeginRequestEvent struct {
Path string
backgroundEvent backgroundEvent
} }

@ -1,8 +1,9 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "ui_darwin.h"
@protocol EventListener @protocol EventListener
- (void) serverDidSetRoot:(NSString *)path; - (void) serverDidSetRoot:(NSString *)path;
- (void) serverDidBeginHandlingRequest; - (void) serverDidBeginHandlingRequest:(RequestMeta *)meta;
- (void) serverDidFinishHandlingRequest; - (void) serverDidFinishHandlingRequest;
@end @end

@ -2,5 +2,4 @@
#import "EventListener.h" #import "EventListener.h"
@interface MainViewController : NSViewController <EventListener> @interface MainViewController : NSViewController <EventListener>
- (void) serverDidSetRoot:(NSString *)path;
@end @end

@ -79,8 +79,8 @@
[self.selectedDirectoryText setStringValue:path]; [self.selectedDirectoryText setStringValue:path];
} }
- (void) serverDidBeginHandlingRequest { - (void) serverDidBeginHandlingRequest:(RequestMeta *)meta {
NSLog(@"[MainViewController] request start"); NSLog(@"[MainViewController] request start: %s", meta->path);
} }
- (void) serverDidFinishHandlingRequest { - (void) serverDidFinishHandlingRequest {

@ -42,21 +42,35 @@ func (ui *cocoaUI) Run(out chan events.UserEvent, in chan events.BackgroundEvent
return nil return nil
} }
func (ui *cocoaUI) forwardEvent(e events.BackgroundEvent) {
switch v := e.(type) {
case events.SigIntEvent:
log.Println("Cocoa UI sees sig int, forwarding to NSApp")
C.shutdown()
case events.SetRootEvent:
cpath := C.CString(v.Path)
defer C.free(unsafe.Pointer(cpath))
C.set_root(cpath)
case events.BeginRequestEvent:
cpath := C.CString(v.Path)
defer C.free(unsafe.Pointer(cpath))
req := &C.struct_RequestMeta{
path: cpath,
}
C.begin_request(req)
case events.EndRequestEvent:
C.end_request()
}
}
func (ui *cocoaUI) forwardEvents() { func (ui *cocoaUI) forwardEvents() {
for e := range ui.in { for e := range ui.in {
switch v := e.(type) { ui.forwardEvent(e)
case events.SigIntEvent:
log.Println("Cocoa UI sees sig int, forwarding to NSApp")
C.shutdown()
case events.SetRootEvent:
cs := C.CString(v.Path)
C.set_root(cs)
C.free(unsafe.Pointer(cs))
case events.BeginRequestEvent:
C.begin_request()
case events.EndRequestEvent:
C.end_request()
}
} }
} }

@ -1,6 +1,18 @@
struct RequestMeta {
char *path;
};
typedef struct RequestMeta RequestMeta;
struct ResponseMeta {
};
typedef struct ResponseMeta ResponseMeta;
void initialize(); void initialize();
int run(); int run();
void shutdown(); void shutdown();
void set_root(char *); void set_root(char *);
void begin_request(); void begin_request(RequestMeta *);
void end_request(); void end_request();

@ -1,6 +1,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "AppDelegate.h" #import "AppDelegate.h"
#import "EventBridge.h" #import "EventBridge.h"
#import "ui_darwin.h"
id defaultAutoreleasePool; id defaultAutoreleasePool;
id appDelegate; id appDelegate;
@ -27,9 +28,9 @@ void set_root(char *path) {
[listener serverDidSetRoot:[NSString stringWithUTF8String:path]]; [listener serverDidSetRoot:[NSString stringWithUTF8String:path]];
} }
void begin_request() { void begin_request(RequestMeta *meta) {
id listener = [[EventBridge shared] listener]; id listener = [[EventBridge shared] listener];
[listener serverDidBeginHandlingRequest]; [listener serverDidBeginHandlingRequest:meta];
} }
void end_request() { void end_request() {

Loading…
Cancel
Save