request start/end events to ui

master
Jordan Orelli 8 years ago
parent 199c59b786
commit 848c56099e

@ -11,7 +11,10 @@ func Run(out chan events.BackgroundEvent, in chan events.UserEvent) {
bg := &background{
in: in,
out: out,
server: newServer(),
server: &server{
port: 8000,
out: out,
},
}
go bg.handleSignals()
go bg.listen()

@ -4,15 +4,14 @@ import (
"fmt"
"log"
"net/http"
"github.com/jordanorelli/dws/events"
)
type server struct {
port int
root string
}
func newServer() *server {
return &server{port: 8000}
out chan events.BackgroundEvent
}
func (s *server) listen() {
@ -29,11 +28,13 @@ func (s *server) setRoot(path string) {
}
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.out <- events.BeginRequestEvent{}
if s.root == "" {
writeNotInitializedResponse(w)
return
}
fmt.Fprintf(w, "root: %s", s.root)
s.out <- events.EndRequestEvent{}
}
func writeNotInitializedResponse(w http.ResponseWriter) {

@ -15,3 +15,11 @@ type SetRootEvent struct {
Path string
backgroundEvent
}
type BeginRequestEvent struct {
backgroundEvent
}
type EndRequestEvent struct {
backgroundEvent
}

@ -2,5 +2,7 @@
@protocol EventListener
- (void) serverDidSetRoot:(NSString *)path;
- (void) serverDidBeginHandlingRequest;
- (void) serverDidFinishHandlingRequest;
@end

@ -75,38 +75,16 @@
}];
}
- (void) viewWillAppear {
NSLog(@"[MainViewController] viewWillAppear");
return [super viewWillAppear];
}
- (void) viewDidAppear {
NSLog(@"[MainViewController] viewDidAppear");
return [super viewDidAppear];
}
- (void) viewWillDisappear {
NSLog(@"[MainViewController] viewWillDisappear");
return [super viewWillDisappear];
}
- (void) viewDidDisappear {
NSLog(@"[MainViewController] viewDidDisappear");
return [super viewDidDisappear];
}
- (void) viewWillLayout {
NSLog(@"[MainViewController] viewWillLayout");
return [super viewWillLayout];
- (void) serverDidSetRoot:(NSString *)path {
[self.selectedDirectoryText setStringValue:path];
}
- (void) viewDidLayout {
NSLog(@"[MainViewController] viewDidLayout");
return [super viewDidLayout];
- (void) serverDidBeginHandlingRequest {
NSLog(@"[MainViewController] request start");
}
- (void) serverDidSetRoot:(NSString *)path {
[self.selectedDirectoryText setStringValue:path];
- (void) serverDidFinishHandlingRequest {
NSLog(@"[MainViewController] request finish");
}
@end

@ -52,6 +52,10 @@ func (ui *cocoaUI) forwardEvents() {
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()
}
}
}

@ -2,3 +2,5 @@ void initialize();
int run();
void shutdown();
void set_root(char *);
void begin_request();
void end_request();

@ -26,3 +26,13 @@ void set_root(char *path) {
id listener = [[EventBridge shared] listener];
[listener serverDidSetRoot:[NSString stringWithUTF8String:path]];
}
void begin_request() {
id listener = [[EventBridge shared] listener];
[listener serverDidBeginHandlingRequest];
}
void end_request() {
id listener = [[EventBridge shared] listener];
[listener serverDidFinishHandlingRequest];
}

Loading…
Cancel
Save