@@ -32,6 +32,80 @@ def __str__(self):
3232 if self ._message :
3333 return 'RTTIException ' + str (self ._code ) + ': ' + str (self ._message )
3434 return 'RTTIException ' + str (self ._code )
35+
36+ def get_error_code (self ):
37+ """Returns the error code"""
38+ return self ._code
39+
40+ def get_error_message (self ):
41+ """Returns the custom error message"""
42+ return self ._message
43+
44+ def get_error_name (self ):
45+ """Returns the error name (constant name)"""
46+ if self ._code == ErrorCodes .SUCCESS :
47+ return 'SUCCESS'
48+ elif self ._code == ErrorCodes .NOTIMPLEMENTED :
49+ return 'NOTIMPLEMENTED'
50+ elif self ._code == ErrorCodes .INVALIDPARAM :
51+ return 'INVALIDPARAM'
52+ elif self ._code == ErrorCodes .INVALIDCAST :
53+ return 'INVALIDCAST'
54+ elif self ._code == ErrorCodes .BUFFERTOOSMALL :
55+ return 'BUFFERTOOSMALL'
56+ elif self ._code == ErrorCodes .GENERICEXCEPTION :
57+ return 'GENERICEXCEPTION'
58+ elif self ._code == ErrorCodes .COULDNOTLOADLIBRARY :
59+ return 'COULDNOTLOADLIBRARY'
60+ elif self ._code == ErrorCodes .COULDNOTFINDLIBRARYEXPORT :
61+ return 'COULDNOTFINDLIBRARYEXPORT'
62+ elif self ._code == ErrorCodes .INCOMPATIBLEBINARYVERSION :
63+ return 'INCOMPATIBLEBINARYVERSION'
64+ else :
65+ return 'UNKNOWN'
66+
67+ def get_error_description (self ):
68+ """Returns the error description (human-readable)"""
69+ if self ._code == ErrorCodes .SUCCESS :
70+ return 'success'
71+ elif self ._code == ErrorCodes .NOTIMPLEMENTED :
72+ return 'functionality not implemented'
73+ elif self ._code == ErrorCodes .INVALIDPARAM :
74+ return 'an invalid parameter was passed'
75+ elif self ._code == ErrorCodes .INVALIDCAST :
76+ return 'a type cast failed'
77+ elif self ._code == ErrorCodes .BUFFERTOOSMALL :
78+ return 'a provided buffer is too small'
79+ elif self ._code == ErrorCodes .GENERICEXCEPTION :
80+ return 'a generic exception occurred'
81+ elif self ._code == ErrorCodes .COULDNOTLOADLIBRARY :
82+ return 'the library could not be loaded'
83+ elif self ._code == ErrorCodes .COULDNOTFINDLIBRARYEXPORT :
84+ return 'a required exported symbol could not be found in the library'
85+ elif self ._code == ErrorCodes .INCOMPATIBLEBINARYVERSION :
86+ return 'the version of the binary interface does not match the bindings interface'
87+ else :
88+ return 'unknown error'
89+
90+ @property
91+ def error_code (self ):
92+ """Property to access error code"""
93+ return self ._code
94+
95+ @property
96+ def error_message (self ):
97+ """Property to access custom error message"""
98+ return self ._message
99+
100+ @property
101+ def error_name (self ):
102+ """Property to access error name"""
103+ return self .get_error_name ()
104+
105+ @property
106+ def error_description (self ):
107+ """Property to access error description"""
108+ return self .get_error_description ()
35109
36110'''Definition of binding API version
37111'''
@@ -260,23 +334,23 @@ def checkError(self, instance, errorCode):
260334 message ,_ = self .GetLastError (instance )
261335 raise ERTTIException (errorCode , message )
262336
263- def GetVersion (self ):
264- pMajor = ctypes .c_uint32 ()
265- pMinor = ctypes .c_uint32 ()
266- pMicro = ctypes .c_uint32 ()
337+ def GetVersion (self , Major = None , Minor = None , Micro = None ):
338+ pMajor = ctypes .c_uint32 (Major if Major is not None else 0 )
339+ pMinor = ctypes .c_uint32 (Minor if Minor is not None else 0 )
340+ pMicro = ctypes .c_uint32 (Micro if Micro is not None else 0 )
267341 self .checkError (None , self .lib .rtti_getversion (pMajor , pMinor , pMicro ))
268342
269343 return pMajor .value , pMinor .value , pMicro .value
270344
271- def GetLastError (self , InstanceObject ):
345+ def GetLastError (self , InstanceObject , ErrorMessage = None ):
272346 InstanceHandle = None
273347 if InstanceObject :
274348 InstanceHandle = InstanceObject ._handle
275349 else :
276350 raise ERTTIException (ErrorCodes .INVALIDPARAM , 'Invalid return/output value' )
277- nErrorMessageBufferSize = ctypes .c_uint64 (0 )
351+ nErrorMessageBufferSize = ctypes .c_uint64 (len ( ErrorMessage ) if ErrorMessage else 0 )
278352 nErrorMessageNeededChars = ctypes .c_uint64 (0 )
279- pErrorMessageBuffer = ctypes .c_char_p (None )
353+ pErrorMessageBuffer = ctypes .c_char_p (str . encode ( ErrorMessage ) if ErrorMessage else None )
280354 pHasError = ctypes .c_bool ()
281355 self .checkError (None , self .lib .rtti_getlasterror (InstanceHandle , nErrorMessageBufferSize , nErrorMessageNeededChars , pErrorMessageBuffer , pHasError ))
282356 nErrorMessageBufferSize = ctypes .c_uint64 (nErrorMessageNeededChars .value )
@@ -469,23 +543,27 @@ def GetNextAnimal(self):
469543
470544 return AnimalObject
471545
472- def GetNextOptinalAnimal (self ):
546+ def GetNextOptinalAnimal (self , AnimalObject = None ):
473547 AnimalHandle = ctypes .c_void_p ()
548+ if AnimalObject is not None :
549+ AnimalHandle = ctypes .c_void_p (AnimalObject ._handle )
474550 pError = ctypes .c_bool ()
475551 self ._wrapper .checkError (self , self ._wrapper .lib .rtti_animaliterator_getnextoptinalanimal (self ._handle , AnimalHandle , pError ))
476- if AnimalHandle :
477- AnimalObject = self ._wrapper ._polymorphicFactory (AnimalHandle )
552+ if AnimalHandle . value :
553+ AnimalObject = self ._wrapper ._polymorphicFactory (AnimalHandle . value )
478554 else :
479555 AnimalObject = None
480556
481557 return AnimalObject , pError .value
482558
483- def GetNextMandatoryAnimal (self ):
559+ def GetNextMandatoryAnimal (self , AnimalObject = None ):
484560 AnimalHandle = ctypes .c_void_p ()
561+ if AnimalObject is not None :
562+ AnimalHandle = ctypes .c_void_p (AnimalObject ._handle )
485563 pError = ctypes .c_bool ()
486564 self ._wrapper .checkError (self , self ._wrapper .lib .rtti_animaliterator_getnextmandatoryanimal (self ._handle , AnimalHandle , pError ))
487- if AnimalHandle :
488- AnimalObject = self ._wrapper ._polymorphicFactory (AnimalHandle )
565+ if AnimalHandle . value :
566+ AnimalObject = self ._wrapper ._polymorphicFactory (AnimalHandle . value )
489567 else :
490568 AnimalObject = None
491569
0 commit comments