Update of /cvsroot/playerstage/code/player/libplayerxdr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25787/libplayerxdr
Modified Files:
Tag: b_thjc_dynamic_arrays
Makefile.am playerxdrgen.py functiontable.h .cvsignore
functiontable.c
Log Message:
Merged some changes from head a while back
Work on updating drivers, A-J done, laser is next
Index: .cvsignore
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/.cvsignore,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -C2 -d -r1.4 -r1.4.2.1
*** .cvsignore 20 Aug 2007 06:37:26 -0000 1.4
--- .cvsignore 10 Oct 2007 09:26:07 -0000 1.4.2.1
***************
*** 5,6 ****
--- 5,11 ----
playerxdr.pc
functiontable_gen.c
+ .deps
+ .libs
+ *.lo
+ *.la
+ *.a
Index: playerxdrgen.py
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/playerxdrgen.py,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -C2 -d -r1.12 -r1.12.2.1
*** playerxdrgen.py 20 Aug 2007 19:42:48 -0000 1.12
--- playerxdrgen.py 10 Oct 2007 09:26:07 -0000 1.12.2.1
***************
*** 12,15 ****
--- 12,455 ----
USAGE = 'USAGE: playerxdrgen.y [-distro] <interface-spec.h>
[<extra_interface-spec.h>] <pack.c> <pack.h>'
+
+
+ hasdynamic = [] # A list of types that contain dynamic data. During pass 1,
+ # if a type is found to have dynamic data it will be added
+ # to this list. Then, during other passes for this and
+ # other types, necessary deep copy/clean up functions can
+ # be created and called.
+
+ class DataTypeMember:
+ arraypattern = re.compile('\[(.*?)\]')
+ pointerpattern = re.compile('\*')
+
+ def __init__(self, body):
+ # is it an array or a scalar?
+ self.array = False
+ self.pointer = False
+ self.arraysize = self.arraypattern.findall(body)
+ pointers = self.pointerpattern.findall(body)
+ if len(self.arraysize) > 0:
+ self.array = True
+ self.arraysize = self.arraysize[0]
+ body = self.arraypattern.sub('', body)
+ elif len(pointers) > 1: # This checks for things like "uint8_t* *data"
+ raise 'Illegal pointer declaration in struct\n' + body
+ elif len(pointers) > 0:
+ self.array = True
+ self.arraysize = ''
+ self.pointer = True
+ body = self.pointerpattern.sub('', body)
+
+ self.Name = body.strip()
+ self.pointervar = self.Name + '_p'
+ self.countvar = self.Name + '_count'
+
+ # multiple variables can occur with single type, i.e. int a,b,c so we first
get the type and then add each variable to the entry
+ class DataTypeMemberSet:
+ typepattern = re.compile('\s*\w+')
+ variablepattern = re.compile('\s*([^,;]+?)\s*[,;]')
+
+ def __init__(self, body):
+ self.haspointer = False
+ self.hasarray = False
+ self.variables = []
+ self.typename = self.typepattern.findall(body)[0].strip()
+ if self.typename in hasdynamic:
+ self.dynamic = True
+ else:
+ self.dynamic = False
+
+ # find the variable names
+ body = self.typepattern.sub('', body, 1)
+ vars = self.variablepattern.findall(body)
+
+
+ # iterate through each variable
+ for varstring in vars:
+ member = DataTypeMember(varstring)
+ self.variables.append(member)
+ if member.pointer:
+ self.haspointer = True
+ if member.array:
+ self.hasarray = True
+
+
+ class DataType:
+ contentspattern = re.compile('.*\{\s*(.*?)\s*\}', re.MULTILINE | re.DOTALL)
+ declpattern = re.compile('\s*([^;]*?;)', re.MULTILINE)
+
+ def __init__(self, body):
+ split = string.split(body)
+ self.prefix = split[2]
+ self.typename = split[-1]
+ self.dynamic = False
+ self.hasarray = False
+ self.haspointer = False
+
+ self.members = []
+ # pick out the contents of the struct
+ varpart = self.contentspattern.findall(body)
+ if len(varpart) != 1:
+ print 'skipping nested / empty struct ' + typename
+ raise "Empty Struct"
+ # separate the variable declarations
+ decls = self.declpattern.findall(varpart[0])
+ for dstring in decls:
+ ms = DataTypeMemberSet(dstring)
+ self.members.append(ms)
+ if ms.haspointer or ms.dynamic:
+ self.dynamic = True
+ if ms.hasarray:
+ self.hasarray = True
+ if ms.haspointer:
+ self.haspointer = True
+
+ if self.dynamic:
+ hasdynamic.append (self.typename)
+
+
+ def GetVarNames(self):
+ varnames = []
+ for m in self.members:
+ for v in m.variables:
+ varnames.append(v.Name)
+ return varnames
+
+ def HasDynamicArray(self):
+ for m in self.members:
+ if m.dynamic:
+ for v in m.variables:
+ if v.array:
+ return True
+ return False
+
+
+ class MethodGenerator:
+ def __init__(self,headerfile,sourcefile):
+ self.headerfile = headerfile
+ self.sourcefile = sourcefile
+
+
+ def gen_internal_pack(self,datatype):
+ self.headerfile.write("int xdr_%(typename)s (XDR* xdrs, %(typename)s *
msg);\n" % {"typename":datatype.typename})
+
+ self.sourcefile.write("""
+ int xdr_%(typename)s (XDR* xdrs, %(typename)s * msg)
+ { """ % {"typename":datatype.typename})
+
+ sourcefile = self.sourcefile
+
+ for member in datatype.members:
+ # Do some name mangling for common types
+ if member.typename == 'long long':
+ xdr_proc = 'xdr_longlong_t'
+ elif member.typename == 'int64_t':
+ xdr_proc = 'xdr_longlong_t'
+ elif member.typename == 'uint64_t':
+ xdr_proc = 'xdr_u_long'
+ elif member.typename == 'int32_t':
+ xdr_proc = 'xdr_int'
+ elif member.typename == 'uint32_t':
+ xdr_proc = 'xdr_u_int'
+ elif member.typename == 'int16_t':
+ xdr_proc = 'xdr_short'
+ elif member.typename == 'uint16_t':
+ xdr_proc = 'xdr_u_short'
+ elif member.typename == 'int8_t' or member.typename == 'char':
+ xdr_proc = 'xdr_char'
+ elif member.typename == 'uint8_t':
+ xdr_proc = 'xdr_u_char'
+ elif member.typename == 'bool_t':
+ xdr_proc = 'xdr_bool'
+ else:
+ # rely on a previous declaration of an xdr_ proc for this type
+ xdr_proc = 'xdr_' + member.typename
+
+ for var in member.variables:
+ if var.array:
+ if var.arraysize == '': # Handle a dynamically allocated array
+ # Check for a matching count variable, because compulsory for
dynamic arrays
+ # FIXME: Add this test back
+ if var.countvar not in datatype.GetVarNames():
+ raise 'Missing count var "' + countvar + '" in\n' + s
+ # First put in a check to see if unpacking, and if so allocate
memory for the array
+ sourcefile.write(' if(xdrs->x_op == XDR_DECODE)\n {\n')
+ sourcefile.write(' if((msg->' + var.Name + ' = malloc(msg->' +
var.countvar + '*sizeof(' + member.typename + '))) == NULL)\n
return(0);\n')
+ #sourcefile.write(' memset(msg->' + varstring + ', 0, msg->' +
countvar + '*sizeof(' + typestring + '));\n')
+ sourcefile.write(' }\n')
+ # Write the lines to (un)pack/convert
+ # Is it an array of bytes? If so, then we'll encode
+ # it a packed opaque bytestring, rather than an array of
4-byte-aligned
+ # chars.
+ if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
+ sourcefile.write(' {\n')
+ sourcefile.write(' ' + member.typename + '* ' +
var.pointervar + ' = msg->' + var.Name + ';\n')
+ sourcefile.write(' if(xdr_bytes(xdrs, (char**)&' +
var.pointervar + ', &msg->' + var.countvar + ', msg->' + var.countvar + ') !=
1)\n return(0);\n')
+ sourcefile.write(' }\n')
+ else:
+ sourcefile.write(' {\n')
+ sourcefile.write(' ' + member.typename + '* ' +
var.pointervar + ' = msg->' + var.Name + ';\n')
+ sourcefile.write(' if(xdr_array(xdrs, (char**)&' +
var.pointervar + ', &msg->' + var.countvar + ', msg->' + var.countvar +',
sizeof(' + member.typename + '), (xdrproc_t)' + xdr_proc + ') != 1)\n
return(0);\n')
+ sourcefile.write(' }\n')
+ else: # Handle a static array
+ # Was a _count variable declared? If so, we'll encode as a
+ # variable-length array (with xdr_array); otherwise we'll
+ # do it fixed-length (with xdr_vector). xdr_array is picky; we
+ # have to declare a pointer to the array, then pass in the
+ # address of this pointer. Passing the address of the array
+ # does NOT work.
+ if var.countvar in datatype.GetVarNames():
+
+ # Is it an array of bytes? If so, then we'll encode
+ # it a packed opaque bytestring, rather than an array of
4-byte-aligned
+ # chars.
+ if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
+ sourcefile.write(' {\n')
+ sourcefile.write(' ' + member.typename + '* ' +
var.pointervar +
+ ' = msg->' + var.Name + ';\n')
+ sourcefile.write(' if(xdr_bytes(xdrs, (char**)&' +
var.pointervar +
+ ', &msg->' + var.countvar +
+ ', ' + var.arraysize + ') != 1)\n
return(0);\n')
+ sourcefile.write(' }\n')
+ else:
+ sourcefile.write(' {\n')
+ sourcefile.write(' ' + member.typename + '* ' +
var.pointervar +
+ ' = msg->' + var.Name + ';\n')
+ sourcefile.write(' if(xdr_array(xdrs, (char**)&' +
var.pointervar +
+ ', &msg->' + var.countvar +
+ ', ' + var.arraysize + ', sizeof(' +
member.typename + '), (xdrproc_t)' +
+ xdr_proc + ') != 1)\n return(0);\n')
+ sourcefile.write(' }\n')
+ else:
+ # Is it an array of bytes? If so, then we'll encode
+ # it a packed opaque bytestring, rather than an array of
4-byte-aligned
+ # chars.
+ if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
+ sourcefile.write(' if(xdr_opaque(xdrs, (char*)&msg->' +
+ var.Name + ', ' + var.arraysize + ') !=
1)\n return(0);\n')
+ else:
+ sourcefile.write(' if(xdr_vector(xdrs, (char*)&msg->' +
+ var.Name + ', ' + var.arraysize +
+ ', sizeof(' + member.typename + '),
(xdrproc_t)' +
+ xdr_proc + ') != 1)\n return(0);\n')
+ else:
+ sourcefile.write(' if(' + xdr_proc + '(xdrs,&msg->' +
+ var.Name + ') != 1)\n return(0);\n')
+ #varlist.append(varstring)
+ sourcefile.write(' return(1);\n}\n')
+
+
+ def gen_external_pack(self,datatype):
+ self.headerfile.write("int %(prefix)s_pack(void* buf, size_t buflen,
%(typename)s * msg, int op);\n" % {"typename":datatype.typename,
"prefix":datatype.prefix})
+
+ self.sourcefile.write("""int
+ %(prefix)s_pack(void* buf, size_t buflen, %(typename)s * msg, int op)
+ {
+ XDR xdrs;
+ int len;
+ if(!buflen)
+ return 0;
+ xdrmem_create(&xdrs, buf, buflen, op);
+ if(xdr_%(typename)s(&xdrs,msg) != 1)
+ return(-1);
+ if(op == PLAYERXDR_ENCODE)
+ len = xdr_getpos(&xdrs);
+ else
+ len = sizeof(%(typename)s);
+ xdr_destroy(&xdrs);
+ return(len);
+ } """ % {"typename":datatype.typename, "prefix":datatype.prefix})
+
+
+ def gen_copy(self,datatype):
+ # If type is not in hasdynamic, not going to write a function so may as
well just continue with the next struct
+ self.headerfile.write("unsigned int %(typename)s_copy(%(typename)s *dest,
const %(typename)s *src);\n" % {"typename":datatype.typename,
"prefix":datatype.prefix})
+ if datatype.typename not in hasdynamic:
+ self.sourcefile.write("""
+ unsigned int %(typename)s_copy(%(typename)s *dest, const %(typename)s *src)
+ {
+ if (dest == NULL || src == NULL)
+ return 0;
+ memcpy(dest,src,sizeof(%(typename)s));
+ return sizeof(%(typename)s);
+ } """ % {"typename":datatype.typename})
+ else:
+ if datatype.HasDynamicArray():
+ itrdec = "unsigned ii;"
+ else:
+ itrdec = ""
+ self.sourcefile.write("""
+ unsigned int %(typename)s_copy(%(typename)s *dest, const %(typename)s *src)
+ {
+ %(itrdec)s
+ unsigned int size = 0;
+ if(src == NULL)
+ return(0);""" % {"typename":datatype.typename, "itrdec" : itrdec} )
+
+ for member in datatype.members:
+ for var in member.variables:
+ subs = {"varstring" : var.Name, "countvar" : var.countvar,
"typestring" : member.typename, "arraysize" : var.arraysize }
+ if var.pointer: # Handle a dynamically allocated array
+ sourcefile.write("""
+ if(src->%(varstring)s != NULL && src->%(countvar)s > 0)
+ {
+ if((dest->%(varstring)s =
calloc(src->%(countvar)s,sizeof(%(typestring)s))) == NULL)
+ return(0);
+ }
+ else
+ dest->%(varstring)s = NULL;""" % subs)
+
+ if var.array:
+ subs["amp"] = ""
+ subs["index"] = "[ii]"
+ if var.countvar in datatype.GetVarNames():
+ subs["arraysize"] = "src->"+var.countvar
+ else:
+ subs["arraysize"] = var.arraysize
+ else:
+ subs["arraysize"] = 1
+ subs["amp"] = "&"
+ subs["index"] = ""
+
+ if member.dynamic:
+ if var.array:
+ sourcefile.write("""
+ for(ii = 0; ii < %(arraysize)s; ii++)""" % subs)
+ sourcefile.write("""
+ {size += %(typestring)s_copy(&dest->%(varstring)s%(index)s,
&src->%(varstring)s%(index)s);}""" % subs)
+
+
+ else: #plain old variable or array
+ sourcefile.write("""
+ size += sizeof(%(typestring)s)*%(arraysize)s;
+
memcpy(%(amp)sdest->%(varstring)s,%(amp)ssrc->%(varstring)s,sizeof(%(typestring)s)*%(arraysize)s);
""" % subs)
+
+ sourcefile.write("""
+ return(size);
+ }""")
+
+
+
+ def gen_cleanup(self,datatype):
+ # If type is not in hasdynamic, not going to write a function so may as
well just continue with the next struct
+ self.headerfile.write("void %(typename)s_cleanup(const %(typename)s
*msg);\n" % {"typename":datatype.typename})
+ if datatype.typename not in hasdynamic:
+ self.sourcefile.write("""
+ void %(typename)s_cleanup(const %(typename)s *msg)
+ {
+ } """ % {"typename":datatype.typename})
+ else:
+ if datatype.HasDynamicArray():
+ itrdec = "unsigned ii;"
+ else:
+ itrdec = ""
+ self.sourcefile.write("""
+ void %(typename)s_cleanup(const %(typename)s *msg)
+ {
+ %(itrdec)s
+ if(msg == NULL)
+ return;""" % {"typename":datatype.typename, "itrdec" : itrdec} )
+
+ for member in datatype.members:
+ for var in member.variables:
+ subs = {"varstring" : var.Name, "countvar" : var.countvar,
"typestring" : member.typename, "arraysize" : var.arraysize }
+ if member.dynamic:
+ if var.array:
+ if var.countvar in datatype.GetVarNames():
+ formax = "msg->"+var.countvar
+ else:
+ formax = var.arraysize
+ subs["formax"] = formax
+ sourcefile.write("""
+ for(ii = 0; ii < %(formax)s; ii++)
+ {
+ %(typestring)s_cleanup(&msg->%(varstring)s[ii]);
+ }""" % subs)
+ else:
+ sourcefile.write("""
+ %(typestring)s_cleanup(&msg->%(varstring)s); """ % subs)
+ if var.pointer:
+ sourcefile.write("""
+ free(msg->%(varstring)s); """ % subs)
+
+ sourcefile.write("\n}")
+
+ def gen_clone(self,datatype):
+ # If type is not in hasdynamic, not going to write a function so may as
well just continue with the next struct
+ self.headerfile.write("%(typename)s * %(typename)s_clone(const
%(typename)s *msg);\n" % {"typename":datatype.typename})
+ self.sourcefile.write("""
+ %(typename)s * %(typename)s_clone(const %(typename)s *msg)
+ {
+ %(typename)s * clone = malloc(sizeof(%(typename)s));
+ if (clone)
+ %(typename)s_copy(clone,msg);
+ return clone;
+ }""" % {"typename":datatype.typename})
+
+ def gen_free(self,datatype):
+ # If type is not in hasdynamic, not going to write a function so may as
well just continue with the next struct
+ self.headerfile.write("void %(typename)s_free(%(typename)s *msg);\n" %
{"typename":datatype.typename})
+ self.sourcefile.write("""
+ void %(typename)s_free(%(typename)s *msg)
+ {
+ %(typename)s_cleanup(msg);
+ free(msg);
+ }""" % {"typename":datatype.typename})
+
+
+ def gen_sizeof(self,datatype):
+ self.headerfile.write("unsigned int %(typename)s_sizeof(%(typename)s
*msg);\n" % {"typename":datatype.typename})
+ if datatype.typename not in hasdynamic:
+ self.sourcefile.write("""
+ unsigned int %(typename)s_sizeof(%(typename)s *msg)
+ {
+ return sizeof(%(typename)s);
+ } """ % {"typename":datatype.typename})
+ else:
+ if datatype.HasDynamicArray():
+ itrdec = "unsigned ii;"
+ else:
+ itrdec = ""
+ self.sourcefile.write("""
+ unsigned int %(typename)s_sizeof(%(typename)s *msg)
+ {
+ %(itrdec)s
+ unsigned int size = 0;
+ if(msg == NULL)
+ return(0);""" % {"typename":datatype.typename, "itrdec" : itrdec} )
+
+ for member in datatype.members:
+ for var in member.variables:
+ subs = {"varstring" : var.Name, "countvar" : var.countvar,
"typestring" : member.typename, "arraysize" : var.arraysize }
+ if var.array:
+ subs["amp"] = ""
+ subs["index"] = "[ii]"
+ if var.countvar in datatype.GetVarNames():
+ subs["arraysize"] = "msg->"+var.countvar
+ else:
+ subs["arraysize"] = var.arraysize
+ else:
+ subs["arraysize"] = 1
+ subs["amp"] = "&"
+ subs["index"] = ""
+
+ if member.dynamic:
+ if var.array:
+ sourcefile.write("""
+ for(ii = 0; ii < %(arraysize)s; ii++)""" % subs)
+ sourcefile.write("""
+ {size += %(typestring)s_sizeof(&msg->%(varstring)s%(index)s);}""" % subs)
+
+
+ else: #plain old variable or array
+ sourcefile.write("""
+ size += sizeof(%(typestring)s)*%(arraysize)s; """ % subs)
+
+ sourcefile.write("""
+ return(size);
+ }""")
+
+
if __name__ == '__main__':
***************
*** 50,53 ****
--- 490,542 ----
headerfile = open(headerfilename, 'w+')
+ if distro:
+ headerfile.write("""
+ /** @ingroup libplayerxdr
+ @{ */
+ #ifndef _PLAYERXDR_PACK_H_
+ #define _PLAYERXDR_PACK_H_
+
+ #include <rpc/types.h>
+ #include <rpc/xdr.h>
+
+ #include <libplayercore/player.h>
+ #include <libplayerxdr/functiontable.h>
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ #ifndef XDR_ENCODE
+ #define XDR_ENCODE 0
+ #endif
+ #ifndef XDR_DECODE
+ #define XDR_DECODE 1
+ #endif
+ #define PLAYERXDR_ENCODE XDR_ENCODE
+ #define PLAYERXDR_DECODE XDR_DECODE
+
+ #define PLAYERXDR_MSGHDR_SIZE 40
+ #define PLAYERXDR_MAX_MESSAGE_SIZE (4*PLAYER_MAX_MESSAGE_SIZE)
+ """)
+ sourcefile.write("""
+ #include <libplayerxdr/%(headerfilename)s>
+ #include <string.h>
+
+ #include <stdlib.h>
+ """ % {"headerfilename":headerfilename})
+ else:
+ ifndefsymbol = '_'
+ for i in range(0,len(string.split(infilenames[0],'.')[0])):
+ ifndefsymbol += string.capitalize(infilenames[0][i])
+ ifndefsymbol += '_'
+ headerfile.write('#ifndef ' + ifndefsymbol + '\n\n')
+ headerfile.write('#include <libplayerxdr/playerxdr.h>\n\n')
+ headerfile.write('#include "' + infilenames[0] + '"\n\n')
+ headerfile.write('#ifdef __cplusplus\nextern "C" {\n#endif\n\n')
+ sourcefile.write('#include <rpc/types.h>\n')
+ sourcefile.write('#include <rpc/xdr.h>\n\n')
+ sourcefile.write('#include "' + headerfilename + '"\n')
+ sourcefile.write('#include <string.h>\n')
+ sourcefile.write('#include <stdlib.h>\n\n')
+
+
# strip C++-style comments
pattern = re.compile('//.*')
***************
*** 68,420 ****
print 'Found ' + `len(structs)` + ' struct(s)'
!
! if distro:
! headerfile.write(
! '''/** @ingroup libplayerxdr
! @{ */\n\n''')
! headerfile.write('#ifndef _PLAYERXDR_PACK_H_\n')
! headerfile.write('#define _PLAYERXDR_PACK_H_\n\n')
! headerfile.write('#include <rpc/types.h>\n')
! headerfile.write('#include <rpc/xdr.h>\n\n')
! headerfile.write('#include <libplayercore/player.h>\n\n')
! headerfile.write('#include <libplayerxdr/functiontable.h>\n\n')
! headerfile.write('#ifdef __cplusplus\nextern "C" {\n#endif\n\n')
! headerfile.write('#ifndef XDR_ENCODE\n')
! headerfile.write(' #define XDR_ENCODE 0\n')
! headerfile.write('#endif\n')
! headerfile.write('#ifndef XDR_DECODE\n')
! headerfile.write(' #define XDR_DECODE 1\n')
! headerfile.write('#endif\n')
! headerfile.write('#define PLAYERXDR_ENCODE XDR_ENCODE\n')
! headerfile.write('#define PLAYERXDR_DECODE XDR_DECODE\n\n')
! headerfile.write('#define PLAYERXDR_MSGHDR_SIZE 40\n\n')
! headerfile.write('#define PLAYERXDR_MAX_MESSAGE_SIZE
(4*PLAYER_MAX_MESSAGE_SIZE)\n\n')
!
! sourcefile.write('#include <libplayerxdr/' + headerfilename + '>\n')
! sourcefile.write('#include <string.h>\n\n')
! sourcefile.write('#include <stdlib.h>\n\n')
! else:
! ifndefsymbol = '_'
! for i in range(0,len(string.split(infilename,'.')[0])):
! ifndefsymbol += string.capitalize(infilename[i])
! ifndefsymbol += '_'
! headerfile.write('#ifndef ' + ifndefsymbol + '\n\n')
! headerfile.write('#include <libplayerxdr/playerxdr.h>\n\n')
! headerfile.write('#include "' + infilename + '"\n\n')
! headerfile.write('#ifdef __cplusplus\nextern "C" {\n#endif\n\n')
! sourcefile.write('#include <rpc/types.h>\n')
! sourcefile.write('#include <rpc/xdr.h>\n\n')
! sourcefile.write('#include "' + headerfilename + '"\n')
! sourcefile.write('#include <string.h>')
! sourcefile.write('#include <stdlib.h>\n\n')
!
! contentspattern = re.compile('.*\{\s*(.*?)\s*\}', re.MULTILINE | re.DOTALL)
! declpattern = re.compile('\s*([^;]*?;)', re.MULTILINE)
! typepattern = re.compile('\s*\S+')
! variablepattern = re.compile('\s*([^,;]+?)\s*[,;]')
#arraypattern = re.compile('\[\s*(\w*?)\s*\]')
- arraypattern = re.compile('\[(.*?)\]')
# pointerpattern = re.compile('[A-Za-z0-9_]+\*|\*[A-Za-z0-9_]+')
- pointerpattern = re.compile('\*')
! hasdynamic = [] # A list of types that contain dynamic data. During pass
1,
! # if a type is found to have dynamic data it will be
added
! # to this list. Then, during other passes for this and
! # other types, necessary deep copy/clean up functions can
! # be created and called.
for s in structs:
# extract prefix for packing function name and type of struct
! split = string.split(s)
! prefix = split[2]
! typename = split[-1]
!
! # pick out the contents of the struct
! varpart = contentspattern.findall(s)
! if len(varpart) != 1:
! print 'skipping nested / empty struct ' + typename
! continue
!
! # First time through this loop, we write an xdr_ function for the
! # struct; this function will be used internally if the struct appears
! # inside another struct.
! #
! # Second time through, we write a _pack function for external use.
! # Third time through, we write a _dpcpy function if needed.
! # Fourth time through, we write a _cleanup function if needed.
! for i in range(0,4):
!
! if i == 0:
! headerfile.write('int xdr_' + typename + '(XDR* xdrs, ' + typename +
! '* msg);\n')
! sourcefile.write('int\nxdr_' + typename + '(XDR* xdrs, ' + typename +
! '* msg)\n{\n')
! elif i == 1:
! headerfile.write('int ' + prefix + '_pack(void* buf, size_t buflen, '
+
! typename + '* msg, int op);\n')
! sourcefile.write('int\n' + prefix + '_pack(void* buf, size_t buflen,
' +
! typename + '* msg, int op)\n{\n')
! sourcefile.write(' XDR xdrs;\n')
! sourcefile.write(' int len;\n')
! sourcefile.write(' if(!buflen)\n')
! sourcefile.write(' return(0);\n')
! sourcefile.write(' xdrmem_create(&xdrs, buf, buflen, op);\n')
! elif i == 2:
! # If type is not in hasdynamic, not going to write a function so may
as well just continue with the next struct
! if typename not in hasdynamic:
! headerfile.write('#define ' + typename + '_dpcpy NULL\n')
! continue
! headerfile.write('unsigned int ' + typename + '_dpcpy(const ' +
typename + '* src, ' + typename + '* dest);\n')
! sourcefile.write('unsigned int\n' + typename + '_dpcpy(const ' +
typename + '* src, ' + typename + '* dest)\n{\n')
! #sourcefile.write(' printf ("' + typename + '_dpcpy starting\\n");
fflush(NULL);\n')
! sourcefile.write(' unsigned ii;\nif(src == NULL)\n return(0);\n')
! sourcefile.write(' unsigned int size = 0;\n')
! else:
! # If type is not in hasdynamic, not going to write a function so may
as well just continue with the next struct
! if typename not in hasdynamic:
! headerfile.write('#define ' + typename + '_cleanup NULL\n')
! continue
! headerfile.write('void ' + typename + '_cleanup(' + typename + '*
msg);\n')
! sourcefile.write('void\n' + typename + '_cleanup(' + typename + '*
msg)\n{\n')
! #sourcefile.write(' printf("' + typename + '_cleanup starting\\n");
fflush(NULL);\n')
! sourcefile.write(' unsigned ii;\nif(msg == NULL)\n return;\n')
!
! varlist = []
!
! # separate the variable declarations
! decls = declpattern.findall(varpart[0])
! for dstring in decls:
! # find the type and variable names in this declaration
! typestring = typepattern.findall(dstring)[0]
! dstring = typepattern.sub('', dstring, 1)
! vars = variablepattern.findall(dstring)
!
! # Check for pointer in type part
! numstars = len (pointerpattern.findall (typestring))
! if numstars > 0:
! typestring = typestring[:-1 * numstars]
! # Do some name mangling for common types
! if typestring == 'long long':
! xdr_proc = 'xdr_longlong_t'
! elif typestring == 'int64_t':
! xdr_proc = 'xdr_longlong_t'
! elif typestring == 'uint64_t':
! xdr_proc = 'xdr_u_long'
! elif typestring == 'int32_t':
! xdr_proc = 'xdr_int'
! elif typestring == 'uint32_t':
! xdr_proc = 'xdr_u_int'
! elif typestring == 'int16_t':
! xdr_proc = 'xdr_short'
! elif typestring == 'uint16_t':
! xdr_proc = 'xdr_u_short'
! elif typestring == 'int8_t' or typestring == 'char':
! xdr_proc = 'xdr_char'
! elif typestring == 'uint8_t':
! xdr_proc = 'xdr_u_char'
! elif typestring == 'bool_t':
! xdr_proc = 'xdr_bool'
! else:
! # rely on a previous declaration of an xdr_ proc for this type
! xdr_proc = 'xdr_' + typestring
! # Check if this type has dynamic data, if it does then the current
struct will to
! if typestring in hasdynamic and typename not in hasdynamic:
! hasdynamic.append (typename)
!
! # iterate through each variable
! for varstring in vars:
! # is it an array or a scalar?
! array = False
! arraysize = arraypattern.findall(varstring)
! pointersize = pointerpattern.findall(varstring)
! if len(arraysize) > 0:
! array = True
! arraysize = arraysize[0]
! varstring = arraypattern.sub('', varstring)
! elif len(pointersize) > 0 and numstars > 0: # This checks for
things like "uint8_t* *data"
! raise 'Illegal pointer declaration in struct\n' + s
! elif len(pointersize) > 0 or numstars > 0:
! array = True
! arraysize = ''
! varstring = pointerpattern.sub('', varstring)
!
! if array:
! pointervar = varstring + '_p'
! countvar = varstring + '_count'
! if arraysize == '': # Handle a dynamically allocated array
! # Make a note that this structure has dynamic data (need to
know for passes 3 and 4, and for other messages)
! if typename not in hasdynamic:
! hasdynamic.append (typename)
! # Check for a matching count variable, because compulsory for
dynamic arrays
! if countvar not in varlist:
! raise 'Missing count var "' + countvar + '" in\n' + s
! # First put in a check to see if unpacking, and if so allocate
memory for the array
! if i == 0:
! sourcefile.write(' if(xdrs->x_op == XDR_DECODE)\n {\n')
! sourcefile.write(' if((msg->' + varstring + ' =
malloc(msg->' + countvar + '*sizeof(' + typestring + '))) == NULL)\n
return(0);\n')
! #sourcefile.write(' memset(msg->' + varstring + ', 0,
msg->' + countvar + '*sizeof(' + typestring + '));\n')
! sourcefile.write(' }\n')
! if i == 1:
! sourcefile.write(' if(op == PLAYERXDR_DECODE)\n {\n')
! sourcefile.write(' if((msg->' + varstring + ' =
malloc(msg->' + countvar + '*sizeof(' + typestring + '))) == NULL)\n
return(-1);\n')
! #sourcefile.write(' memset(msg->' + varstring + ', 0,
msg->' + countvar + '*sizeof(' + typestring + '));\n')
! sourcefile.write(' }\n')
! # Write the lines to (un)pack/convert
! # Is it an array of bytes? If so, then we'll encode
! # it a packed opaque bytestring, rather than an array of
4-byte-aligned
! # chars.
! if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
! if i == 0:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_bytes(xdrs, (char**)&' +
pointervar + ', &msg->' + countvar + ', msg->' + countvar + ') != 1)\n
return(0);\n')
! sourcefile.write(' }\n')
! elif i == 1:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_bytes(&xdrs, (char**)&' +
pointervar + ', &msg->' + countvar + ', msg->' + countvar + ') != 1)\n
return(-1);\n')
! sourcefile.write(' }\n')
! else:
! if i == 0:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_array(xdrs, (char**)&' +
pointervar + ', &msg->' + countvar + ', msg->' + countvar +', sizeof(' +
typestring + '), (xdrproc_t)' + xdr_proc + ') != 1)\n return(0);\n')
! sourcefile.write(' }\n')
! elif i == 1:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_array(&xdrs, (char**)&' +
pointervar + ', &msg->' + countvar + ', msg->' + countvar +', sizeof(' +
typestring + '), (xdrproc_t)' + xdr_proc + ') != 1)\n return(-1);\n')
! sourcefile.write(' }\n')
! if i == 2:
! #sourcefile.write(' printf ("deep copying, src = %p, dest =
%p\\n", src, dest);\n')
! sourcefile.write(' if(src->' + varstring + ' != NULL &&
src->' + countvar + ' > 0)\n {\n')
! #sourcefile.write(' printf ("deep copying, src->' +
varstring + ' = %p, dest->' + varstring + ' = %p\\n", src->' + varstring + ',
dest->' + varstring + ');\n')
! sourcefile.write(' if((dest->' + varstring + ' =
malloc(src->' + countvar + '*sizeof(' + typestring + '))) == NULL)\n
return(0);\n')
! sourcefile.write(' memcpy(dest->' + varstring + ', src->'
+ varstring + ', src->' + countvar + '*sizeof(' + typestring + '));\n')
! sourcefile.write(' size += src->' + countvar + '*sizeof('
+ typestring + ');\n }\n')
! sourcefile.write(' else\n dest->' + varstring + ' =
NULL;\n')
! if typestring in hasdynamic: # Need to deep copy embedded
structures
! sourcefile.write(' for(ii = 0; ii < src->' + countvar + ';
ii++)\n {\n')
! sourcefile.write(' size += ' + typestring +
'_dpcpy(&(src->' + varstring + '[ii]), &(dest->' + varstring + '[ii]));\n }\n')
! elif i == 3:
! sourcefile.write(' if(msg->' + varstring + ' == NULL)\n
return;\n')
! if typestring in hasdynamic: # Need to clean up embedded
structures
! sourcefile.write(' for(ii = 0; ii < msg->' + countvar + ';
ii++)\n {\n')
! sourcefile.write(' ' + typestring + '_cleanup(&(msg->' +
varstring + '[ii]));\n }\n')
! sourcefile.write(' free(msg->' + varstring + ');\n')
! else: # Handle a static array
! # Was a _count variable declared? If so, we'll encode as a
! # variable-length array (with xdr_array); otherwise we'll
! # do it fixed-length (with xdr_vector). xdr_array is picky; we
! # have to declare a pointer to the array, then pass in the
! # address of this pointer. Passing the address of the array
! # does NOT work.
! if countvar in varlist:
!
! # Is it an array of bytes? If so, then we'll encode
! # it a packed opaque bytestring, rather than an array of
4-byte-aligned
! # chars.
! if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
! if i == 0:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
! ' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_bytes(xdrs, (char**)&' +
pointervar +
! ', &msg->' + countvar +
! ', ' + arraysize + ') != 1)\n
return(0);\n')
! sourcefile.write(' }\n')
! elif i == 1:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
! ' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_bytes(&xdrs, (char**)&' +
pointervar +
! ', &msg->' + countvar +
! ', ' + arraysize + ') != 1)\n
return(-1);\n')
! sourcefile.write(' }\n')
! else:
! if i == 0:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
! ' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_array(xdrs, (char**)&' +
pointervar +
! ', &msg->' + countvar +
! ', ' + arraysize + ', sizeof(' +
typestring + '), (xdrproc_t)' +
! xdr_proc + ') != 1)\n return(0);\n')
! sourcefile.write(' }\n')
! elif i == 1:
! sourcefile.write(' {\n')
! sourcefile.write(' ' + typestring + '* ' + pointervar +
! ' = msg->' + varstring + ';\n')
! sourcefile.write(' if(xdr_array(&xdrs, (char**)&' +
pointervar +
! ', &msg->' + countvar +
! ', ' + arraysize + ', sizeof(' +
typestring + '), (xdrproc_t)' +
! xdr_proc + ') != 1)\n return(-1);\n')
! sourcefile.write(' }\n')
! if typestring in hasdynamic: # Need to deep copy/clean
up embedded structures
! if i == 2:
! sourcefile.write(' for(ii = 0; ii < src->' + countvar
+ '; ii++)\n {\n')
! sourcefile.write(' size += ' + typestring +
'_dpcpy(&(src->' + varstring + '[ii]), &(dest->' + varstring + '[ii]));\n }\n')
! elif i == 3:
! sourcefile.write(' for(ii = 0; ii < msg->' + countvar
+ '; ii++)\n {\n')
! sourcefile.write(' ' + typestring +
'_cleanup(&(msg->' + varstring + '[ii]));\n }\n')
! else:
! # Is it an array of bytes? If so, then we'll encode
! # it a packed opaque bytestring, rather than an array of
4-byte-aligned
! # chars.
! if xdr_proc == 'xdr_u_char' or xdr_proc == 'xdr_char':
! if i == 0:
! sourcefile.write(' if(xdr_opaque(xdrs, (char*)&msg->' +
! varstring + ', ' + arraysize + ') != 1)\n
return(0);\n')
! elif i == 1:
! sourcefile.write(' if(xdr_opaque(&xdrs, (char*)&msg->' +
! varstring + ', ' + arraysize + ') != 1)\n
return(-1);\n')
! else:
! if i == 0:
! sourcefile.write(' if(xdr_vector(xdrs, (char*)&msg->' +
! varstring + ', ' + arraysize +
! ', sizeof(' + typestring + '),
(xdrproc_t)' +
! xdr_proc + ') != 1)\n return(0);\n')
! elif i == 1:
! sourcefile.write(' if(xdr_vector(&xdrs, (char*)&msg->' +
! varstring + ', ' + arraysize +
! ', sizeof(' + typestring + '),
(xdrproc_t)' +
! xdr_proc + ') != 1)\n return(-1);\n')
! if typestring in hasdynamic: # Need to deep copy/clean
up embedded structures
! if i == 2:
! sourcefile.write(' for(ii = 0; ii < ' + arraysize + ';
ii++)\n {\n')
! sourcefile.write(' size += ' + typestring +
'_dpcpy(&(src->' + varstring + '[ii]), &(dest->' + varstring + '[ii]));\n }\n')
! elif i == 3:
! sourcefile.write(' for(ii = 0; ii < ' + arraysize + ';
ii++)\n {\n')
! sourcefile.write(' ' + typestring +
'_cleanup(&(msg->' + varstring + '[ii]_);\n }\n')
! else:
! if i == 0:
! sourcefile.write(' if(' + xdr_proc + '(xdrs,&msg->' +
! varstring + ') != 1)\n return(0);\n')
! elif i == 1:
! sourcefile.write(' if(' + xdr_proc + '(&xdrs,&msg->' +
! varstring + ') != 1)\n return(-1);\n')
! if typestring in hasdynamic: # Need to deep copy/clean up
embedded structures
! if i == 2:
! sourcefile.write(' size += ' + typestring + '_dpcpy(&src->'
+ varstring + ', &dest->' + varstring + ');\n')
! elif i == 3:
! sourcefile.write(' ' + typestring + '_cleanup(&msg->' +
varstring + ');\n')
!
! varlist.append(varstring)
! if i == 0:
! sourcefile.write(' return(1);\n}\n\n')
! elif i == 1:
! sourcefile.write(' if(op == PLAYERXDR_ENCODE)\n')
! sourcefile.write(' len = xdr_getpos(&xdrs);\n')
! sourcefile.write(' else\n')
! sourcefile.write(' len = sizeof(' + typename + ');\n')
! sourcefile.write(' xdr_destroy(&xdrs);\n')
! sourcefile.write(' return(len);\n')
! sourcefile.write('}\n\n')
! elif i == 2:
! #sourcefile.write(' printf ("' + typename + '_dpcpy done, size =
%d\\n", size); fflush(NULL);\n')
! sourcefile.write(' return(size);\n}\n\n')
! else:
! #sourcefile.write(' printf("' + typename + '_cleanup done\\n");
fflush(NULL);\n')
! sourcefile.write('}\n\n')
headerfile.write('\n#ifdef __cplusplus\n}\n#endif\n\n')
headerfile.write('#endif\n')
--- 557,580 ----
print 'Found ' + `len(structs)` + ' struct(s)'
!
#arraypattern = re.compile('\[\s*(\w*?)\s*\]')
# pointerpattern = re.compile('[A-Za-z0-9_]+\*|\*[A-Za-z0-9_]+')
! gen = MethodGenerator(headerfile,sourcefile)
!
for s in structs:
# extract prefix for packing function name and type of struct
! current = DataType(s)
+ # Generate the methods
+ gen.gen_internal_pack(current)
+ gen.gen_external_pack(current)
+ gen.gen_copy(current)
+ gen.gen_cleanup(current)
+ gen.gen_clone(current)
+ gen.gen_free(current)
+ gen.gen_sizeof(current)
+ sourcefile.write('\n')
+
headerfile.write('\n#ifdef __cplusplus\n}\n#endif\n\n')
headerfile.write('#endif\n')
***************
*** 424,426 ****
sourcefile.close()
headerfile.close()
!
--- 584,586 ----
sourcefile.close()
headerfile.close()
!
\ No newline at end of file
Index: functiontable.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/functiontable.c,v
retrieving revision 1.89
retrieving revision 1.89.2.1
diff -C2 -d -r1.89 -r1.89.2.1
*** functiontable.c 20 Aug 2007 06:37:26 -0000 1.89
--- functiontable.c 10 Oct 2007 09:26:07 -0000 1.89.2.1
***************
*** 64,82 ****
(player_pack_fn_t)player_capabilities_req_pack, NULL, NULL},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_INTPROP_REQ,
! (player_pack_fn_t)player_intprop_req_pack,
(player_dpcpy_fn_t)player_intprop_req_t_dpcpy,
(player_cleanup_fn_t)player_intprop_req_t_cleanup},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_INTPROP_REQ,
! (player_pack_fn_t)player_intprop_req_pack,
(player_dpcpy_fn_t)player_intprop_req_t_dpcpy,
(player_cleanup_fn_t)player_intprop_req_t_cleanup},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_DBLPROP_REQ,
! (player_pack_fn_t)player_dblprop_req_pack,
(player_dpcpy_fn_t)player_dblprop_req_t_dpcpy,
(player_cleanup_fn_t)player_dblprop_req_t_cleanup},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_DBLPROP_REQ,
! (player_pack_fn_t)player_dblprop_req_pack,
(player_dpcpy_fn_t)player_dblprop_req_t_dpcpy,
(player_cleanup_fn_t)player_dblprop_req_t_cleanup},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_STRPROP_REQ,
! (player_pack_fn_t)player_strprop_req_pack,
(player_dpcpy_fn_t)player_strprop_req_t_dpcpy,
(player_cleanup_fn_t)player_strprop_req_t_cleanup},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_STRPROP_REQ,
! (player_pack_fn_t)player_strprop_req_pack,
(player_dpcpy_fn_t)player_strprop_req_t_dpcpy,
(player_cleanup_fn_t)player_strprop_req_t_cleanup},
/* Special messages */
{PLAYER_PLAYER_CODE, PLAYER_MSGTYPE_SYNCH, 0,
! (player_pack_fn_t)player_add_replace_rule_req_pack, NULL, NULL},
/* generated messages from the interface definitions */
--- 64,88 ----
(player_pack_fn_t)player_capabilities_req_pack, NULL, NULL},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_INTPROP_REQ,
! (player_pack_fn_t)player_intprop_req_pack,
(player_copy_fn_t)player_intprop_req_t_copy,
(player_cleanup_fn_t)player_intprop_req_t_cleanup,
!
(player_clone_fn_t)player_intprop_req_t_clone,(player_free_fn_t)player_intprop_req_t_free,(player_sizeof_fn_t)player_intprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_INTPROP_REQ,
! (player_pack_fn_t)player_intprop_req_pack,
(player_copy_fn_t)player_intprop_req_t_copy,
(player_cleanup_fn_t)player_intprop_req_t_cleanup,
!
(player_clone_fn_t)player_intprop_req_t_clone,(player_free_fn_t)player_intprop_req_t_free,(player_sizeof_fn_t)player_intprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_DBLPROP_REQ,
! (player_pack_fn_t)player_dblprop_req_pack,
(player_copy_fn_t)player_dblprop_req_t_copy,
(player_cleanup_fn_t)player_dblprop_req_t_cleanup,
!
(player_clone_fn_t)player_dblprop_req_t_clone,(player_free_fn_t)player_dblprop_req_t_free,(player_sizeof_fn_t)player_dblprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_DBLPROP_REQ,
! (player_pack_fn_t)player_dblprop_req_pack,
(player_copy_fn_t)player_dblprop_req_t_copy,
(player_cleanup_fn_t)player_dblprop_req_t_cleanup,
!
(player_clone_fn_t)player_dblprop_req_t_clone,(player_free_fn_t)player_dblprop_req_t_free,(player_sizeof_fn_t)player_dblprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_GET_STRPROP_REQ,
! (player_pack_fn_t)player_strprop_req_pack,
(player_copy_fn_t)player_strprop_req_t_copy,
(player_cleanup_fn_t)player_strprop_req_t_cleanup,
!
(player_clone_fn_t)player_strprop_req_t_clone,(player_free_fn_t)player_strprop_req_t_free,(player_sizeof_fn_t)player_strprop_req_t_sizeof},
{0, PLAYER_MSGTYPE_REQ, PLAYER_SET_STRPROP_REQ,
! (player_pack_fn_t)player_strprop_req_pack,
(player_copy_fn_t)player_strprop_req_t_copy,
(player_cleanup_fn_t)player_strprop_req_t_cleanup,
!
(player_clone_fn_t)player_strprop_req_t_clone,(player_free_fn_t)player_strprop_req_t_free,(player_sizeof_fn_t)player_strprop_req_t_sizeof},
/* Special messages */
{PLAYER_PLAYER_CODE, PLAYER_MSGTYPE_SYNCH, 0,
! (player_pack_fn_t)player_add_replace_rule_req_pack, NULL, NULL, NULL,
NULL, NULL},
/* generated messages from the interface definitions */
***************
*** 132,138 ****
(curr->type == f.type))
{
! curr->packfunc = f.packfunc;
! curr->dpcpyfunc = f.dpcpyfunc;
! curr->cleanupfunc = f.cleanupfunc;
return(0);
}
--- 138,142 ----
(curr->type == f.type))
{
! *curr = f;
return(0);
}
***************
*** 223,233 ****
}
! player_dpcpy_fn_t
! playerxdr_get_dpcpyfunc(uint16_t interf, uint8_t type, uint8_t subtype)
{
playerxdr_function_t* row=NULL;
if ((row = playerxdr_get_ftrow (interf, type, subtype)) != NULL)
! return(row->dpcpyfunc);
return(NULL);
--- 227,237 ----
}
! player_copy_fn_t
! playerxdr_get_copyfunc(uint16_t interf, uint8_t type, uint8_t subtype)
{
playerxdr_function_t* row=NULL;
if ((row = playerxdr_get_ftrow (interf, type, subtype)) != NULL)
! return(row->copyfunc);
return(NULL);
***************
*** 245,263 ****
}
// Deep copy a message structure
unsigned int
playerxdr_deepcopy_message(void* src, void* dest, uint16_t interf, uint8_t
type, uint8_t subtype)
{
! player_dpcpy_fn_t dpcpyfunc = NULL;
! if ((dpcpyfunc = playerxdr_get_dpcpyfunc(interf, type, subtype)) == NULL)
return 0;
! return (*dpcpyfunc)(src, dest);
}
! // Delete any dynamically allocated data in a message structure
void
! playerxdr_delete_message(void* msg, uint16_t interf, uint8_t type, uint8_t
subtype)
{
player_cleanup_fn_t cleanupfunc = NULL;
--- 249,321 ----
}
+ player_clone_fn_t
+ playerxdr_get_clonefunc(uint16_t interf, uint8_t type, uint8_t subtype)
+ {
+ playerxdr_function_t* row=NULL;
+
+ if ((row = playerxdr_get_ftrow (interf, type, subtype)) != NULL)
+ return(row->clonefunc);
+
+ return(NULL);
+ }
+
+ player_free_fn_t
+ playerxdr_get_freefunc(uint16_t interf, uint8_t type, uint8_t subtype)
+ {
+ playerxdr_function_t* row=NULL;
+
+ if ((row = playerxdr_get_ftrow (interf, type, subtype)) != NULL)
+ return(row->freefunc);
+
+ return(NULL);
+ }
+
+ player_sizeof_fn_t
+ playerxdr_get_sizeoffunc(uint16_t interf, uint8_t type, uint8_t subtype)
+ {
+ playerxdr_function_t* row=NULL;
+
+ if ((row = playerxdr_get_ftrow (interf, type, subtype)) != NULL)
+ return(row->sizeoffunc);
+
+ return(NULL);
+ }
+
// Deep copy a message structure
unsigned int
playerxdr_deepcopy_message(void* src, void* dest, uint16_t interf, uint8_t
type, uint8_t subtype)
{
! player_copy_fn_t copyfunc = NULL;
! if ((copyfunc = playerxdr_get_copyfunc(interf, type, subtype)) == NULL)
return 0;
! return (*copyfunc)(dest, src);
}
! void *
! playerxdr_clone_message(void* msg, uint16_t interf, uint8_t type, uint8_t
subtype)
! {
! player_clone_fn_t clonefunc = NULL;
!
! if ((clonefunc = playerxdr_get_clonefunc(interf, type, subtype)) == NULL)
! return NULL;
!
! return (*clonefunc)(msg);
! }
!
!
void
! playerxdr_free_message(void* msg, uint16_t interf, uint8_t type, uint8_t
subtype)
! {
! player_free_fn_t freefunc = NULL;
!
! if ((freefunc = playerxdr_get_freefunc(interf, type, subtype)) == NULL)
! return;
!
! (*freefunc)(msg);
! }
! void
! playerxdr_cleanup_message(void* msg, uint16_t interf, uint8_t type, uint8_t
subtype)
{
player_cleanup_fn_t cleanupfunc = NULL;
Index: Makefile.am
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/Makefile.am,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -C2 -d -r1.19 -r1.19.2.1
*** Makefile.am 20 Aug 2007 06:37:26 -0000 1.19
--- Makefile.am 10 Oct 2007 09:26:07 -0000 1.19.2.1
***************
*** 5,12 ****
pkgincludedir = $(includedir)/player-2.0/libplayerxdr
! BUILT_SOURCES =
! if HAVE_PYTHON
! BUILT_SOURCES += playerxdr.c playerxdr.h functiontable_gen.c
! endif
lib_LTLIBRARIES = libplayerxdr.la
--- 5,9 ----
pkgincludedir = $(includedir)/player-2.0/libplayerxdr
! BUILT_SOURCES = playerxdr.c playerxdr.h functiontable_gen.c
lib_LTLIBRARIES = libplayerxdr.la
***************
*** 16,27 ****
dist_bin_SCRIPTS = playerxdrgen.py
! EXTRA_DIST = playerxdr.pc.in playerxdr.html playerxdr.c playerxdr.h
CLEANFILES = playerxdr.pc
functiontable_gen.c: $(top_srcdir)/libplayercore/playerinterfacegen.py
$(top_srcdir)/libplayercore/interfaces/*
! if ! $(top_srcdir)/libplayercore/playerinterfacegen.py --functiontable
$(top_srcdir)/libplayercore/interfaces/ > functiontable_gen.c; then rm
functiontable_gen.c; fi
! $(top_srcdir)/libplayercore/player_interfaces.h:
$(top_srcdir)/libplayercore/interfaces/*
make -C $(top_srcdir)/libplayercore/ player_interfaces.h
--- 13,27 ----
dist_bin_SCRIPTS = playerxdrgen.py
! EXTRA_DIST = playerxdr.pc.in playerxdr.html playerxdr.c playerxdr.h
functiontable_gen.c
CLEANFILES = playerxdr.pc
functiontable_gen.c: $(top_srcdir)/libplayercore/playerinterfacegen.py
$(top_srcdir)/libplayercore/interfaces/*
! python $(top_srcdir)/libplayercore/playerinterfacegen.py
--functiontable $(top_srcdir)/libplayercore/interfaces/ >
$(top_builddir)/libplayerxdr/functiontable_gen.c
! # if ! $(top_srcdir)/libplayercore/playerinterfacegen.py --functiontable
$(top_srcdir)/libplayercore/interfaces/ > functiontable_gen.c; then rm
functiontable_gen.c; fi
! # This target duplicates one in libplayercore/Makefile.am, but we need it
! # here because libplayerxdr gets built prior to libplayercore
! $(top_builddir)/libplayercore/player_interfaces.h:
$(top_srcdir)/libplayercore/interfaces/*
$(top_srcdir)/libplayercore/playerinterfacegen.py
make -C $(top_srcdir)/libplayercore/ player_interfaces.h
Index: functiontable.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/functiontable.h,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -C2 -d -r1.12 -r1.12.2.1
*** functiontable.h 10 Jul 2007 09:01:52 -0000 1.12
--- functiontable.h 10 Oct 2007 09:26:07 -0000 1.12.2.1
***************
*** 59,65 ****
typedef int (*player_pack_fn_t) (void* buf, size_t buflen, void* msg, int op);
/** Generic Prototype for a player message structure deep copy function */
! typedef unsigned int (*player_dpcpy_fn_t) (const void* src, void* dest);
/** Generic Prototype for a player message structure cleanup function */
typedef void (*player_cleanup_fn_t) (void* msg);
/** Structure to link an (interface,type,subtype) tuple with an XDR
--- 59,71 ----
typedef int (*player_pack_fn_t) (void* buf, size_t buflen, void* msg, int op);
/** Generic Prototype for a player message structure deep copy function */
! typedef unsigned int (*player_copy_fn_t) (void* dest, const void* src);
/** Generic Prototype for a player message structure cleanup function */
typedef void (*player_cleanup_fn_t) (void* msg);
+ /** Generic Prototype for a player message structure clone function */
+ typedef void * (*player_clone_fn_t) (void* msg);
+ /** Generic Prototype for a player message structure free function */
+ typedef void (*player_free_fn_t) (void* msg);
+ /** Generic Prototype for a player message structure sizeof function */
+ typedef unsigned int (*player_sizeof_fn_t) (void* msg);
/** Structure to link an (interface,type,subtype) tuple with an XDR
***************
*** 71,76 ****
uint8_t subtype;
player_pack_fn_t packfunc;
! player_dpcpy_fn_t dpcpyfunc;
player_cleanup_fn_t cleanupfunc;
} playerxdr_function_t;
--- 77,85 ----
uint8_t subtype;
player_pack_fn_t packfunc;
! player_copy_fn_t copyfunc;
player_cleanup_fn_t cleanupfunc;
+ player_clone_fn_t clonefunc;
+ player_free_fn_t freefunc;
+ player_sizeof_fn_t sizeoffunc;
} playerxdr_function_t;
***************
*** 87,91 ****
uint8_t subtype);
! player_dpcpy_fn_t playerxdr_get_dpcpyfunc(uint16_t interf, uint8_t type,
uint8_t subtype);
--- 96,100 ----
uint8_t subtype);
! player_copy_fn_t playerxdr_get_copyfunc(uint16_t interf, uint8_t type,
uint8_t subtype);
***************
*** 93,96 ****
--- 102,114 ----
uint8_t subtype);
+ player_clone_fn_t playerxdr_get_clonefunc(uint16_t interf, uint8_t type,
+ uint8_t subtype);
+
+ player_free_fn_t playerxdr_get_freefunc(uint16_t interf, uint8_t type,
+ uint8_t subtype);
+
+ player_sizeof_fn_t playerxdr_get_sizeoffunc(uint16_t interf, uint8_t type,
+ uint8_t subtype);
+
/** @brief Add an entry to the function table.
*
***************
*** 138,147 ****
uint8_t subtype);
/** @brief Delete a message structure's dynamic elements.
*
! * Deletes any dynamically allocated data used by a message structure. NOTE:
! * Does not delete the message structure itself, even if it is dynamically
! * allocated. Only data pointed to by the message structure's members will be
! * deleted.
*
* @param msg : The message to clean up.
--- 156,173 ----
uint8_t subtype);
+ /** @brief Clones a message structure.
+ *
+ * Allocates memory for and copies the src message. The caller is responsible
for player_type_free'ing the returned data
+ *
+ * @param src : The source message
+ *
+ * @returns : The message clone
+ */
+ void * playerxdr_clone_message(void* msg, uint16_t interf, uint8_t type,
uint8_t subtype);
+
/** @brief Delete a message structure's dynamic elements.
*
! * Deletes any dynamically allocated data used by a message structure and then
! * frees the structure itself
*
* @param msg : The message to clean up.
***************
*** 149,153 ****
* @returns: Nothing.
*/
! void playerxdr_delete_message(void* msg, uint16_t interf, uint8_t type,
uint8_t subtype);
--- 175,191 ----
* @returns: Nothing.
*/
! void playerxdr_free_message(void* msg, uint16_t interf, uint8_t type,
! uint8_t subtype);
!
! /** @brief Cleanup a message structure's dynamic elements.
! *
! * Deletes any dynamically allocated data used by a message structure, It
does not
! * free the structure itself.
! *
! * @param msg : The message to clean up.
! *
! * @returns: Nothing.
! */
! void playerxdr_cleanup_message(void* msg, uint16_t interf, uint8_t type,
uint8_t subtype);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit