blob: 9d15e23b954d82da61091c33a35c70ae6635fdf6 [file] [log] [blame]
adamdunkels35298692003-08-31 22:16:49 +00001/**
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
adamdunkels4292c862003-04-08 17:56:43 +000015/*
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.
adamdunkels35298692003-08-31 22:16:49 +000028 * 3. The name of the author may not be used to endorse or promote
adamdunkels4292c862003-04-08 17:56:43 +000029 * 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 *
adamdunkels6b3c8582003-04-08 19:25:38 +000044 * This file is part of the Contiki desktop OS
adamdunkels4292c862003-04-08 17:56:43 +000045 *
oliverschmidta9209532006-05-14 23:23:30 +000046 * $Id: program-handler.c,v 1.32 2006/05/14 23:23:30 oliverschmidt Exp $
adamdunkels4292c862003-04-08 17:56:43 +000047 *
48 */
49
adamdunkelsdb300d22004-02-24 09:57:49 +000050#include <string.h>
oliverschmidt0c64f872006-05-07 23:02:54 +000051#include <stdlib.h>
adamdunkels4292c862003-04-08 17:56:43 +000052
adamdunkelsf2f8cb22004-07-04 11:35:07 +000053#include "ek.h"
adamdunkels4292c862003-04-08 17:56:43 +000054#include "petsciiconv.h"
adamdunkels4292c862003-04-08 17:56:43 +000055#include "ctk.h"
56#include "ctk-draw.h"
adamdunkels8a8138b2003-08-09 23:30:37 +000057#include "ctk-conf.h"
adamdunkels4292c862003-04-08 17:56:43 +000058
adamdunkels0eeeba72004-08-20 21:32:41 +000059#include "log.h"
60
adamdunkels4292c862003-04-08 17:56:43 +000061#include "loader.h"
62
adamdunkels43c3d1d2003-04-17 19:00:00 +000063#include "program-handler.h"
adamdunkels4292c862003-04-08 17:56:43 +000064
oliverschmidtcd5e89a2005-02-15 14:31:52 +000065#include "program-handler-conf.h"
66
adamdunkels4292c862003-04-08 17:56:43 +000067/* Menus */
68static struct ctk_menu contikimenu;
adamdunkels4292c862003-04-08 17:56:43 +000069
oliverschmidtcd5e89a2005-02-15 14:31:52 +000070#ifndef PROGRAM_HANDLER_CONF_MAX_NUMDSCS
adamdunkels4d2d2762003-09-04 19:34:22 +000071#define MAX_NUMDSCS 10
oliverschmidtcd5e89a2005-02-15 14:31:52 +000072#else /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */
73#define MAX_NUMDSCS PROGRAM_HANDLER_CONF_MAX_NUMDSCS
74#endif /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */
adamdunkels4d2d2762003-09-04 19:34:22 +000075
76static struct dsc *contikidsc[MAX_NUMDSCS];
adamdunkels43c3d1d2003-04-17 19:00:00 +000077static unsigned char contikidsclast = 0;
adamdunkels4292c862003-04-08 17:56:43 +000078
oliverschmidt0c64f872006-05-07 23:02:54 +000079#ifndef PROGRAM_HANDLER_CONF_QUIT_MENU
80#define QUIT_MENU 0
81#else /* PROGRAM_HANDLER_CONF_QUIT_MENU */
82#define QUIT_MENU PROGRAM_HANDLER_CONF_QUIT_MENU
83#endif /* PROGRAM_HANDLER_CONF_QUIT_MENU */
84
85#if QUIT_MENU
86
87static unsigned char quitmenuitem;
88
oliverschmidta9209532006-05-14 23:23:30 +000089/* "Quit" dialog */
oliverschmidt0c64f872006-05-07 23:02:54 +000090static struct ctk_window quitdialog;
91static struct ctk_label quitdialoglabel =
92 {CTK_LABEL(2, 1, 20, 1, "Really quit Contiki?")};
93static struct ctk_button quityesbutton =
94 {CTK_BUTTON(4, 3, 3, "Yes")};
95static struct ctk_button quitnobutton =
96 {CTK_BUTTON(16, 3, 2, "No")};
97
98#endif /* QUIT_MENU */
99
adamdunkels045437c2003-06-30 20:49:01 +0000100#if WITH_LOADER_ARCH
oliverschmidt0c64f872006-05-07 23:02:54 +0000101
adamdunkels43c3d1d2003-04-17 19:00:00 +0000102/* "Run..." window */
adamdunkels4292c862003-04-08 17:56:43 +0000103static struct ctk_window runwindow;
adamdunkels43c3d1d2003-04-17 19:00:00 +0000104static unsigned char runmenuitem;
adamdunkels4292c862003-04-08 17:56:43 +0000105static struct ctk_label namelabel =
106 {CTK_LABEL(0, 0, 13, 1, "Program name:")};
adamdunkels4292c862003-04-08 17:56:43 +0000107static char name[31];
108static struct ctk_textentry nameentry =
adamdunkelsdc57fb02003-04-10 07:05:18 +0000109 {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)};
adamdunkels4292c862003-04-08 17:56:43 +0000110static struct ctk_button loadbutton =
adamdunkelsdc57fb02003-04-10 07:05:18 +0000111 {CTK_BUTTON(10, 2, 4, "Load")};
adamdunkels4292c862003-04-08 17:56:43 +0000112
adamdunkels045437c2003-06-30 20:49:01 +0000113static struct ctk_window loadingdialog;
114static struct ctk_label loadingmsg =
115 {CTK_LABEL(0, 0, 8, 1, "Starting")};
116static struct ctk_label loadingname =
117 {CTK_LABEL(9, 0, 16, 1, name)};
118
119static struct ctk_window errordialog;
120static struct ctk_label errormsg =
121 {CTK_LABEL(0, 1, 22, 1, "Error loading program:")};
adamdunkels506d6c42003-08-20 20:52:22 +0000122static char errorfilename[22];
adamdunkels8a8138b2003-08-09 23:30:37 +0000123static struct ctk_label errorfilelabel =
adamdunkels506d6c42003-08-20 20:52:22 +0000124 {CTK_LABEL(0, 3, 22, 1, errorfilename)};
adamdunkels045437c2003-06-30 20:49:01 +0000125static struct ctk_label errortype =
adamdunkels8a8138b2003-08-09 23:30:37 +0000126 {CTK_LABEL(4, 5, 16, 1, "")};
adamdunkels045437c2003-06-30 20:49:01 +0000127static struct ctk_button errorokbutton =
adamdunkels8a8138b2003-08-09 23:30:37 +0000128 {CTK_BUTTON(9, 7, 2, "Ok")};
adamdunkels045437c2003-06-30 20:49:01 +0000129
adamdunkels045437c2003-06-30 20:49:01 +0000130#endif /* WITH_LOADER_ARCH */
131
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000132/*static DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data);
adamdunkels4292c862003-04-08 17:56:43 +0000133static struct dispatcher_proc p =
adamdunkelsc1272b22003-04-11 20:11:40 +0000134 {DISPATCHER_PROC("Program handler", NULL, program_handler_sighandler, NULL)};
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000135 static ek_id_t id;*/
136EK_EVENTHANDLER(program_handler_eventhandler, ev, data);
137EK_PROCESS(p, "Program handler", EK_PRIO_NORMAL,
138 program_handler_eventhandler, NULL, NULL);
139static ek_id_t id = EK_ID_NONE;
adamdunkels4292c862003-04-08 17:56:43 +0000140
adamdunkels4d2d2762003-09-04 19:34:22 +0000141static const char * const errormsgs[] = {
adamdunkels4292c862003-04-08 17:56:43 +0000142 "Ok",
143 "Read error",
144 "Header error",
145 "OS error",
146 "Data format error",
adamdunkels46dbaed2003-07-31 23:47:30 +0000147 "Out of memory",
adamdunkels4d2d2762003-09-04 19:34:22 +0000148 "File not found",
149 "No loader"
adamdunkels4292c862003-04-08 17:56:43 +0000150};
151
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000152#define LOADER_EVENT_LOAD 1
153#define LOADER_EVENT_DISPLAY_NAME 2
adamdunkels19539282003-08-05 23:27:23 +0000154
155static char *displayname;
adamdunkels4292c862003-04-08 17:56:43 +0000156
oliverschmidt533f7e22005-01-24 23:20:50 +0000157#if CTK_CONF_SCREENSAVER
oliverschmidt1df710f2005-05-12 23:55:18 +0000158char program_handler_screensaver[20];
oliverschmidt533f7e22005-01-24 23:20:50 +0000159#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000160
adamdunkels43c3d1d2003-04-17 19:00:00 +0000161/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000162/**
163 * Add a program to the program handler.
164 *
165 * \param dsc The DSC description structure for the program to be added.
166 *
167 * \param menuname The name that the program should have in the
168 * Contiki menu.
169 *
170 * \param desktop Flag which specifies if the program should show up
171 * as an icon on the desktop or not.
172 */
173/*-----------------------------------------------------------------------------------*/
adamdunkels43c3d1d2003-04-17 19:00:00 +0000174void
175program_handler_add(struct dsc *dsc, char *menuname,
176 unsigned char desktop)
177{
178 contikidsc[contikidsclast++] = dsc;
179 ctk_menuitem_add(&contikimenu, menuname);
180 if(desktop) {
adamdunkels4d2d2762003-09-04 19:34:22 +0000181 CTK_ICON_ADD(dsc->icon, id);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000182 }
183}
adamdunkels4292c862003-04-08 17:56:43 +0000184/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000185/**
186 * Initializes the program handler.
187 *
188 * Is called by the initialization before any programs have been added
189 * with program_handler_add().
190 *
191 */
192/*-----------------------------------------------------------------------------------*/
adamdunkels4292c862003-04-08 17:56:43 +0000193void
194program_handler_init(void)
195{
adamdunkels0eeeba72004-08-20 21:32:41 +0000196 id = ek_start(&p);
197 ctk_menu_new(&contikimenu, "Contiki");
adamdunkels4292c862003-04-08 17:56:43 +0000198}
199/*-----------------------------------------------------------------------------------*/
adamdunkels4a5eadf2003-08-05 22:02:52 +0000200#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000201#define NUM_PNARGS 6
adamdunkels4a5eadf2003-08-05 22:02:52 +0000202#define NAMELEN 16
adamdunkels8bb5cca2003-08-24 22:41:31 +0000203struct pnarg {
204 char name[NAMELEN];
205 char *arg;
206};
207static struct pnarg pnargs[NUM_PNARGS];
208static struct pnarg *
209pnarg_copy(char *name, char *arg)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000210{
211 char i;
adamdunkels8bb5cca2003-08-24 22:41:31 +0000212 struct pnarg *pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000213
adamdunkels8bb5cca2003-08-24 22:41:31 +0000214 pnargsptr = pnargs;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000215 /* Allocate a place in the loadernames table. */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000216 for(i = 0; i < NUM_PNARGS; ++i) {
217 if(*(pnargsptr->name) == 0) {
218 strncpy(pnargsptr->name, name, NAMELEN);
219 pnargsptr->arg = arg;
220 return pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000221 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000222 ++pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000223 }
224 return NULL;
225}
226
227static void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000228pnarg_free(struct pnarg *pn)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000229{
adamdunkels8bb5cca2003-08-24 22:41:31 +0000230 *(pn->name) = 0;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000231}
232#endif /* WITH_LOADER_ARCH */
233/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000234/**
235 * Loads a program and displays a dialog telling the user about it.
236 *
237 * \param name The name of the program to be loaded.
238 *
239 * \param arg An argument which is passed to the new process when it
240 * is loaded.
241 */
242/*-----------------------------------------------------------------------------------*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000243void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000244program_handler_load(char *name, char *arg)
adamdunkels4292c862003-04-08 17:56:43 +0000245{
adamdunkelsc1272b22003-04-11 20:11:40 +0000246#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000247 struct pnarg *pnarg;
248
249 pnarg = pnarg_copy(name, arg);
250 if(pnarg != NULL) {
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000251 ek_post(id, LOADER_EVENT_DISPLAY_NAME, pnarg);
adamdunkels4a5eadf2003-08-05 22:02:52 +0000252 } else {
253 ctk_label_set_text(&errortype, "Out of memory");
254 ctk_dialog_open(&errordialog);
255 }
adamdunkels12467a72003-04-24 17:21:12 +0000256 /* ctk_redraw(); */
adamdunkels045437c2003-06-30 20:49:01 +0000257 /* ctk_window_redraw(&loadingdialog);*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000258#endif /* WITH_LOADER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000259}
adamdunkelsc1272b22003-04-11 20:11:40 +0000260
261#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000262#define RUN(prg, name, arg) program_handler_load(prg, arg)
adamdunkels4292c862003-04-08 17:56:43 +0000263#else /* WITH_LOADER_ARCH */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000264#define RUN(prg, initfunc, arg) initfunc(arg)
adamdunkels4292c862003-04-08 17:56:43 +0000265#endif /* WITH_LOADER_ARCH */
adamdunkels78c03dc2003-04-09 13:45:05 +0000266/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000267/**
268 * Configures the name of the screensaver to be loaded when
269 * appropriate.
270 *
271 * \param name The name of the screensaver or NULL if no screensaver
272 * should be used.
273 */
274/*-----------------------------------------------------------------------------------*/
oliverschmidt533f7e22005-01-24 23:20:50 +0000275#if CTK_CONF_SCREENSAVER
adamdunkels8a8138b2003-08-09 23:30:37 +0000276void
oliverschmidt124c3ee2005-05-12 21:27:20 +0000277program_handler_setscreensaver(char *name)
adamdunkels8a8138b2003-08-09 23:30:37 +0000278{
adamdunkels15e26dd2003-08-11 22:24:20 +0000279 if(name == NULL) {
oliverschmidt1df710f2005-05-12 23:55:18 +0000280 program_handler_screensaver[0] = 0;
adamdunkels15e26dd2003-08-11 22:24:20 +0000281 } else {
oliverschmidt1df710f2005-05-12 23:55:18 +0000282 strncpy(program_handler_screensaver, name, sizeof(program_handler_screensaver));
adamdunkels15e26dd2003-08-11 22:24:20 +0000283 }
adamdunkels8a8138b2003-08-09 23:30:37 +0000284}
oliverschmidt533f7e22005-01-24 23:20:50 +0000285#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000286/*-----------------------------------------------------------------------------------*/
adamdunkels0eeeba72004-08-20 21:32:41 +0000287static void
288make_windows(void)
289{
290#ifdef WITH_LOADER_ARCH
291 ctk_window_new(&runwindow, 16, 3, "Run");
292
293 CTK_WIDGET_ADD(&runwindow, &namelabel);
294 CTK_WIDGET_ADD(&runwindow, &nameentry);
295 CTK_WIDGET_ADD(&runwindow, &loadbutton);
296
297 CTK_WIDGET_FOCUS(&runwindow, &nameentry);
298
299 ctk_dialog_new(&loadingdialog, 25, 1);
300 CTK_WIDGET_ADD(&loadingdialog, &loadingmsg);
301 CTK_WIDGET_ADD(&loadingdialog, &loadingname);
302
303 ctk_dialog_new(&errordialog, 22, 8);
304 CTK_WIDGET_ADD(&errordialog, &errormsg);
305 CTK_WIDGET_ADD(&errordialog, &errorfilelabel);
306 CTK_WIDGET_ADD(&errordialog, &errortype);
307 CTK_WIDGET_ADD(&errordialog, &errorokbutton);
308 CTK_WIDGET_FOCUS(&errordialog, &errorokbutton);
309#endif /* WITH_LOADER_ARCH */
310}
311/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000312/*static
313 DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data)*/
314EK_EVENTHANDLER(program_handler_eventhandler, ev, data)
adamdunkels4292c862003-04-08 17:56:43 +0000315{
adamdunkelse937ded2003-10-01 07:53:57 +0000316#ifdef WITH_LOADER_ARCH
317 unsigned char err;
adamdunkelse0635172003-08-09 13:31:18 +0000318 struct dsc *dsc;
adamdunkelse937ded2003-10-01 07:53:57 +0000319#endif /* WITH_LOADER_ARCH */
320 unsigned char i;
adamdunkelse0635172003-08-09 13:31:18 +0000321 struct dsc **dscp;
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000322 /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/
323 EK_EVENTHANDLER_ARGS(ev, data);
324
325 if(ev == EK_EVENT_INIT) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000326 /* Create the menus */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000327 ctk_menu_add(&contikimenu);
328#if WITH_LOADER_ARCH
329 runmenuitem = ctk_menuitem_add(&contikimenu, "Run program...");
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000330
adamdunkels0eeeba72004-08-20 21:32:41 +0000331 make_windows();
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000332#endif /* WITH_LOADER_ARCH */
oliverschmidt0c64f872006-05-07 23:02:54 +0000333#if QUIT_MENU
334 quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit");
335#endif /* QUIT_MENU */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000336
337 displayname = NULL;
338
oliverschmidt533f7e22005-01-24 23:20:50 +0000339#if CTK_CONF_SCREENSAVER
oliverschmidt1df710f2005-05-12 23:55:18 +0000340 program_handler_screensaver[0] = 0;
oliverschmidt533f7e22005-01-24 23:20:50 +0000341#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000342
343 } else if(ev == ctk_signal_button_activate) {
adamdunkels045437c2003-06-30 20:49:01 +0000344#ifdef WITH_LOADER_ARCH
adamdunkels4292c862003-04-08 17:56:43 +0000345 if(data == (ek_data_t)&loadbutton) {
346 ctk_window_close(&runwindow);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000347 program_handler_load(name, NULL);
adamdunkels4292c862003-04-08 17:56:43 +0000348 } else if(data == (ek_data_t)&errorokbutton) {
349 ctk_dialog_close();
adamdunkels4292c862003-04-08 17:56:43 +0000350 }
adamdunkels045437c2003-06-30 20:49:01 +0000351#endif /* WITH_LOADER_ARCH */
oliverschmidt0c64f872006-05-07 23:02:54 +0000352#if QUIT_MENU
353 if(data == (ek_data_t)&quityesbutton) {
354 ctk_draw_init();
355 exit(EXIT_SUCCESS);
356 } else if(data == (ek_data_t)&quitnobutton) {
357 ctk_dialog_close();
358 }
359#endif /* QUIT_MENU */
adamdunkelse0635172003-08-09 13:31:18 +0000360 dscp = &contikidsc[0];
361 for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) {
362 if(*dscp != NULL &&
363 data == (ek_data_t)(*dscp)->icon) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000364 RUN((*dscp)->prgname, (*dscp)->init, NULL);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000365 break;
366 }
adamdunkelse0635172003-08-09 13:31:18 +0000367 ++dscp;
368 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000369 } else if(ev == ctk_signal_menu_activate) {
adamdunkels43c3d1d2003-04-17 19:00:00 +0000370 if((struct ctk_menu *)data == &contikimenu) {
adamdunkels045437c2003-06-30 20:49:01 +0000371#if WITH_LOADER_ARCH
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000372 dsc = contikidsc[contikimenu.active];
adamdunkelse0635172003-08-09 13:31:18 +0000373 if(dsc != NULL) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000374 RUN(dsc->prgname, dsc->init, NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000375 } else if(contikimenu.active == runmenuitem) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000376 make_windows();
adamdunkelsb1a88e22004-09-09 21:15:55 +0000377 ctk_window_close(&runwindow);
adamdunkels045437c2003-06-30 20:49:01 +0000378 ctk_window_open(&runwindow);
adamdunkels46dbaed2003-07-31 23:47:30 +0000379 CTK_WIDGET_FOCUS(&runwindow, &nameentry);
adamdunkels4292c862003-04-08 17:56:43 +0000380 }
adamdunkels045437c2003-06-30 20:49:01 +0000381#else /* WITH_LOADER_ARCH */
382 if(contikidsc[contikimenu.active] != NULL) {
383 RUN(contikidsc[contikimenu.active]->prgname,
adamdunkels8bb5cca2003-08-24 22:41:31 +0000384 contikidsc[contikimenu.active]->init,
385 NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000386 }
387#endif /* WITH_LOADER_ARCH */
oliverschmidt0c64f872006-05-07 23:02:54 +0000388#if QUIT_MENU
389 if(contikimenu.active == quitmenuitem) {
390 ctk_dialog_new(&quitdialog, 24, 5);
391 CTK_WIDGET_ADD(&quitdialog, &quitdialoglabel);
392 CTK_WIDGET_ADD(&quitdialog, &quityesbutton);
393 CTK_WIDGET_ADD(&quitdialog, &quitnobutton);
394 CTK_WIDGET_FOCUS(&quitdialog, &quitnobutton);
395 ctk_dialog_open(&quitdialog);
396 }
397#endif /* QUIT_MENU */
adamdunkels8a8138b2003-08-09 23:30:37 +0000398 }
399#if CTK_CONF_SCREENSAVER
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000400 } else if(ev == ctk_signal_screensaver_start) {
adamdunkels8a8138b2003-08-09 23:30:37 +0000401#if WITH_LOADER_ARCH
oliverschmidt1df710f2005-05-12 23:55:18 +0000402 if(program_handler_screensaver[0] != 0) {
403 program_handler_load(program_handler_screensaver, NULL);
adamdunkels8a8138b2003-08-09 23:30:37 +0000404 }
405#endif /* WITH_LOADER_ARCH */
406#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000407 } else if(ev == LOADER_EVENT_DISPLAY_NAME) {
adamdunkels19539282003-08-05 23:27:23 +0000408#if WITH_LOADER_ARCH
409 if(displayname == NULL) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000410 make_windows();
411
adamdunkels8bb5cca2003-08-24 22:41:31 +0000412 ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name);
adamdunkels19539282003-08-05 23:27:23 +0000413 ctk_dialog_open(&loadingdialog);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000414 /* dispatcher_emit(loader_signal_load, data, id);*/
415 ek_post(id, LOADER_EVENT_LOAD, data);
adamdunkels19539282003-08-05 23:27:23 +0000416 displayname = data;
417 } else {
418 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000419 /* dispatcher_emit(loader_signal_display_name, data, id);*/
420 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels19539282003-08-05 23:27:23 +0000421 }
422#endif /* WITH_LOADER_ARCH */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000423 } else if(ev == LOADER_EVENT_LOAD) {
adamdunkels045437c2003-06-30 20:49:01 +0000424#if WITH_LOADER_ARCH
adamdunkels19539282003-08-05 23:27:23 +0000425 if(displayname == data) {
426 ctk_dialog_close();
427 displayname = NULL;
adamdunkels0eeeba72004-08-20 21:32:41 +0000428 log_message("Loading ", ((struct pnarg *)data)->name);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000429 err = LOADER_LOAD(((struct pnarg *)data)->name,
430 ((struct pnarg *)data)->arg);
adamdunkels19539282003-08-05 23:27:23 +0000431 if(err != LOADER_OK) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000432 make_windows();
adamdunkels506d6c42003-08-20 20:52:22 +0000433 errorfilename[0] = '"';
adamdunkels8bb5cca2003-08-24 22:41:31 +0000434 strncpy(errorfilename + 1, ((struct pnarg *)data)->name,
435 sizeof(errorfilename) - 2);
436 errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"';
adamdunkels4d2d2762003-09-04 19:34:22 +0000437 ctk_label_set_text(&errortype, (char *)errormsgs[err]);
adamdunkels19539282003-08-05 23:27:23 +0000438 ctk_dialog_open(&errordialog);
adamdunkels0eeeba72004-08-20 21:32:41 +0000439 log_message((char *)errormsgs[err], errorfilename);
adamdunkels19539282003-08-05 23:27:23 +0000440 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000441 pnarg_free(data);
adamdunkels19539282003-08-05 23:27:23 +0000442 } else {
443 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000444/* dispatcher_emit(loader_signal_display_name, data, id);*/
445 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels4292c862003-04-08 17:56:43 +0000446 }
adamdunkels045437c2003-06-30 20:49:01 +0000447#endif /* WITH_LOADEER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000448 }
449}
450/*-----------------------------------------------------------------------------------*/