%% -*- erlang -*- %% %% cf_client %% %% Copyright 2015-2018 Jörgen Brandt %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. %% You may obtain a copy of the License at %% %% http://www.apache.org/licenses/LICENSE-2.0 %% %% Unless required by applicable law or agreed to in writing, software %% distributed under the License is distributed on an "AS IS" BASIS, %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %% See the License for the specific language governing permissions and %% limitations under the License. %% %% ------------------------------------------------------------------- %% @author Jörgen Brandt %% @version 0.1.6 %% @copyright 2015-2018 Jörgen Brandt %% %% %% %% %% %% @end %% ------------------------------------------------------------------- -module( cf_client_process ). -behaviour( cre_client ). %%==================================================================== %% Exports %%==================================================================== %% CRE client callbacks -export( [init/1, is_value/2, recv/3, step/2] ). %% API functions -export( [start_link/1, start_link/2] ). -define( CUNEIFORM_SEM, cuneiform_sem_cek ). -include_lib( "cuneiform.hrl" ). %%==================================================================== %% API functions %%==================================================================== start_link( F ) when is_function( F, 0 ) -> case F() of {ok, CreName} -> start_link( CreName ); {error, E} -> {error, E} end; start_link( CreName ) -> cre_client:start_link( CreName, ?MODULE, [] ). start_link( ClientName, F ) when is_function( F, 0 ) -> case F() of {ok, CreName} -> start_link( ClientName, CreName ); {error, E} -> {error, E} end; start_link( Clientname, CreName ) -> cre_client:start_link( Clientname, CreName, ?MODULE, [] ). %%==================================================================== %% CRE client callback implementations %%==================================================================== -spec init( ClientArg :: _ ) -> []. init( _ClientArg ) -> []. -spec is_value( E :: e(), UsrInfo :: _ ) -> boolean(). is_value( {err, _, _, _}, _ ) -> true; is_value( E, _ ) -> cuneiform_sem:is_value( E ). -spec recv( E, ReplyLst, UsrInfo ) -> e() when E :: e(), ReplyLst :: [{#{ atom() => _ }, #{ atom() => _ }}], UsrInfo :: _. recv( E, ReplyLst, _UsrInfo ) -> ReplyLst1 = [{AppId, cf_client_effi:effi_reply_to_expr( A, R )} || {A = #{ app_id := AppId }, R} <- ReplyLst], cuneiform_sem:subst_fut( E, ReplyLst1 ). -spec step( E, UsrInfo ) -> Result when E :: e(), UsrInfo :: _, Result :: {ok, e(), [e()]}. step( E, _UsrInfo ) -> ?CUNEIFORM_SEM:step( E ).