Update of /cvsroot/playerstage/code/player/libplayerxdr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7891/libplayerxdr

Modified Files:
        functiontable.c playerxdrgen.py functiontable.h 
Log Message:
Changes to message class to remove option to set size explicitly.
This only work by coincidence for structures with one array at the end of them.
Also Message class now uses the auto generated clone and free methods.

Index: playerxdrgen.py
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/playerxdrgen.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** playerxdrgen.py     20 Sep 2007 23:15:47 -0000      1.15
--- playerxdrgen.py     21 Sep 2007 03:31:50 -0000      1.16
***************
*** 398,401 ****
--- 398,454 ----
  }""" % {"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__':
***************
*** 521,524 ****
--- 574,578 ----
      gen.gen_clone(current)
      gen.gen_free(current)    
+     gen.gen_sizeof(current)    
      sourcefile.write('\n')
      

Index: functiontable.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/functiontable.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -C2 -d -r1.90 -r1.91
*** functiontable.c     17 Sep 2007 02:18:51 -0000      1.90
--- functiontable.c     21 Sep 2007 03:31:50 -0000      1.91
***************
*** 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_copy_fn_t)player_intprop_req_t_copy, 
(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_copy_fn_t)player_intprop_req_t_copy, 
(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_copy_fn_t)player_dblprop_req_t_copy, 
(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_copy_fn_t)player_dblprop_req_t_copy, 
(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_copy_fn_t)player_strprop_req_t_copy, 
(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_copy_fn_t)player_strprop_req_t_copy, 
(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->copyfunc = f.copyfunc;
!           curr->cleanupfunc = f.cleanupfunc;
            return(0);
          }
--- 138,142 ----
             (curr->type == f.type))
          {
!           *curr = f;
            return(0);
          }
***************
*** 245,248 ****
--- 249,285 ----
  }
  
+ 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
***************
*** 257,263 ****
  }
  
! // 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;
--- 294,321 ----
  }
  
! 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: functiontable.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayerxdr/functiontable.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** functiontable.h     17 Sep 2007 02:18:51 -0000      1.13
--- functiontable.h     21 Sep 2007 03:31:50 -0000      1.14
***************
*** 62,65 ****
--- 62,71 ----
  /** 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
***************
*** 73,76 ****
--- 79,85 ----
    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;
  
***************
*** 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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to