blob: f55dfd7aae77c4b4e348d90a04671152a8a12027 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// 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_DsRestAPI_Storage_Functions
//
// Purpose:
// This module contains the functions of EPTF_CLL_DsRestAPI_Storage.
//
// Module depends on:
// <EPTF_CLL_DataSource_Definitions>
// <EPTF_CLL_Variable_Definitions>
// <EPTF_CLL_DsRestAPI_Storage_Definitions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_HashMapStr2Int_Functions>
//
// Current Owner:
// Tamas Kis (ekistam)
//
// Last Review Date:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////////
module EPTF_CLL_DsRestAPI_Storage_Functions {
import from EPTF_CLL_DataSource_Definitions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_DsRestAPI_Storage_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_HashMap_Functions all;
import from EPTF_CLL_HashMapStr2Int_Functions all;
friend module EPTF_CLL_DsRestAPI_DSServer_Functions;
friend module EPTF_CLL_DsRestAPI_Filter_Functions;
//=========================================================================
// Functions
//=========================================================================
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_init_CT
//
// Purpose:
// Initialize the storage for DsRestAPI
//
// Parameters:
// pl_selfName - *in* *charstring* - the name of the component
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_init_CT(in charstring pl_selfName) runs on EPTF_DsRestAPI_Storage_CT {
if (not v_DsRestAPI_Storage_initialized) {
f_EPTF_Base_init_CT(pl_selfName);
f_EPTF_HashMap_init_CT(pl_selfName);
f_EPTF_Base_registerCleanup(refers(f_EPTF_DsRestAPI_Storage_cleanup_CT));
v_DsRestAPI_Storage_initialized := true;
}
}
private function f_EPTF_DsRestAPI_Storage_cleanup_CT() runs on EPTF_DsRestAPI_Storage_CT {
if (v_DsRestAPI_Storage_initialized) {
for (var integer i := 0; i < sizeof(v_DsRestAPI_Storages); i := i + 1) {
if (isbound(v_DsRestAPI_Storages[i])) {
f_EPTF_str2int_HashMap_Delete(f_EPTF_DsRestAPI_Storage_getHashMapName(i));
}
}
v_DsRestAPI_Storage_initialized := false;
}
}
private function f_EPTF_DsRestAPI_Storage_getHashMapName(in integer pl_id) return charstring {
return "f_EPTF_DsRestAPI_Storage_" & int2str(pl_id);
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_getKey
//
// Purpose:
// Creates a key for a request.
//
// Parameters:
// pl_source - *in* *chartstring* - the source
// pl_ptcname - *in* *chartstring* - the ptcname
// pl_element - *in* *chartstring* - the element
// pl_params - *in* *EPTF_DataSource_Params* - the params
// pl_filter - *in* *EPTF_DataSource_Filter* - the filter
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_getKey(
in charstring pl_source,
in charstring pl_ptcname,
in charstring pl_element,
in EPTF_DataSource_Params pl_params,
in EPTF_DataSource_Filter pl_filter
) return charstring {
return pl_source & "_" & pl_ptcname & "_" & pl_element & "_" & log2str(pl_params) & "_" & log2str(pl_filter);
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_newStorage
//
// Purpose:
// Initialize a storage for DsRestAPI
//
// Parameters:
// pl_id - *in* *integer* - the id of the new storage
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_newStorage(in integer pl_id) runs on EPTF_DsRestAPI_Storage_CT {
var integer vl_hashMapId;
if (isbound(v_DsRestAPI_Storages[pl_id]) and v_DsRestAPI_Storages[pl_id].hashMapId != -1) {
f_EPTF_str2int_HashMap_Clear(v_DsRestAPI_Storages[pl_id].hashMapId);
vl_hashMapId := v_DsRestAPI_Storages[pl_id].hashMapId;
} else {
vl_hashMapId := f_EPTF_str2int_HashMap_New(f_EPTF_DsRestAPI_Storage_getHashMapName(pl_id));
}
v_DsRestAPI_Storages[pl_id] := {
storedContents := {},
nextPosition := 0,
hashMapId := vl_hashMapId
}
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_deleteStorage
//
// Purpose:
// Deletes a storage for DsRestAPI
//
// Parameters:
// pl_id - *in* *integer* - the id of the storage to delete
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_deleteStorage(in integer pl_id) runs on EPTF_DsRestAPI_Storage_CT {
if (isbound(v_DsRestAPI_Storages[pl_id]) and v_DsRestAPI_Storages[pl_id].hashMapId != -1) {
f_EPTF_str2int_HashMap_DeleteById(v_DsRestAPI_Storages[pl_id].hashMapId);
}
v_DsRestAPI_Storages[pl_id] := {
storedContents := {},
nextPosition := 0,
hashMapId := -1
}
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_preStoreItem
//
// Purpose:
// Creates an item which shows that the current request is pending.
//
// Parameters:
// pl_id - *in* *integer* - the id of the storage
// pl_key - *in* *charstring* - the key of the stored item
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_preStoreItem(in integer pl_id, in charstring pl_key) runs on EPTF_DsRestAPI_Storage_CT {
if (v_DsRestAPI_Storages[pl_id].hashMapId < 0) {
return;
}
f_EPTF_str2int_HashMap_Insert(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, v_DsRestAPI_Storages[pl_id].nextPosition);
v_DsRestAPI_Storages[pl_id].storedContents[v_DsRestAPI_Storages[pl_id].nextPosition] := {preStoredItems := {}};
v_DsRestAPI_Storages[pl_id].nextPosition := v_DsRestAPI_Storages[pl_id].nextPosition + 1;
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_addContentArrivedHandler
//
// Purpose:
// Adds a handler function which will be called with the given user data and a content when it gets saved.
//
// Parameters:
// pl_id - *in* *integer* - the id of the storage
// pl_key - *in* *charstring* - the key of the stored item
// pl_item - *in* *EPTF_CLL_DsRestAPI_Storage_PreStoredItem* - the handler function and user data to use when the content arrives
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_addContentArrivedHandler(in integer pl_id, in charstring pl_key, in EPTF_CLL_DsRestAPI_Storage_PreStoredItem pl_item) runs on EPTF_DsRestAPI_Storage_CT {
var integer vl_contentIndex;
if (v_DsRestAPI_Storages[pl_id].hashMapId < 0) {
return;
}
if (f_EPTF_str2int_HashMap_Find(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, vl_contentIndex)) {
if (ischosen(v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].preStoredItems)) {
var integer vl_preItemsLength := sizeof(v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].preStoredItems);
v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].preStoredItems[vl_preItemsLength] := pl_item;
} else /*if (ischosen(v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].content))*/ {
pl_item.contentReady.apply(0, v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].content, pl_item.userData);
}
} else {
f_EPTF_str2int_HashMap_Insert(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, v_DsRestAPI_Storages[pl_id].nextPosition);
v_DsRestAPI_Storages[pl_id].storedContents[v_DsRestAPI_Storages[pl_id].nextPosition] := {preStoredItems := {pl_item}};
v_DsRestAPI_Storages[pl_id].nextPosition := v_DsRestAPI_Storages[pl_id].nextPosition + 1;
}
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_storeItem
//
// Purpose:
// Stores an item in the storage.
//
// Parameters:
// pl_id - *in* *integer* - the id of the storage
// pl_key - *in* *charstring* - the key of the stored item
// pl_content - *in* *EPTF_Var_DirectContent* - the content to store
//
// Return Value:
// -
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_storeItem(in integer pl_id, in charstring pl_key, in EPTF_Var_DirectContent pl_content) runs on EPTF_DsRestAPI_Storage_CT {
var integer vl_contentIndex;
if (v_DsRestAPI_Storages[pl_id].hashMapId < 0) {
return;
}
if (f_EPTF_str2int_HashMap_Find(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, vl_contentIndex)) {
if (ischosen(v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].preStoredItems)) {
var EPTF_CLL_DsRestAPI_Storage_PreStoredItems vl_preStoredItems := v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex].preStoredItems;
v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex] := {content := pl_content};
for (var integer i := 0; i < sizeof(vl_preStoredItems); i := i + 1) {
vl_preStoredItems[i].contentReady.apply(0, pl_content, vl_preStoredItems[i].userData);
}
}
} else {
f_EPTF_str2int_HashMap_Insert(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, v_DsRestAPI_Storages[pl_id].nextPosition);
v_DsRestAPI_Storages[pl_id].storedContents[v_DsRestAPI_Storages[pl_id].nextPosition] := {content := pl_content};
v_DsRestAPI_Storages[pl_id].nextPosition := v_DsRestAPI_Storages[pl_id].nextPosition + 1;
}
}
/////////////////////////////////////////////////////////////////////////
// Function: f_EPTF_DsRestAPI_Storage_getStoredItem
//
// Purpose:
// Returns an item from the storage.
//
// Parameters:
// pl_id - *in* *integer* - the id of the storage
// pl_key - *in* *charstring* - the key of the stored item
// pl_item - *out* *EPTF_CLL_DsRestAPI_Storage_Item* - the content to store
//
// Return Value:
// Whther the item can be found in the storage.
/////////////////////////////////////////////////////////////////////////
friend function f_EPTF_DsRestAPI_Storage_getStoredItem(in integer pl_id, in charstring pl_key, out EPTF_CLL_DsRestAPI_Storage_Item pl_item) runs on EPTF_DsRestAPI_Storage_CT return boolean {
var integer vl_contentIndex := -1;
if (v_DsRestAPI_Storages[pl_id].hashMapId < 0) {
return false;
}
if (f_EPTF_str2int_HashMap_Find(v_DsRestAPI_Storages[pl_id].hashMapId, pl_key, vl_contentIndex)) {
pl_item := v_DsRestAPI_Storages[pl_id].storedContents[vl_contentIndex];
return true;
} else {
return false;
}
}
}