adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * The program handler, used for loading programs and starting the |
| 4 | * screensaver. |
| 5 | * \author Adam Dunkels <adam@dunkels.com> |
| 6 | * |
| 7 | * The Contiki program handler is responsible for the Contiki menu and |
| 8 | * the desktop icons, as well as for loading programs and displaying a |
| 9 | * dialog with a message telling which program that is loading. |
| 10 | * |
| 11 | * The program handler also is responsible for starting the |
| 12 | * screensaver when the CTK detects that it should be started. |
| 13 | */ |
| 14 | |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 15 | /* |
| 16 | * Copyright (c) 2003, Adam Dunkels. |
| 17 | * All rights reserved. |
| 18 | * |
| 19 | * Redistribution and use in source and binary forms, with or without |
| 20 | * modification, are permitted provided that the following conditions |
| 21 | * are met: |
| 22 | * 1. Redistributions of source code must retain the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer. |
| 24 | * 2. Redistributions in binary form must reproduce the above |
| 25 | * copyright notice, this list of conditions and the following |
| 26 | * disclaimer in the documentation and/or other materials provided |
| 27 | * with the distribution. |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 28 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 29 | * products derived from this software without specific prior |
| 30 | * written permission. |
| 31 | * |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 33 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 36 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 38 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 39 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 40 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 41 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 42 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 43 | * |
adamdunkels | 6b3c858 | 2003-04-08 19:25:38 +0000 | [diff] [blame] | 44 | * This file is part of the Contiki desktop OS |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 45 | * |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 46 | * $Id: program-handler.c,v 1.27 2005/01/24 23:20:50 oliverschmidt Exp $ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 47 | * |
| 48 | */ |
| 49 | |
adamdunkels | db300d2 | 2004-02-24 09:57:49 +0000 | [diff] [blame] | 50 | #include <string.h> |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 51 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 52 | #include "ek.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 53 | #include "petsciiconv.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 54 | #include "ctk.h" |
| 55 | #include "ctk-draw.h" |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 56 | #include "ctk-conf.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 57 | |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 58 | #include "log.h" |
| 59 | |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 60 | #include "loader.h" |
| 61 | |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 62 | #include "program-handler.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 63 | |
| 64 | /* Menus */ |
| 65 | static struct ctk_menu contikimenu; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 66 | |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 67 | #define MAX_NUMDSCS 10 |
| 68 | |
| 69 | static struct dsc *contikidsc[MAX_NUMDSCS]; |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 70 | static unsigned char contikidsclast = 0; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 71 | |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 72 | #if WITH_LOADER_ARCH |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 73 | /* "Run..." window */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 74 | static struct ctk_window runwindow; |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 75 | static unsigned char runmenuitem; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 76 | static struct ctk_label namelabel = |
| 77 | {CTK_LABEL(0, 0, 13, 1, "Program name:")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 78 | static char name[31]; |
| 79 | static struct ctk_textentry nameentry = |
adamdunkels | dc57fb0 | 2003-04-10 07:05:18 +0000 | [diff] [blame] | 80 | {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 81 | static struct ctk_button loadbutton = |
adamdunkels | dc57fb0 | 2003-04-10 07:05:18 +0000 | [diff] [blame] | 82 | {CTK_BUTTON(10, 2, 4, "Load")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 83 | |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 84 | static struct ctk_window loadingdialog; |
| 85 | static struct ctk_label loadingmsg = |
| 86 | {CTK_LABEL(0, 0, 8, 1, "Starting")}; |
| 87 | static struct ctk_label loadingname = |
| 88 | {CTK_LABEL(9, 0, 16, 1, name)}; |
| 89 | |
| 90 | static struct ctk_window errordialog; |
| 91 | static struct ctk_label errormsg = |
| 92 | {CTK_LABEL(0, 1, 22, 1, "Error loading program:")}; |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 93 | static char errorfilename[22]; |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 94 | static struct ctk_label errorfilelabel = |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 95 | {CTK_LABEL(0, 3, 22, 1, errorfilename)}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 96 | static struct ctk_label errortype = |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 97 | {CTK_LABEL(4, 5, 16, 1, "")}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 98 | static struct ctk_button errorokbutton = |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 99 | {CTK_BUTTON(9, 7, 2, "Ok")}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | #endif /* WITH_LOADER_ARCH */ |
| 103 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 104 | /*static DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 105 | static struct dispatcher_proc p = |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 106 | {DISPATCHER_PROC("Program handler", NULL, program_handler_sighandler, NULL)}; |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 107 | static ek_id_t id;*/ |
| 108 | EK_EVENTHANDLER(program_handler_eventhandler, ev, data); |
| 109 | EK_PROCESS(p, "Program handler", EK_PRIO_NORMAL, |
| 110 | program_handler_eventhandler, NULL, NULL); |
| 111 | static ek_id_t id = EK_ID_NONE; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 112 | |
| 113 | |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 114 | static const char * const errormsgs[] = { |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 115 | "Ok", |
| 116 | "Read error", |
| 117 | "Header error", |
| 118 | "OS error", |
| 119 | "Data format error", |
adamdunkels | 46dbaed | 2003-07-31 23:47:30 +0000 | [diff] [blame] | 120 | "Out of memory", |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 121 | "File not found", |
| 122 | "No loader" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 125 | #define LOADER_EVENT_LOAD 1 |
| 126 | #define LOADER_EVENT_DISPLAY_NAME 2 |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 127 | |
| 128 | static char *displayname; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 129 | |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 130 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 131 | static char screensaver[20]; |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 132 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 133 | |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 134 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 135 | /** |
| 136 | * Add a program to the program handler. |
| 137 | * |
| 138 | * \param dsc The DSC description structure for the program to be added. |
| 139 | * |
| 140 | * \param menuname The name that the program should have in the |
| 141 | * Contiki menu. |
| 142 | * |
| 143 | * \param desktop Flag which specifies if the program should show up |
| 144 | * as an icon on the desktop or not. |
| 145 | */ |
| 146 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 147 | void |
| 148 | program_handler_add(struct dsc *dsc, char *menuname, |
| 149 | unsigned char desktop) |
| 150 | { |
| 151 | contikidsc[contikidsclast++] = dsc; |
| 152 | ctk_menuitem_add(&contikimenu, menuname); |
| 153 | if(desktop) { |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 154 | CTK_ICON_ADD(dsc->icon, id); |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 157 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 158 | /** |
| 159 | * Initializes the program handler. |
| 160 | * |
| 161 | * Is called by the initialization before any programs have been added |
| 162 | * with program_handler_add(). |
| 163 | * |
| 164 | */ |
| 165 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 166 | void |
| 167 | program_handler_init(void) |
| 168 | { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 169 | id = ek_start(&p); |
| 170 | ctk_menu_new(&contikimenu, "Contiki"); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 171 | } |
| 172 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 173 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 174 | #define NUM_PNARGS 6 |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 175 | #define NAMELEN 16 |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 176 | struct pnarg { |
| 177 | char name[NAMELEN]; |
| 178 | char *arg; |
| 179 | }; |
| 180 | static struct pnarg pnargs[NUM_PNARGS]; |
| 181 | static struct pnarg * |
| 182 | pnarg_copy(char *name, char *arg) |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 183 | { |
| 184 | char i; |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 185 | struct pnarg *pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 186 | |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 187 | pnargsptr = pnargs; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 188 | /* Allocate a place in the loadernames table. */ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 189 | for(i = 0; i < NUM_PNARGS; ++i) { |
| 190 | if(*(pnargsptr->name) == 0) { |
| 191 | strncpy(pnargsptr->name, name, NAMELEN); |
| 192 | pnargsptr->arg = arg; |
| 193 | return pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 194 | } |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 195 | ++pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 196 | } |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | static void |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 201 | pnarg_free(struct pnarg *pn) |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 202 | { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 203 | *(pn->name) = 0; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 204 | } |
| 205 | #endif /* WITH_LOADER_ARCH */ |
| 206 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 207 | /** |
| 208 | * Loads a program and displays a dialog telling the user about it. |
| 209 | * |
| 210 | * \param name The name of the program to be loaded. |
| 211 | * |
| 212 | * \param arg An argument which is passed to the new process when it |
| 213 | * is loaded. |
| 214 | */ |
| 215 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 216 | void |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 217 | program_handler_load(char *name, char *arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 218 | { |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 219 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 220 | struct pnarg *pnarg; |
| 221 | |
| 222 | pnarg = pnarg_copy(name, arg); |
| 223 | if(pnarg != NULL) { |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 224 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, pnarg); |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 225 | } else { |
| 226 | ctk_label_set_text(&errortype, "Out of memory"); |
| 227 | ctk_dialog_open(&errordialog); |
| 228 | } |
adamdunkels | 12467a7 | 2003-04-24 17:21:12 +0000 | [diff] [blame] | 229 | /* ctk_redraw(); */ |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 230 | /* ctk_window_redraw(&loadingdialog);*/ |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 231 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 232 | } |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 233 | |
| 234 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 235 | #define RUN(prg, name, arg) program_handler_load(prg, arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 236 | #else /* WITH_LOADER_ARCH */ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 237 | #define RUN(prg, initfunc, arg) initfunc(arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 238 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 239 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 240 | /** |
| 241 | * Configures the name of the screensaver to be loaded when |
| 242 | * appropriate. |
| 243 | * |
| 244 | * \param name The name of the screensaver or NULL if no screensaver |
| 245 | * should be used. |
| 246 | */ |
| 247 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 248 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 249 | void |
| 250 | program_handler_screensaver(char *name) |
| 251 | { |
adamdunkels | 15e26dd | 2003-08-11 22:24:20 +0000 | [diff] [blame] | 252 | if(name == NULL) { |
| 253 | screensaver[0] = 0; |
| 254 | } else { |
| 255 | strncpy(screensaver, name, sizeof(screensaver)); |
| 256 | } |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 257 | } |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 258 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 259 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 260 | static void |
| 261 | make_windows(void) |
| 262 | { |
| 263 | #ifdef WITH_LOADER_ARCH |
| 264 | ctk_window_new(&runwindow, 16, 3, "Run"); |
| 265 | |
| 266 | CTK_WIDGET_ADD(&runwindow, &namelabel); |
| 267 | CTK_WIDGET_ADD(&runwindow, &nameentry); |
| 268 | CTK_WIDGET_ADD(&runwindow, &loadbutton); |
| 269 | |
| 270 | CTK_WIDGET_FOCUS(&runwindow, &nameentry); |
| 271 | |
| 272 | ctk_dialog_new(&loadingdialog, 25, 1); |
| 273 | CTK_WIDGET_ADD(&loadingdialog, &loadingmsg); |
| 274 | CTK_WIDGET_ADD(&loadingdialog, &loadingname); |
| 275 | |
| 276 | ctk_dialog_new(&errordialog, 22, 8); |
| 277 | CTK_WIDGET_ADD(&errordialog, &errormsg); |
| 278 | CTK_WIDGET_ADD(&errordialog, &errorfilelabel); |
| 279 | CTK_WIDGET_ADD(&errordialog, &errortype); |
| 280 | CTK_WIDGET_ADD(&errordialog, &errorokbutton); |
| 281 | CTK_WIDGET_FOCUS(&errordialog, &errorokbutton); |
| 282 | #endif /* WITH_LOADER_ARCH */ |
| 283 | } |
| 284 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 285 | /*static |
| 286 | DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data)*/ |
| 287 | EK_EVENTHANDLER(program_handler_eventhandler, ev, data) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 288 | { |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 289 | #ifdef WITH_LOADER_ARCH |
| 290 | unsigned char err; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 291 | struct dsc *dsc; |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 292 | #endif /* WITH_LOADER_ARCH */ |
| 293 | unsigned char i; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 294 | struct dsc **dscp; |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 295 | /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/ |
| 296 | EK_EVENTHANDLER_ARGS(ev, data); |
| 297 | |
| 298 | if(ev == EK_EVENT_INIT) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 299 | /* Create the menus */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 300 | ctk_menu_add(&contikimenu); |
| 301 | #if WITH_LOADER_ARCH |
| 302 | runmenuitem = ctk_menuitem_add(&contikimenu, "Run program..."); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 303 | |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 304 | make_windows(); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 305 | #endif /* WITH_LOADER_ARCH */ |
| 306 | |
| 307 | |
| 308 | displayname = NULL; |
| 309 | |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 310 | #if CTK_CONF_SCREENSAVER |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 311 | screensaver[0] = 0; |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame^] | 312 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 313 | |
| 314 | } else if(ev == ctk_signal_button_activate) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 315 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 316 | if(data == (ek_data_t)&loadbutton) { |
| 317 | ctk_window_close(&runwindow); |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 318 | program_handler_load(name, NULL); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 319 | } else if(data == (ek_data_t)&errorokbutton) { |
| 320 | ctk_dialog_close(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 321 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 322 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 323 | dscp = &contikidsc[0]; |
| 324 | for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) { |
| 325 | if(*dscp != NULL && |
| 326 | data == (ek_data_t)(*dscp)->icon) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 327 | RUN((*dscp)->prgname, (*dscp)->init, NULL); |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 328 | break; |
| 329 | } |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 330 | ++dscp; |
| 331 | } |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 332 | } else if(ev == ctk_signal_menu_activate) { |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 333 | if((struct ctk_menu *)data == &contikimenu) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 334 | #if WITH_LOADER_ARCH |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 335 | dsc = contikidsc[contikimenu.active]; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 336 | if(dsc != NULL) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 337 | RUN(dsc->prgname, dsc->init, NULL); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 338 | } else if(contikimenu.active == runmenuitem) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 339 | make_windows(); |
adamdunkels | b1a88e2 | 2004-09-09 21:15:55 +0000 | [diff] [blame] | 340 | ctk_window_close(&runwindow); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 341 | ctk_window_open(&runwindow); |
adamdunkels | 46dbaed | 2003-07-31 23:47:30 +0000 | [diff] [blame] | 342 | CTK_WIDGET_FOCUS(&runwindow, &nameentry); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 343 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 344 | #else /* WITH_LOADER_ARCH */ |
| 345 | if(contikidsc[contikimenu.active] != NULL) { |
| 346 | RUN(contikidsc[contikimenu.active]->prgname, |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 347 | contikidsc[contikimenu.active]->init, |
| 348 | NULL); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 349 | } |
| 350 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 351 | } |
| 352 | #if CTK_CONF_SCREENSAVER |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 353 | } else if(ev == ctk_signal_screensaver_start) { |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 354 | #if WITH_LOADER_ARCH |
| 355 | if(screensaver[0] != 0) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 356 | program_handler_load(screensaver, NULL); |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 357 | } |
| 358 | #endif /* WITH_LOADER_ARCH */ |
| 359 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 360 | } else if(ev == LOADER_EVENT_DISPLAY_NAME) { |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 361 | #if WITH_LOADER_ARCH |
| 362 | if(displayname == NULL) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 363 | make_windows(); |
| 364 | |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 365 | ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 366 | ctk_dialog_open(&loadingdialog); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 367 | /* dispatcher_emit(loader_signal_load, data, id);*/ |
| 368 | ek_post(id, LOADER_EVENT_LOAD, data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 369 | displayname = data; |
| 370 | } else { |
| 371 | /* Try again. */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 372 | /* dispatcher_emit(loader_signal_display_name, data, id);*/ |
| 373 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 374 | } |
| 375 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 376 | } else if(ev == LOADER_EVENT_LOAD) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 377 | #if WITH_LOADER_ARCH |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 378 | if(displayname == data) { |
| 379 | ctk_dialog_close(); |
| 380 | displayname = NULL; |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 381 | log_message("Loading ", ((struct pnarg *)data)->name); |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 382 | err = LOADER_LOAD(((struct pnarg *)data)->name, |
| 383 | ((struct pnarg *)data)->arg); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 384 | if(err != LOADER_OK) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 385 | make_windows(); |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 386 | errorfilename[0] = '"'; |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 387 | strncpy(errorfilename + 1, ((struct pnarg *)data)->name, |
| 388 | sizeof(errorfilename) - 2); |
| 389 | errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"'; |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 390 | ctk_label_set_text(&errortype, (char *)errormsgs[err]); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 391 | ctk_dialog_open(&errordialog); |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 392 | log_message((char *)errormsgs[err], errorfilename); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 393 | } |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 394 | pnarg_free(data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 395 | } else { |
| 396 | /* Try again. */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 397 | /* dispatcher_emit(loader_signal_display_name, data, id);*/ |
| 398 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 399 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 400 | #endif /* WITH_LOADEER_ARCH */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | /*-----------------------------------------------------------------------------------*/ |