Skip to content

Commit

Permalink
Merge branch 'ctx'
Browse files Browse the repository at this point in the history
  • Loading branch information
PMeira committed Aug 29, 2022
2 parents 8436b4b + 78e3c0c commit a51d59c
Show file tree
Hide file tree
Showing 52 changed files with 4,968 additions and 4,918 deletions.
109 changes: 68 additions & 41 deletions +DSS_MATLAB/APIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@
CountPtr_PInteger
CountPtr_PByte
libname
dssctx
is_prime
end
methods
function obj = APIUtil()
function obj = APIUtil(varargin)

if getenv('DSS_EXTENSIONS_DEBUG') == '1'
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
obj.libname = 'dss_capid';
else
obj.libname = 'dss_capi';
end

MfilePath = fileparts(mfilename('fullpath'));
DLLfilePath = fullfile(MfilePath, obj.libname);
PropertiesMOfilePath = fullfile(MfilePath, 'messages', 'properties-en-US.mo');
DSS_MATLAB.librefcount(1);
if libisloaded(obj.libname)
if (nargin > 0) && (varargin{1} ~= 0)
obj.dssctx = calllib(obj.libname, 'ctx_New');
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
obj.is_prime = 0;
else
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
obj.is_prime = 1;
end
return;
end
orig_state = warning;
Expand All @@ -35,28 +45,45 @@
loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_no_thunk);
end
calllib(obj.libname, 'DSS_Start', 0);
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
if (nargin > 0) && (varargin{1} ~= 0)
obj.dssctx = calllib(obj.libname, 'ctx_New');
DSS_MATLAB.ctxrefcount(obj.dssctx, 1);
obj.is_prime = 0;
else
obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime');
obj.is_prime = 1;
calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath);
end
warning(orig_state);
end

function delete(obj)

if obj.is_prime == 0
cnt = DSS_MATLAB.ctxrefcount(obj.dssctx, -1);
if cnt == 0
calllib(obj.libname, 'ctx_Dispose', obj.dssctx);
end
end

% If nothing is using the library, unload it.
% Required to properly exit MATLAB.
cnt = DSS_MATLAB.librefcount(-1);
if (cnt == 0)
calllib(obj.libname, 'Text_Set_Command', 'Set Parallel=no');
calllib(obj.libname, 'DSS_ClearAll');
prime_ctx = calllib(obj.libname, 'ctx_Get_Prime');
calllib(obj.libname, 'ctx_Text_Set_Command', prime_ctx, 'Set Parallel=no');
calllib(obj.libname, 'ctx_DSS_ClearAll', prime_ctx);
unloadlibrary(obj.libname);
end
end

function obj = InitBuffers(obj)
% obj.DataPtr_PDouble = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
% obj.DataPtr_PInteger = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
% obj.DataPtr_PByte = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
obj.CountPtr_PDouble = calllib(obj.libname, 'DSS_GR_CountPtr_PDouble');
obj.CountPtr_PInteger = calllib(obj.libname, 'DSS_GR_CountPtr_PInteger');
obj.CountPtr_PByte = calllib(obj.libname, 'DSS_GR_CountPtr_PByte');
% obj.DataPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
% obj.DataPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
% obj.DataPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
obj.CountPtr_PDouble = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PDouble', obj.dssctx);
obj.CountPtr_PInteger = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PInteger', obj.dssctx);
obj.CountPtr_PByte = calllib(obj.libname, 'ctx_DSS_GR_CountPtr_PByte', obj.dssctx);

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


function result = get_float64_gr_array(obj)
data = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PDouble', obj.dssctx);
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
result = data.Value;
end

function result = get_int32_gr_array(obj)
data = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PInteger', obj.dssctx);
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
result = data.Value;
end

function result = get_int8_gr_array(obj)
data = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
data = calllib(obj.libname, 'ctx_DSS_GR_DataPtr_PByte', obj.dssctx);
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
result = data.Value;
end

function result = get_string_array(obj, funcname, varargin)
dataPointer = libpointer('voidPtr', 0);
countPointer = libpointer('int32Ptr', [0, 0]);
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
calllib(obj.libname, funcname, obj.dssctx, dataPointer, countPointer, varargin{:});
result = cell(countPointer.Value(1), 1);
for i=1:countPointer.Value(1)
result(i) = cellstr(calllib(obj.libname, 'DSS_Get_PAnsiChar', dataPointer, i - 1));
end
calllib(obj.libname, 'DSS_Dispose_PPAnsiChar', dataPointer, countPointer.Value(2));
end

function result = get_int8_array(obj, funcname, varargin)
dataPointer = libpointer('int8PtrPtr');
countPointer = libpointer('int32Ptr', [0, 0]);
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
dataPointer.Value
setdatatype(dataPointer.Value, 'int8Ptr', 1, countPointer.Value(1));
result = dataPointer.Value;
calllib(obj.libname, 'DSS_Dispose_PByte', dataPointer);
obj.CheckForError();
end
% function result = get_int8_array(obj, funcname, varargin)
% dataPointer = libpointer('int8PtrPtr');
% countPointer = libpointer('int32Ptr', [0, 0]);
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
% dataPointer.Value
% setdatatype(dataPointer.Value, 'int8Ptr', 1, countPointer.Value(1));
% result = dataPointer.Value;
% calllib(obj.libname, 'DSS_Dispose_PByte', dataPointer);
% obj.CheckForError();
% end

