note description: "Origo API service base class." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" deferred class API_SERVICE inherit GOA_SERVICE rename make as make_goa end ARGUMENT_VALIDATOR O_ERRORS A_CONSTANTS feature {NONE} -- Initialization make (a_node: A_NODE) -- Create. require a_node_not_void: a_node /= Void do make_goa node := a_node ensure node_set: node = a_node end feature {NONE} -- Status is_ok: BOOLEAN -- Was everything ok during the last send_and_wait_for_reply (no timeout and no error status message)? feature {NONE} -- Access node: A_NODE -- Origo node to use for communication. last_reply: A_MESSAGE -- The last reply we received (filled by send_and_wait_for_reply). feature {NONE} -- Command send_and_wait_for_reply (a_msg: A_MESSAGE) -- Send a_msg and wait for the reply, set last_error on error, else last_reply local l_cv: CONDITION_VARIABLE l_mutex: MUTEX l_status: A_GENERAL_STATUS_MESSAGE do is_ok := True create l_mutex.make create l_cv.make -- set reply handler a_msg.set_reply_handler (agent (aa_msg: A_MESSAGE; ll_cv: CONDITION_VARIABLE; ll_mutex: MUTEX) do last_reply := aa_msg ll_mutex.lock ll_cv.signal ll_mutex.unlock end (?, l_cv, l_mutex)) l_mutex.lock node.send_message (a_msg, node.aranea_core_queue) -- wait for status reply or timeout (20 sec), otherwise we set is_timeout to true if not l_cv.wait_with_timeout (l_mutex, 20000) then is_ok := False last_fault := err_timeout else l_status ?= last_reply if l_status /= Void and then not l_status.is_success.value then is_ok := False last_fault := l_status.message.value end end l_mutex.unlock ensure ok_implies_reply: is_ok implies last_reply /= Void not_ok_implies_fault: not is_ok implies last_fault /= Void end check_anonymous_session (a_session: STRING) -- if a_session is empty, fill it with the anonymous session string -- this marks a not logged in user. require a_session_not_void: a_session /= Void do if a_session.is_empty then a_session.append (anonymous_user_session) end ensure a_session_set: a_session.is_empty implies a_session.is_equal (anonymous_user_session) end invariant node_set: node /= Void end