| /////////////////////////////////////////////////////////////////////////////// |
| // // |
| // Copyright (c) 2000-2019 Ericsson Telecom AB // |
| // // |
| // All rights reserved. This program and the accompanying materials // |
| // are made available under the terms of the Eclipse Public License v2.0 // |
| // which accompanies this distribution, and is available at // |
| // https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html // |
| /////////////////////////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| // Module: EPTF_CLL_NameService_Functions |
| // |
| // Purpose: |
| // This module contains the implementation of the EPTF_NameService functions. |
| // |
| // Module depends on: |
| // <EPTF_CLL_Base_Functions> |
| // <EPTF_CLL_NameService_Definitions> |
| // <EPTF_CLL_Logging_Definitions> |
| // <EPTF_CLL_Logging_Functions> |
| // |
| // Module Parameters: |
| // tsp_debug_EPTF_NameService_Functions - boolean |
| // |
| // Current Owner: |
| // Jozsef Gyurusi (ETHJGI) |
| // |
| // Last Review Date: |
| // 2008-05-20 |
| // |
| // Detailed Comments: |
| // This module contains the interface functions for the EPTF_NameService. |
| // |
| /////////////////////////////////////////////////////////////// |
| |
| module EPTF_CLL_NameService_Functions { |
| |
| import from EPTF_CLL_NameService_Definitions all; |
| import from EPTF_CLL_Base_Functions all; |
| import from EPTF_CLL_Logging_Definitions all; |
| import from EPTF_CLL_Logging_Functions all; |
| |
| modulepar boolean tsp_debug_EPTF_NameService_Functions := false; |
| |
| // INIT |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NS_init_CT |
| // |
| // Purpose: |
| // Initialises the EPTF_NS_CT component |
| // |
| // Parameters: |
| // pl_selfName - *in* *charstring* - name of the component |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // This function should be called before using the EPTF NS |
| // component. |
| // |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_NS_init_CT(in charstring pl_selfName) runs on EPTF_NS_CT { |
| if (v_NS_initialized) { |
| return; |
| } |
| f_EPTF_Logging_init_CT(pl_selfName); |
| v_NameService_loggingMaskId := f_EPTF_Logging_registerComponentMasks(tsp_EPTF_NameService_loggingComponentMask, c_EPTF_NameService_loggingEventClasses, EPTF_Logging_CLL); |
| if(tsp_debug_EPTF_NameService_Functions) { |
| f_EPTF_Logging_enableLocalMask(v_NameService_loggingMaskId, c_EPTF_NameService_loggingClassIdx_Debug); |
| } else { |
| f_EPTF_Logging_disableLocalMask(v_NameService_loggingMaskId, c_EPTF_NameService_loggingClassIdx_Debug); |
| } |
| |
| |
| |
| v_EPTF_NS_RegisteredItems := {}; |
| v_EPTF_NS_def := activate(as_handle_main_EPTF_NS_MgmtIf()); |
| v_NS_initialized := true; |
| |
| f_EPTF_Base_registerCleanup(refers(f_EPTF_NS_cleanup_CT)); |
| |
| //log("----NS INIT DONE----"); |
| f_EPTF_NameService_debug("---- EPTF_NS INIT "&pl_selfName&" DONE----"); |
| |
| } |
| |
| // MAIN |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NS_main_CT |
| // |
| // Purpose: |
| // Behaviour function for the EPTF_NS_CT component |
| // |
| // Parameters: |
| // pl_selfName - *in* *charstring* - name of the component |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // This function can be started on the EPTF_NS_CT component as a behaviour function. |
| // |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_NS_main_CT(in charstring pl_selfName) runs on EPTF_NS_CT { |
| f_EPTF_NS_init_CT(pl_selfName); |
| //var default v_def := activate(as_handle_main_EPTF_NS_MgmtIf()); |
| alt { |
| [] as_handle_main_EPTF_NS_MgmtIf(); |
| } |
| f_EPTF_Base_cleanup_CT(); |
| } |
| |
| |
| //************************************************************* |
| // private |
| //************************************************************* |
| |
| // LOGGING |
| |
| // log everything in EPTF_Var_CT |
| private function f_EPTF_NS_CT_LogAll(in charstring pl_msg) runs on EPTF_NS_CT { |
| |
| if (pl_msg!="") //{log(pl_msg)}; |
| {f_EPTF_NameService_debug(pl_msg);} |
| |
| //log("EPTF_NS_CT.v_EPTF_NS_RegisteredItems: ", v_EPTF_NS_RegisteredItems); |
| f_EPTF_NameService_debug(log2str("EPTF_NS_CT.v_EPTF_NS_RegisteredItems: ",v_EPTF_NS_RegisteredItems)); |
| |
| if (pl_msg!="") //{log(pl_msg)}; |
| {f_EPTF_NameService_debug(pl_msg);} |
| } |
| |
| // log a given EPTF_NS_RegisteredItem |
| private function f_EPTF_NS_Log(in charstring pl_msg, in integer pl_idx) runs on EPTF_NS_CT { |
| |
| if (pl_msg!="") //{log(pl_msg)}; |
| {f_EPTF_NameService_debug(pl_msg);} |
| |
| //log("EPTF_NS_CT.v_EPTF_NS_RegisteredItems[",pl_idx,"]: ", v_EPTF_NS_RegisteredItems[pl_idx]); |
| f_EPTF_NameService_debug(log2str("EPTF_NS_CT.v_EPTF_NS_RegisteredItems[",pl_idx,"]: ", v_EPTF_NS_RegisteredItems[pl_idx])); |
| |
| if (pl_msg!="") //{log(pl_msg)}; |
| {f_EPTF_NameService_debug(pl_msg);} |
| } |
| |
| // SEND FUNCTION |
| |
| private function f_EPTF_NS_send(in EPTF_NS_MgmtMsg pl_EPTF_NS_MgmtMsg, in EPTF_NS_Client_CT pl_remoteCompRef) runs on EPTF_NS_CT { |
| EPTF_NS_MgmtIf.send(pl_EPTF_NS_MgmtMsg) to pl_remoteCompRef; |
| } |
| |
| private function f_EPTF_NS_cleanup_CT() runs on EPTF_NS_CT { |
| if (v_NS_initialized == false) { |
| return; |
| } |
| v_NS_initialized := false; |
| //log("----NS CLEANUP DONE----"); |
| f_EPTF_NameService_debug("----NS CLEANUP DONE----"); |
| } |
| |
| // REGISTER |
| |
| // removes all registered entry made by the given component |
| private function f_EPTF_NS_RemoveAllByOwner(in EPTF_NS_Client_CT pl_owner) runs on EPTF_NS_CT { |
| var EPTF_NS_RegisteredItems vl_newRegisteredItems := {}; |
| for(var integer i:=0; i<sizeof(v_EPTF_NS_RegisteredItems); i:=i+1) { |
| if (v_EPTF_NS_RegisteredItems[i].ownerComp != pl_owner) { |
| vl_newRegisteredItems[sizeof(vl_newRegisteredItems)] := v_EPTF_NS_RegisteredItems[i]; |
| } |
| } |
| v_EPTF_NS_RegisteredItems := vl_newRegisteredItems; |
| } |
| |
| // searches the database for the name and returns its index in pl_idx |
| // returns -1 if not found |
| private function f_EPTF_NS_QueryName(in charstring pl_name, out integer pl_idx) runs on EPTF_NS_CT { |
| pl_idx := -1; |
| for(var integer i:=0; i<sizeof(v_EPTF_NS_RegisteredItems); i:=i+1) { |
| if (v_EPTF_NS_RegisteredItems[i].name == pl_name) { |
| pl_idx := i; |
| return; |
| } |
| } |
| } |
| |
| // HANDLER FUNCTIONS |
| |
| private function f_EPTF_NS_handle_RegisterName(in EPTF_NS_RegisterName pl_registerName, in EPTF_NS_Client_CT pl_EPTF_NS_MgmtIf_msg_sender) runs on EPTF_NS_CT { |
| var integer vl_idx; |
| f_EPTF_NS_QueryName(pl_registerName.name,vl_idx); |
| if (vl_idx!=-1) { |
| // name already registered |
| |
| //log("WARNING:","The name already registered in msg: ", pl_registerName, |
| // " Original item is at ",vl_idx," : ",v_EPTF_NS_RegisteredItems[vl_idx]); |
| f_EPTF_NameService_warning(log2str( "The name already registered in msg: ", pl_registerName," Original item is at ",vl_idx," : ",v_EPTF_NS_RegisteredItems[vl_idx])); |
| |
| f_EPTF_NS_send({registerNAck:=pl_registerName},pl_EPTF_NS_MgmtIf_msg_sender); |
| return; |
| } |
| v_EPTF_NS_RegisteredItems[sizeof(v_EPTF_NS_RegisteredItems)] := { |
| name := pl_registerName.name, |
| ownerComp := pl_EPTF_NS_MgmtIf_msg_sender, |
| id := pl_registerName.id |
| } |
| f_EPTF_NS_CT_LogAll("---------REGISTER NAME RECEIVED-----------"); |
| } |
| |
| private function f_EPTF_NS_handle_DeregisterName(in EPTF_NS_DeregisterName pl_deregisterName, in EPTF_NS_Client_CT pl_EPTF_NS_MgmtIf_msg_sender) runs on EPTF_NS_CT { |
| var integer vl_idx; |
| f_EPTF_NS_QueryName(pl_deregisterName.name,vl_idx); |
| if (vl_idx==-1) { |
| // name is not registered |
| //log("WARNING:","The name is not registered in msg: ", pl_deregisterName); |
| f_EPTF_NameService_warning(log2str("The name is not registered in msg: ", pl_deregisterName)); |
| return; |
| } |
| var EPTF_NS_RegisteredItems vl_newRegisteredItems := {}; |
| for(var integer i:=0; i<sizeof(v_EPTF_NS_RegisteredItems); i:=i+1) { |
| if (i != vl_idx) { |
| vl_newRegisteredItems[sizeof(vl_newRegisteredItems)] := v_EPTF_NS_RegisteredItems[i]; |
| } |
| } |
| v_EPTF_NS_RegisteredItems := vl_newRegisteredItems; |
| f_EPTF_NS_CT_LogAll("---------DEREGISTER NAME RECEIVED-----------"); |
| } |
| |
| private function f_EPTF_NS_handle_Query(in EPTF_NS_Query pl_queryName, in EPTF_NS_Client_CT pl_EPTF_NS_MgmtIf_msg_sender) runs on EPTF_NS_CT { |
| var integer vl_idx; |
| f_EPTF_NS_QueryName(pl_queryName.name,vl_idx); |
| if (vl_idx==-1) { |
| // name is not registered |
| //log("WARNING:","The name is not registered in msg: ", pl_queryName); |
| f_EPTF_NameService_warning(log2str("The name is not registered in msg: ", pl_queryName)); |
| |
| |
| f_EPTF_NS_send({queryResp:={ pl_queryName.name, omit,omit}},pl_EPTF_NS_MgmtIf_msg_sender); |
| return; |
| } |
| f_EPTF_NS_send({queryResp:= { |
| name := v_EPTF_NS_RegisteredItems[vl_idx].name, |
| ownerComp := v_EPTF_NS_RegisteredItems[vl_idx].ownerComp, |
| id := v_EPTF_NS_RegisteredItems[vl_idx].id |
| }},pl_EPTF_NS_MgmtIf_msg_sender); |
| f_EPTF_NS_CT_LogAll("---------QUERY NAME RECEIVED-----------"); |
| } |
| |
| private function f_EPTF_NS_handle_Bye(in EPTF_NS_Client_CT pl_EPTF_NS_MgmtIf_msg_sender) runs on EPTF_NS_CT { |
| f_EPTF_NS_RemoveAllByOwner(pl_EPTF_NS_MgmtIf_msg_sender); |
| f_EPTF_NS_send({byeAck:={}},pl_EPTF_NS_MgmtIf_msg_sender); |
| f_EPTF_NS_CT_LogAll("---------BYE RECEIVED-----------"); |
| } |
| |
| // the main handler function of the EPTF_NS_MgmtIf. |
| // returns true if the repeat, false to exit from the main altsep |
| function f_handle_main_EPTF_NS_MgmtIf( |
| in EPTF_NS_MgmtMsg vl_EPTF_NS_MgmtIf_msg, |
| in EPTF_NS_Client_CT vl_EPTF_NS_MgmtIf_msg_sender) runs on EPTF_NS_CT return boolean { |
| if (ischosen(vl_EPTF_NS_MgmtIf_msg.registerName)) { |
| f_EPTF_NS_handle_RegisterName(vl_EPTF_NS_MgmtIf_msg.registerName, vl_EPTF_NS_MgmtIf_msg_sender); |
| return true; |
| } |
| if (ischosen(vl_EPTF_NS_MgmtIf_msg.deregisterName)) { |
| f_EPTF_NS_handle_DeregisterName(vl_EPTF_NS_MgmtIf_msg.deregisterName, vl_EPTF_NS_MgmtIf_msg_sender); |
| return true; |
| } |
| if (ischosen(vl_EPTF_NS_MgmtIf_msg.query)) { |
| f_EPTF_NS_handle_Query(vl_EPTF_NS_MgmtIf_msg.query, vl_EPTF_NS_MgmtIf_msg_sender); |
| return true; |
| } |
| if (ischosen(vl_EPTF_NS_MgmtIf_msg.bye)) { |
| f_EPTF_NS_handle_Bye(vl_EPTF_NS_MgmtIf_msg_sender); |
| return true; |
| } |
| //log("ERROR:","Unexpected message received from ",vl_EPTF_NS_MgmtIf_msg_sender,": ",vl_EPTF_NS_MgmtIf_msg); |
| f_EPTF_NameService_warning(log2str("Unexpected message received from ",vl_EPTF_NS_MgmtIf_msg_sender,": ",vl_EPTF_NS_MgmtIf_msg)); |
| |
| return false; |
| } |
| |
| |
| // MAIN ALTSTEP |
| private altstep as_handle_main_EPTF_NS_MgmtIf() runs on EPTF_NS_CT { |
| var EPTF_NS_MgmtMsg vl_EPTF_NS_MgmtIf_msg; |
| var EPTF_NS_Client_CT vl_EPTF_NS_MgmtIf_msg_sender; |
| [] EPTF_NS_MgmtIf.receive(?) -> value vl_EPTF_NS_MgmtIf_msg sender vl_EPTF_NS_MgmtIf_msg_sender { |
| if (f_handle_main_EPTF_NS_MgmtIf(vl_EPTF_NS_MgmtIf_msg,vl_EPTF_NS_MgmtIf_msg_sender)) {repeat;} |
| } |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Group: Private |
| // |
| // Purpose: |
| // Private functions. These functions must not be called by the user of <EPTF_NameService_CT> |
| // |
| // Elements: |
| /////////////////////////////////////////////////////////// |
| |
| group Private { |
| group Logging { |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NameService_error |
| // |
| // Purpose: |
| // Function to log an error from NameService feature. |
| // |
| // Parameters: |
| // - pl_message - *in* *charstring* - the message to log |
| // |
| // Return Value: |
| // - |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_NameService_error(in charstring pl_message) |
| runs on EPTF_NS_CT |
| { |
| f_EPTF_Logging_error(true, tsp_EPTF_NameService_loggingComponentMask&": "&pl_message); |
| f_EPTF_Base_stopAll(); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NameService_warning |
| // |
| // Purpose: |
| // Function to log a warning from NameService feature. |
| // |
| // Parameters: |
| // - pl_message - *in* *charstring* - the message to log |
| // |
| // Return Value: |
| // - |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_NameService_warning(in @lazy charstring pl_message) |
| runs on EPTF_NS_CT |
| { |
| f_EPTF_Logging_warningV2(pl_message, v_NameService_loggingMaskId, {c_EPTF_NameService_loggingClassIdx_Warning}); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NameService_debug |
| // |
| // Purpose: |
| // Function to log a debug message from NameService feature. |
| // |
| // Parameters: |
| // - pl_message - *in* *charstring* - the message to log |
| // |
| // Return Value: |
| // - |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_NameService_debug(in @lazy charstring pl_message) |
| runs on EPTF_NS_CT |
| { |
| f_EPTF_Logging_debugV2(pl_message, v_NameService_loggingMaskId, {c_EPTF_NameService_loggingClassIdx_Debug}); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_NameService_debugEnabled |
| // |
| // Purpose: |
| // Function to check if debug is enabled for NameService |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // *boolean* - true if debug enalbed |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_NameService_debugEnabled() |
| runs on EPTF_NS_CT |
| return boolean |
| { |
| return f_EPTF_Logging_isEnabled(v_NameService_loggingMaskId, c_EPTF_NameService_loggingClassIdx_Debug); |
| } |
| } // group Logging |
| |
| } // group Private |
| |
| } // end of module |