Skip to content

Commit

Permalink
Building architecture, allowing modular addition of services.
Browse files Browse the repository at this point in the history
  • Loading branch information
akoprow committed Mar 5, 2012
1 parent 3b70037 commit 02c0ce0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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)
Expand Down
4 changes: 2 additions & 2 deletions src/dropbox.opa
Expand Up @@ -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()
}
Expand Down
67 changes: 67 additions & 0 deletions 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)
}

}
2 changes: 1 addition & 1 deletion src/webshell.opa
Expand Up @@ -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
Expand Down

0 comments on commit 02c0ce0

Please sign in to comment.