Subversion Repositories HelenOS

Rev

Rev 3886 | Rev 4307 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3666 mejdrech 1
/*
3912 mejdrech 2
 * Copyright (c) 2009 Lukas Mejdrech
3666 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
3846 mejdrech 30
 *  @{
3666 mejdrech 31
 */
32
 
3846 mejdrech 33
/** @file
3912 mejdrech 34
 *  Character string with measured length.
35
 *  The structure has been designed for serialization of character strings between modules.
3666 mejdrech 36
 */
37
 
38
#ifndef __MEASURED_STRINGS_H__
39
#define __MEASURED_STRINGS_H__
40
 
3912 mejdrech 41
/** Type definition of the character string with measured length.
3846 mejdrech 42
 *  @see measured_string
43
 */
3666 mejdrech 44
typedef struct measured_string  measured_string_t;
45
 
3912 mejdrech 46
/** Type definition of the character string with measured length pointer.
3846 mejdrech 47
 *  @see measured_string
48
 */
49
typedef measured_string_t *     measured_string_ref;
50
 
3912 mejdrech 51
/** Character string with measured length.
3846 mejdrech 52
 *  This structure has been designed for serialization of character strings between modules.
53
 */
3666 mejdrech 54
struct  measured_string{
3912 mejdrech 55
    /** Character string data.
3846 mejdrech 56
     */
3685 mejdrech 57
    char *  value;
3912 mejdrech 58
    /** Character string length.
3846 mejdrech 59
     */
3666 mejdrech 60
    size_t  length;
61
};
62
 
3846 mejdrech 63
/** Creates a new measured string bundled with a copy of the given string itself as one memory block.
64
 *  If the measured string is being freed, whole memory block is freed.
65
 *  The measured string should be used only as a constant.
66
 *  @param string The initial character string to be stored. Input parameter.
3912 mejdrech 67
 *  @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.
68
 *  @returns The new bundled character string with measured length.
69
 *  @returns NULL if there is not enough memory left.
3846 mejdrech 70
 */
3666 mejdrech 71
measured_string_ref measured_string_create_bulk( const char * string, size_t length );
72
 
3846 mejdrech 73
/** Receives a measured strings array from a calling module.
74
 *  Creates the array and the data memory blocks.
75
 *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
76
 *  @param strings The received measured strings array. Output parameter.
77
 *  @param data The measured strings data. This memory block stores the actual character strings. Output parameter.
78
 *  @param count The size of the measured strings array. Input parameter.
79
 *  @returns EOK on success.
80
 *  @returns EINVAL if the strings or data parameter is NULL.
81
 *  @returns EINVAL if the count parameter is zero (0).
82
 *  @returns EINVAL if the sent array differs in size.
83
 *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
3912 mejdrech 84
 *  @returns ENOMEM if there is not enough memory left.
3846 mejdrech 85
 *  @returns Other error codes as defined for the ipc_data_write_finalize() function.
86
 */
87
int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count );
88
 
89
/** Replies the given measured strings array to a calling module.
90
 *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
91
 *  @param strings The measured strings array to be transferred. Input parameter.
92
 *  @param count The measured strings array size. Input parameter.
93
 *  @returns EOK on success.
94
 *  @returns EINVAL if the strings parameter is NULL.
95
 *  @returns EINVAL if the count parameter is zero (0).
96
 *  @returns EINVAL if the calling module does not accept the given array size.
97
 *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
98
 *  @returns Other error codes as defined for the ipc_data_read_finalize() function.
99
 */
100
int measured_strings_reply( const measured_string_ref strings, size_t count );
101
 
102
/** Receives a measured strings array from another module.
103
 *  Creates the array and the data memory blocks.
104
 *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
105
 *  @param phone The other module phone. Input parameter.
106
 *  @param strings The returned measured strings array. Output parameter.
107
 *  @param data The measured strings data. This memory block stores the actual character strings. Output parameter.
108
 *  @param count The size of the measured strings array. Input parameter.
109
 *  @returns EOK on success.
110
 *  @returns EINVAL if the strings or data parameter is NULL.
111
 *  @returns EINVAL if the phone or count parameter is not positive (<=0).
112
 *  @returns EINVAL if the sent array differs in size.
3912 mejdrech 113
 *  @returns ENOMEM if there is not enough memory left.
3846 mejdrech 114
 *  @returns Other error codes as defined for the ipc_data_read_start() function.
115
 */
116
int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count );
117
 
118
/** Sends the given measured strings array to another module.
119
 *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
120
 *  @param phone The other module phone. Input parameter.
121
 *  @param strings The measured strings array to be transferred. Input parameter.
122
 *  @param count The measured strings array size. Input parameter.
123
 *  @returns EOK on success.
124
 *  @returns EINVAL if the strings parameter is NULL.
125
 *  @returns EINVAL if the phone or count parameter is not positive (<=0).
126
 *  @returns Other error codes as defined for the ipc_data_write_start() function.
127
 */
128
int measured_strings_send( int phone, const measured_string_ref strings, size_t count );
129
 
3666 mejdrech 130
#endif
131
 
132
/** @}
133
 */
134