Skip to content

Commit a51d59c

Browse files
committed
Merge branch 'ctx'
2 parents 8436b4b + 78e3c0c commit a51d59c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4968
-4918
lines changed

+DSS_MATLAB/APIUtil.m

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@
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(varargin)
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) && (varargin{1} ~= 0)
29+
obj.dssctx = calllib(obj.libname, 'ctx_New');
30+
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
31+
obj.is_prime = 0;
32+
else
33+
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
34+
obj.is_prime = 1;
35+
end
2636
return;
2737
end
2838
orig_state = warning;
@@ -35,28 +45,45 @@
3545
loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_no_thunk);
3646
end
3747
calllib(obj.libname, 'DSS_Start', 0);
38-
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
48+
if (nargin > 0) && (varargin{1} ~= 0)
49+
obj.dssctx = calllib(obj.libname, 'ctx_New');
50+
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
51+
obj.is_prime = 0;
52+
else
53+
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
54+
obj.is_prime = 1;
55+
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
56+
end
3957
warning(orig_state);
4058
end
4159

4260
function delete(obj)
61+
62+
if obj.is_prime == 0
63+
cnt = DSS_MATLAB.ctxrefcount(obj.dssctx, -1);
64+
if cnt == 0
65+
calllib(obj.libname, 'ctx_Dispose', obj.dssctx);
66+
end
67+
end
68+
4369
% If nothing is using the library, unload it.
4470
% Required to properly exit MATLAB.
4571
cnt = DSS_MATLAB.librefcount(-1);
4672
if (cnt == 0)
47-
calllib(obj.libname, 'Text_Set_Command', 'Set Parallel=no');
48-
calllib(obj.libname, 'DSS_ClearAll');
73+
prime_ctx = calllib(obj.libname, 'ctx_Get_Prime');
74+
calllib(obj.libname, 'ctx_Text_Set_Command', prime_ctx, 'Set Parallel=no');
75+
calllib(obj.libname, 'ctx_DSS_ClearAll', prime_ctx);
4976
unloadlibrary(obj.libname);
5077
end
5178
end
5279

5380
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');
81+
% obj.DataPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
82+
% obj.DataPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
83+
% obj.DataPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
84+
obj.CountPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PDouble', obj.dssctx);
85+
obj.CountPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PInteger', obj.dssctx);
86+
obj.CountPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PByte', obj.dssctx);
6087

6188
% if (obj.DataPtr_PDouble.isNull || obj.DataPtr_PDouble.isNull || obj.DataPtr_PByte.isNull)
6289
% disp('Null-pointer return from the API! Cannot continue!');
@@ -75,62 +102,62 @@ function delete(obj)
75102

76103

77104
function result = get_float64_gr_array(obj)
78-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
105+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
79106
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
80107
result = data.Value;
81108
end
82109

83110
function result = get_int32_gr_array(obj)
84-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
111+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
85112
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
86113
result = data.Value;
87114
end
88115

89116
function result = get_int8_gr_array(obj)
90-
data = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
117+
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
91118
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
92119
result = data.Value;
93120
end
94121

95122
function result = get_string_array(obj, funcname, varargin)
96123
dataPointer = libpointer('voidPtr', 0);
97124
countPointer = libpointer('int32Ptr', [0, 0]);
98-
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
125+
calllib(obj.libname, funcname, obj.dssctx, dataPointer, countPointer, varargin{:});
99126
result = cell(countPointer.Value(1), 1);
100127
for i=1:countPointer.Value(1)
101128
result(i) = cellstr(calllib(obj.libname, 'DSS_Get_PAnsiChar', dataPointer, i - 1));
102129
end
103130
calllib(obj.libname, 'DSS_Dispose_PPAnsiChar', dataPointer, countPointer.Value(2));
104131
end
105132

106-
function result = get_int8_array(obj, funcname, varargin)
107-
dataPointer = libpointer('int8PtrPtr');
108-
countPointer = libpointer('int32Ptr', [0, 0]);
109-
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
110-
dataPointer.Value
111-
setdatatype(dataPointer.Value, 'int8Ptr', 1, countPointer.Value(1));
112-
result = dataPointer.Value;
113-
calllib(obj.libname, 'DSS_Dispose_PByte', dataPointer);
114-
obj.CheckForError();
115-
end
133+
% function result = get_int8_array(obj, funcname, varargin)
134+
% dataPointer = libpointer('int8PtrPtr');
135+
% countPointer = libpointer('int32Ptr', [0, 0]);
136+
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
137+
% dataPointer.Value
138+
% setdatatype(dataPointer.Value, 'int8Ptr', 1, countPointer.Value(1));
139+
% result = dataPointer.Value;
140+
% calllib(obj.libname, 'DSS_Dispose_PByte', dataPointer);
141+
% obj.CheckForError();
142+
% end
116143

117-
function result = get_int32_array(obj, funcname, varargin)
118-
dataPointer = libpointer('int32PtrPtr');
119-
countPointer = libpointer('int32Ptr', [0, 0]);
120-
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
121-
setdatatype(dataPointer.Value, 'int32Ptr', 1, countPointer.Value(1));
122-
result = dataPointer.Value;
123-
calllib(obj.libname, 'DSS_Dispose_PInteger', dataPointer);
124-
end
144+
% function result = get_int32_array(obj, funcname, varargin)
145+
% dataPointer = libpointer('int32PtrPtr');
146+
% countPointer = libpointer('int32Ptr', [0, 0]);
147+
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
148+
% setdatatype(dataPointer.Value, 'int32Ptr', 1, countPointer.Value(1));
149+
% result = dataPointer.Value;
150+
% calllib(obj.libname, 'DSS_Dispose_PInteger', dataPointer);
151+
% end
125152

