Subversion Repositories HelenOS

Rev

Rev 4307 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas Mejdrech
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup net
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  34.  *  Character string with measured length.
  35.  *  The structure has been designed for serialization of character strings between modules.
  36.  */
  37.  
  38. #ifndef __MEASURED_STRINGS_H__
  39. #define __MEASURED_STRINGS_H__
  40.  
  41. #include <sys/types.h>
  42.  
  43. /** Type definition of the character string with measured length.
  44.  *  @see measured_string
  45.  */
  46. typedef struct measured_string  measured_string_t;
  47.  
  48. /** Type definition of the character string with measured length pointer.
  49.  *  @see measured_string
  50.  */
  51. typedef measured_string_t *     measured_string_ref;
  52.  
  53. /** Character string with measured length.
  54.  *  This structure has been designed for serialization of character strings between modules.
  55.  */
  56. struct  measured_string{
  57.     /** Character string data.
  58.      */
  59.     char *  value;
  60.     /** Character string length.
  61.      */
  62.     size_t  length;
  63. };
  64.  
  65. /** Creates a&nbsp;new measured string bundled with a&nbsp;copy of the given string itself as one memory block.
  66.  *  If the measured string is being freed, whole memory block is freed.
  67.  *  The measured string should be used only as a&nbsp;constant.
  68.  *  @param[in] string The initial character string to be stored.
  69.  *  @param[in] length The length of the given string without the terminating zero ('/0') character. If the length is zero (0), the actual length is computed. The given length is used and appended with the terminating zero ('\\0') character otherwise.
  70.  *  @returns The new bundled character string with measured length.
  71.  *  @returns NULL if there is not enough memory left.
  72.  */
  73. measured_string_ref measured_string_create_bulk( const char * string, size_t length );
  74.  
  75. /** Copies the given measured string with separated header and data parts.
  76.  *  @param[in] source The source measured string to be copied.
  77.  *  @returns The copy of the given measured string.
  78.  *  @returns NULL if the source parameter is NULL.
  79.  *  @returns NULL if there is not enough memory left.
  80.  */
  81. measured_string_ref measured_string_copy( measured_string_ref source );
  82.  
  83. /** Receives a&nbsp;measured strings array from a&nbsp;calling module.
  84.  *  Creates the array and the data memory blocks.
  85.  *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
  86.  *  @param[out] strings The received measured strings array.
  87.  *  @param[out] data The measured strings data. This memory block stores the actual character strings.
  88.  *  @param[in] count The size of the measured strings array.
  89.  *  @returns EOK on success.
  90.  *  @returns EINVAL if the strings or data parameter is NULL.
  91.  *  @returns EINVAL if the count parameter is zero (0).
  92.  *  @returns EINVAL if the sent array differs in size.
  93.  *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
  94.  *  @returns ENOMEM if there is not enough memory left.
  95.  *  @returns Other error codes as defined for the ipc_data_write_finalize() function.
  96.  */
  97. int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count );
  98.  
  99. /** Replies the given measured strings array to a&nbsp;calling module.
  100.  *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
  101.  *  @param[in] strings The measured strings array to be transferred.
  102.  *  @param[in] count The measured strings array size.
  103.  *  @returns EOK on success.
  104.  *  @returns EINVAL if the strings parameter is NULL.
  105.  *  @returns EINVAL if the count parameter is zero (0).
  106.  *  @returns EINVAL if the calling module does not accept the given array size.
  107.  *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
  108.  *  @returns Other error codes as defined for the ipc_data_read_finalize() function.
  109.  */
  110. int measured_strings_reply( const measured_string_ref strings, size_t count );
  111.  
  112. /** Receives a&nbsp;measured strings array from another module.
  113.  *  Creates the array and the data memory blocks.
  114.  *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
  115.  *  @param[in] phone The other module phone.
  116.  *  @param[out] strings The returned measured strings array.
  117.  *  @param[out] data The measured strings data. This memory block stores the actual character strings.
  118.  *  @param[in] count The size of the measured strings array.
  119.  *  @returns EOK on success.
  120.  *  @returns EINVAL if the strings or data parameter is NULL.
  121.  *  @returns EINVAL if the phone or count parameter is not positive (<=0).
  122.  *  @returns EINVAL if the sent array differs in size.
  123.  *  @returns ENOMEM if there is not enough memory left.
  124.  *  @returns Other error codes as defined for the ipc_data_read_start() function.
  125.  */
  126. int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count );
  127.  
  128. /** Sends the given measured strings array to another module.
  129.  *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
  130.  *  @param[in] phone The other module phone.
  131.  *  @param[in] strings The measured strings array to be transferred.
  132.  *  @param[in] count The measured strings array size.
  133.  *  @returns EOK on success.
  134.  *  @returns EINVAL if the strings parameter is NULL.
  135.  *  @returns EINVAL if the phone or count parameter is not positive (<=0).
  136.  *  @returns Other error codes as defined for the ipc_data_write_start() function.
  137.  */
  138. int measured_strings_send( int phone, const measured_string_ref strings, size_t count );
  139.  
  140. #endif
  141.  
  142. /** @}
  143.  */
  144.  
  145.