Subversion Repositories HelenOS

Rev

Rev 4307 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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