Browse Source

n2o_heart to n4u_heart

221V 3 years ago
parent
commit
678468e542
4 changed files with 57 additions and 44 deletions
  1. 1 1
      ebin/n4u.app
  2. 1 1
      src/endpoints/n2o_proto.erl
  3. 0 42
      src/protocols/n2o_heart.erl
  4. 55 0
      src/protocols/n4u_heart.erl

+ 1 - 1
ebin/n4u.app

@@ -2,7 +2,7 @@
   {description, "N4U WebSocket Application Server"},
   {description, "N4U WebSocket Application Server"},
   {vsn, "4.4.20"},
   {vsn, "4.4.20"},
   {applications, [kernel, stdlib, asn1, public_key, ssl, crypto, ranch, cowboy, fs, active, sh, gproc, nitro]},
   {applications, [kernel, stdlib, asn1, public_key, ssl, crypto, ranch, cowboy, fs, active, sh, gproc, nitro]},
-  {modules, [n2o, n4u_app, n4u_sup, n4u_async, n2o_xhr, n4u_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n4u_document, n2o_proto, n2o_relay, n4u_error, n2o_io, n2o_log, n2o_mq, n2o_pickle, n2o_query, n2o_secret, n2o_session, n2o_syn, n4u_client, n2o_file, n2o_heart, n2o_http, n2o_nitrogen, n2o_text, wf, wf_convert, wf_utils]},
+  {modules, [n2o, n4u_app, n4u_sup, n4u_async, n2o_xhr, n4u_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n4u_document, n2o_proto, n2o_relay, n4u_error, n2o_io, n2o_log, n2o_mq, n2o_pickle, n2o_query, n2o_secret, n2o_session, n2o_syn, n4u_client, n2o_file, n4u_heart, n2o_http, n2o_nitrogen, n2o_text, wf, wf_convert, wf_utils]},
   {registered, [n4u_sup]},
   {registered, [n4u_sup]},
   {mod, {n4u_app, []}},
   {mod, {n4u_app, []}},
   {env, []}
   {env, []}

+ 1 - 1
src/endpoints/n2o_proto.erl

@@ -5,7 +5,7 @@
 
 
 formatter(O)-> case lists:keyfind(formatter,1,O) of {formatter,F} -> F; X -> X end.
 formatter(O)-> case lists:keyfind(formatter,1,O) of {formatter,F} -> F; X -> X end.
 upack(D)    -> binary_to_term(D,[safe]).
 upack(D)    -> binary_to_term(D,[safe]).