function result = get_int32_array(obj, funcname, varargin)
dataPointer = libpointer('int32PtrPtr');
countPointer = libpointer('int32Ptr', [0, 0]);
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
setdatatype(dataPointer.Value, 'int32Ptr', 1, countPointer.Value(1));
result = dataPointer.Value;
calllib(obj.libname, 'DSS_Dispose_PInteger', dataPointer);
end
% function result = get_int32_array(obj, funcname, varargin)
% dataPointer = libpointer('int32PtrPtr');
% countPointer = libpointer('int32Ptr', [0, 0]);
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
% setdatatype(dataPointer.Value, 'int32Ptr', 1, countPointer.Value(1));
% result = dataPointer.Value;
% calllib(obj.libname, 'DSS_Dispose_PInteger', dataPointer);
% end

function result = get_float64_array(obj, funcname, varargin)
dataPointer = libpointer('doublePtrPtr');
countPointer = libpointer('int32Ptr', [0, 0]);
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
setdatatype(dataPointer.Value, 'doublePtr', 1, countPointer.Value(1));
result = dataPointer.Value;
calllib(obj.libname, 'DSS_Dispose_PDouble', dataPointer);
end
% function result = get_float64_array(obj, funcname, varargin)
% dataPointer = libpointer('doublePtrPtr');
% countPointer = libpointer('int32Ptr', [0, 0]);
% calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
% setdatatype(dataPointer.Value, 'doublePtr', 1, countPointer.Value(1));
% result = dataPointer.Value;
% calllib(obj.libname, 'DSS_Dispose_PDouble', dataPointer);
% end

end
end
10 changes: 6 additions & 4 deletions +DSS_MATLAB/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
properties (Access = protected, Hidden = true)
apiutil
libname
dssctx
end

methods (Access = protected)
Expand All @@ -24,24 +25,25 @@
function obj = Base(apiutil)
obj.apiutil = apiutil;
obj.libname = apiutil.libname;
obj.dssctx = apiutil.dssctx;
end

end

methods

function varargout = CheckForError(obj, varargin)
error = calllib(obj.libname, 'Error_Get_Number');
error = calllib(obj.libname, 'ctx_Error_Get_Number', obj.dssctx);
if error ~= 0
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'Error_Get_Description'), '\', '\\'));
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'ctx_Error_Get_Description', obj.dssctx), '\', '\\'));
throw(ME);
end
varargout = varargin;
end

function obj = clear_api_buffers(obj)
calllib(obj.libname, 'DSS_DisposeGRData');
calllib(obj.libname, 'DSS_ResetStringBuffer');
calllib(obj.libname, 'ctx_DSS_DisposeGRData', obj.dssctx);
calllib(obj.libname, 'ctx_DSS_ResetStringBuffer', obj.dssctx);
end
end
end
20 changes: 10 additions & 10 deletions +DSS_MATLAB/IActiveClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,61 @@
options = 0;
end

result = calllib(obj.libname, 'ActiveClass_ToJSON', options);
result = calllib(obj.libname, 'ctx_ActiveClass_ToJSON', obj.dssctx, options);
obj.CheckForError();
end
end
methods

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

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

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

function result = get.First(obj)
% (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.
result = calllib(obj.libname, 'ActiveClass_Get_First');
result = calllib(obj.libname, 'ctx_ActiveClass_Get_First', obj.dssctx);
obj.CheckForError();
end

function result = get.Name(obj)
% Name of the Active Element of the Active Class
result = calllib(obj.libname, 'ActiveClass_Get_Name');
result = calllib(obj.libname, 'ctx_ActiveClass_Get_Name', obj.dssctx);
obj.CheckForError();
end
function obj = set.Name(obj, Value)
calllib(obj.libname, 'ActiveClass_Set_Name', Value);
calllib(obj.libname, 'ctx_ActiveClass_Set_Name', obj.dssctx, Value);
obj.CheckForError();
end

function result = get.Next(obj)
% (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.
result = calllib(obj.libname, 'ActiveClass_Get_Next');
result = calllib(obj.libname, 'ctx_ActiveClass_Get_Next', obj.dssctx);
obj.CheckForError();
end

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

function result = get.ActiveClassParent(obj)
% Get the name of the parent class of the active class
result = calllib(obj.libname, 'ActiveClass_Get_ActiveClassParent');
result = calllib(obj.libname, 'ctx_ActiveClass_Get_ActiveClassParent', obj.dssctx);
obj.CheckForError();
end
end
Expand Down
Loading

0 comments on commit a51d59c

Please sign in to comment.