Permalink
Browse files

Building architecture, allowing modular addition of services.

  • Loading branch information...
1 parent 3b70037 commit 02c0ce061060a584f79cee0b443543e937021193 @akoprow akoprow committed Mar 5, 2012
Showing with 71 additions and 4 deletions.
  1. +1 −1 Makefile
  2. +2 −2 src/dropbox.opa
  3. +67 −0 src/service.opa
  4. +1 −1 src/webshell.opa
View
@@ -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)
View
@@ -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()
}
View
@@ -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)
+ }
+
+}
View
@@ -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

0 comments on commit 02c0ce0

Please sign in to comment.