Protocol halfway ported

This commit is contained in:
Jonatan Pålsson 2011-02-14 17:18:24 +01:00
parent 6aad821279
commit 973f2fcf98
4 changed files with 66 additions and 56 deletions

View file

@ -95,30 +95,30 @@ handle_cast(stop, State) ->
{stop, normal, State};
% Handle javascript defines
handle_cast({define, Token, Payload}, State) ->
JSVM = getJSVM(Token, State),
js_runner:define(JSVM, Payload),
send(State#state.lsock, Token, "Okay, defined that for you!"),
handle_cast({srv_cmd, "define", Args, Data}, State) ->
%JSVM = getJSVM(Token, State),
%js_runner:define(JSVM, Payload),
send(State#state.lsock, "Token", "Okay, defined that for you!"),
{noreply, State};
% Handle javascript calls
handle_cast({call, Token, Payload}, State) ->
io:format("Got call request: ~p~n", [Payload]),
JSVM = getJSVM(Token, State),
erlang:display(erlang:port_info(JSVM)),
{ok, Ret} = js_runner:call(JSVM, Payload, []),%Payload, []),
send(State#state.lsock, Token, "JS says:", binary_to_list(Ret)),
handle_cast({srv_cmd, "call", Args, Data}, State) ->
%io:format("Got call request: ~p~n", [Payload]),
%JSVM = getJSVM(Token, State),
%erlang:display(erlang:port_info(JSVM)),
%{ok, Ret} = js_runner:call(JSVM, Payload, []),%Payload, []),
%send(State#state.lsock, Token, "JS says:", binary_to_list(Ret)),
{noreply, State};
% Set the new state to the reference generated, and JSVM associated
handle_cast({hello, _, _}, State) ->
JSVM = js_runner:boot(),
handle_cast({srv_cmd, "hello", Headers, Data}, State) ->
%JSVM = js_runner:boot(),
Client = getRef(),
send(State#state.lsock, Client, "This is your refID"),
OldMap = State#state.client_vm_map,
NewState = State#state{client_vm_map = OldMap ++ [{Client, JSVM}]},
gen_server:cast(ggs_backup, {set_backup, NewState}),
{noreply, NewState}.
%OldMap = State#state.client_vm_map,
%NewState = State#state{client_vm_map = OldMap ++ [{Client, JSVM}]},
%gen_server:cast(ggs_backup, {set_backup, NewState}),
{noreply, State}. %NewState
%%-----------------------------------------------------
%% Helpers
%%-----------------------------------------------------