Permalink
Browse files

add some naming utility functions

  • Loading branch information...
1 parent 325584e commit 24515e3059d77b9d5f86cc52f7a455970cfadc7d @gleber committed May 2, 2012
Showing with 40 additions and 10 deletions.
  1. +29 −3 src/agent.erl
  2. +11 −7 src/exat.erl
View
@@ -28,10 +28,12 @@
-include("fipa_ontology.hrl").
-export([get_acl_semantics/1, get_mind/1, get_property/2, join/1,
- kill/1, new/2, new/3, set_property/3, set_rational/3,
+ kill/1, new/2, new/3, set_property/3, set_rational/3,
stop/1, cast/2, call/2
]).
+-export([names/1, name/1, host/1, ap/1]).
+
-export([code_change/3, terminate/2, handle_call/3, handle_cast/2,
init/1, handle_info/2, behaviour_info/1]).
@@ -60,7 +62,6 @@ new(AgentName, Callback, Parameters) ->
[]).
call(Ref, Call) ->
- io:format("~p ~p ~p~n", [Ref, whereis(Ref), Call]),
gen_server:call(Ref, Call).
cast(Ref, Call) ->
gen_server:cast(Ref, Call).
@@ -157,6 +158,7 @@ handle_call([acl_erl_native, Acl], _From,
handle_call(Call, From,
#state{int_state = IntState, callback = Callback} =
State) ->
+ io:format("~p ~p~n", [From, Call]),
R = Callback:handle_call(Call, From, IntState),
IntState2 = element(size(R), R),
setelement(size(R), R,
@@ -200,4 +202,28 @@ proplists_extract(Key, Proplist0, Default) ->
false ->
{Default, Params}
end.
-
+
+
+%%
+%% Utils
+%%
+
+
+names(List) ->
+ [ name(A) || A <- List ].
+
+name(#'agent-identifier'{name = N}) ->
+ N.
+
+ap(#'agent-identifier'{name = N}) ->
+ ap(N);
+ap(N) ->
+ {Name, HAP} = exat:split_agent_identifier(N),
+ HAP.
+
+host(#'agent-identifier'{} = A) ->
+ HAP = ap(A),
+ host(HAP);
+host(HAP) ->
+ {_APName, Hostname} = exat:split_exat_platform_identifier(HAP),
+ Hostname.
View
@@ -33,7 +33,9 @@
%%====================================================================
-export([current_platform/0, get_argument/1,
- split_agent_identifier/1, start/2, stop/1]).
+ split_agent_identifier/1, split_exat_platform_identifier/1,
+
+ start/2, stop/1]).
%%====================================================================
%% Internal exports
@@ -58,7 +60,7 @@
%% {ok, Pid, State} |
%% {error, Reason}
%%====================================================================
-start(_Type, _StartArgs) ->
+start(_Type, _StartArgs) ->
exat_sup:start_link().
%%====================================================================
@@ -72,11 +74,8 @@ stop(_State) -> ok.
%% Returns: string()
%%====================================================================
current_platform() ->
- {CurrentPlatform, [$@ | Hostname]} = lists:splitwith(fun
- (X) -> X =/= $@
- end,
- atom_to_list(node())),
- iolist_to_binary([CurrentPlatform, ".", Hostname]).
+ [Node, Host] = string:tokens(atom_to_list(node()), "@"),
+ iolist_to_binary([Node, ":", Host]).
%%====================================================================
%% Func: split_agent_identifier/1
@@ -88,6 +87,11 @@ split_agent_identifier(AgentID) ->
[LocalID, RealHAP] -> {LocalID, RealHAP}
end.
+split_exat_platform_identifier(AP) ->
+ [APName, APHost] = binary:split(AP, <<":">>),
+ {APName, APHost}.
+
+
%%====================================================================
%% Func: get_argument/1
%% Returns: {ok, [string()]} | error

0 comments on commit 24515e3

Please sign in to comment.