Commit b5db51d1 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Additional work on the move to ctypes

parent 98942265
......@@ -35,6 +35,9 @@ TASTE Data Modelling Technologies
CHANGELOG
1.2.0
Not using SWIG anymore for the Python mappers
1.1.2
pyside_b_mapper: added combo box for the asn1 value editor
......
......@@ -232,17 +232,7 @@ def setUDP():
def {tmName}(tm_ptr, size):
""" Callback function when receiving this TM """
if editor:
# Cast the void* pointer to an array of bytes
as_bytes = ctypes.cast(tm_ptr,
ctypes.POINTER((ctypes.c_ubyte * (size / 8))))
# Create a corrsponding SWIG buffer and copy the content
swig_ptr = DV.new_byte_SWIG_PTR(size / 8)
for idx in xrange(size/8):
DV.byte_SWIG_PTR_setitem(swig_ptr, idx, as_bytes.contents[idx])
# Notify the GUI that the TM has been received
editor.pendingTM = swig_ptr
editor.pendingTM = tm_ptr
tm_callback.got_tm.emit()
......@@ -337,18 +327,16 @@ udpController = None
def checkConstraints(asnVal):
\'\'\' Check if the ASN.1 constraints are respected \'\'\'
_pErr = DV.new_int_SWIG_PTR(1)
_pErr = DV.CreateInstanceOf_int()
if not DV.{asn1Type}_IsConstraintValid(asnVal._ptr, _pErr):
errCode = DV.int_SWIG_PTR_getitem(_pErr, 0)
errCode = DV.{asn1Type}.getErrCode(_pErr)
errorMsg = datamodel.errCodes[errCode]['name'] + ': Constraint error! Constraint is: ' + datamodel.errCodes[errCode]['constraint']
DV.DestroyInstanceOf_int(pErr)
if log:
log.error(errorMsg)
#if statusbar:
# statusbar.showMessage(errorMsg)
return False
else:
#if statusbar:
# statusbar.showMessage('ASN.1 value is valid')
DV.DestroyInstanceOf_int(pErr)
return True
......@@ -423,7 +411,7 @@ def decode_uPER(uPER_encodedBuffer):
def decode_TM(rawTM):
\'\'\' Decode a msgQ message (native encoding) \'\'\'
tm = ASN1.{asn1Type}()
DV.SetDataFor_{asn1Type}(tm._ptr, rawTM)
tm.SetData(rawTM)
return tm
......
......@@ -166,8 +166,7 @@ def OnStartup(modelingLanguage, asnFile, subProgram, unused_subProgramImplementa
CleanParam = CleanName(param._id)
g_TMprocessors.append(" # Read the data for param %s" % param._id)
g_TMprocessors.append(" var_%s = %s_asn.%s()" % (CleanParam, g_asn_name, CleanName(param._signal._asnNodename)))
g_TMprocessors.append(" DV.SetDataFor_%s(var_%s._ptr, self._pMem)" %
(CleanName(param._signal._asnNodename), CleanParam))
g_TMprocessors.append(" var_%s.SetData(self._pMem)" % CleanParam)
g_TMprocessors.append(' print "Parameter %s:"' % CleanParam)
g_TMprocessors.append(' var_%s.PrintAll()' % CleanParam)
g_TMprocessors.append(' print')
......
......@@ -40,7 +40,7 @@ if len(soFileNames) != 1:
print "Failed to locate a single _getset.so under", script_path
sys.exit(1)
JMP = cdll.LoadLibrary(soFileNames[0])
JMP = cdll.LoadLibrary('.' + os.sep + soFileNames[0])
# BitStream constructor
CreateStream = JMP.CreateStream
......@@ -182,15 +182,17 @@ An example for SetLength:
a.y[3].Set(16)
"""
allowed = ["_nodeTypeName", "_ptr", "_pErr", "_Caccessor", "_accessPath", "_params"]
allowed = ["_nodeTypeName", "_ptr", "_pErr", "_Caccessor", "_accessPath",
"_params", "_new_ptr"]
# , "Get", "GetLength", "Set", "SetLength", "Reset", "Encode", "Decode", "SetFromPyString", "GetPyString", "allowed"]
def __init__(self, nodeTypeName):
def __init__(self, nodeTypeName, ptr=None):
myassert(isinstance(nodeTypeName, str))
self._nodeTypeName = nodeTypeName
self._new_ptr = ptr is None
constructor = getattr(JMP, "CreateInstanceOf_" + Clean(nodeTypeName))
constructor.restype = c_void_p
self._ptr = constructor()
self._ptr = ptr or constructor()
self._pErr = CreateInstanceOf_int()
self._Caccessor = ""
self._params = []
......@@ -207,10 +209,16 @@ An example for SetLength:
def GetState(self):
return self._Caccessor[:], copy.deepcopy(self._params), self._accessPath[:]
def SetData(self, src):
bridgeFct = getattr(JMP, "SetDataFor_" + Clean(self._nodeTypeName))
bridgeFct(self._ptr, src)
def __del__(self):
''' Destructor: free memory only if it was allocated at creation '''
DestroyInstanceOf_int(self._pErr)
destructor = getattr(JMP, "DestroyInstanceOf_" + Clean(self._nodeTypeName))
destructor(self._ptr)
if self._new_ptr:
destructor = getattr(JMP, "DestroyInstanceOf_" + Clean(self._nodeTypeName))
destructor(self._ptr)
def __str__(self):
return "Choose the information you want - whole-structure or sequence dump not supported."
......
......@@ -10,15 +10,15 @@ enums_dump = "\n ".join(
for e in enums
)
uniq = os.getpid()
extractor_filename ="/tmp/enums_%d" % uniq
extractor_filename ="/tmp/enums_%d" % uniq
f = open(extractor_filename + ".c", 'w')
f.write("""
#include <stdio.h>
#include "%(base)s.h"
main()
void main()
{
%(enums_dump)s
%(enums_dump)s
}""" % {"enums_dump":enums_dump, "base":sys.argv[1]})
f.close()
if 0 != os.system(
......
......@@ -68,7 +68,7 @@ def OnStartup(unused_modelingLanguage, asnFile, outputDir):
outputFilename = os.path.basename(asnFile)
outputFilename = re.sub(r'[^a-zA-Z0-9_]', '_', outputFilename) + ".py"
origGrammarBase = os.path.basename(asnFile.replace(".asn", ""))
base = re.sub(r'[^a-zA-Z0-9_]', '_', origGrammarBase)
base = re.sub(r'[^a-zA-Z0-9_-]', '_', origGrammarBase)
inform("Python_A_mapper: Creating file '%s'...", outputFilename)
global g_outputFile
g_outputFile = open(outputDir + outputFilename, 'w')
......@@ -157,7 +157,7 @@ $(BDIR)/asn1crt.c $(BDIR)/$(GRAMMAR).c $(BDIR)/real.c $(BDIR)/acn.c $(BDIR)/ber.
$(BDIR)/DV.py: $(GRAMMAR).asn
%(tab)sgrep 'REQUIRED_BYTES_FOR_ENCODING' $(BDIR)/$(GRAMMAR).h | awk '{print $$2 " = " $$3}' > $@
%(tab)slearn_CHOICE_enums.py %(base)s >> $@
%(tab)spython learn_CHOICE_enums.py %(base)s >> $@
$(BDIR)/%%.o: $(BDIR)/%%.c
%(tab)sgcc -g -fPIC -c `python-config --includes` -o $@ $<
......@@ -476,8 +476,8 @@ def CreateDeclarationForType(nodeTypename, names, leafTypeDict):
children = [child[0] for child in node._members]
g_outputFile.write(" children_ordered = ['{}']\n\n"
.format("', '".join(children)))
g_outputFile.write(" def __init__(self):\n")
g_outputFile.write(" COMMON.__init__(self, \"" + name + "\")\n")
g_outputFile.write(" def __init__(self, ptr=None):\n")
g_outputFile.write(" super(" + name + ", self).__init__(\"" + name + "\", ptr)\n")
if isinstance(node, AsnString):
g_outputFile.write('''#\n''')
CreateGettersAndSetters(name+"_", Params(nodeTypename), "", node, names, leafTypeDict)
......
......@@ -13,4 +13,4 @@ import verify
import recursiveMapper
import cleanupNodes
__version__ = "1.1.4"
__version__ = "1.2.0"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment