Permalink
Browse files

[update] hello multitub example compiles again

  • Loading branch information...
1 parent ba1d066 commit e4bbebe30f17572e94be467c497d3ce4331a5eb4 Mathieu Barbin committed Mar 28, 2011
Showing with 14 additions and 144 deletions.
  1. +6 −1 multitub/Makefile
  2. +0 −137 multitub/draft/multitub_functor.opa
  3. +8 −6 multitub/hello_multitub.opa
View
@@ -1,9 +1,14 @@
# compile a simple example using multitub pattern
-OPA=s3opa.exe
+OPA=opa.exe
SOURCES=multitub.opa hello_multitub.opa
all:hello_multitub.exe
hello_multitub.exe : $(SOURCES)
$(OPA) $(OPAOPT) $(SOURCES)
+
+clean:
+ rm -f *.exe
+ rm -rf _build _tracks
+ rm -f *.log
@@ -1,137 +0,0 @@
-/**
- * OPA design pattern collection. (c) MLstate - 2010
- *
- * The Mutlitub pattern.
- * @author Mathieu Barbin
- */
-
-/**
- * In this design pattern, we denote by 'tub' a new connexion.
- * For each 'tub', we have 2 session, one on the server, and one on the client.
- *
- * The type of messages handled by theses 2 session are the only authorized exchanges
- * between the client and the server.
- *
- * The server part of the code does not have the right to access the DOM, or anything from
- * the client. The page is generated by the client.
- *
- * The client has 2 different kind of messages, one from the server (contract) and one
- * from some funaction which the client has generated itself.
- *
- */
-
-/**
- * {1 Events}
- * Public contract : just the interface of messages (event)
- */
-
-/**
- * {2 Server}
- */
-
-/**
- * + {a} : a first message, without argument
- * + {b:int} : a message interracting with the state of the server
- */
-type S.message = { a } / { b : int }
-
-type S.channel = channel(S.message)
-
-/**
- * {2 Client}
- */
-
-/**
- * In this prototype, only 1 message, a value from the server.
- */
-type C.message = { value : int }
-
-type C.channel = channel(C.message)
-
-/**
- * {1 Handler, components}
- */
-
-/**
- * Once this contract is established, handler on the 2 sides are independant,
- * and can be switched. We could imagine have serveral implementation of (init, handler)
- * with the corresponding type of message.
- */
-
-/**
- * {2 Server}
- */
-// FIXME: should be a module interface
-type S.ARG.interface('state) = {
- init : void -> 'state
- on_message : C.channel, 'state, S.message -> Session.instruction('state)
-}
-
-/**
- * {2 Client}
- */
-// FIXME: should be a module interface
-type C.ARG.interface('state) = {
- init : void -> 'state
- on_message : S.channel, 'state, C.message -> Session.instruction('state)
-}
-
-/**
- * {1 Functorisation}
- */
-
-type S.M.state('state) = {
- c_channel : option(C.channel)
- state : 'state
-}
-
-type S.M.message = { message : S.message } / { set_c_channel : C.channel }
-
-session_map_instruction(map, i) =
- match i : Session.instruction with
- | {set = state} -> {set = map(state)}
- | {unchanged}
- | {stop} -> Magic.id(i) : Session.instruction // Fixme: do something with the typer
-
-M(C : C.ARG.interface('c_state), S : S.ARG.interface('s_state)) = {{
- c_init(server) =
- state = C.init()
- ~{ server state }
-
- c_on_message(state, message) =
- map(internal_state) = { state with state = internal_state }
- session_map_instruction(map, C.on_message(state.server, state.state, message))
-
- s_init() =
- state = S.init()
- {c_channel = {none} ; ~state} : S.M.state('s_state)
-
- s_on_message(state, message) =
- match message with
- | { set_c_channel = channel } ->
- { set = { state with c_channel = { some = channel } } }
- | { ~message } -> (
- match state.c_channel with
- | {none} -> error("Internal error, the client has not been set yet")
- | {some = c_channel} ->
- map(internal_state) = { state with state = internal_state }
- session_map_instruction(map, S.on_message(c_channel, state.state, message))
- )
-
- client c_onload(s_channel, _) =
- c_channel = Session.make(c_init(s_channel), c_on_message)
- do send(s_channel, {set_c_channel = c_channel})
- do exec_actions( [ #main <- C.page(s_channel, c_channel) ] )
- void
-
- server page() =
- s_channel = Session.make(s_init(), s_on_message)
- <>
- <div id="main" onready={c_onload(s_channel, _)}>
- "default page (not yet set by the client)"
- </div>
- </>
-
- server one_page_server(name) = @toplevel.one_page_server(name, page)
-
-}}
@@ -1,5 +1,5 @@
/**
- * OPA design pattern collection. (c) MLstate - 2010
+ * OPA design pattern collection. (c) MLstate - 2010-2011
*
* The Mutlitub pattern, for OPA-S3.
* @author Mathieu Barbin
@@ -45,7 +45,7 @@ type Multitub.C.message = { value : int } / { funaction }
type S1.state = { value : int }
-server Multitub_S : Multitub.S.interface(S1.state) = {{
+@server Multitub_S : Multitub.S.interface(S1.state) = {{
init() =
{ value = 0 } : S1.state
@@ -60,6 +60,8 @@ server Multitub_S : Multitub.S.interface(S1.state) = {{
value = { value = int }
do Multitub.send_client(c_channel, value)
{ set = value }
+
+ on_connection(_ : Multitub.C.channel, state : S1.state) = state
}}
/**
@@ -75,16 +77,16 @@ type C1.state = { num_a : int }
* Example of a funaction sending directly a message to the server.
*/
-client messageB(s_channel, i, _) =
+@client messageB(s_channel, i, _) =
Multitub.send_server(s_channel, {b=i})
/**
* Example of a funaction which use the client session
*/
-client messageA(c_channel, _) =
+@client messageA(c_channel, _) =
Multitub.send_client(c_channel, {funaction})
-client page(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel) =
+@client page(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel) =
<>
<h2>Response of the server</h2>
<div id="response"/>
@@ -98,7 +100,7 @@ client page(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel) =
<a id={"messageB3"} class="button" href="#" onclick={messageB(s_channel, 3, _)}>{"Message B(3)"}</a>
</>
-client Multitub_C : Multitub.C.interface(C1.state) = {{
+@client Multitub_C : Multitub.C.interface(C1.state) = {{
init() =
{ num_a = 0 } : C1.state

0 comments on commit e4bbebe

Please sign in to comment.