From c623b59b0854dfe8e8c0cca73b8c475a6cdc5aa0 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 17 Jun 2017 23:06:50 -0500 Subject: [PATCH] request meta --- bg/server.go | 4 +++- events/background_event.go | 1 + ui/EventListener.h | 3 ++- ui/MainViewController.h | 1 - ui/MainViewController.m | 4 ++-- ui/ui_darwin.go | 40 +++++++++++++++++++++++++------------- ui/ui_darwin.h | 14 ++++++++++++- ui/ui_darwin.m | 5 +++-- 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/bg/server.go b/bg/server.go index a714f09..9cf1af1 100644 --- a/bg/server.go +++ b/bg/server.go @@ -28,7 +28,9 @@ func (s *server) setRoot(path string) { } 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 == "" { writeNotInitializedResponse(w) return diff --git a/events/background_event.go b/events/background_event.go index af109b3..3d2997e 100644 --- a/events/background_event.go +++ b/events/background_event.go @@ -17,6 +17,7 @@ type SetRootEvent struct { } type BeginRequestEvent struct { + Path string backgroundEvent } diff --git a/ui/EventListener.h b/ui/EventListener.h index 6b38860..8cfa1dd 100644 --- a/ui/EventListener.h +++ b/ui/EventListener.h @@ -1,8 +1,9 @@ #import +#import "ui_darwin.h" @protocol EventListener - (void) serverDidSetRoot:(NSString *)path; -- (void) serverDidBeginHandlingRequest; +- (void) serverDidBeginHandlingRequest:(RequestMeta *)meta; - (void) serverDidFinishHandlingRequest; @end diff --git a/ui/MainViewController.h b/ui/MainViewController.h index 5ae97d8..11079f2 100644 --- a/ui/MainViewController.h +++ b/ui/MainViewController.h @@ -2,5 +2,4 @@ #import "EventListener.h" @interface MainViewController : NSViewController -- (void) serverDidSetRoot:(NSString *)path; @end diff --git a/ui/MainViewController.m b/ui/MainViewController.m index 3f69eca..f95ef8e 100644 --- a/ui/MainViewController.m +++ b/ui/MainViewController.m @@ -79,8 +79,8 @@ [self.selectedDirectoryText setStringValue:path]; } -- (void) serverDidBeginHandlingRequest { - NSLog(@"[MainViewController] request start"); +- (void) serverDidBeginHandlingRequest:(RequestMeta *)meta { + NSLog(@"[MainViewController] request start: %s", meta->path); } - (void) serverDidFinishHandlingRequest { diff --git a/ui/ui_darwin.go b/ui/ui_darwin.go index a3e9d98..077d0bc 100644 --- a/ui/ui_darwin.go +++ b/ui/ui_darwin.go @@ -42,21 +42,35 @@ func (ui *cocoaUI) Run(out chan events.UserEvent, in chan events.BackgroundEvent 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() { for e := range ui.in { - switch v := e.(type) { - 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() - } + ui.forwardEvent(e) } } diff --git a/ui/ui_darwin.h b/ui/ui_darwin.h index 9d82cae..05a20ff 100644 --- a/ui/ui_darwin.h +++ b/ui/ui_darwin.h @@ -1,6 +1,18 @@ +struct RequestMeta { + char *path; +}; + +typedef struct RequestMeta RequestMeta; + +struct ResponseMeta { + +}; + +typedef struct ResponseMeta ResponseMeta; + void initialize(); int run(); void shutdown(); void set_root(char *); -void begin_request(); +void begin_request(RequestMeta *); void end_request(); diff --git a/ui/ui_darwin.m b/ui/ui_darwin.m index 5407675..bf38b04 100644 --- a/ui/ui_darwin.m +++ b/ui/ui_darwin.m @@ -1,6 +1,7 @@ #import #import "AppDelegate.h" #import "EventBridge.h" +#import "ui_darwin.h" id defaultAutoreleasePool; id appDelegate; @@ -27,9 +28,9 @@ void set_root(char *path) { [listener serverDidSetRoot:[NSString stringWithUTF8String:path]]; } -void begin_request() { +void begin_request(RequestMeta *meta) { id listener = [[EventBridge shared] listener]; - [listener serverDidBeginHandlingRequest]; + [listener serverDidBeginHandlingRequest:meta]; } void end_request() {