home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / ntwrkprt / mastrxdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  5.8 KB  |  191 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/drapeau/NetworkProtocol/RCS/MAEstroxdr.c,v 1.16 92/05/29 12:40:34 drapeau Exp $ */
  25. /* $Log:    MAEstroxdr.c,v $
  26.  * Revision 1.16  92/05/29  12:40:34  drapeau
  27.  * Changed the name of the "Selection" structure to "MAESelection",
  28.  * to avoid name conflicts with other software packages and toolkits
  29.  * that might also define a "Selection" structure.
  30.  * 
  31.  * Revision 1.15  91/11/25  13:01:40  drapeau
  32.  * Added a function, DestroyPort(), to free space taken by a Port*.
  33.  * 
  34.  * Revision 1.14  91/09/18  12:45:29  drapeau
  35.  * - Added a utility function "DestroyPortArray()", to help programmers clean up after they have
  36.  *   called the SenderGetPortFromName() method.  The function will free all of the data in a
  37.  *   PortArray* passed in as argument, including the component Port* data.
  38.  * - Changed the name of the major include file from LinkProtocol.h to MAEstro.h, in keeping with the
  39.  *   project name.
  40.  * 
  41.  * Revision 1.13  91/06/19  14:01:53  drapeau
  42.  * Minor cosmetic changes (reformatting of code).
  43.  * Also, modified xdr_Selection to accomodate the new Selection structure (two
  44.  * new fields, offset and label were added).  For the label, which is declared
  45.  * as a "char[LabelLength]", this meant adding a temporary pointer of type
  46.  * "char*".  Evidently, the xdr_string() function doesn't like using character
  47.  * arrays (char[]), so a string (char*) is used to point to the beginning of
  48.  * the character array.  xdr_string() seems to like that better.
  49.  * 
  50.  * Also, added a new function, xdr_IconData(), to transfer icons among apps.
  51.  * 
  52.  * Revision 1.12  91/06/17  18:17:18  drapeau
  53.  * Added copyright notice.
  54.  * 
  55.  * Revision 1.11  1991/02/28  07:29:48  drapeau
  56.  * No code changes; this version uses a new version numbering scheme and a new
  57.  * version of RCS.
  58.  *
  59.  * Revision 1.1  90/10/24  18:22:00  drapeau
  60.  * Initial revision
  61.  *  */
  62.  
  63. static char maestroxdrRcsid[] = "$Header: /Source/Media/drapeau/NetworkProtocol/RCS/MAEstroxdr.c,v 1.16 92/05/29 12:40:34 drapeau Exp $";
  64.  
  65. #include <rpc/rpc.h>
  66. #include <MAEstro.h>
  67.  
  68.  
  69. bool_t    xdr_Port(XDR* xdrs, Port *objp)
  70. {
  71.   if (!xdr_string(xdrs, &objp->hostName, ~0))
  72.   {
  73.     return (FALSE);
  74.   }
  75.   if (!xdr_string(xdrs, &objp->appName, ~0))
  76.   {
  77.     return (FALSE);
  78.   }
  79.   if (!xdr_int(xdrs, &objp->portNumber))
  80.   {
  81.     return (FALSE);
  82.   }
  83.   return (TRUE);
  84. }
  85.  
  86.  
  87.  
  88. bool_t    xdr_PortArray(XDR *xdrs, PortArray *objp)
  89. {
  90.   if (!xdr_array(xdrs, (char **)&objp->portArray,
  91.          (u_int *)&objp->numberOfPorts, ~0,
  92.          sizeof(Port), xdr_Port))
  93.   {
  94.     return (FALSE);
  95.   }
  96.   if (!xdr_int(xdrs, &objp->numberOfPorts))
  97.   {
  98.     return (FALSE);
  99.   }
  100.   return (TRUE);
  101. }
  102.  
  103.  
  104.  
  105. bool_t    xdr_MAESelection(XDR *xdrs, MAESelection *objp)
  106. {
  107.   char*    tempString = (char*)objp->label;                /* xdr_string doesn't like char[]; char* tempString...  */
  108.   
  109.   if (!xdr_int(xdrs, &objp->start))                    /*  ...works around this problem */
  110.   {
  111.     return (FALSE);
  112.   }
  113.   if (!xdr_int(xdrs, &objp->end))
  114.   {
  115.     return (FALSE);
  116.   }
  117.   if (!xdr_int(xdrs, &objp->duration))
  118.   {
  119.     return (FALSE);
  120.   }
  121.   if (!xdr_int(xdrs, &objp->offset))
  122.   {
  123.     return (FALSE);
  124.   }
  125.   if (!xdr_string(xdrs, &tempString, LabelLength))
  126.   {
  127.     return (FALSE);
  128.   }
  129.   return (TRUE);
  130. }
  131.  
  132.  
  133. bool_t    xdr_IconData(XDR *xdrs, IconData *objp)
  134. {
  135.   if (!xdr_bytes(xdrs, (char **)&objp->iconData,
  136.          (u_int *)&objp->dataLength, ~0))
  137.   {
  138.     return (FALSE);
  139.   }
  140.   if (!xdr_int(xdrs, &objp->dataLength))
  141.   {
  142.     return (FALSE);
  143.   }
  144.   return (TRUE);
  145. }
  146.  
  147.  
  148.  
  149. void    DestroyPortArray(PortArray* thePortArray)
  150. {
  151.   int    arrayElement = 0;
  152.   Port*    thePort = (Port*) NULL;
  153.   
  154.   if (thePortArray == (PortArray*)NULL)
  155.     return;
  156.   for (arrayElement = 0;                        /* Traverse list of Ports in array, freeing space one by one */
  157.        arrayElement < thePortArray->numberOfPorts;
  158.        arrayElement++)
  159.   {
  160.     thePort = &(thePortArray->portArray[arrayElement]);            /* Point to the current Port in the array */
  161.     if (thePort != (Port*)NULL)                        /* Is this a valid Port*? */
  162.     {                                    /* Yes, free space taken by each element of the Port* */
  163.       if (thePort->appName)
  164.     free(thePort->appName);
  165.       if (thePort->hostName)
  166.     free(thePort->hostName);
  167.     }
  168.   }                                    /* end for... */
  169.   if (thePortArray->portArray != (Port*)NULL)
  170.   {
  171.     free(thePortArray->portArray);                    /* Now that each Port's fields have been freed, free Port's */
  172.     thePortArray->portArray = (Port*)NULL;                /* Re-initialize the PortArray passed in as argument */
  173.     thePortArray->numberOfPorts = 0;
  174.   }
  175.   return;
  176. }                                    /* end function DestroyPortArray */
  177.  
  178.  
  179. void    DestroyPort(Port* thePort)
  180. {
  181.   if (thePort != (Port*)NULL)                        /* Make sure a non-NULL Port* was passed in */
  182.   {
  183.     if (thePort->hostName != (char*)NULL)
  184.       free(thePort->hostName);
  185.     if (thePort->appName != (char*)NULL)
  186.       free(thePort->appName);
  187.     free(thePort);
  188.   }
  189.   return;
  190. }                                    /* end function DestroyPort */
  191.