Ignore:
File:
1 edited

Legend:

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

    r14f1db0 r849ed54  
    5151#include <nil_interface.h>
    5252#include <nil_messages.h>
    53 #include <netif_interface.h>
    54 #include <netif_local.h>
     53#include <netif.h>
     54#include <netif_module.h>
    5555
    5656/** Default hardware address.
     
    6464/** Loopback module name.
    6565 */
    66 #define NAME  "lo"
     66#define NAME    "lo - loopback interface"
    6767
    6868/** Network interface global data.
     
    7676 *  @returns EOK otherwise.
    7777 */
    78 int change_state_message(netif_device_t * device, device_state_t state);
     78int change_state_message(device_ref device, device_state_t state);
    7979
    8080/** Creates and returns the loopback network interface structure.
     
    8585 *  @returns ENOMEM if there is not enough memory left.
    8686 */
    87 int create(device_id_t device_id, netif_device_t * * device);
     87int create(device_id_t device_id, device_ref * device);
    8888
    8989int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     
    103103        ERROR_DECLARE;
    104104
    105         netif_device_t * device;
     105        device_ref device;
    106106
    107107        if(! stats){
     
    113113}
    114114
    115 int change_state_message(netif_device_t * device, device_state_t state)
    116 {
    117         if (device->state != state) {
     115int change_state_message(device_ref device, device_state_t state){
     116        if(device->state != state){
    118117                device->state = state;
    119                
    120                 printf("%s: State changed to %s\n", NAME,
    121                     (state == NETIF_ACTIVE) ? "active" : "stopped");
    122                
     118                printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED");
    123119                return state;
    124120        }
    125        
    126         return EOK;
    127 }
    128 
    129 int create(device_id_t device_id, netif_device_t * * device){
     121        return EOK;
     122}
     123
     124int create(device_id_t device_id, device_ref * device){
    130125        int index;
    131126
    132         if(netif_device_map_count(&netif_globals.device_map) > 0){
     127        if(device_map_count(&netif_globals.device_map) > 0){
    133128                return EXDEV;
    134129        }else{
    135                 *device = (netif_device_t *) malloc(sizeof(netif_device_t));
     130                *device = (device_ref) malloc(sizeof(device_t));
    136131                if(!(*device)){
    137132                        return ENOMEM;
     
    146141                (** device).nil_phone = -1;
    147142                (** device).state = NETIF_STOPPED;
    148                 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device);
     143                index = device_map_add(&netif_globals.device_map, (** device).device_id, * device);
    149144                if(index < 0){
    150145                        free(*device);
     
    166161        ERROR_DECLARE;
    167162
    168         netif_device_t * device;
     163        device_ref device;
    169164
    170165        // create a new device
    171166        ERROR_PROPAGATE(create(device_id, &device));
    172167        // print the settings
    173         printf("%s: Device created (id: %d)\n", NAME, device->device_id);
     168        printf("New device created:\n\tid\t= %d\n", device->device_id);
    174169        return EOK;
    175170}
     
    178173        ERROR_DECLARE;
    179174
    180         netif_device_t * device;
     175        device_ref device;
    181176        size_t length;
    182177        packet_t next;
     
    204199}
    205200
    206 int netif_start_message(netif_device_t * device){
     201int netif_start_message(device_ref device){
    207202        return change_state_message(device, NETIF_ACTIVE);
    208203}
    209204
    210 int netif_stop_message(netif_device_t * device){
     205int netif_stop_message(device_ref device){
    211206        return change_state_message(device, NETIF_STOPPED);
    212207}
    213208
     209#ifdef CONFIG_NETWORKING_modular
     210
     211#include <netif_standalone.h>
     212
    214213/** Default thread for new connections.
    215214 *
    216  * @param[in] iid The initial message identifier.
    217  * @param[in] icall The initial message call structure.
    218  *
    219  */
    220 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     215 *  @param[in] iid The initial message identifier.
     216 *  @param[in] icall The initial message call structure.
     217 *
     218 */
     219static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)
    221220{
    222221        /*
     
    238237               
    239238                /* Process the message */
    240                 int res = netif_module_message(NAME, callid, &call, &answer,
    241                     &answer_count);
     239                int res = netif_module_message(callid, &call, &answer, &answer_count);
    242240               
    243241                /* End if said to either by the message or the processing result */
     
    250248}
    251249
     250/** Starts the module.
     251 *
     252 *  @param argc The count of the command line arguments. Ignored parameter.
     253 *  @param argv The command line parameters. Ignored parameter.
     254 *
     255 *  @returns EOK on success.
     256 *  @returns Other error codes as defined for each specific module start function.
     257 *
     258 */
    252259int main(int argc, char *argv[])
    253260{
    254261        ERROR_DECLARE;
    255262       
     263        /* Print the module label */
     264        printf("Task %d - %s\n", task_get_id(), NAME);
     265       
    256266        /* Start the module */
    257         if (ERROR_OCCURRED(netif_module_start(netif_client_connection)))
     267        if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) {
     268                printf(" - ERROR %i\n", ERROR_CODE);
    258269                return ERROR_CODE;
    259        
    260         return EOK;
    261 }
     270        }
     271       
     272        return EOK;
     273}
     274
     275#endif /* CONFIG_NETWORKING_modular */
    262276
    263277/** @}
Note: See TracChangeset for help on using the changeset viewer.