[r923]: / branches / develop / mqttsparkplug / mqttsparkplug / Sparkplug™ MQTT edge and host / Function Blocks / FB_Payload_1 / FB_Payload / Pool / ClaimNextFreeKey / svnobj  Maximize  Restore  History

Download this file

25 lines (24 with data), 3.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
METHOD ClaimNextFreeKey : REFERENCE TO LinkedListWStringElement
VAR_OUTPUT
    eError : ERROR;
END_VAR
VAR
	pObject : POINTER TO LinkedListWStringElement;
	initData        : DummyData;
//Try and get an Object from the existing pool
KeysPool.ItterateNext( itfElement => _COL_Element,
                          HasNext => );
IF _COL_Element <> 0 THEN
    IF __QUERYPOINTER( _COL_Element,
                         pObject ) THEN
        ClaimNextFreeKey REF= pObject^;
        ClaimNextFreeKey.WStringValue := "";
    ELSE
        eError := ERROR.PayloadNotACollectionOfStorage;
    END_IF
ELSE
	//No free object? No worries, we will just create one
		//Better add it to the Pool and "itterate" it, so future generations of payload can use it
		KeysPool.AppendElem(itfElement := ClaimNextFreeKey);
		KeysPool.ItterateNext();
END_IF