Changeset aadf01e in mainline for uspace/srv/net/netif/lo/lo.c


Ignore:
Timestamp:
2010-03-07T15:13:28Z (15 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
936835e
Parents:
aa85487
Message:

Coding style (no functional change)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/netif/lo/lo.c

    raa85487 raadf01e  
    6464/** Default address length.
    6565 */
    66 #define DEFAULT_ADDR_LEN        ( sizeof( DEFAULT_ADDR ) / sizeof( char ))
     66#define DEFAULT_ADDR_LEN        (sizeof(DEFAULT_ADDR) / sizeof(char))
    6767
    6868/** Loopback module name.
     
    8080 *  @returns EOK otherwise.
    8181 */
    82 int     change_state_message( device_ref device, device_state_t state );
     82int change_state_message(device_ref device, device_state_t state);
    8383
    8484/** Creates and returns the loopback network interface structure.
     
    8989 *  @returns ENOMEM if there is not enough memory left.
    9090 */
    91 int     create( device_id_t device_id, device_ref * device );
     91int create(device_id_t device_id, device_ref * device);
    9292
    9393/** Prints the module name.
    9494 *  @see NAME
    9595 */
    96 void    module_print_name( void );
    97 
    98 int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
     96void module_print_name(void);
     97
     98int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    9999        return ENOTSUP;
    100100}
    101101
    102 int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){
    103         if( ! address ) return EBADMEM;
     102int netif_get_addr_message(device_id_t device_id, measured_string_ref address){
     103        if(! address){
     104                return EBADMEM;
     105        }
    104106        address->value = str_dup(DEFAULT_ADDR);
    105107        address->length = DEFAULT_ADDR_LEN;
     
    107109}
    108110
    109 int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){
     111int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){
    110112        ERROR_DECLARE;
    111113
    112         device_ref      device;
    113 
    114         if( ! stats ) return EBADMEM;
    115         ERROR_PROPAGATE( find_device( device_id, & device ));
    116         memcpy( stats, ( device_stats_ref ) device->specific, sizeof( device_stats_t ));
    117         return EOK;
    118 }
    119 
    120 int change_state_message( device_ref device, device_state_t state ){
    121         if( device->state != state ){
     114        device_ref device;
     115
     116        if(! stats){
     117                return EBADMEM;
     118        }
     119        ERROR_PROPAGATE(find_device(device_id, &device));
     120        memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t));
     121        return EOK;
     122}
     123
     124int change_state_message(device_ref device, device_state_t state){
     125        if(device->state != state){
    122126                device->state = state;
    123                 printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" );
     127                printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED");
    124128                return state;
    125129        }
     
    127131}
    128132
    129 int create( device_id_t device_id, device_ref * device ){
    130         int     index;
    131 
    132         if( device_map_count( & netif_globals.device_map ) > 0 ){
     133int create(device_id_t device_id, device_ref * device){
     134        int index;
     135
     136        if(device_map_count(&netif_globals.device_map) > 0){
    133137                return EXDEV;
    134138        }else{
    135                 * device = ( device_ref ) malloc( sizeof( device_t ));
    136                 if( !( * device )) return ENOMEM;
    137                 ( ** device ).specific = malloc( sizeof( device_stats_t ));
    138                 if( ! ( ** device ).specific ){
    139                         free( * device );
     139                *device = (device_ref) malloc(sizeof(device_t));
     140                if(!(*device)){
    140141                        return ENOMEM;
    141142                }
    142                 null_device_stats(( device_stats_ref )( ** device ).specific );
    143                 ( ** device ).device_id = device_id;
    144                 ( ** device ).nil_phone = -1;
    145                 ( ** device ).state = NETIF_STOPPED;
    146                 index = device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device );
    147                 if( index < 0 ){
    148                         free( * device );
    149                         free(( ** device ).specific );
    150                         * device = NULL;
     143                (** device).specific = malloc(sizeof(device_stats_t));
     144                if(! (** device).specific){
     145                        free(*device);
     146                        return ENOMEM;
     147                }
     148                null_device_stats((device_stats_ref)(** device).specific);
     149                (** device).device_id = device_id;
     150                (** device).nil_phone = -1;
     151                (** device).state = NETIF_STOPPED;
     152                index = device_map_add(&netif_globals.device_map, (** device).device_id, * device);
     153                if(index < 0){
     154                        free(*device);
     155                        free((** device).specific);
     156                        *device = NULL;
    151157                        return index;
    152158                }
     
    155161}
    156162
    157 int netif_initialize( void ){
    158         ipcarg_t        phonehash;
    159 
    160         return REGISTER_ME( SERVICE_LO, & phonehash );
    161 }
    162 
    163 void module_print_name( void ){
    164         printf( "%s", NAME );
    165 }
    166 
    167 int netif_probe_message( device_id_t device_id, int irq, uintptr_t io ){
     163int netif_initialize(void){
     164        ipcarg_t phonehash;
     165
     166        return REGISTER_ME(SERVICE_LO, &phonehash);
     167}
     168
     169void module_print_name(void){
     170        printf("%s", NAME);
     171}
     172
     173int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    168174        ERROR_DECLARE;
    169175
    170         device_ref                      device;
     176        device_ref device;
    171177
    172178        // create a new device
    173         ERROR_PROPAGATE( create( device_id, & device ));
     179        ERROR_PROPAGATE(create(device_id, &device));
    174180        // print the settings
    175         printf("New device created:\n\tid\t= %d\n", device->device_id );
    176         return EOK;
    177 }
    178 
    179 int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){
     181        printf("New device created:\n\tid\t= %d\n", device->device_id);
     182        return EOK;
     183}
     184
     185int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){
    180186        ERROR_DECLARE;
    181187
    182         device_ref      device;
    183         size_t          length;
    184         packet_t        next;
    185         int                     phone;
    186 
    187         ERROR_PROPAGATE( find_device( device_id, & device ));
    188         if( device->state != NETIF_ACTIVE ){
    189                 netif_pq_release( packet_get_id( packet ));
     188        device_ref device;
     189        size_t length;
     190        packet_t next;
     191        int phone;
     192
     193        ERROR_PROPAGATE(find_device(device_id, &device));
     194        if(device->state != NETIF_ACTIVE){
     195                netif_pq_release(packet_get_id(packet));
    190196                return EFORWARD;
    191197        }
    192198        next = packet;
    193199        do{
    194                 ++ (( device_stats_ref ) device->specific )->send_packets;
    195                 ++ (( device_stats_ref ) device->specific )->receive_packets;
    196                 length = packet_get_data_length( next );
    197                 (( device_stats_ref ) device->specific )->send_bytes += length;
    198                 (( device_stats_ref ) device->specific )->receive_bytes += length;
    199                 next = pq_next( next );
    200         }while( next );
     200                ++ ((device_stats_ref) device->specific)->send_packets;
     201                ++ ((device_stats_ref) device->specific)->receive_packets;
     202                length = packet_get_data_length(next);
     203                ((device_stats_ref) device->specific)->send_bytes += length;
     204                ((device_stats_ref) device->specific)->receive_bytes += length;
     205                next = pq_next(next);
     206        }while(next);
    201207        phone = device->nil_phone;
    202         fibril_rwlock_write_unlock( & netif_globals.lock );
    203         nil_received_msg( phone, device_id, packet, sender );
    204         fibril_rwlock_write_lock( & netif_globals.lock );
    205         return EOK;
    206 }
    207 
    208 int netif_start_message( device_ref device ){
    209         return change_state_message( device, NETIF_ACTIVE );
    210 }
    211 
    212 int netif_stop_message( device_ref device ){
    213         return change_state_message( device, NETIF_STOPPED );
     208        fibril_rwlock_write_unlock(&netif_globals.lock);
     209        nil_received_msg(phone, device_id, packet, sender);
     210        fibril_rwlock_write_lock(&netif_globals.lock);
     211        return EOK;
     212}
     213
     214int netif_start_message(device_ref device){
     215        return change_state_message(device, NETIF_ACTIVE);
     216}
     217
     218int netif_stop_message(device_ref device){
     219        return change_state_message(device, NETIF_STOPPED);
    214220}
    215221
Note: See TracChangeset for help on using the changeset viewer.