[r895]: / trunk / mqttsparkplug / mqttsparkplug / Sparkplug™ MQTT edge and host / Function Blocks / FB_PrimaryHost / FB_PrimaryHost / PoolManager / allocMetric / svnobj  Maximize  Restore  History

Download this file

29 lines (28 with data), 4.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
25
26
27
28
// Will try to allocate a new Metric with the given name
METHOD allocMetric : REFERENCE TO FB_Metric
VAR_INPUT
    itfMetricOwner : IMetricOwner;
END_VAR
VAR_OUTPUT
    eError : ERROR;
VAR
    itfElement                 : IElement;
    pfb_Metric                 : POINTER TO FB_Metric;
	initData                   : DummyData;
	FBFError                   : FBF.ERROR;
    itfElement := THIS^._MetricPool.HeadElem.RemoveElem(); //Remove it, but now it is not part of a group anymore
    IF __QUERYPOINTER( itfElement, pfb_Metric ) THEN
        pfb_Metric^( itfMetricOwner := itfMetricOwner );
        allocMetric REF= pfb_Metric^;
    ELSE
		newObjectFromThinAirPlease := TRUE;
	END_IF
ELSE
	newObjectFromThinAirPlease := TRUE;
END_IF
IF newObjectFromThinAirPlease THEN
	//No metric? No worries, we will just create one
		//No need to add it to the pool... we add it instead when we assign the owner
        eError := ERROR.HostNotEnoughBlankMetrics;
		allocMetric REF= GVL_sparkplug.InvalidMetric;
    END_IF