From 02c0ce061060a584f79cee0b443543e937021193 Mon Sep 17 00:00:00 2001 From: Adam Koprowski Date: Mon, 5 Mar 2012 15:33:43 +0100 Subject: [PATCH] Building architecture, allowing modular addition of services. --- Makefile | 2 +- src/dropbox.opa | 4 +-- src/service.opa | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ src/webshell.opa | 2 +- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/service.opa diff --git a/Makefile b/Makefile index 36b8640..4839867 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ NAME = webshell.exe -SRC = parser.opa editor.opa webshell.opa login.opa facebook.opa search.opa dropbox.opa config.opa +SRC = service.opa parser.opa editor.opa webshell.opa login.opa facebook.opa search.opa dropbox.opa config.opa SRCS = $(SRC:%=src/%) all: $(NAME) diff --git a/src/dropbox.opa b/src/dropbox.opa index efd8e3c..8340666 100644 --- a/src/dropbox.opa +++ b/src/dropbox.opa @@ -123,8 +123,8 @@ Please re-run your application with: --dropbox-config option") function ls() { match (get_creds()) { case {some: creds}: - acc_info = DB.Account.info(creds) - Log.info("Dropbox", "Account info: {acc_info}") + files = DB.Files("dropbox", "/").metadata(DB.default_metadata_options, creds) + Log.info("Dropbox", "Files: {files}") default: authentication_failed() } diff --git a/src/service.opa b/src/service.opa new file mode 100644 index 0000000..0c71622 --- /dev/null +++ b/src/service.opa @@ -0,0 +1,67 @@ +// license: AGPL +// (c) MLstate, 2011, 2012 +// author: Adam Koprowski + + // service response to a command +type Service.response('t) = + { xhtml response, 't new_state } + + // specification of a single service +type Service.spec('t) = + { 't initial_state, + ('t -> Parser.general_parser(Service.response('t))) parse_cmd + } + + // implementation of a service +abstract type Service.t = + Cell.cell(string, {cannot_handle} or {xhtml response}) + +server module Service { + + // builds a service from its specification + function Service.t make(Service.spec('t) spec) { + function process_cmd(state, cmd) { + cmd_parser = spec.parse_cmd(state) + match (Parser.try_parse(cmd_parser, cmd)) { + case {some: res}: + { return: {response: res.response}, + instruction: {set: res.new_state} + } + default: + { return: {cannot_handle}, + instruction: {unchanged} + } + } + } + Cell.make(spec.initial_state, process_cmd) + } + +} + +// implementation of a system (consisting of a bunch of services) +abstract type System.t = list(Service.t) + +server module System { + + function System.t build(list(Service.t) services) { + services + } + + function xhtml process(System.t sys, string cmd) { + recursive function aux(services) { + match (services) { + case []: + <>Unknown command + case [x | xs]: + match (Cell.call(x, cmd)) { + case ~{response}: + response + default: + aux(xs) + } + } + } + aux(sys) + } + +} diff --git a/src/webshell.opa b/src/webshell.opa index 3555149..4ba0ef2 100644 --- a/src/webshell.opa +++ b/src/webshell.opa @@ -3,7 +3,7 @@ // author: Henri Binsztok // author: Adam Koprowski (adding Facebook-connectivity) -import stdlib.themes.bootstrap +import stdlib.themes.bootstrap.v1.4.0 import stdlib.widgets.bootstrap WB = WBootstrap