Rev 4271 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4271 | Rev 4307 | ||
---|---|---|---|
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> |
|
- | 42 | ||
41 | /** Type definition of the character string with measured length. |
43 | /** Type definition of the character string with measured length. |
42 | * @see measured_string |
44 | * @see measured_string |
43 | */ |
45 | */ |
44 | typedef struct measured_string measured_string_t; |
46 | typedef struct measured_string measured_string_t; |
45 | 47 | ||
46 | /** Type definition of the character string with measured length pointer. |
48 | /** Type definition of the character string with measured length pointer. |
47 | * @see measured_string |
49 | * @see measured_string |
48 | */ |
50 | */ |
49 | typedef measured_string_t * measured_string_ref; |
51 | typedef measured_string_t * measured_string_ref; |
50 | 52 | ||
51 | /** Character string with measured length. |
53 | /** Character string with measured length. |
52 | * 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. |
53 | */ |
55 | */ |
54 | struct measured_string{ |
56 | struct measured_string{ |
55 | /** Character string data. |
57 | /** Character string data. |
56 | */ |
58 | */ |
57 | char * value; |
59 | char * value; |
58 | /** Character string length. |
60 | /** Character string length. |
59 | */ |
61 | */ |
60 | size_t length; |
62 | size_t length; |
61 | }; |
63 | }; |
62 | 64 | ||
63 | /** Creates a new measured string bundled with a copy of the given string itself as one memory block. |
65 | /** 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. |
66 | * If the measured string is being freed, whole memory block is freed. |
65 | * The measured string should be used only as a constant. |
67 | * The measured string should be used only as a constant. |
66 | * @param string The initial character string to be stored. Input parameter. |
68 | * @param string The initial character string to be stored. Input parameter. |
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. |
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. |
68 | * @returns The new bundled character string with measured length. |
70 | * @returns The new bundled character string with measured length. |
69 | * @returns NULL if there is not enough memory left. |
71 | * @returns NULL if there is not enough memory left. |
70 | */ |
72 | */ |
71 | 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 ); |
72 | 74 | ||
73 | /** Copies the given measured string with separated header and data parts. |
75 | /** Copies the given measured string with separated header and data parts. |
74 | * @param source The source measured string to be copied. Input parameter. |
76 | * @param source The source measured string to be copied. Input parameter. |
75 | * @returns The copy of the given measured string. |
77 | * @returns The copy of the given measured string. |
76 | * @returns NULL if the source parameter is NULL. |
78 | * @returns NULL if the source parameter is NULL. |
77 | * @returns NULL if there is not enough memory left. |
79 | * @returns NULL if there is not enough memory left. |
78 | */ |
80 | */ |
79 | measured_string_ref measured_string_copy( measured_string_ref source ); |
81 | measured_string_ref measured_string_copy( measured_string_ref source ); |
80 | 82 | ||
81 | /** Receives a measured strings array from a calling module. |
83 | /** Receives a measured strings array from a calling module. |
82 | * Creates the array and the data memory blocks. |
84 | * Creates the array and the data memory blocks. |
83 | * 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. |
84 | * @param strings The received measured strings array. Output parameter. |
86 | * @param strings The received measured strings array. Output parameter. |
85 | * @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
87 | * @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
86 | * @param count The size of the measured strings array. Input parameter. |
88 | * @param count The size of the measured strings array. Input parameter. |
87 | * @returns EOK on success. |
89 | * @returns EOK on success. |
88 | * @returns EINVAL if the strings or data parameter is NULL. |
90 | * @returns EINVAL if the strings or data parameter is NULL. |
89 | * @returns EINVAL if the count parameter is zero (0). |
91 | * @returns EINVAL if the count parameter is zero (0). |
90 | * @returns EINVAL if the sent array differs in size. |
92 | * @returns EINVAL if the sent array differs in size. |
91 | * @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). |
92 | * @returns ENOMEM if there is not enough memory left. |
94 | * @returns ENOMEM if there is not enough memory left. |
93 | * @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. |
94 | */ |
96 | */ |
95 | 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 ); |
96 | 98 | ||
97 | /** Replies the given measured strings array to a calling module. |
99 | /** Replies the given measured strings array to a calling module. |
98 | * 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. |
99 | * @param strings The measured strings array to be transferred. Input parameter. |
101 | * @param strings The measured strings array to be transferred. Input parameter. |
100 | * @param count The measured strings array size. Input parameter. |
102 | * @param count The measured strings array size. Input parameter. |
101 | * @returns EOK on success. |
103 | * @returns EOK on success. |
102 | * @returns EINVAL if the strings parameter is NULL. |
104 | * @returns EINVAL if the strings parameter is NULL. |
103 | * @returns EINVAL if the count parameter is zero (0). |
105 | * @returns EINVAL if the count parameter is zero (0). |
104 | * @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. |
105 | * @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). |
106 | * @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. |
107 | */ |
109 | */ |
108 | 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 ); |
109 | 111 | ||
110 | /** Receives a measured strings array from another module. |
112 | /** Receives a measured strings array from another module. |
111 | * Creates the array and the data memory blocks. |
113 | * Creates the array and the data memory blocks. |
112 | * 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. |
113 | * @param phone The other module phone. Input parameter. |
115 | * @param phone The other module phone. Input parameter. |
114 | * @param strings The returned measured strings array. Output parameter. |
116 | * @param strings The returned measured strings array. Output parameter. |
115 | * @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
117 | * @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
116 | * @param count The size of the measured strings array. Input parameter. |
118 | * @param count The size of the measured strings array. Input parameter. |
117 | * @returns EOK on success. |
119 | * @returns EOK on success. |
118 | * @returns EINVAL if the strings or data parameter is NULL. |
120 | * @returns EINVAL if the strings or data parameter is NULL. |
119 | * @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). |
120 | * @returns EINVAL if the sent array differs in size. |
122 | * @returns EINVAL if the sent array differs in size. |
121 | * @returns ENOMEM if there is not enough memory left. |
123 | * @returns ENOMEM if there is not enough memory left. |
122 | * @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. |
123 | */ |
125 | */ |
124 | 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 ); |
125 | 127 | ||
126 | /** Sends the given measured strings array to another module. |
128 | /** Sends the given measured strings array to another module. |
127 | * 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. |
128 | * @param phone The other module phone. Input parameter. |
130 | * @param phone The other module phone. Input parameter. |
129 | * @param strings The measured strings array to be transferred. Input parameter. |
131 | * @param strings The measured strings array to be transferred. Input parameter. |
130 | * @param count The measured strings array size. Input parameter. |
132 | * @param count The measured strings array size. Input parameter. |
131 | * @returns EOK on success. |
133 | * @returns EOK on success. |
132 | * @returns EINVAL if the strings parameter is NULL. |
134 | * @returns EINVAL if the strings parameter is NULL. |
133 | * @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). |
134 | * @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. |
135 | */ |
137 | */ |
136 | 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 ); |
137 | 139 | ||
138 | #endif |
140 | #endif |
139 | 141 | ||
140 | /** @} |
142 | /** @} |
141 | */ |
143 | */ |
142 | 144 | ||
143 | 145 |