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


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.)

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.