diff --git a/calexium_lib/net_services/CXM_generic_client.anubis b/calexium_lib/net_services/CXM_generic_client.anubis index 5c90073..5fa234a 100644 --- a/calexium_lib/net_services/CXM_generic_client.anubis +++ b/calexium_lib/net_services/CXM_generic_client.anubis @@ -32,6 +32,9 @@ public type NetServiceAnswer: // --Generic functions--------------------------------------------------------------------- +/** + * Sends the message to the server then parses the answer and returns the RESULT message on CMD success. + */ public define Maybe(NetServiceAnswer) generic_send_message ( @@ -57,40 +60,63 @@ public define Maybe(NetServiceAnswer) if v = _CXM_OK then success(netservice_ok(cmd, find_message(msg, "RESULT"))) else - with error_string = if find_string(msg, "STATUS_STR") is success(s) then s else "", + with error_string = if find_string(msg, "STATUS_MSG") is success(s) then s else "", success(netservice_error(cmd, v, error_string)) } } }. public define Maybe($T) - generic_handler + simple_handler ( MessageQueue queue, Int timeout, Message msg_to_send, (Message) -> Maybe($T) handler, (String) -> One logger - )= - queue.add_Message_to_send(msg_to_send); - if queue.get_next_received_Message(timeout) is + ) = + if generic_send_message(queue, msg_to_send, timeout, logger) is { - timeout then logger("["+queue.get_name(unique)+"]: receive timeout");failure, - closed then logger("["+queue.get_name(unique)+"]: socket closed");failure, - msg(msg) then - if find_int32(msg, "STATUS") is + failure then failure, + success(net_result) then + if net_result is { - failure then logger("["+queue.get_name(unique)+"]: status not found");failure, - success(v) then - if v = _CXM_OK then - //println("generic_handler("+queue.get_name(unique)+"): message status ok"); - if find_message(msg, "RESULT") is - { - failure then logger("["+queue.get_name(unique)+"]: can't find RESULT");failure, - success(result) then handler(result) - } - else - logger("["+queue.get_name(unique)+"]: message status ERROR");failure + netservice_error(cmd, err_code, err_str) then + logger("["+queue.get_name(unique)+"]: message status ERROR [0x" + to_hexa(err_code) + ", '" + err_str + "']"); + failure, + netservice_ok(cmd, mb_msg) then + if mb_msg is + { + failure then logger("["+queue.get_name(unique)+"]: can't find RESULT message."); failure, + success(result) then handler(result) + } + } + }. + +public define Maybe(One) + no_result_handler + ( + MessageQueue queue, + Int timeout, + Message msg_to_send, + (String) -> One logger + ) = + if generic_send_message(queue, msg_to_send, timeout, logger) is + { + failure then failure, + success(net_result) then + if net_result is + { + netservice_error(cmd, err_code, err_str) then + logger("["+queue.get_name(unique)+"]: message status ERROR [0x" + to_hexa(err_code) + ", '" + err_str + "']"); + failure, + netservice_ok(cmd, mb_msg) then + if mb_msg is + { + failure then unique, + success(result) then logger("An unattended RESULT msg was found. Ignoring it...") + }; + success(unique) } }. @@ -103,7 +129,7 @@ public define (MessageQueue, String) -> Maybe($T) (String) -> One logger ) = (MessageQueue queue, String timestamp) |-> - generic_handler(queue, timeout, msg_to_send, handler, logger). + simple_handler(queue, timeout, msg_to_send, handler, logger). define Maybe($T) generic_request_for_service diff --git a/calexium_lib/net_services/CXM_generic_protocol.anubis b/calexium_lib/net_services/CXM_generic_protocol.anubis index 82f3a8d..5c52d25 100644 --- a/calexium_lib/net_services/CXM_generic_protocol.anubis +++ b/calexium_lib/net_services/CXM_generic_protocol.anubis @@ -18,6 +18,7 @@ public define Word32 _CXM_OK = 0. public define Word32 _CXM_ERROR = 1. public define Word32 _CXM_UNKNOW_CMD = 2. public define Word32 _CXM_UNKNOW_SERVICE = 3. +public define Word32 _CXM_MISSING_REQUIRED_FIELD = 4. public type ProtocolResult: failure, @@ -38,7 +39,7 @@ public define One with err_msg = message(_CXM_ACK), forget(add_int32(err_msg, "CMD", cmd_id)); forget(add_int32(err_msg, "STATUS", error_code)); - (if error_string /= "" then forget(add_string(err_msg, "STATUS_STR", error_string)) + (if error_string /= "" then forget(add_string(err_msg, "STATUS_MSG", error_string)) else unique); forget(queue.add_Message_to_send(err_msg)). -- libgit2 0.21.4