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) {
s.out <- events.BeginRequestEvent{}
s.out <- events.BeginRequestEvent{
Path: r.URL.Path,
}
if s.root == "" {
writeNotInitializedResponse(w)
return

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

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

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

@ -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 {

@ -42,22 +42,36 @@ func (ui *cocoaUI) Run(out chan events.UserEvent, in chan events.BackgroundEvent
return nil
}
func (ui *cocoaUI) forwardEvents() {
for e := range ui.in {
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:
cs := C.CString(v.Path)
C.set_root(cs)
C.free(unsafe.Pointer(cs))
cpath := C.CString(v.Path)
defer C.free(unsafe.Pointer(cpath))
C.set_root(cpath)
case events.BeginRequestEvent:
C.begin_request()
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 {
ui.forwardEvent(e)
}
}
//export selectDirectory

@ -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();

@ -1,6 +1,7 @@
#import <Cocoa/Cocoa.h>
#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() {

Loading…
Cancel
Save