-protocols() -> wf:config(n2o,protocols,[ n2o_heart,
+protocols() -> wf:config(n2o,protocols,[ n4u_heart,
                                          n2o_nitrogen,
                                          n2o_nitrogen,
                                          n2o_file,
                                          n2o_file,
                                          n4u_client,
                                          n4u_client,

+ 0 - 42
src/protocols/n2o_heart.erl

@@ -1,42 +0,0 @@
--module(n2o_heart).
--include_lib("n4u/include/n4u.hrl").
--compile([export_all, nowarn_export_all]).
-
-info({text,<<"PING">> = _Ping}=Message, Req, State) ->
-    wf:info(?MODULE,"PING: ~p",[Message]),
-    {reply, <<"PONG">>, Req, State};
-
-info({text,<<"N2O,",Process/binary>> = _InitMarker}=Message, Req, State) ->
-    wf:info(?MODULE,"N2O INIT: ~p",[Message]),
-    n2o_proto:push({init,Process},Req,State,n2o_proto:protocols(),[]);
-
-% ETS access protocol
-info({cache,Operation,Key,Value},Req,State)   -> {reply, case Operation of
-                                                              get -> wf:cache(Key);
-                                                              set -> wf:cache(Key,Value) end, Req, State};
-info({session,Operation,Key,Value},Req,State) -> {reply, case Operation of
-                                                              get -> wf:session(Key);
-                                                              set -> wf:session(Key,Value) end, Req, State};
-
-% MQ protocol
-info({pub, _Topic, _Message} = _Message, Req, State) -> {reply, <<"OK">>, Req, State};
-info({sub, _Topic, _Args} = _Message, Req, State)    -> {reply, <<"OK">>, Req, State};
-info({unsub, _Topic} = _Message, Req, State)         -> {reply, <<"OK">>, Req, State};
-
-% WF protocol
-info({q, _Operation, _Key} = _Message, Req, State)                 -> {reply, <<"OK">>, Req, State};
-info({qc, _Operation, _Key} = _Message, Req, State)                -> {reply, <<"OK">>, Req, State};
-info({cookie, _Operation, _Key, _Value} = _Message, Req, State)    -> {reply, <<"OK">>, Req, State};
-info({wire, _Parameter} = _Message, Req, State)                    -> {reply, <<"OK">>, Req, State};
-info({update, _Target, _Elements} = _Message, Req, State)          -> {reply, <<"OK">>, Req, State};
-info({insert_top, _Target, _Elements} = _Message, Req, State)      -> {reply, <<"OK">>, Req, State};
-info({insert_bottom, _Target, _Elements} = _Message, Req, State) -> {reply, <<"OK">>, Req, State};
-
-% ASYNC protocol
-info({start, _Handler} = _Message, Req, State)          -> {reply, <<"OK">>, Req, State};
-info({stop, _Name} = _Message, Req, State)              -> {reply, <<"OK">>, Req, State};
-info({restart, _Name} = _Message, Req, State)           -> {reply, <<"OK">>, Req, State};
-info({async, _Name, _Function} = _Message, Req, State)  -> {reply, <<"OK">>, Req, State};
-info({flush} = _Message, Req, State)                    -> {reply, <<"OK">>, Req, State};
-
-info(Message, Req, State) -> {unknown, Message, Req, State}.

+ 55 - 0
src/protocols/n4u_heart.erl

@@ -0,0 +1,55 @@
+-module(n4u_heart).
+
+-export([info/3]).
+
+
+info({text, <<"PING">> = _Ping} = Message, Req, State) ->
+  wf:info(?MODULE, "PING: ~p", [Message]),
+  {reply, <<"PONG">>, Req, State};
+
+info({text, <<"N4U,", Process/binary>> = _InitMarker} = Message, Req, State) ->
+  wf:info(?MODULE, "N4U INIT: ~p", [Message]),
+  n2o_proto:push({init, Process}, Req, State, n2o_proto:protocols(), []);
+
+
+% ETS access protocol
+info({cache, 'get', Key, _}, Req, State) ->
+  {reply, wf:cache(Key), Req, State};
+  
+info({cache, set, Key, Value}, Req, State) ->
+  {reply, wf:cache(Key, Value), Req, State};
+
+
+info({session, 'get', Key, _}, Req, State) ->
+  {reply, wf:session(Key), Req, State};
+  
+info({session, set, Key, Value}, Req, State) ->
+  {reply, wf:session(Key, Value), Req, State};
+
+
+% MQ protocol
+info({pub, _Topic, _Message} = _Message2, Req, State) -> {reply, <<"OK">>, Req, State};
+info({sub, _Topic, _Args} = _Message, Req, State)     -> {reply, <<"OK">>, Req, State};
+info({unsub, _Topic} = _Message, Req, State)          -> {reply, <<"OK">>, Req, State};
+
+
+% todo - check where/how this used
+% Web Framework protocol
+info({q, _Operation, _Key} = _Message, Req, State)                 -> {reply, <<"OK">>, Req, State};
+info({qc, _Operation, _Key} = _Message, Req, State)                -> {reply, <<"OK">>, Req, State};
+info({cookie, _Operation, _Key, _Value} = _Message, Req, State)    -> {reply, <<"OK">>, Req, State};
+info({wire, _Parameter} = _Message, Req, State)                    -> {reply, <<"OK">>, Req, State};
+info({update, _Target, _Elements} = _Message, Req, State)          -> {reply, <<"OK">>, Req, State};
+info({insert_top, _Target, _Elements} = _Message, Req, State)      -> {reply, <<"OK">>, Req, State};
+info({insert_bottom, _Target, _Elements} = _Message, Req, State)   -> {reply, <<"OK">>, Req, State};
+
+
+% ASYNC protocol
+info({start, _Handler} = _Message, Req, State)         -> {reply, <<"OK">>, Req, State};
+info({stop, _Name} = _Message, Req, State)             -> {reply, <<"OK">>, Req, State};
+info({restart, _Name} = _Message, Req, State)          -> {reply, <<"OK">>, Req, State};
+info({async, _Name, _Function} = _Message, Req, State) -> {reply, <<"OK">>, Req, State};
+info({flush} = _Message, Req, State)                   -> {reply, <<"OK">>, Req, State};
+
+info(Message, Req, State) -> {unknown, Message, Req, State}.
+