Commit 726439d3ab9358946ef6efe08a1234471719761e
1 parent
27567d6e
add + (plus) operator for DB_ib with String
add Anubix authentication message constant add get_message_queue_to_net_service. Which connect to remote net_service, apply the given function (like authentication process) and return the message_queue if every thing is success add generic_request_for_service and generic_send_message with logger name instead of logger function (String s) -> One. This means the UDP logger must be already started by the main application add class for one_line_fields in CXM_form
Showing
4 changed files
with
131 additions
and
14 deletions
Show diff stats
CXM_message_constants.anubis
| @@ -207,5 +207,6 @@ public define Word32 _CXM_HK_MSG_END = 0x3379FFFF. | @@ -207,5 +207,6 @@ public define Word32 _CXM_HK_MSG_END = 0x3379FFFF. | ||
| 207 | 207 | ||
| 208 | public define Word32 _RMT_ANUBIX_MSG_BASIS = 0x33800000. | 208 | public define Word32 _RMT_ANUBIX_MSG_BASIS = 0x33800000. |
| 209 | public define Word32 _RMT_ANUBIX_CORE_SERVICE_ID = 0x33800000. | 209 | public define Word32 _RMT_ANUBIX_CORE_SERVICE_ID = 0x33800000. |
| 210 | +public define Word32 _RMT_ANUBIX_CORE_AUTH = 0x33800001. | ||
| 210 | 211 | ||
| 211 | public define Word32 _RMT_ANUBIX_MSG_END = 0x3380FFFF. | 212 | public define Word32 _RMT_ANUBIX_MSG_END = 0x3380FFFF. |
database/db_types.anubis
| @@ -46,6 +46,16 @@ public define String | @@ -46,6 +46,16 @@ public define String | ||
| 46 | none then "none", | 46 | none then "none", |
| 47 | db_id(_idx) then abs_to_decimal(_idx) | 47 | db_id(_idx) then abs_to_decimal(_idx) |
| 48 | }. | 48 | }. |
| 49 | + | ||
| 50 | +public define String | ||
| 51 | + String s + DB_id idx = | ||
| 52 | + s + to_String(idx) | ||
| 53 | +. | ||
| 54 | + | ||
| 55 | +public define String | ||
| 56 | + DB_id idx + String s = | ||
| 57 | + to_String(idx) + s | ||
| 58 | +. | ||
| 49 | 59 | ||
| 50 | public define Int | 60 | public define Int |
| 51 | to_Int | 61 | to_Int |
net_services/CXM_generic_client.anubis
| @@ -7,19 +7,12 @@ | @@ -7,19 +7,12 @@ | ||
| 7 | * | 7 | * |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | +transmit system/message_transceiver.anubis | ||
| 11 | +transmit calexium_lib/net_services_protocols/logger_service.anubis | ||
| 10 | 12 | ||
| 11 | -read tools/basis.anubis | ||
| 12 | -read system/muscle.anubis | ||
| 13 | -read system/data_io.anubis | ||
| 14 | -read system/convert.anubis | ||
| 15 | -read system/string.anubis | ||
| 16 | -read system/message_queue.anubis | ||
| 17 | -read system/message_transceiver.anubis | ||
| 18 | -read tools/connections.anubis | ||
| 19 | - | ||
| 20 | -read calexium_lib/CXM_message_constants.anubis | ||
| 21 | -read calexium_lib/net_services/CXM_net_services.anubis | ||
| 22 | -read calexium_lib/net_services/CXM_generic_protocol.anubis | 13 | +transmit calexium_lib/CXM_message_constants.anubis |
| 14 | +transmit calexium_lib/net_services/CXM_net_services.anubis | ||
| 15 | +transmit calexium_lib/net_services/CXM_generic_protocol.anubis | ||
| 23 | 16 | ||
| 24 | // --Generic types--------------------------------------------------------------------- | 17 | // --Generic types--------------------------------------------------------------------- |
| 25 | public type NetServiceAnswer: | 18 | public type NetServiceAnswer: |
| @@ -31,7 +24,6 @@ public type NetServiceAnswer: | @@ -31,7 +24,6 @@ public type NetServiceAnswer: | ||
| 31 | 24 | ||
| 32 | // --Generic functions--------------------------------------------------------------------- | 25 | // --Generic functions--------------------------------------------------------------------- |
| 33 | 26 | ||
| 34 | - | ||
| 35 | /** | 27 | /** |
| 36 | * Sends the message to the server then parses the answer and returns the RESULT message on CMD success. | 28 | * Sends the message to the server then parses the answer and returns the RESULT message on CMD success. |
| 37 | */ | 29 | */ |
| @@ -66,6 +58,42 @@ public define Maybe(NetServiceAnswer) | @@ -66,6 +58,42 @@ public define Maybe(NetServiceAnswer) | ||
| 66 | } | 58 | } |
| 67 | }. | 59 | }. |
| 68 | 60 | ||
| 61 | + | ||
| 62 | +public define Maybe(NetServiceAnswer) | ||
| 63 | +/** | ||
| 64 | + * Sends the message to the server then parses the answer and returns the RESULT message on CMD success. | ||
| 65 | + * | ||
| 66 | + */ | ||
| 67 | + generic_send_message | ||
| 68 | + ( | ||
| 69 | + MessageQueue queue, | ||
| 70 | + Message msg_to_send, | ||
| 71 | + Int timeout, | ||
| 72 | + String logger_name | ||
| 73 | + )= | ||
| 74 | + queue.add_Message_to_send(msg_to_send); | ||
| 75 | + if queue.get_next_received_Message(timeout) is | ||
| 76 | + { | ||
| 77 | + timeout then logError(logger_name, "["+queue.get_name(unique)+"]: receive timeout");failure, | ||
| 78 | + closed then logError(logger_name, "["+queue.get_name(unique)+"]: socket closed");failure, | ||
| 79 | + msg(msg) then | ||
| 80 | + if find_int32(msg, "CMD") is | ||
| 81 | + { | ||
| 82 | + failure then logError(logger_name, "["+queue.get_name(unique)+"]: CMD field not found"); failure, | ||
| 83 | + success(cmd) then | ||
| 84 | + if find_int32(msg, "STATUS") is | ||
| 85 | + { | ||
| 86 | + failure then logError(logger_name, "["+queue.get_name(unique)+"]: STATUS field not found"); failure, | ||
| 87 | + success(v) then | ||
| 88 | + if v = _CXM_OK then | ||
| 89 | + success(netservice_ok(cmd, find_message(msg, "RESULT"))) | ||
| 90 | + else | ||
| 91 | + with error_string = if find_string(msg, "STATUS_MSG") is success(s) then s else "", | ||
| 92 | + success(netservice_error(cmd, v, error_string)) | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + }. | ||
| 96 | + | ||
| 69 | public define Maybe($T) | 97 | public define Maybe($T) |
| 70 | simple_handler | 98 | simple_handler |
| 71 | ( | 99 | ( |
| @@ -173,6 +201,80 @@ define Maybe($T) | @@ -173,6 +201,80 @@ define Maybe($T) | ||
| 173 | } | 201 | } |
| 174 | }. | 202 | }. |
| 175 | 203 | ||
| 204 | +define Maybe($T) | ||
| 205 | + generic_request_for_service | ||
| 206 | + ( | ||
| 207 | + MessageQueue queue, | ||
| 208 | + Word32 service_id, | ||
| 209 | + Word32 service_version, | ||
| 210 | + String domain, | ||
| 211 | + (MessageQueue, String) -> Maybe($T) handler, | ||
| 212 | + String logger | ||
| 213 | + )= | ||
| 214 | + with test_msg = message(_CXM_REQUEST_FOR_SERVICE), | ||
| 215 | + forget(add_int32(test_msg, "SERVICE", service_id)); | ||
| 216 | + forget(add_int32(test_msg, "VERSION", service_version)); | ||
| 217 | + forget(add_string(test_msg, "DOMAIN", domain)); | ||
| 218 | + queue.add_Message_to_send(test_msg); | ||
| 219 | + if queue.get_next_received_Message(10) is | ||
| 220 | + { | ||
| 221 | + timeout then logError(logger, "["+queue.get_name(unique)+"]: requesting service receive timeout");failure, | ||
| 222 | + closed then logError(logger, "["+queue.get_name(unique)+"]: requesting service socket closed");failure, | ||
| 223 | + msg(msg) then | ||
| 224 | + if find_int32(msg, "STATUS") is | ||
| 225 | + { | ||
| 226 | + failure then logError(logger, "["+queue.get_name(unique)+"]: requesting service STATUS not found");failure, | ||
| 227 | + success(v) then | ||
| 228 | + if v = _CXM_OK then | ||
| 229 | + if find_message(msg, "RESULT") is | ||
| 230 | + { | ||
| 231 | + failure then logError(logger, "["+queue.get_name(unique)+"]: requesting service RESULT not found");failure, | ||
| 232 | + success(result) then | ||
| 233 | + with timestamp = if find_string(result, "TIMESTAMP") is | ||
| 234 | + { | ||
| 235 | + failure then logError(logger, "["+queue.get_name(unique)+"]: requesting service TIMESTAMP not found"); "", | ||
| 236 | + success(timestamp) then timestamp | ||
| 237 | + }, | ||
| 238 | + handler(queue, timestamp) | ||
| 239 | + } | ||
| 240 | + else | ||
| 241 | + logError(logger, "["+queue.get_name(unique)+"]: the requested service is not available on server.");failure | ||
| 242 | + } | ||
| 243 | + }. | ||
| 244 | + | ||
| 245 | +public define Maybe(MessageQueue) | ||
| 246 | + get_message_queue_to_net_service | ||
| 247 | + ( | ||
| 248 | + String queue_name, | ||
| 249 | + Word32 server, | ||
| 250 | + Word32 port, | ||
| 251 | + Word32 service_id, | ||
| 252 | + Word32 service_version, | ||
| 253 | + String domain, | ||
| 254 | + (MessageQueue, String) -> Maybe(One) handler, //1st function to apply if need (i.e authentication to remote service) | ||
| 255 | + String logger | ||
| 256 | + ) | ||
| 257 | + = | ||
| 258 | + if connect( server, port) is | ||
| 259 | + { | ||
| 260 | + error(_) then logError(logger, queue_name + ": Can't connect to service ["+ip_addr_to_string(server)+":"+port+"]");failure, | ||
| 261 | + ok(conn) then | ||
| 262 | +// println("[" + virtual_machine_id + "] netservices create queue"); | ||
| 263 | + with queue = create_MessageQueue(queue_name), | ||
| 264 | + message_transceiver(tcp(conn), queue); | ||
| 265 | +// println("[" + virtual_machine_id + "] netservices generic_request_for_service()"); | ||
| 266 | + if generic_request_for_service(queue, service_id, service_version, domain, handler, logger) is | ||
| 267 | + { | ||
| 268 | + failure then | ||
| 269 | + //we can't apply first function correctly, so we ask to Message Queue to quit and return failure | ||
| 270 | + logError(logger, "can't apply first function correctly"); | ||
| 271 | + queue.quit(unique); | ||
| 272 | + failure, | ||
| 273 | + success(_) then success(queue) | ||
| 274 | + } | ||
| 275 | + }. | ||
| 276 | + | ||
| 277 | + | ||
| 176 | public define Maybe($T) | 278 | public define Maybe($T) |
| 177 | generic_connect_to_net_service | 279 | generic_connect_to_net_service |
| 178 | ( | 280 | ( |
web/CXM_form.anubis
| @@ -317,6 +317,10 @@ public define CXM_Form_Field | @@ -317,6 +317,10 @@ public define CXM_Form_Field | ||
| 317 | submit(WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) | 317 | submit(WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) |
| 318 | = submit([], htmlClass(""), action_name, label, button_text, extra_operands). | 318 | = submit([], htmlClass(""), action_name, label, button_text, extra_operands). |
| 319 | 319 | ||
| 320 | +public define CXM_Form_Field | ||
| 321 | + submit(WEB_Action_Name action_name, Maybe(String) label, String button_text) | ||
| 322 | + = submit([], htmlClass(""), action_name, label, button_text, []). | ||
| 323 | + | ||
| 320 | public define CXM_Form_Field //Helper for older project wich use only String as Action name | 324 | public define CXM_Form_Field //Helper for older project wich use only String as Action name |
| 321 | submit(String _action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) | 325 | submit(String _action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) |
| 322 | = submit([], htmlClass(""), action_name(_action_name), label, button_text, extra_operands). | 326 | = submit([], htmlClass(""), action_name(_action_name), label, button_text, extra_operands). |
| @@ -535,7 +539,7 @@ public define HTML_In_Form | @@ -535,7 +539,7 @@ public define HTML_In_Form | ||
| 535 | ), | 539 | ), |
| 536 | ]), | 540 | ]), |
| 537 | one_line_fields(fields) then | 541 | one_line_fields(fields) then |
| 538 | - table([nude],[row([], | 542 | + table([nude, class("form_one_line")],[row([], |
| 539 | map((CXM_Form_Field ff2) |-> cell([],format_CXM_Form_Field(ff2, lwa)),fields))]) | 543 | map((CXM_Form_Field ff2) |-> cell([],format_CXM_Form_Field(ff2, lwa)),fields))]) |
| 540 | , | 544 | , |
| 541 | 545 |