/*
* Copyright (c) 2008 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup net
* @{
*/
/** @file
* A character string with measured length header file.
* This structure has been designed for serialization of character strings between modules.
*/
#ifndef __MEASURED_STRINGS_H__
#define __MEASURED_STRINGS_H__
/** A type definition of a character string with measured length.
* @see measured_string
*/
typedef struct measured_string measured_string_t;
/** A type definition of a character string with measured length pointer.
* @see measured_string
*/
typedef measured_string_t * measured_string_ref;
/** A character string with measured length.
* This structure has been designed for serialization of character strings between modules.
*/
struct measured_string{
/** The character string data.
*/
char * value;
/** The character string length.
*/
size_t length;
};
/** Creates a new measured string bundled with a copy of the given string itself as one memory block.
* If the measured string is being freed, whole memory block is freed.
* The measured string should be used only as a constant.
* @param string The initial character string to be stored. Input parameter.
* @param 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. Input parameter.
* @returns The new bundled charecter string with measured length.
* @returns NULL if there is no memory left.
*/
measured_string_ref measured_string_create_bulk( const char * string, size_t length );
/** Receives a measured strings array from a calling module.
* Creates the array and the data memory blocks.
* This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
* @param strings The received measured strings array. Output parameter.
* @param data The measured strings data. This memory block stores the actual character strings. Output parameter.
* @param count The size of the measured strings array. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the strings or data parameter is NULL.
* @returns EINVAL if the count parameter is zero (0).
* @returns EINVAL if the sent array differs in size.
* @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
* @returns ENOMEM if there is no memory left.
* @returns Other error codes as defined for the ipc_data_write_finalize() function.
*/
int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count );
/** Replies the given measured strings array to a calling module.
* This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
* @param strings The measured strings array to be transferred. Input parameter.
* @param count The measured strings array size. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the strings parameter is NULL.
* @returns EINVAL if the count parameter is zero (0).
* @returns EINVAL if the calling module does not accept the given array size.
* @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
* @returns Other error codes as defined for the ipc_data_read_finalize() function.
*/
int measured_strings_reply( const measured_string_ref strings, size_t count );
/** Receives a measured strings array from another module.
* Creates the array and the data memory blocks.
* This method should be used only following other IPC messages as the array size has to be negotiated in advance.
* @param phone The other module phone. Input parameter.
* @param strings The returned measured strings array. Output parameter.
* @param data The measured strings data. This memory block stores the actual character strings. Output parameter.
* @param count The size of the measured strings array. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the strings or data parameter is NULL.
* @returns EINVAL if the phone or count parameter is not positive (<=0).
* @returns EINVAL if the sent array differs in size.
* @returns ENOMEM if there is no memory left.
* @returns Other error codes as defined for the ipc_data_read_start() function.
*/
int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count );
/** Sends the given measured strings array to another module.
* This method should be used only following other IPC messages as the array size has to be negotiated in advance.
* @param phone The other module phone. Input parameter.
* @param strings The measured strings array to be transferred. Input parameter.
* @param count The measured strings array size. Input parameter.
* @returns EOK on success.
* @returns EINVAL if the strings parameter is NULL.
* @returns EINVAL if the phone or count parameter is not positive (<=0).
* @returns Other error codes as defined for the ipc_data_write_start() function.
*/
int measured_strings_send( int phone, const measured_string_ref strings, size_t count );
#endif
/** @}
*/