summaryrefslogtreecommitdiff
path: root/components/schedule
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2015-04-12 20:14:09 -0700
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2015-04-12 20:14:09 -0700
commitc700d4c8d817d2eba9c14d41499c320b3c539096 (patch)
tree16bece1f30e08e9f79a9174d1c038a8a4bf447e6 /components/schedule
parentd9ae25ba4ded507ee057e0d099eb77e8d36e8cf8 (diff)
downloadrvi_core-c700d4c8d817d2eba9c14d41499c320b3c539096.tar.gz
Temp
Diffstat (limited to 'components/schedule')
-rw-r--r--components/schedule/src/schedule_rpc.erl47
1 files changed, 34 insertions, 13 deletions
diff --git a/components/schedule/src/schedule_rpc.erl b/components/schedule/src/schedule_rpc.erl
index 0b4ad38..37bca89 100644
--- a/components/schedule/src/schedule_rpc.erl
+++ b/components/schedule/src/schedule_rpc.erl
@@ -140,6 +140,7 @@ schedule_message(CompSpec,
service_available(CompSpec, SvcName, DataLinkModule) ->
+
rvi_common:notification(schedule, ?MODULE,
service_available,
[{ service, SvcName },
@@ -261,7 +262,7 @@ handle_call(Other, _From, St) ->
handle_cast( {rvi, service_available, [SvcName, DataLinkModule]}, St) ->
%% Find or create the service.
- ?debug("sched:service_available(): ~p:~p", [ DataLinkModule, SvcName ]),
+ ?debug("sched:service_available(): ~p:~s", [ DataLinkModule, SvcName ]),
%% Create a new or update an existing service.
SvcRec = update_service(SvcName, DataLinkModule, available, St),
@@ -518,7 +519,7 @@ try_sending_messages(#service {
available = available,
messages_tid = Tid } = SvcRec, St) ->
- ?debug("sched:try_send(): Service: ~p:~p", [DataLinkMod, SvcName]),
+ ?debug("sched:try_send(): Service: ~p:~p", [DataLinkMod, SvcName]),
%% Extract the first message of the queue.
case first_service_message(SvcRec) of
@@ -538,7 +539,10 @@ try_sending_messages(#service {
erlang:cancel_timer(Msg#message.timeout_tref),
%% Forward to protocol.
+ ?debug("sched:try_send(): DataLink: ~p", [Msg#message.data_link]),
{ _, DataLinkOpts } = Msg#message.data_link,
+
+ ?debug("sched:try_send(): Proto: ~p", [Msg#message.protocol]),
{ ProtoMod, ProtoOpts } = Msg#message.protocol,
%% Send off message to the correct protocol module
@@ -600,27 +604,44 @@ find_or_create_service(SvcName, DataLinkMod, #st { services_tid = SvcTid } = St)
-%% Create a new service, or update an existing one, and return the new
-%% state (not currently modified) and the newly initialized service
-%% revord.
-%%
+%% Create a new service.
+%% Warning: Will overwrite existing service (and its message table reference).
+%%
update_service(SvcName, DataLinkMod, Available,
- #st { services_tid = SvcsTid }) ->
- %% Return new service and existing state.
- ?debug("sched:create_service(): ~p:~s ", [ DataLinkMod, SvcName]),
+ #st { services_tid = SvcsTid, cs = CS }) ->
+
+ MsgTID =
+ case ets:lookup(SvcsTid, { SvcName, DataLinkMod }) of
+ [] -> %% The given service does not exist, create a new message TID
+ ?debug("sched:update_service(~p:~p): ~p - Creating new",
+ [ DataLinkMod, SvcName, Available]),
+ ets:new(rvi_messages,
+ [ ordered_set, private,
+ { keypos, #message.transaction_id } ]);
+
+ [ TmpSvcRec ] ->
+ %% Grab the existing messagae table ID
+ ?debug("sched:update_service(~p:~p): ~p - Updating existing",
+ [ DataLinkMod, SvcName, Available]),
+
+ #service { messages_tid = TID } = TmpSvcRec,
+ TID
+ end,
+
+
+ %% Insert new service to ets table.
SvcRec = #service {
key = { SvcName, DataLinkMod },
available = Available,
- messages_tid = ets:new(rvi_messages,
- [ ordered_set, private,
- { keypos, #message.transaction_id } ])
+ messages_tid = MsgTID,
+ cs = CS
},
- %% Insert new service to ets table.
ets:insert(SvcsTid, SvcRec),
SvcRec.
+
%% Create a new and unique transaction id
create_transaction_id(St) ->
?debug("sched:create_transaction_id(~p): ", [ St#st.next_transaction_id ]),