Changeset 24ab58b3 in mainline for uspace/lib/net/netif


Ignore:
Timestamp:
2010-04-06T11:41:48Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14f1db0
Parents:
4dd8529
Message:

more compact network startup messages (usually one line instead of multiple lines)
pass module name as an argument to nil_message() and friends
deeper cstyle changes (replace forward prototypes with proper extern declarations and static functions, change doxygen comments, stick more closely to the 80-column rule, no argument names in header files, spacing, comments, etc.)

Location:
uspace/lib/net/netif
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/netif/netif.c

    r4dd8529 r24ab58b3  
    176176}
    177177
    178 /** Registers the device notification receiver, the network interface layer module.
    179  *  @param[in] device_id The device identifier.
    180  *  @param[in] phone The network interface layer module phone.
    181  *  @returns EOK on success.
    182  *  @returns ENOENT if there is no such device.
    183  *  @returns ELIMIT if there is another module registered.
    184  */
    185 static int register_message(device_id_t device_id, int phone){
    186         ERROR_DECLARE;
    187 
     178/** Register the device notification receiver, the network interface layer module.
     179 *
     180 * @param[in] name      Module name.
     181 * @param[in] device_id The device identifier.
     182 * @param[in] phone     The network interface layer module phone.
     183 *
     184 * @return EOK on success.
     185 * @return ENOENT if there is no such device.
     186 * @return ELIMIT if there is another module registered.
     187 *
     188 */
     189static int register_message(const char *name, device_id_t device_id, int phone)
     190{
     191        ERROR_DECLARE;
     192       
    188193        device_ref device;
    189 
    190194        ERROR_PROPAGATE(find_device(device_id, &device));
    191         if(device->nil_phone > 0){
     195        if(device->nil_phone > 0)
    192196                return ELIMIT;
    193         }
     197       
    194198        device->nil_phone = phone;
    195         printf("New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone);
    196         return EOK;
    197 }
    198 
    199 int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    200         ERROR_DECLARE;
    201 
     199        printf("%s: Receiver of device %d registered (phone: %d)\n",
     200            name, device->device_id, device->nil_phone);
     201        return EOK;
     202}
     203
     204int netif_message(const char *name, ipc_callid_t callid, ipc_call_t *call,
     205    ipc_call_t *answer, int *answer_count)
     206{
     207        ERROR_DECLARE;
     208       
    202209        size_t length;
    203210        device_stats_t stats;
    204211        packet_t packet;
    205212        measured_string_t address;
    206 
    207 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST);
     213       
    208214        *answer_count = 0;
    209215        switch(IPC_GET_METHOD(*call)){
     
    211217                        return EOK;
    212218                case NET_NETIF_PROBE:
    213                         return netif_probe_req(0, IPC_GET_DEVICE(call), NETIF_GET_IRQ(call), NETIF_GET_IO(call));
     219                        return netif_probe_req(0, IPC_GET_DEVICE(call),
     220                            NETIF_GET_IRQ(call), NETIF_GET_IO(call));
    214221                case IPC_M_CONNECT_TO_ME:
    215222                        fibril_rwlock_write_lock(&netif_globals.lock);
    216                         ERROR_CODE = register_message(IPC_GET_DEVICE(call), IPC_GET_PHONE(call));
     223                        ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
     224                            IPC_GET_PHONE(call));
    217225                        fibril_rwlock_write_unlock(&netif_globals.lock);
    218226                        return ERROR_CODE;
    219227                case NET_NETIF_SEND:
    220                         ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, &packet, IPC_GET_PACKET(call)));
    221                         return netif_send_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_SENDER(call));
     228                        ERROR_PROPAGATE(packet_translate(netif_globals.net_phone,
     229                            &packet, IPC_GET_PACKET(call)));
     230                        return netif_send_msg(0, IPC_GET_DEVICE(call), packet,
     231                            IPC_GET_SENDER(call));
    222232                case NET_NETIF_START:
    223233                        return netif_start_req(0, IPC_GET_DEVICE(call));
    224234                case NET_NETIF_STATS:
    225235                        fibril_rwlock_read_lock(&netif_globals.lock);
    226                         if(! ERROR_OCCURRED(async_data_read_receive(&callid, &length))){
    227                                 if(length < sizeof(device_stats_t)){
     236                        if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
     237                                if (length < sizeof(device_stats_t))
    228238                                        ERROR_CODE = EOVERFLOW;
    229                                 }else{
    230                                         if(! ERROR_OCCURRED(netif_get_device_stats(IPC_GET_DEVICE(call), &stats))){
    231                                                 ERROR_CODE = async_data_read_finalize(callid, &stats, sizeof(device_stats_t));
    232                                         }
     239                                else {
     240                                        if (!ERROR_OCCURRED(netif_get_device_stats(
     241                                            IPC_GET_DEVICE(call), &stats)))
     242                                                ERROR_CODE = async_data_read_finalize(callid, &stats,
     243                                                    sizeof(device_stats_t));
    233244                                }
    234245                        }
     
    239250                case NET_NETIF_GET_ADDR:
    240251                        fibril_rwlock_read_lock(&netif_globals.lock);
    241                         if(! ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), &address))){
     252                        if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call),
     253                            &address)))
    242254                                ERROR_CODE = measured_strings_reply(&address, 1);
    243                         }
    244255                        fibril_rwlock_read_unlock(&netif_globals.lock);
    245256                        return ERROR_CODE;
    246257        }
     258       
    247259        return netif_specific_message(callid, call, answer, answer_count);
    248260}
  • uspace/lib/net/netif/netif_nil_bundle.c

    r4dd8529 r24ab58b3  
    4545#include <netif.h>
    4646
    47 /** Distributes the messages between the module parts.
    48  *  @param[in] callid The message identifier.
    49  *  @param[in] call The message parameters.
    50  *  @param[out] answer The message answer parameters.
    51  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    52  *  @returns EOK on success.
    53  *  @returns ENOTSUP if the message is not known.
    54  *  @returns Other error codes as defined for each specific module message function.
     47/** Distribute the messages between the module parts.
     48 *
     49 * @param[in]  name         Module name.
     50 * @param[in]  callid       The message identifier.
     51 * @param[in]  call         The message parameters.
     52 * @param[out] answer       The message answer parameters.
     53 * @param[out] answer_count The last parameter for the actual
     54 *                          answer in the answer parameter.
     55 *
     56 * @return EOK on success.
     57 * @return ENOTSUP if the message is not known.
     58 * @return Other error codes as defined for each specific module message function.
     59 *
    5560 */
    56 int netif_nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    57         if(IS_NET_NIL_MESSAGE(call) || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)){
    58                 return nil_message(callid, call, answer, answer_count);
    59         }else{
    60                 return netif_message(callid, call, answer, answer_count);
    61         }
     61int netif_nil_module_message(const char *name, ipc_callid_t callid,
     62    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
     63{
     64        if (IS_NET_NIL_MESSAGE(call)
     65            || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME))
     66                return nil_message(name, callid, call, answer, answer_count);
     67        else
     68                return netif_message(name, callid, call, answer, answer_count);
    6269}
    6370
  • uspace/lib/net/netif/netif_standalone.c

    r4dd8529 r24ab58b3  
    4141#include <netif_standalone.h>
    4242
    43 /** Delegates the messages to the netif_message() function.
    44  *  @param[in] callid The message identifier.
    45  *  @param[in] call The message parameters.
    46  *  @param[out] answer The message answer parameters.
    47  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    48  *  @returns EOK on success.
    49  *  @returns ENOTSUP if the message is not known.
    50  *  @returns Other error codes as defined for each specific module message function.
     43/** Delegate the messages to the netif_message() function.
     44 *
     45 * @param[in]  name         Module name.
     46 * @param[in]  callid       The message identifier.
     47 * @param[in]  call         The message parameters.
     48 * @param[out] answer       The message answer parameters.
     49 * @param[out] answer_count The last parameter for the actual answer
     50 *                          in the answer parameter.
     51 *
     52 * @return EOK on success.
     53 * @return ENOTSUP if the message is not known.
     54 * @return Other error codes as defined for each specific module message function.
     55 *
    5156 */
    52 int netif_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    53         return netif_message(callid, call, answer, answer_count);
     57int netif_module_message(const char *name, ipc_callid_t callid,
     58    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
     59{
     60        return netif_message(name, callid, call, answer, answer_count);
    5461}
    5562
Note: See TracChangeset for help on using the changeset viewer.