A resource class can always be created by library calls. It is the mediator between asynchronous events of the runtime system and the controlled release of resources. For a class it is characteristic that all resources managed by it are released by the same release function.
A class is created by the following call:
hClass := RSM.CreateClass(
iPOUIndex := INDEXOF(SysFileClose),
ctMaxHandles := 0,
peError := CAA.gc_pNULL
);
Single resources may then be added to the maintenance of the Resource Manager as follows:
hFile := SysFileOpen(
FileName:='Test.txt',
Mode:='rw'
);
hCheck := RSM.Register(
hClass := hClass,
hResource := hFile
);
After a resource has been passed to the maintenance of the Resource Manager, the latter may always release it asynchronously without notification by the application. Thus, each use of a handle must be preceded by checking its validity:
hFile := RSM.Check(hCheck := hCheck)
IF hFile <> CAA.gc_hINVALID THEN
(* Handle verwenden *)
END_IF
For releasing the resource the following exemplary protocol has to be followed:
hFile := RSM.Check(hCheck := hCheck)
IF hFile <> CAA.gc_hINVALID THEN
SysFileClose(hFile);
RSM.Unregister(
hCheck := hCheck
);
hFile := CAA.gc_hINVALID;
hCheck := CAA.gc_hINVALID;
END_IF
Hence, it becomes apparent that the management of resources (e.g. system libraries) will always require a wrapping function serving as connector between the Resource Manager and the system library. The CAA libraries have to guarantee the connection to eventually required system libraries via the Resource Manager.
Examples: CAA.File, CAA.Com, CAA.MemBlockMan, CAA.CanL2, CAA.CanOpen,…
Thus the user is concerned by the existence of the Resource Manager only insofar, as the effects of an invalid treatment of handles by the applicator are resolved by an Online/Reset or a repeated download of the application and will not cause permanent Resource Leaks.