126-
function result = get_float64_array(obj, funcname, varargin)
127-
dataPointer = libpointer('doublePtrPtr');
128-
countPointer = libpointer('int32Ptr', [0, 0]);
129-
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
130-
setdatatype(dataPointer.Value, 'doublePtr', 1, countPointer.Value(1));
131-
result = dataPointer.Value;
132-
calllib(obj.libname, 'DSS_Dispose_PDouble', dataPointer);
133-
end
153+
% function result = get_float64_array(obj, funcname, varargin)
154+
% dataPointer = libpointer('doublePtrPtr');
155+
% countPointer = libpointer('int32Ptr', [0, 0]);
156+
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
157+
% setdatatype(dataPointer.Value, 'doublePtr', 1, countPointer.Value(1));
158+
% result = dataPointer.Value;
159+
% calllib(obj.libname, 'DSS_Dispose_PDouble', dataPointer);
160+
% end
134161

135162
end
136163
end

+DSS_MATLAB/Base.m

Lines changed: 6 additions & 4 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,24 +25,25 @@
2425
function obj = Base(apiutil)
2526
obj.apiutil = apiutil;
2627
obj.libname = apiutil.libname;
28+
obj.dssctx = apiutil.dssctx;
2729
end
2830

2931
end
3032

3133
methods
3234

3335
function varargout = CheckForError(obj, varargin)
34-
error = calllib(obj.libname, 'Error_Get_Number');
36+
error = calllib(obj.libname, 'ctx_Error_Get_Number', obj.dssctx);
3537
if error ~= 0
36-
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'Error_Get_Description'), '\', '\\'));
38+
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'ctx_Error_Get_Description', obj.dssctx), '\', '\\'));
3739
throw(ME);
3840
end
3941
varargout = varargin;
4042
end
4143

4244
function obj = clear_api_buffers(obj)
43-
calllib(obj.libname, 'DSS_DisposeGRData');
44-
calllib(obj.libname, 'DSS_ResetStringBuffer');
45+
calllib(obj.libname, 'ctx_DSS_DisposeGRData', obj.dssctx);
46+
calllib(obj.libname, 'ctx_DSS_ResetStringBuffer', obj.dssctx);
4547
end
4648
end
4749
end

+DSS_MATLAB/IActiveClass.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,61 +43,61 @@
4343
options = 0;
4444
end
4545

46-
result = calllib(obj.libname, 'ActiveClass_ToJSON', options);
46+
result = calllib(obj.libname, 'ctx_ActiveClass_ToJSON', obj.dssctx, options);
4747
obj.CheckForError();
4848
end
4949
end
5050
methods
5151

5252
function result = get.ActiveClassName(obj)
5353
% (read-only) Returns name of active class.
54-
result = calllib(obj.libname, 'ActiveClass_Get_ActiveClassName');
54+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_ActiveClassName', obj.dssctx);
5555
obj.CheckForError();
5656
end
5757

5858
function result = get.AllNames(obj)
5959
% (read-only) Array of strings consisting of all element names in the active class.
60-
result = obj.apiutil.get_string_array('ActiveClass_Get_AllNames');
60+
result = obj.apiutil.get_string_array('ctx_ActiveClass_Get_AllNames');
6161
obj.CheckForError();
6262
end
6363

6464
function result = get.Count(obj)
6565
% (read-only) Number of elements in Active Class. Same as NumElements Property.
66-
result = calllib(obj.libname, 'ActiveClass_Get_Count');
66+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_Count', obj.dssctx);
6767
obj.CheckForError();
6868
end
6969

7070
function result = get.First(obj)
7171
% (read-only) Sets first element in the active class to be the active DSS object. If object is a CktElement, ActiveCktELment also points to this element. Returns 0 if none.
72-
result = calllib(obj.libname, 'ActiveClass_Get_First');
72+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_First', obj.dssctx);
7373
obj.CheckForError();
7474
end
7575

7676
function result = get.Name(obj)
7777
% Name of the Active Element of the Active Class
78-
result = calllib(obj.libname, 'ActiveClass_Get_Name');
78+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_Name', obj.dssctx);
7979
obj.CheckForError();
8080
end
8181
function obj = set.Name(obj, Value)
82-
calllib(obj.libname, 'ActiveClass_Set_Name', Value);
82+
calllib(obj.libname, 'ctx_ActiveClass_Set_Name', obj.dssctx, Value);
8383
obj.CheckForError();
8484
end
8585

8686
function result = get.Next(obj)
8787
% (read-only) Sets next element in active class to be the active DSS object. If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if no more.
88-
result = calllib(obj.libname, 'ActiveClass_Get_Next');
88+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_Next', obj.dssctx);
8989
obj.CheckForError();
9090
end
9191

9292
function result = get.NumElements(obj)
9393
% (read-only) Number of elements in this class. Same as Count property.
94-
result = calllib(obj.libname, 'ActiveClass_Get_NumElements');
94+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_NumElements', obj.dssctx);
9595
obj.CheckForError();
9696
end
9797

9898
function result = get.ActiveClassParent(obj)
9999
% Get the name of the parent class of the active class
100-
result = calllib(obj.libname, 'ActiveClass_Get_ActiveClassParent');
100+
result = calllib(obj.libname, 'ctx_ActiveClass_Get_ActiveClassParent', obj.dssctx);
101101
obj.CheckForError();
102102
end
103103
end

0 commit comments

Comments
 (0)