Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <debug.h> |
| 24 | #include <app.h> |
| 25 | #include <kernel/thread.h> |
| 26 | |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 27 | extern const struct app_descriptor __apps_start; |
| 28 | extern const struct app_descriptor __apps_end; |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 29 | |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 30 | static void start_app(const struct app_descriptor *app); |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 31 | |
| 32 | /* one time setup */ |
| 33 | void apps_init(void) |
| 34 | { |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 35 | const struct app_descriptor *app; |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 36 | |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 37 | /* call all the init routines */ |
| 38 | for (app = &__apps_start; app != &__apps_end; app++) { |
| 39 | if (app->init) |
| 40 | app->init(app); |
| 41 | } |
| 42 | |
| 43 | /* start any that want to start on boot */ |
| 44 | for (app = &__apps_start; app != &__apps_end; app++) { |
| 45 | if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) { |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 46 | start_app(app); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static int app_thread_entry(void *arg) |
| 52 | { |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 53 | const struct app_descriptor *app = (const struct app_descriptor *)arg; |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 54 | |
| 55 | app->entry(app, NULL); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 60 | static void start_app(const struct app_descriptor *app) |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 61 | { |
| 62 | printf("starting app %s\n", app->name); |
Travis Geiselbrecht | 668383c | 2009-01-24 21:44:52 -0800 | [diff] [blame] | 63 | |
| 64 | thread_resume(thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 65 | } |
| 66 | |