Rev 4743 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3666 | mejdrech | 1 | /* |
3912 | mejdrech | 2 | * Copyright (c) 2009 Lukas Mejdrech |
3666 | 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 |
||
3912 | mejdrech | 30 | * @{ |
3666 | mejdrech | 31 | */ |
32 | |||
33 | /** @file |
||
4704 | mejdrech | 34 | * Starts the networking subsystem. |
35 | * Performs self test if configured to. |
||
3912 | mejdrech | 36 | * @see configuration.h |
3666 | mejdrech | 37 | */ |
38 | |||
39 | #include <async.h> |
||
40 | #include <stdio.h> |
||
41 | #include <task.h> |
||
3846 | mejdrech | 42 | |
3666 | mejdrech | 43 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
||
45 | |||
3886 | mejdrech | 46 | #include "../../err.h" |
47 | #include "../../modules.h" |
||
48 | #include "../../self_test.h" |
||
3666 | mejdrech | 49 | |
4743 | mejdrech | 50 | #include "../net_messages.h" |
51 | |||
3912 | mejdrech | 52 | /** Networking startup module name. |
53 | */ |
||
3666 | mejdrech | 54 | #define NAME "Networking startup" |
55 | |||
3912 | mejdrech | 56 | /** Module entry point. |
4756 | mejdrech | 57 | * @param[in] argc The number of command line parameters. |
58 | * @param[in] argv The command line parameters. |
||
3912 | mejdrech | 59 | * @returns EOK on success. |
4307 | mejdrech | 60 | * @returns EINVAL if the net module cannot be started. |
3912 | mejdrech | 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 | */ |
||
3666 | mejdrech | 64 | int main( int argc, char * argv[] ); |
3912 | mejdrech | 65 | |
66 | /** Starts the module. |
||
4756 | mejdrech | 67 | * @param[in] fname The module absolute name. |
3912 | mejdrech | 68 | * @returns The started module task identifier. |
69 | * @returns Other error codes as defined for the task_spawn() function. |
||
70 | */ |
||
4163 | mejdrech | 71 | task_id_t spawn( char * fname ); |
3666 | mejdrech | 72 | |
73 | int main( int argc, char * argv[] ){ |
||
74 | ERROR_DECLARE; |
||
75 | |||
4307 | mejdrech | 76 | int net_phone; |
3666 | mejdrech | 77 | |
4307 | mejdrech | 78 | printf( "Task %d - ", task_get_id()); |
79 | printf( "%s\n", NAME ); |
||
3666 | mejdrech | 80 | // run self tests |
81 | ERROR_PROPAGATE( self_test()); |
||
4307 | mejdrech | 82 | // start net service |
4155 | mejdrech | 83 | if( ! spawn( "/srv/net" )){ |
4603 | mejdrech | 84 | fprintf( stderr, "Could not spawn net\n" ); |
3666 | mejdrech | 85 | return EINVAL; |
86 | } |
||
4307 | mejdrech | 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 ); |
||
3666 | mejdrech | 91 | return ERROR_CODE; |
4743 | mejdrech | 92 | }else{ |
93 | printf( "OK\n" ); |
||
3666 | mejdrech | 94 | } |
4163 | mejdrech | 95 | |
3666 | mejdrech | 96 | return EOK; |
97 | } |
||
98 | |||
4163 | mejdrech | 99 | task_id_t spawn( char * fname ){ |
100 | char * argv[ 2 ]; |
||
3666 | mejdrech | 101 | task_id_t res; |
102 | |||
103 | // printf( "Spawning %s\n", fname ); |
||
4163 | mejdrech | 104 | argv[ 0 ] = fname; |
105 | argv[ 1 ] = NULL; |
||
3666 | mejdrech | 106 | res = task_spawn( fname, argv ); |
107 | if( res != 0 ){ |
||
108 | /* Success */ |
||
109 | usleep( 50000 ); |
||
110 | } |
||
111 | return res; |
||
112 | } |
||
113 | |||
114 | /** @} |
||
115 | */ |