|
1 | 1 | classdef APIUtil < handle |
2 | | - properties (Access = protected) |
3 | | - libraryWasLoaded = 0 |
4 | | - end |
5 | 2 | properties |
6 | 3 | %DataPtr_PDouble |
7 | 4 | %DataPtr_PInteger |
|
13 | 10 | end |
14 | 11 | methods |
15 | 12 | function obj = APIUtil() |
| 13 | + |
16 | 14 | if getenv('DSS_EXTENSIONS_DEBUG') == '1' |
17 | 15 | warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library') |
18 | 16 | obj.libname = 'dss_capid'; |
|
23 | 21 | MfilePath = fileparts(mfilename('fullpath')); |
24 | 22 | DLLfilePath = fullfile(MfilePath, obj.libname); |
25 | 23 | PropertiesMOfilePath = fullfile(MfilePath, 'messages', 'properties-en-US.mo'); |
| 24 | + DSS_MATLAB.librefcount(1); |
26 | 25 | if libisloaded(obj.libname) |
27 | 26 | return; |
28 | 27 | end |
|
37 | 36 | end |
38 | 37 | calllib(obj.libname, 'DSS_Start', 0); |
39 | 38 | calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath); |
40 | | - obj.libraryWasLoaded = 1; |
41 | 39 | warning(orig_state); |
42 | 40 | end |
43 | 41 |
|
44 | 42 | function delete(obj) |
45 | | - % Don't unload the library anymore for better compatibility with |
46 | | - % the COM behavior |
47 | | - |
48 | | - % if (obj.libraryWasLoaded ~= 0) |
49 | | - % unloadlibrary(obj.libname); |
50 | | - % end |
| 43 | + % If nothing is using the library, unload it. |
| 44 | + % Required to properly exit MATLAB. |
| 45 | + cnt = DSS_MATLAB.librefcount(-1); |
| 46 | + if (cnt == 0) |
| 47 | + calllib(obj.libname, 'Text_Set_Command', 'Set Parallel=no'); |
| 48 | + calllib(obj.libname, 'DSS_ClearAll'); |
| 49 | + unloadlibrary(obj.libname); |
| 50 | + end |
51 | 51 | end |
52 | 52 |
|
53 | 53 | function obj = InitBuffers(obj) |
|
0 commit comments