[r895]: / trunk / mqttsparkplug / mqttsparkplug / Sparkplug™ MQTT edge and host / Function Blocks / FB_Payload_1 / FB_Payload / Pool / ClaimNextFreeMetric / svnobj  Maximize  Restore  History

Download this file

25 lines (24 with data), 3.6 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 ClaimNextFreeMetric : REFERENCE TO FB_PayloadMetric
VAR_OUTPUT
    eError : ERROR;
END_VAR
VAR
    MyPayloadMetric : POINTER TO FB_PayloadMetric;
	initData        : DummyData;
//Try and get a metric from the existing pool
MetricsPool.ItterateNext( itfElement => _COL_Element,
                          HasNext => );
IF _COL_Element <> 0 THEN
    IF __QUERYPOINTER( _COL_Element,
                         MyPayloadMetric ) THEN
        ClaimNextFreeMetric REF= MyPayloadMetric^;
        ClaimNextFreeMetric.InitializeStructure();
    ELSE
        eError := ERROR.PayloadNotACollectionOfStorage;
    END_IF
ELSE
	//No metric? No worries, we will just create one
		//Better add it to the MetricPool and "itterate" it, so future generations of payload can use it
		MetricsPool.AppendElem(itfElement := ClaimNextFreeMetric);
		MetricsPool.ItterateNext();
END_IF