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 | 124c3ee | 2005-05-12 21:27:20 +0000 | [diff] [blame^] | 46 | * $Id: program-handler.c,v 1.29 2005/05/12 21:27:20 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 | |
oliverschmidt | cd5e89a | 2005-02-15 14:31:52 +0000 | [diff] [blame] | 64 | #include "program-handler-conf.h" |
| 65 | |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 66 | /* Menus */ |
| 67 | static struct ctk_menu contikimenu; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 68 | |
oliverschmidt | cd5e89a | 2005-02-15 14:31:52 +0000 | [diff] [blame] | 69 | #ifndef PROGRAM_HANDLER_CONF_MAX_NUMDSCS |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 70 | #define MAX_NUMDSCS 10 |
oliverschmidt | cd5e89a | 2005-02-15 14:31:52 +0000 | [diff] [blame] | 71 | #else /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */ |
| 72 | #define MAX_NUMDSCS PROGRAM_HANDLER_CONF_MAX_NUMDSCS |
| 73 | #endif /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */ |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 74 | |
| 75 | static struct dsc *contikidsc[MAX_NUMDSCS]; |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 76 | static unsigned char contikidsclast = 0; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 77 | |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 78 | #if WITH_LOADER_ARCH |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 79 | /* "Run..." window */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 80 | static struct ctk_window runwindow; |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 81 | static unsigned char runmenuitem; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 82 | static struct ctk_label namelabel = |
| 83 | {CTK_LABEL(0, 0, 13, 1, "Program name:")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 84 | static char name[31]; |
| 85 | static struct ctk_textentry nameentry = |
adamdunkels | dc57fb0 | 2003-04-10 07:05:18 +0000 | [diff] [blame] | 86 | {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 87 | static struct ctk_button loadbutton = |
adamdunkels | dc57fb0 | 2003-04-10 07:05:18 +0000 | [diff] [blame] | 88 | {CTK_BUTTON(10, 2, 4, "Load")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 89 | |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 90 | static struct ctk_window loadingdialog; |
| 91 | static struct ctk_label loadingmsg = |
| 92 | {CTK_LABEL(0, 0, 8, 1, "Starting")}; |
| 93 | static struct ctk_label loadingname = |
| 94 | {CTK_LABEL(9, 0, 16, 1, name)}; |
| 95 | |
| 96 | static struct ctk_window errordialog; |
| 97 | static struct ctk_label errormsg = |
| 98 | {CTK_LABEL(0, 1, 22, 1, "Error loading program:")}; |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 99 | static char errorfilename[22]; |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 100 | static struct ctk_label errorfilelabel = |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 101 | {CTK_LABEL(0, 3, 22, 1, errorfilename)}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 102 | static struct ctk_label errortype = |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 103 | {CTK_LABEL(4, 5, 16, 1, "")}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 104 | static struct ctk_button errorokbutton = |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 105 | {CTK_BUTTON(9, 7, 2, "Ok")}; |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 106 | |
| 107 | |
| 108 | #endif /* WITH_LOADER_ARCH */ |
| 109 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 110 | /*static DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 111 | static struct dispatcher_proc p = |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 112 | {DISPATCHER_PROC("Program handler", NULL, program_handler_sighandler, NULL)}; |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 113 | static ek_id_t id;*/ |
| 114 | EK_EVENTHANDLER(program_handler_eventhandler, ev, data); |
| 115 | EK_PROCESS(p, "Program handler", EK_PRIO_NORMAL, |
| 116 | program_handler_eventhandler, NULL, NULL); |
| 117 | static ek_id_t id = EK_ID_NONE; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 118 | |
| 119 | |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 120 | static const char * const errormsgs[] = { |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 121 | "Ok", |
| 122 | "Read error", |
| 123 | "Header error", |
| 124 | "OS error", |
| 125 | "Data format error", |
adamdunkels | 46dbaed | 2003-07-31 23:47:30 +0000 | [diff] [blame] | 126 | "Out of memory", |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 127 | "File not found", |
| 128 | "No loader" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 131 | #define LOADER_EVENT_LOAD 1 |
| 132 | #define LOADER_EVENT_DISPLAY_NAME 2 |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 133 | |
| 134 | static char *displayname; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 135 | |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 136 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 137 | static char screensaver[20]; |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 138 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 139 | |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 140 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 141 | /** |
| 142 | * Add a program to the program handler. |
| 143 | * |
| 144 | * \param dsc The DSC description structure for the program to be added. |
| 145 | * |
| 146 | * \param menuname The name that the program should have in the |
| 147 | * Contiki menu. |
| 148 | * |
| 149 | * \param desktop Flag which specifies if the program should show up |
| 150 | * as an icon on the desktop or not. |
| 151 | */ |
| 152 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 153 | void |
| 154 | program_handler_add(struct dsc *dsc, char *menuname, |
| 155 | unsigned char desktop) |
| 156 | { |
| 157 | contikidsc[contikidsclast++] = dsc; |
| 158 | ctk_menuitem_add(&contikimenu, menuname); |
| 159 | if(desktop) { |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 160 | CTK_ICON_ADD(dsc->icon, id); |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 163 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 164 | /** |
| 165 | * Initializes the program handler. |
| 166 | * |
| 167 | * Is called by the initialization before any programs have been added |
| 168 | * with program_handler_add(). |
| 169 | * |
| 170 | */ |
| 171 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 172 | void |
| 173 | program_handler_init(void) |
| 174 | { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 175 | id = ek_start(&p); |
| 176 | ctk_menu_new(&contikimenu, "Contiki"); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 177 | } |
| 178 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 179 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 180 | #define NUM_PNARGS 6 |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 181 | #define NAMELEN 16 |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 182 | struct pnarg { |
| 183 | char name[NAMELEN]; |
| 184 | char *arg; |
| 185 | }; |
| 186 | static struct pnarg pnargs[NUM_PNARGS]; |
| 187 | static struct pnarg * |
| 188 | pnarg_copy(char *name, char *arg) |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 189 | { |
| 190 | char i; |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 191 | struct pnarg *pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 192 | |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 193 | pnargsptr = pnargs; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 194 | /* Allocate a place in the loadernames table. */ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 195 | for(i = 0; i < NUM_PNARGS; ++i) { |
| 196 | if(*(pnargsptr->name) == 0) { |
| 197 | strncpy(pnargsptr->name, name, NAMELEN); |
| 198 | pnargsptr->arg = arg; |
| 199 | return pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 200 | } |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 201 | ++pnargsptr; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 202 | } |
| 203 | return NULL; |
| 204 | } |
| 205 | |
| 206 | static void |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 207 | pnarg_free(struct pnarg *pn) |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 208 | { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 209 | *(pn->name) = 0; |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 210 | } |
| 211 | #endif /* WITH_LOADER_ARCH */ |
| 212 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 213 | /** |
| 214 | * Loads a program and displays a dialog telling the user about it. |
| 215 | * |
| 216 | * \param name The name of the program to be loaded. |
| 217 | * |
| 218 | * \param arg An argument which is passed to the new process when it |
| 219 | * is loaded. |
| 220 | */ |
| 221 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 222 | void |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 223 | program_handler_load(char *name, char *arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 224 | { |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 225 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 226 | struct pnarg *pnarg; |
| 227 | |
| 228 | pnarg = pnarg_copy(name, arg); |
| 229 | if(pnarg != NULL) { |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 230 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, pnarg); |
adamdunkels | 4a5eadf | 2003-08-05 22:02:52 +0000 | [diff] [blame] | 231 | } else { |
| 232 | ctk_label_set_text(&errortype, "Out of memory"); |
| 233 | ctk_dialog_open(&errordialog); |
| 234 | } |
adamdunkels | 12467a7 | 2003-04-24 17:21:12 +0000 | [diff] [blame] | 235 | /* ctk_redraw(); */ |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 236 | /* ctk_window_redraw(&loadingdialog);*/ |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 237 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 238 | } |
adamdunkels | c1272b2 | 2003-04-11 20:11:40 +0000 | [diff] [blame] | 239 | |
| 240 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 241 | #define RUN(prg, name, arg) program_handler_load(prg, arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 242 | #else /* WITH_LOADER_ARCH */ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 243 | #define RUN(prg, initfunc, arg) initfunc(arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 244 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 245 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 246 | /** |
| 247 | * Configures the name of the screensaver to be loaded when |
| 248 | * appropriate. |
| 249 | * |
| 250 | * \param name The name of the screensaver or NULL if no screensaver |
| 251 | * should be used. |
| 252 | */ |
| 253 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 254 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 255 | void |
oliverschmidt | 124c3ee | 2005-05-12 21:27:20 +0000 | [diff] [blame^] | 256 | program_handler_setscreensaver(char *name) |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 257 | { |
adamdunkels | 15e26dd | 2003-08-11 22:24:20 +0000 | [diff] [blame] | 258 | if(name == NULL) { |
| 259 | screensaver[0] = 0; |
| 260 | } else { |
| 261 | strncpy(screensaver, name, sizeof(screensaver)); |
| 262 | } |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 263 | } |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 264 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 265 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 266 | static void |
| 267 | make_windows(void) |
| 268 | { |
| 269 | #ifdef WITH_LOADER_ARCH |
| 270 | ctk_window_new(&runwindow, 16, 3, "Run"); |
| 271 | |
| 272 | CTK_WIDGET_ADD(&runwindow, &namelabel); |
| 273 | CTK_WIDGET_ADD(&runwindow, &nameentry); |
| 274 | CTK_WIDGET_ADD(&runwindow, &loadbutton); |
| 275 | |
| 276 | CTK_WIDGET_FOCUS(&runwindow, &nameentry); |
| 277 | |
| 278 | ctk_dialog_new(&loadingdialog, 25, 1); |
| 279 | CTK_WIDGET_ADD(&loadingdialog, &loadingmsg); |
| 280 | CTK_WIDGET_ADD(&loadingdialog, &loadingname); |
| 281 | |
| 282 | ctk_dialog_new(&errordialog, 22, 8); |
| 283 | CTK_WIDGET_ADD(&errordialog, &errormsg); |
| 284 | CTK_WIDGET_ADD(&errordialog, &errorfilelabel); |
| 285 | CTK_WIDGET_ADD(&errordialog, &errortype); |
| 286 | CTK_WIDGET_ADD(&errordialog, &errorokbutton); |
| 287 | CTK_WIDGET_FOCUS(&errordialog, &errorokbutton); |
| 288 | #endif /* WITH_LOADER_ARCH */ |
| 289 | } |
| 290 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 291 | /*static |
| 292 | DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data)*/ |
| 293 | EK_EVENTHANDLER(program_handler_eventhandler, ev, data) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 294 | { |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 295 | #ifdef WITH_LOADER_ARCH |
| 296 | unsigned char err; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 297 | struct dsc *dsc; |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 298 | #endif /* WITH_LOADER_ARCH */ |
| 299 | unsigned char i; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 300 | struct dsc **dscp; |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 301 | /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/ |
| 302 | EK_EVENTHANDLER_ARGS(ev, data); |
| 303 | |
| 304 | if(ev == EK_EVENT_INIT) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 305 | /* Create the menus */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 306 | ctk_menu_add(&contikimenu); |
| 307 | #if WITH_LOADER_ARCH |
| 308 | runmenuitem = ctk_menuitem_add(&contikimenu, "Run program..."); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 309 | |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 310 | make_windows(); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 311 | #endif /* WITH_LOADER_ARCH */ |
| 312 | |
| 313 | |
| 314 | displayname = NULL; |
| 315 | |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 316 | #if CTK_CONF_SCREENSAVER |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 317 | screensaver[0] = 0; |
oliverschmidt | 533f7e2 | 2005-01-24 23:20:50 +0000 | [diff] [blame] | 318 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 319 | |
| 320 | } else if(ev == ctk_signal_button_activate) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 321 | #ifdef WITH_LOADER_ARCH |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 322 | if(data == (ek_data_t)&loadbutton) { |
| 323 | ctk_window_close(&runwindow); |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 324 | program_handler_load(name, NULL); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 325 | } else if(data == (ek_data_t)&errorokbutton) { |
| 326 | ctk_dialog_close(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 327 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 328 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 329 | dscp = &contikidsc[0]; |
| 330 | for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) { |
| 331 | if(*dscp != NULL && |
| 332 | data == (ek_data_t)(*dscp)->icon) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 333 | RUN((*dscp)->prgname, (*dscp)->init, NULL); |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 334 | break; |
| 335 | } |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 336 | ++dscp; |
| 337 | } |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 338 | } else if(ev == ctk_signal_menu_activate) { |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 339 | if((struct ctk_menu *)data == &contikimenu) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 340 | #if WITH_LOADER_ARCH |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 341 | dsc = contikidsc[contikimenu.active]; |
adamdunkels | e063517 | 2003-08-09 13:31:18 +0000 | [diff] [blame] | 342 | if(dsc != NULL) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 343 | RUN(dsc->prgname, dsc->init, NULL); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 344 | } else if(contikimenu.active == runmenuitem) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 345 | make_windows(); |
adamdunkels | b1a88e2 | 2004-09-09 21:15:55 +0000 | [diff] [blame] | 346 | ctk_window_close(&runwindow); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 347 | ctk_window_open(&runwindow); |
adamdunkels | 46dbaed | 2003-07-31 23:47:30 +0000 | [diff] [blame] | 348 | CTK_WIDGET_FOCUS(&runwindow, &nameentry); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 349 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 350 | #else /* WITH_LOADER_ARCH */ |
| 351 | if(contikidsc[contikimenu.active] != NULL) { |
| 352 | RUN(contikidsc[contikimenu.active]->prgname, |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 353 | contikidsc[contikimenu.active]->init, |
| 354 | NULL); |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 355 | } |
| 356 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 357 | } |
| 358 | #if CTK_CONF_SCREENSAVER |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 359 | } else if(ev == ctk_signal_screensaver_start) { |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 360 | #if WITH_LOADER_ARCH |
| 361 | if(screensaver[0] != 0) { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 362 | program_handler_load(screensaver, NULL); |
adamdunkels | 8a8138b | 2003-08-09 23:30:37 +0000 | [diff] [blame] | 363 | } |
| 364 | #endif /* WITH_LOADER_ARCH */ |
| 365 | #endif /* CTK_CONF_SCREENSAVER */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 366 | } else if(ev == LOADER_EVENT_DISPLAY_NAME) { |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 367 | #if WITH_LOADER_ARCH |
| 368 | if(displayname == NULL) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 369 | make_windows(); |
| 370 | |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 371 | ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 372 | ctk_dialog_open(&loadingdialog); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 373 | /* dispatcher_emit(loader_signal_load, data, id);*/ |
| 374 | ek_post(id, LOADER_EVENT_LOAD, data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 375 | displayname = data; |
| 376 | } else { |
| 377 | /* Try again. */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 378 | /* dispatcher_emit(loader_signal_display_name, data, id);*/ |
| 379 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 380 | } |
| 381 | #endif /* WITH_LOADER_ARCH */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 382 | } else if(ev == LOADER_EVENT_LOAD) { |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 383 | #if WITH_LOADER_ARCH |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 384 | if(displayname == data) { |
| 385 | ctk_dialog_close(); |
| 386 | displayname = NULL; |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 387 | log_message("Loading ", ((struct pnarg *)data)->name); |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 388 | err = LOADER_LOAD(((struct pnarg *)data)->name, |
| 389 | ((struct pnarg *)data)->arg); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 390 | if(err != LOADER_OK) { |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 391 | make_windows(); |
adamdunkels | 506d6c4 | 2003-08-20 20:52:22 +0000 | [diff] [blame] | 392 | errorfilename[0] = '"'; |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 393 | strncpy(errorfilename + 1, ((struct pnarg *)data)->name, |
| 394 | sizeof(errorfilename) - 2); |
| 395 | errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"'; |
adamdunkels | 4d2d276 | 2003-09-04 19:34:22 +0000 | [diff] [blame] | 396 | ctk_label_set_text(&errortype, (char *)errormsgs[err]); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 397 | ctk_dialog_open(&errordialog); |
adamdunkels | 0eeeba7 | 2004-08-20 21:32:41 +0000 | [diff] [blame] | 398 | log_message((char *)errormsgs[err], errorfilename); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 399 | } |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 400 | pnarg_free(data); |
adamdunkels | 1953928 | 2003-08-05 23:27:23 +0000 | [diff] [blame] | 401 | } else { |
| 402 | /* Try again. */ |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 403 | /* dispatcher_emit(loader_signal_display_name, data, id);*/ |
| 404 | ek_post(id, LOADER_EVENT_DISPLAY_NAME, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 405 | } |
adamdunkels | 045437c | 2003-06-30 20:49:01 +0000 | [diff] [blame] | 406 | #endif /* WITH_LOADEER_ARCH */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | /*-----------------------------------------------------------------------------------*/ |