Changeset 24ab58b3 in mainline for uspace/srv/net/nil/nildummy


Ignore:
Timestamp:
2010-04-06T11:41:48Z (16 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/srv/net/nil/nildummy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/nil/nildummy/nildummy.c

    r4dd8529 r24ab58b3  
    6060/** The module name.
    6161 */
    62 #define NAME    "Dummy nil protocol"
     62#define NAME  "nildummy"
    6363
    6464/** Default maximum transmission unit.
     
    228228                        return index;
    229229                }
    230                 printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n", device->device_id, device->service, device->mtu);
     230                printf("%s: Device registered (id: %d, service: %d, mtu: %d)\n",
     231                    NAME, device->device_id, device->service, device->mtu);
    231232        }
    232233        fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    290291        nildummy_globals.proto.service = service;
    291292        nildummy_globals.proto.phone = phone;
    292         printf("New protocol registered:\n\tservice\t= %d\n\tphone\t= %d\n", nildummy_globals.proto.service, nildummy_globals.proto.phone);
     293       
     294        printf("%s: Protocol registered (service: %d, phone: %d)\n",
     295            NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone);
     296       
    293297        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
    294298        return EOK;
     
    312316}
    313317
    314 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     318int nil_message(const char *name, ipc_callid_t callid, ipc_call_t *call,
     319    ipc_call_t *answer, int *answer_count)
     320{
    315321        ERROR_DECLARE;
    316 
     322       
    317323        measured_string_ref address;
    318324        packet_t packet;
     
    321327        size_t suffix;
    322328        size_t content;
    323 
    324 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
     329       
    325330        *answer_count = 0;
    326         switch(IPC_GET_METHOD(*call)){
     331        switch (IPC_GET_METHOD(*call)) {
    327332                case IPC_M_PHONE_HUNGUP:
    328333                        return EOK;
    329334                case NET_NIL_DEVICE:
    330                         return nildummy_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call));
     335                        return nildummy_device_message(IPC_GET_DEVICE(call),
     336                            IPC_GET_SERVICE(call), IPC_GET_MTU(call));
    331337                case NET_NIL_SEND:
    332                         ERROR_PROPAGATE(packet_translate(nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call)));
    333                         return nildummy_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call));
     338                        ERROR_PROPAGATE(packet_translate(nildummy_globals.net_phone,
     339                            &packet, IPC_GET_PACKET(call)));
     340                        return nildummy_send_message(IPC_GET_DEVICE(call), packet,
     341                            IPC_GET_SERVICE(call));
    334342                case NET_NIL_PACKET_SPACE:
    335                         ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call), &addrlen, &prefix, &content, &suffix));
     343                        ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call),
     344                            &addrlen, &prefix, &content, &suffix));
    336345                        IPC_SET_ADDR(answer, addrlen);
    337346                        IPC_SET_PREFIX(answer, prefix);
     
    341350                        return EOK;
    342351                case NET_NIL_ADDR:
    343                         ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), &address));
     352                        ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call),
     353                            &address));
    344354                        return measured_strings_reply(address, 1);
    345355                case IPC_M_CONNECT_TO_ME:
    346                         return nildummy_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call));
    347         }
     356                        return nildummy_register_message(NIL_GET_PROTO(call),
     357                            IPC_GET_PHONE(call));
     358        }
     359       
    348360        return ENOTSUP;
    349361}
     
    404416               
    405417                /* Process the message */
    406                 int res = nil_module_message(callid, &call, &answer, &answer_count);
     418                int res = nil_module_message(NAME, callid, &call, &answer,
     419                    &answer_count);
    407420               
    408421                /* End if said to either by the message or the processing result */
     
    428441        ERROR_DECLARE;
    429442       
    430         /* Print the module label */
    431         printf("Task %d - %s\n", task_get_id(), NAME);
    432        
    433443        /* Start the module */
    434         if (ERROR_OCCURRED(nil_module_start(nil_client_connection))) {
    435                 printf(" - ERROR %i\n", ERROR_CODE);
     444        if (ERROR_OCCURRED(nil_module_start(nil_client_connection)))
    436445                return ERROR_CODE;
    437         }
    438446       
    439447        return EOK;
  • uspace/srv/net/nil/nildummy/nildummy_module.c

    r4dd8529 r24ab58b3  
    5151#include "nildummy.h"
    5252
    53 /** Starts the dummy nil module.
    54  *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
    55  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    56  *  @returns EOK on success.
    57  *  @returns Other error codes as defined for the pm_init() function.
    58  *  @returns Other error codes as defined for the nil_initialize() function.
    59  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
     53/** Start the dummy nil module.
     54 *
     55 * Initialize the client connection serving function, initialize
     56 * the module, register the module service and start the async
     57 * manager, processing IPC messages in an infinite loop.
     58 *
     59 * @param[in] client_connection The client connection processing
     60 *                              function. The module skeleton propagates
     61 *                              its own one.
     62 *
     63 * @return EOK on success.
     64 * @return Other error codes as defined for the pm_init() function.
     65 * @return Other error codes as defined for the nil_initialize() function.
     66 * @return Other error codes as defined for the REGISTER_ME() macro function.
     67 *
    6068 */
    61 int nil_module_start(async_client_conn_t client_connection){
     69int nil_module_start(async_client_conn_t client_connection)
     70{
    6271        ERROR_DECLARE;
    63 
     72       
     73        async_set_client_connection(client_connection);
     74        int net_phone = net_connect_module(SERVICE_NETWORKING);
     75        ERROR_PROPAGATE(pm_init());
     76       
    6477        ipcarg_t phonehash;
    65         int net_phone;
    66 
    67         async_set_client_connection(client_connection);
    68         net_phone = net_connect_module(SERVICE_NETWORKING);
    69         ERROR_PROPAGATE(pm_init());
    70         if(ERROR_OCCURRED(nil_initialize(net_phone))
    71                 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){
     78        if (ERROR_OCCURRED(nil_initialize(net_phone))
     79            || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){
    7280                pm_destroy();
    7381                return ERROR_CODE;
    7482        }
    75 
     83       
    7684        async_manager();
    77 
     85       
    7886        pm_destroy();
    7987        return EOK;
    8088}
    8189
    82 /** Passes the parameters to the module specific nil_message() function.
    83  *  @param[in] callid The message identifier.
    84  *  @param[in] call The message parameters.
    85  *  @param[out] answer The message answer parameters.
    86  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    87  *  @returns EOK on success.
    88  *  @returns ENOTSUP if the message is not known.
    89  *  @returns Other error codes as defined for each specific module message function.
     90/** Pass the parameters to the module specific nil_message() function.
     91 *
     92 * @param[in]  name         Module name.
     93 * @param[in]  callid       The message identifier.
     94 * @param[in]  call         The message parameters.
     95 * @param[out] answer       The message answer parameters.
     96 * @param[out] answer_count The last parameter for the actual answer
     97 *                          in the answer parameter.
     98 *
     99 * @return EOK on success.
     100 * @return ENOTSUP if the message is not known.
     101 * @return Other error codes as defined for each specific
     102 *          module message function.
     103 *
    90104 */
    91 int nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    92         return nil_message(callid, call, answer, answer_count);
     105int nil_module_message(const char *name, ipc_callid_t callid,
     106    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
     107{
     108        return nil_message(name, callid, call, answer, answer_count);
    93109}
    94110
Note: See TracChangeset for help on using the changeset viewer.