Changeset b69ceea in mainline


Ignore:
Timestamp:
2010-10-15T21:40:36Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
614d065
Parents:
b934e43
Message:

Cleanup packet_{client,remote}.[ch].

Location:
uspace/lib/net
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/packet_client.c

    rb934e43 rb69ceea  
    2727 */
    2828
    29 /** @addtogroup packet
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Packet client implementation.
     34 * Packet client implementation.
    3535 */
    3636
     
    3838#include <mem.h>
    3939#include <unistd.h>
    40 
    4140#include <sys/mman.h>
    4241
    4342#include <packet_client.h>
     43#include <packet_remote.h>
    4444
    4545#include <net/packet.h>
    4646#include <net/packet_header.h>
    4747
    48 int packet_copy_data(packet_t packet, const void * data, size_t length)
     48/** Copies the specified data to the beginning of the actual packet content.
     49 *
     50 * Pushes the content end if needed.
     51 *
     52 * @param[in] packet    The packet to be filled.
     53 * @param[in] data      The data to be copied.
     54 * @param[in] length    The length of the copied data.
     55 * @returns             EOK on success.
     56 * @returns             EINVAL if the packet is not valid.
     57 * @returns             ENOMEM if there is not enough memory left.
     58 */
     59int packet_copy_data(packet_t packet, const void *data, size_t length)
    4960{
    5061        if (!packet_is_valid(packet))
     
    6172}
    6273
     74/** Allocates the specified space right before the actual packet content and
     75 * returns its pointer.
     76 *
     77 * @param[in] packet    The packet to be used.
     78 * @param[in] length    The space length to be allocated at the beginning of the
     79 *                      packet content.
     80 * @returns             The pointer to the allocated memory.
     81 * @returns             NULL if there is not enough memory left.
     82 */
    6383void *packet_prefix(packet_t packet, size_t length)
    6484{
     
    7393}
    7494
     95/** Allocates the specified space right after the actual packet content and
     96 * returns its pointer.
     97 *
     98 * @param[in] packet    The packet to be used.
     99 * @param[in] length    The space length to be allocated at the end of the
     100 *                       packet content.
     101 * @returns             The pointer to the allocated memory.
     102 * @returns             NULL if there is not enough memory left.
     103 */
    75104void *packet_suffix(packet_t packet, size_t length)
    76105{
     
    84113}
    85114
     115/** Trims the actual packet content by the specified prefix and suffix lengths.
     116 *
     117 * @param[in] packet    The packet to be trimmed.
     118 * @param[in] prefix    The prefix length to be removed from the beginning of
     119 *                      the packet content.
     120 * @param[in] suffix    The suffix length to be removed from the end of the
     121 *                      packet content.
     122 * @returns             EOK on success.
     123 * @returns             EINVAL if the packet is not valid.
     124 * @returns             ENOMEM if there is not enough memory left.
     125 */
    86126int packet_trim(packet_t packet, size_t prefix, size_t suffix)
    87127{
     
    97137}
    98138
     139/** Returns the packet identifier.
     140 *
     141 * @param[in] packet    The packet.
     142 * @returns             The packet identifier.
     143 * @returns             Zero if the packet is not valid.
     144 */
    99145packet_id_t packet_get_id(const packet_t packet)
    100146{
     
    102148}
    103149
    104 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest)
     150/** Returns the stored packet addresses and their length.
     151 *
     152 * @param[in] packet    The packet.
     153 * @param[out] src      The source address. May be NULL if not desired.
     154 * @param[out] dest     The destination address. May be NULL if not desired.
     155 * @returns             The stored addresses length.
     156 * @returns             Zero if the addresses are not present.
     157 * @returns             EINVAL if the packet is not valid.
     158 */
     159int packet_get_addr(const packet_t packet, uint8_t **src, uint8_t **dest)
    105160{
    106161        if (!packet_is_valid(packet))
     
    116171}
    117172
     173/** Returns the packet content length.
     174 *
     175 * @param[in] packet    The packet.
     176 * @returns             The packet content length in bytes.
     177 * @returns             Zero if the packet is not valid.
     178 */
    118179size_t packet_get_data_length(const packet_t packet)
    119180{
     
    124185}
    125186
     187/** Returns the pointer to the beginning of the packet content.
     188 *
     189 * @param[in] packet    The packet.
     190 * @returns             The pointer to the beginning of the packet content.
     191 * @returns             NULL if the packet is not valid.
     192 */
    126193void *packet_get_data(const packet_t packet)
    127194{
     
    132199}
    133200
     201/** Sets the packet addresses.
     202 *
     203 * @param[in] packet    The packet.
     204 * @param[in] src       The new source address. May be NULL.
     205 * @param[in] dest      The new destination address. May be NULL.
     206 * @param[in] addr_len  The addresses length.
     207 * @returns             EOK on success.
     208 * @returns             EINVAL if the packet is not valid.
     209 * @returns             ENOMEM if there is not enough memory left.
     210 */
    134211int
    135 packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest,
     212packet_set_addr(packet_t packet, const uint8_t *src, const uint8_t *dest,
    136213    size_t addr_len)
    137214{
     
    170247}
    171248
     249/** Returns the packet copy.
     250 *
     251 * Copies the addresses, data, order and metric values.
     252 * Does not copy the queue placement.
     253 *
     254 * @param[in] phone     The packet server module phone.
     255 * @param[in] packet    The original packet.
     256 * @returns             The packet copy.
     257 * @returns             NULL on error.
     258 */
    172259packet_t packet_get_copy(int phone, packet_t packet)
    173260{
  • uspace/lib/net/generic/packet_remote.c

    rb934e43 rb69ceea  
    2727 */
    2828
    29 /** @addtogroup packet
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Packet client interface implementation for remote modules.
    35  *  @see packet_client.h
     34 * Packet client interface implementation for remote modules.
     35 * @see packet_client.h
    3636 */
    3737
     
    8686}
    8787
     88/** Translates the packet identifier to the packet reference.
     89 *
     90 * Tries to find mapping first.
     91 * Contacts the packet server to share the packet if the mapping is not present.
     92 *
     93 * @param[in] phone     The packet server module phone.
     94 * @param[out] packet   The packet reference.
     95 * @param[in] packet_id The packet identifier.
     96 * @returns             EOK on success.
     97 * @returns             EINVAL if the packet parameter is NULL.
     98 * @returns             Other error codes as defined for the NET_PACKET_GET_SIZE
     99 *                      message.
     100 * @returns             Other error codes as defined for the packet_return()
     101 *                      function.
     102 */
    88103int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
    89104{
     
    110125}
    111126
     127/** Obtains the packet of the given dimensions.
     128 *
     129 * Contacts the packet server to return the appropriate packet.
     130 *
     131 * @param[in] phone     The packet server module phone.
     132 * @param[in] addr_len  The source and destination addresses maximal length in
     133 *                      bytes.
     134 * @param[in] max_prefix The maximal prefix length in bytes.
     135 * @param[in] max_content The maximal content length in bytes.
     136 * @param[in] max_suffix The maximal suffix length in bytes.
     137 * @returns             The packet reference.
     138 * @returns             NULL on error.
     139 */
    112140packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
    113141    size_t max_prefix, size_t max_suffix)
     
    133161}
    134162
     163/** Obtains the packet of the given content size.
     164 *
     165 * Contacts the packet server to return the appropriate packet.
     166 *
     167 * @param[in] phone     The packet server module phone.
     168 * @param[in] content   The maximal content length in bytes.
     169 * @returns             The packet reference.
     170 * @returns             NULL on error.
     171 */
    135172packet_t packet_get_1_remote(int phone, size_t content)
    136173{
     
    154191}
    155192
     193/** Releases the packet queue.
     194 *
     195 * All packets in the queue are marked as free for use.
     196 * The packet queue may be one packet only.
     197 * The module should not use the packets after this point until they are
     198 * received or obtained again.
     199 *
     200 * @param[in] phone     The packet server module phone.
     201 * @param[in] packet_id The packet identifier.
     202 */
    156203void pq_release_remote(int phone, packet_id_t packet_id)
    157204{
  • uspace/lib/net/include/packet_client.h

    rb934e43 rb69ceea  
    2727 */
    2828
    29 /** @addtogroup packet
     29/** @addtogroup libnet
    3030 *  @{
    3131 */
    3232
    3333/** @file
    34  *  Packet client.
    35  *  The hosting module has to be compiled with both the packet.c and the packet_client.c source files.
    36  *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
    37  *  The module should not send the packet messages to the packet server but use the functions provided.
    38  *  The packet map should be released by the pm_destroy() function during the module termination.
    39  *  The packets and the packet queues can't be locked at all.
    40  *  The processing modules should process them sequentially -&nbsp;by passing the packets to the next module and stopping using the passed ones.
    41  *  @see packet.h
     34 * Packet client.
     35 *
     36 * To function correctly, initialization of the packet map by the pm_init()
     37 * function has to happen at the first place. The module should not send the
     38 * packet messages to the packet server but use the functions provided. The
     39 * packet map should be released by the pm_destroy() function during the module
     40 * termination. The packets and the packet queues can't be locked at all. The
     41 * processing modules should process them sequentially - by passing the packets
     42 * to the next module and stopping using the passed ones.
     43 *
     44 * @see packet.h
    4245 */
    4346
    44 #ifndef __NET_PACKET_CLIENT_H__
    45 #define __NET_PACKET_CLIENT_H__
     47#ifndef LIBNET_PACKET_CLIENT_H_
     48#define LIBNET_PACKET_CLIENT_H_
    4649
    4750#include <net/packet.h>
    4851
    49 /** @name Packet client interface
    50  */
     52/** @name Packet client interface */
    5153/*@{*/
    5254
    53 /** Allocates the specified type right before the actual packet content and returns its pointer.
    54  *  The wrapper of the packet_prepend() function.
    55  *  @param[in] packet The packet to be used.
    56  *  @param[in] type The type to be allocated at the beginning of the packet content.
    57  *  @returns The typed pointer to the allocated memory.
    58  *  @returns NULL if the packet is not valid.
    59  *  @returns NULL if there is not enough memory left.
     55/** Allocates the specified type right before the actual packet content and
     56 * returns its pointer.
     57 *
     58 * The wrapper of the packet_prepend() function.
     59 *
     60 * @param[in] packet    The packet to be used.
     61 * @param[in] type      The type to be allocated at the beginning of the packet
     62 *                      content.
     63 * @returns             The typed pointer to the allocated memory.
     64 * @returns             NULL if the packet is not valid.
     65 * @returns             NULL if there is not enough memory left.
    6066 */
    61 #define PACKET_PREFIX(packet, type)     (type *) packet_prefix((packet), sizeof(type))
     67#define PACKET_PREFIX(packet, type) \
     68        (type *) packet_prefix((packet), sizeof(type))
    6269
    63 /** Allocates the specified type right after the actual packet content and returns its pointer.
    64  *  The wrapper of the packet_append() function.
    65  *  @param[in] packet The packet to be used.
    66  *  @param[in] type The type to be allocated at the end of the packet content.
    67  *  @returns The typed pointer to the allocated memory.
    68  *  @returns NULL if the packet is not valid.
    69  *  @returns NULL if there is not enough memory left.
     70/** Allocates the specified type right after the actual packet content and
     71 * returns its pointer.
     72 *
     73 * The wrapper of the packet_append() function.
     74 *
     75 * @param[in] packet    The packet to be used.
     76 * @param[in] type      The type to be allocated at the end of the packet
     77 *                      content.
     78 * @returns             The typed pointer to the allocated memory.
     79 * @returns             NULL if the packet is not valid.
     80 * @returns             NULL if there is not enough memory left.
    7081 */
    71 #define PACKET_SUFFIX(packet, type)     (type *) packet_suffix((packet), sizeof(type))
     82#define PACKET_SUFFIX(packet, type) \
     83        (type *) packet_suffix((packet), sizeof(type))
    7284
    7385/** Trims the actual packet content by the specified prefix and suffix types.
    74  *  The wrapper of the packet_trim() function.
    75  *  @param[in] packet The packet to be trimmed.
    76  *  @param[in] prefix The type of the prefix to be removed from the beginning of the packet content.
    77  *  @param[in] suffix The type of the suffix to be removed from the end of the packet content.
    78  *  @returns EOK on success.
    79  *  @returns EINVAL if the packet is not valid.
    80  *  @returns ENOMEM if there is not enough memory left.
     86 *
     87 * The wrapper of the packet_trim() function.
     88 *
     89 * @param[in] packet    The packet to be trimmed.
     90 * @param[in] prefix    The type of the prefix to be removed from the beginning
     91 *                      of the packet content.
     92 * @param[in] suffix    The type of the suffix to be removed from the end of
     93 *                      the packet content.
     94 * @returns             EOK on success.
     95 * @returns             EINVAL if the packet is not valid.
     96 * @returns             ENOMEM if there is not enough memory left.
    8197 */
    82 #define PACKET_TRIM(packet, prefix, suffix)     packet_trim((packet), sizeof(prefix), sizeof(suffix))
     98#define PACKET_TRIM(packet, prefix, suffix) \
     99        packet_trim((packet), sizeof(prefix), sizeof(suffix))
    83100
    84 /** Allocates the specified space right before the actual packet content and returns its pointer.
    85  *  @param[in] packet The packet to be used.
    86  *  @param[in] length The space length to be allocated at the beginning of the packet content.
    87  *  @returns The pointer to the allocated memory.
    88  *  @returns NULL if there is not enough memory left.
    89  */
    90 extern void * packet_prefix(packet_t packet, size_t length);
    91 
    92 /** Allocates the specified space right after the actual packet content and returns its pointer.
    93  *  @param[in] packet The packet to be used.
    94  *  @param[in] length The space length to be allocated at the end of the packet content.
    95  *  @returns The pointer to the allocated memory.
    96  *  @returns NULL if there is not enough memory left.
    97  */
    98 extern void * packet_suffix(packet_t packet, size_t length);
    99 
    100 /** Trims the actual packet content by the specified prefix and suffix lengths.
    101  *  @param[in] packet The packet to be trimmed.
    102  *  @param[in] prefix The prefix length to be removed from the beginning of the packet content.
    103  *  @param[in] suffix The suffix length to be removed from the end of the packet content.
    104  *  @returns EOK on success.
    105  *  @returns EINVAL if the packet is not valid.
    106  *  @returns ENOMEM if there is not enough memory left.
    107  */
    108 extern int packet_trim(packet_t packet, size_t prefix, size_t suffix);
    109 
    110 /** Copies the specified data to the beginning of the actual packet content.
    111  *  Pushes the content end if needed.
    112  *  @param[in] packet The packet to be filled.
    113  *  @param[in] data The data to be copied.
    114  *  @param[in] length The length of the copied data.
    115  *  @returns EOK on success.
    116  *  @returns EINVAL if the packet is not valid.
    117  *  @returns ENOMEM if there is not enough memory left.
    118  */
    119 extern int packet_copy_data(packet_t packet, const void * data, size_t length);
    120 
    121 /** Returns the packet identifier.
    122  *  @param[in] packet The packet.
    123  *  @returns The packet identifier.
    124  *  @returns Zero (0) if the packet is not valid.
    125  */
    126 extern packet_id_t packet_get_id(const packet_t packet);
    127 
    128 /** Returns the packet content length.
    129  *  @param[in] packet The packet.
    130  *  @returns The packet content length in bytes.
    131  *  @returns Zero (0) if the packet is not valid.
    132  */
    133 extern size_t packet_get_data_length(const packet_t packet);
    134 
    135 /** Returns the pointer to the beginning of the packet content.
    136  *  @param[in] packet The packet.
    137  *  @returns The pointer to the beginning of the packet content.
    138  *  @returns NULL if the packet is not valid.
    139  */
    140 extern void * packet_get_data(const packet_t packet);
    141 
    142 /** Returns the stored packet addresses and their length.
    143  *  @param[in] packet The packet.
    144  *  @param[out] src The source address. May be NULL if not desired.
    145  *  @param[out] dest The destination address. May be NULL if not desired.
    146  *  @returns The stored addresses length.
    147  *  @returns Zero (0) if the addresses are not present.
    148  *  @returns EINVAL if the packet is not valid.
    149  */
    150 extern int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest);
    151 
    152 /** Sets the packet addresses.
    153  *  @param[in] packet The packet.
    154  *  @param[in] src The new source address. May be NULL.
    155  *  @param[in] dest The new destination address. May be NULL.
    156  *  @param[in] addr_len The addresses length.
    157  *  @returns EOK on success.
    158  *  @returns EINVAL if the packet is not valid.
    159  *  @returns ENOMEM if there is not enough memory left.
    160  */
    161 extern int packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len);
    162 
    163 /** Translates the packet identifier to the packet reference.
    164  *  Tries to find mapping first.
    165  *  Contacts the packet server to share the packet if the mapping is not present.
    166  *  @param[in] phone The packet server module phone.
    167  *  @param[out] packet The packet reference.
    168  *  @param[in] packet_id The packet identifier.
    169  *  @returns EOK on success.
    170  *  @returns EINVAL if the packet parameter is NULL.
    171  *  @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
    172  *  @returns Other error codes as defined for the packet_return() function.
    173  */
    174 extern int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id);
    175 
    176 /** Obtains the packet of the given dimensions.
    177  *  Contacts the packet server to return the appropriate packet.
    178  *  @param[in] phone The packet server module phone.
    179  *  @param[in] addr_len The source and destination addresses maximal length in bytes.
    180  *  @param[in] max_prefix The maximal prefix length in bytes.
    181  *  @param[in] max_content The maximal content length in bytes.
    182  *  @param[in] max_suffix The maximal suffix length in bytes.
    183  *  @returns The packet reference.
    184  *  @returns NULL on error.
    185  */
    186 extern packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
    187 
    188 /** Obtains the packet of the given content size.
    189  *  Contacts the packet server to return the appropriate packet.
    190  *  @param[in] phone The packet server module phone.
    191  *  @param[in] content The maximal content length in bytes.
    192  *  @returns The packet reference.
    193  *  @returns NULL on error.
    194  */
    195 extern packet_t packet_get_1_remote(int phone, size_t content);
    196 
    197 /** Releases the packet queue.
    198  *  All packets in the queue are marked as free for use.
    199  *  The packet queue may be one packet only.
    200  *  The module should not use the packets after this point until they are received or obtained again.
    201  *  @param[in] phone The packet server module phone.
    202  *  @param[in] packet_id The packet identifier.
    203  */
    204 extern void pq_release_remote(int phone, packet_id_t packet_id);
    205 
    206 /** Returns the packet copy.
    207  *  Copies the addresses, data, order and metric values.
    208  *  Does not copy the queue placement.
    209  *  @param[in] phone The packet server module phone.
    210  *  @param[in] packet The original packet.
    211  *  @returns The packet copy.
    212  *  @returns NULL on error.
    213  */
     101extern void *packet_prefix(packet_t, size_t);
     102extern void *packet_suffix(packet_t, size_t);
     103extern int packet_trim(packet_t, size_t, size_t);
     104extern int packet_copy_data(packet_t, const void *, size_t);
     105extern packet_id_t packet_get_id(const packet_t);
     106extern size_t packet_get_data_length(const packet_t);
     107extern void *packet_get_data(const packet_t);
     108extern int packet_get_addr(const packet_t, uint8_t **, uint8_t **);
     109extern int packet_set_addr(packet_t, const uint8_t *, const uint8_t *, size_t);
    214110extern packet_t packet_get_copy(int phone, packet_t packet);
    215111
  • uspace/lib/net/include/packet_remote.h

    rb934e43 rb69ceea  
    2727 */
    2828
    29 /** @addtogroup packet
     29/** @addtogroup libnet
    3030 * @{
    3131 */
    3232
    33 #ifndef __NET_PACKET_REMOTE_H__
    34 #define __NET_PACKET_REMOTE_H__
     33#ifndef LIBNET_PACKET_REMOTE_H_
     34#define LIBNET_PACKET_REMOTE_H_
    3535
    3636#include <net/packet.h>
     37#include <sys/types.h>
    3738
    3839extern int packet_translate_remote(int, packet_ref, packet_id_t);
Note: See TracChangeset for help on using the changeset viewer.