[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup net
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
| 34 | * Starts the networking subsystem.
|
---|
| 35 | * Performs self test if configured to.
|
---|
| 36 | * @see configuration.h
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <async.h>
|
---|
| 40 | #include <stdio.h>
|
---|
| 41 | #include <task.h>
|
---|
| 42 |
|
---|
| 43 | #include <ipc/ipc.h>
|
---|
| 44 | #include <ipc/services.h>
|
---|
| 45 |
|
---|
| 46 | #include "../../err.h"
|
---|
| 47 | #include "../../modules.h"
|
---|
| 48 | #include "../../self_test.h"
|
---|
| 49 |
|
---|
| 50 | #include "../net_messages.h"
|
---|
| 51 |
|
---|
| 52 | /** Networking startup module name.
|
---|
| 53 | */
|
---|
| 54 | #define NAME "Networking startup"
|
---|
| 55 |
|
---|
| 56 | /** Module entry point.
|
---|
| 57 | * @param[in] argc The number of command line parameters.
|
---|
| 58 | * @param[in] argv The command line parameters.
|
---|
| 59 | * @returns EOK on success.
|
---|
| 60 | * @returns EINVAL if the net module cannot be started.
|
---|
| 61 | * @returns Other error codes as defined for the self_test() function.
|
---|
| 62 | * @returns Other error codes as defined for the NET_NET_STARTUP message.
|
---|
| 63 | */
|
---|
| 64 | int main( int argc, char * argv[] );
|
---|
| 65 |
|
---|
| 66 | /** Starts the module.
|
---|
| 67 | * @param[in] fname The module absolute name.
|
---|
| 68 | * @returns The started module task identifier.
|
---|
| 69 | * @returns Other error codes as defined for the task_spawn() function.
|
---|
| 70 | */
|
---|
| 71 | task_id_t spawn( char * fname );
|
---|
| 72 |
|
---|
| 73 | int main( int argc, char * argv[] ){
|
---|
| 74 | ERROR_DECLARE;
|
---|
| 75 |
|
---|
| 76 | int net_phone;
|
---|
| 77 |
|
---|
| 78 | printf( "Task %d - ", task_get_id());
|
---|
| 79 | printf( "%s\n", NAME );
|
---|
| 80 | // run self tests
|
---|
| 81 | ERROR_PROPAGATE( self_test());
|
---|
| 82 | // start net service
|
---|
| 83 | if( ! spawn( "/srv/net" )){
|
---|
| 84 | fprintf( stderr, "Could not spawn net\n" );
|
---|
| 85 | return EINVAL;
|
---|
| 86 | }
|
---|
| 87 | // start net
|
---|
| 88 | net_phone = connect_to_service( SERVICE_NETWORKING );
|
---|
| 89 | if( ERROR_OCCURRED( ipc_call_sync_0_0( net_phone, NET_NET_STARTUP ))){
|
---|
| 90 | printf( "ERROR %d\n", ERROR_CODE );
|
---|
| 91 | return ERROR_CODE;
|
---|
| 92 | }else{
|
---|
| 93 | printf( "OK\n" );
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | return EOK;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | task_id_t spawn( char * fname ){
|
---|
| 100 | char * argv[ 2 ];
|
---|
| 101 | task_id_t res;
|
---|
| 102 |
|
---|
| 103 | // printf( "Spawning %s\n", fname );
|
---|
| 104 | argv[ 0 ] = fname;
|
---|
| 105 | argv[ 1 ] = NULL;
|
---|
| 106 | res = task_spawn( fname, argv );
|
---|
| 107 | if( res != 0 ){
|
---|
| 108 | /* Success */
|
---|
| 109 | usleep( 50000 );
|
---|
| 110 | }
|
---|
| 111 | return res;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /** @}
|
---|
| 115 | */
|
---|