Skip to content

Commit 73d8c32

Browse files
committed
Initial preparation for DSSContexts
1 parent 8436b4b commit 73d8c32

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

+DSS_MATLAB/APIUtil.m

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@
77
CountPtr_PInteger
88
CountPtr_PByte
99
libname
10+
dssctx
11+
is_prime
1012
end
1113
methods
12-
function obj = APIUtil()
14+
function obj = APIUtil(create)
1315

1416
if getenv('DSS_EXTENSIONS_DEBUG') == '1'
1517
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
1618
obj.libname = 'dss_capid';
1719
else
1820
obj.libname = 'dss_capi';
1921
end
20-
22+
2123
MfilePath = fileparts(mfilename('fullpath'));
2224
DLLfilePath = fullfile(MfilePath, obj.libname);
2325
PropertiesMOfilePath = fullfile(MfilePath, 'messages', 'properties-en-US.mo');
2426
DSS_MATLAB.librefcount(1);
2527
if libisloaded(obj.libname)
28+
if (nargin > 0) && (create ~= 0)
29+
obj.dssctx = calllib(obj.libname, 'ctx_New');
30+
obj.is_prime = 0;
31+
else
32+
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
33+
obj.is_prime = 1;
34+
end
2635
return;
2736
end
2837
orig_state = warning;
@@ -36,27 +45,39 @@
3645
end
3746
calllib(obj.libname, 'DSS_Start', 0);
3847
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
48+
if (nargin > 0) && (create ~= 0)
49+
obj.dssctx = calllib(obj.libname, 'ctx_New');
50+
obj.is_prime = 0;
51+
else
52+
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
53+
obj.is_prime = 1;
54+
end
3955
warning(orig_state);
4056
end
4157

4258
function delete(obj)
59+
if obj.is_prime ~= 0
60+
calllib(obj.libname, 'ctx_Dispose', obj.dssctx);
61+
end
62+
4363
% If nothing is using the library, unload it.
4464
% Required to properly exit MATLAB.
4565
cnt = DSS_MATLAB.librefcount(-1);
4666
if (cnt == 0)
47-
calllib(obj.libname, 'Text_Set_Command', 'Set Parallel=no');
48-
calllib(obj.libname, 'DSS_ClearAll');
67+
prime_ctx = calllib(obj.libname, 'ctx_Get_Prime')
68+
calllib(obj.libname, 'ctx_Text_Set_Command', prime_ctx, 'Set Parallel=no');
69+
calllib(obj.libname, 'ctx_DSS_ClearAll', prime_ctx);
4970
unloadlibrary(obj.libname);
5071
end
5172
end
5273

5374
function obj = InitBuffers(obj)
54-
% obj.DataPtr_PDouble = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
55-
% obj.DataPtr_PInteger = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
56-
% obj.DataPtr_PByte = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
57-
obj.CountPtr_PDouble = calllib(obj.libname, 'DSS_GR_CountPtr_PDouble');
58-
obj.CountPtr_PInteger = calllib(obj.libname, 'DSS_GR_CountPtr_PInteger');
59-
obj.CountPtr_PByte = calllib(obj.libname, 'DSS_GR_CountPtr_PByte');
75+
% obj.DataPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
76+
% obj.DataPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
77+
% obj.DataPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
78+
obj.CountPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PDouble', obj.dssctx);
79+
obj.CountPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PInteger', obj.dssctx);
80+
obj.CountPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PByte', obj.dssctx);
6081

6182
% if (obj.DataPtr_PDouble.isNull || obj.DataPtr_PDouble.isNull || obj.DataPtr_PByte.isNull)
6283
% disp('Null-pointer return from the API! Cannot continue!');
@@ -75,19 +96,19 @@ function delete(obj)
7596

7697

7798
function result = get_float64_gr_array(obj)
78-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
99+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
79100
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
80101
result = data.Value;
81102
end
82103

83104
function result = get_int32_gr_array(obj)
84-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
105+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
85106
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
86107
result = data.Value;
87108
end
88109

89110
function result = get_int8_gr_array(obj)
90-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
111+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
91112
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
92113
result = data.Value;
93114
end

+DSS_MATLAB/Base.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
properties (Access = protected, Hidden = true)
33
apiutil
44
libname
5+
dssctx
56
end
67

78
methods (Access = protected)
@@ -24,6 +25,7 @@
2425
function obj = Base(apiutil)
2526
obj.apiutil = apiutil;
2627
obj.libname = apiutil.libname;
28+
obj.dssctx = apiutil.dssctx;
2729
end
2830

2931
end

0 commit comments

Comments
 (0)