blob: 005ca22757a59382881e2beeb0028a5acff80e92 [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 *
oliverschmidt124c3ee2005-05-12 21:27:20 +000046 * $Id: program-handler.c,v 1.29 2005/05/12 21:27:20 oliverschmidt Exp $
adamdunkels4292c862003-04-08 17:56:43 +000047 *
48 */
49
adamdunkelsdb300d22004-02-24 09:57:49 +000050#include <string.h>
adamdunkels4292c862003-04-08 17:56:43 +000051
adamdunkelsf2f8cb22004-07-04 11:35:07 +000052#include "ek.h"
adamdunkels4292c862003-04-08 17:56:43 +000053#include "petsciiconv.h"
adamdunkels4292c862003-04-08 17:56:43 +000054#include "ctk.h"
55#include "ctk-draw.h"
adamdunkels8a8138b2003-08-09 23:30:37 +000056#include "ctk-conf.h"
adamdunkels4292c862003-04-08 17:56:43 +000057
adamdunkels0eeeba72004-08-20 21:32:41 +000058#include "log.h"
59
adamdunkels4292c862003-04-08 17:56:43 +000060#include "loader.h"
61
adamdunkels43c3d1d2003-04-17 19:00:00 +000062#include "program-handler.h"
adamdunkels4292c862003-04-08 17:56:43 +000063
oliverschmidtcd5e89a2005-02-15 14:31:52 +000064#include "program-handler-conf.h"
65
adamdunkels4292c862003-04-08 17:56:43 +000066/* Menus */
67static struct ctk_menu contikimenu;
adamdunkels4292c862003-04-08 17:56:43 +000068
oliverschmidtcd5e89a2005-02-15 14:31:52 +000069#ifndef PROGRAM_HANDLER_CONF_MAX_NUMDSCS
adamdunkels4d2d2762003-09-04 19:34:22 +000070#define MAX_NUMDSCS 10
oliverschmidtcd5e89a2005-02-15 14:31:52 +000071#else /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */
72#define MAX_NUMDSCS PROGRAM_HANDLER_CONF_MAX_NUMDSCS
73#endif /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */
adamdunkels4d2d2762003-09-04 19:34:22 +000074
75static struct dsc *contikidsc[MAX_NUMDSCS];
adamdunkels43c3d1d2003-04-17 19:00:00 +000076static unsigned char contikidsclast = 0;
adamdunkels4292c862003-04-08 17:56:43 +000077
adamdunkels045437c2003-06-30 20:49:01 +000078#if WITH_LOADER_ARCH
adamdunkels43c3d1d2003-04-17 19:00:00 +000079/* "Run..." window */
adamdunkels4292c862003-04-08 17:56:43 +000080static struct ctk_window runwindow;
adamdunkels43c3d1d2003-04-17 19:00:00 +000081static unsigned char runmenuitem;
adamdunkels4292c862003-04-08 17:56:43 +000082static struct ctk_label namelabel =
83 {CTK_LABEL(0, 0, 13, 1, "Program name:")};
adamdunkels4292c862003-04-08 17:56:43 +000084static char name[31];
85static struct ctk_textentry nameentry =
adamdunkelsdc57fb02003-04-10 07:05:18 +000086 {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)};
adamdunkels4292c862003-04-08 17:56:43 +000087static struct ctk_button loadbutton =
adamdunkelsdc57fb02003-04-10 07:05:18 +000088 {CTK_BUTTON(10, 2, 4, "Load")};
adamdunkels4292c862003-04-08 17:56:43 +000089
adamdunkels045437c2003-06-30 20:49:01 +000090static struct ctk_window loadingdialog;
91static struct ctk_label loadingmsg =
92 {CTK_LABEL(0, 0, 8, 1, "Starting")};
93static struct ctk_label loadingname =
94 {CTK_LABEL(9, 0, 16, 1, name)};
95
96static struct ctk_window errordialog;
97static struct ctk_label errormsg =
98 {CTK_LABEL(0, 1, 22, 1, "Error loading program:")};
adamdunkels506d6c42003-08-20 20:52:22 +000099static char errorfilename[22];
adamdunkels8a8138b2003-08-09 23:30:37 +0000100static struct ctk_label errorfilelabel =
adamdunkels506d6c42003-08-20 20:52:22 +0000101 {CTK_LABEL(0, 3, 22, 1, errorfilename)};
adamdunkels045437c2003-06-30 20:49:01 +0000102static struct ctk_label errortype =
adamdunkels8a8138b2003-08-09 23:30:37 +0000103 {CTK_LABEL(4, 5, 16, 1, "")};
adamdunkels045437c2003-06-30 20:49:01 +0000104static struct ctk_button errorokbutton =
adamdunkels8a8138b2003-08-09 23:30:37 +0000105 {CTK_BUTTON(9, 7, 2, "Ok")};
adamdunkels045437c2003-06-30 20:49:01 +0000106
107
108#endif /* WITH_LOADER_ARCH */
109
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000110/*static DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data);
adamdunkels4292c862003-04-08 17:56:43 +0000111static struct dispatcher_proc p =
adamdunkelsc1272b22003-04-11 20:11:40 +0000112 {DISPATCHER_PROC("Program handler", NULL, program_handler_sighandler, NULL)};
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000113 static ek_id_t id;*/
114EK_EVENTHANDLER(program_handler_eventhandler, ev, data);
115EK_PROCESS(p, "Program handler", EK_PRIO_NORMAL,
116 program_handler_eventhandler, NULL, NULL);
117static ek_id_t id = EK_ID_NONE;
adamdunkels4292c862003-04-08 17:56:43 +0000118
119
adamdunkels4d2d2762003-09-04 19:34:22 +0000120static const char * const errormsgs[] = {
adamdunkels4292c862003-04-08 17:56:43 +0000121 "Ok",
122 "Read error",
123 "Header error",
124 "OS error",
125 "Data format error",
adamdunkels46dbaed2003-07-31 23:47:30 +0000126 "Out of memory",
adamdunkels4d2d2762003-09-04 19:34:22 +0000127 "File not found",
128 "No loader"
adamdunkels4292c862003-04-08 17:56:43 +0000129};
130
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000131#define LOADER_EVENT_LOAD 1
132#define LOADER_EVENT_DISPLAY_NAME 2
adamdunkels19539282003-08-05 23:27:23 +0000133
134static char *displayname;
adamdunkels4292c862003-04-08 17:56:43 +0000135
oliverschmidt533f7e22005-01-24 23:20:50 +0000136#if CTK_CONF_SCREENSAVER
adamdunkels8a8138b2003-08-09 23:30:37 +0000137static char screensaver[20];
oliverschmidt533f7e22005-01-24 23:20:50 +0000138#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000139
adamdunkels43c3d1d2003-04-17 19:00:00 +0000140/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000141/**
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/*-----------------------------------------------------------------------------------*/
adamdunkels43c3d1d2003-04-17 19:00:00 +0000153void
154program_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) {
adamdunkels4d2d2762003-09-04 19:34:22 +0000160 CTK_ICON_ADD(dsc->icon, id);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000161 }
162}
adamdunkels4292c862003-04-08 17:56:43 +0000163/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000164/**
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/*-----------------------------------------------------------------------------------*/
adamdunkels4292c862003-04-08 17:56:43 +0000172void
173program_handler_init(void)
174{
adamdunkels0eeeba72004-08-20 21:32:41 +0000175 id = ek_start(&p);
176 ctk_menu_new(&contikimenu, "Contiki");
adamdunkels4292c862003-04-08 17:56:43 +0000177}
178/*-----------------------------------------------------------------------------------*/
adamdunkels4a5eadf2003-08-05 22:02:52 +0000179#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000180#define NUM_PNARGS 6
adamdunkels4a5eadf2003-08-05 22:02:52 +0000181#define NAMELEN 16
adamdunkels8bb5cca2003-08-24 22:41:31 +0000182struct pnarg {
183 char name[NAMELEN];
184 char *arg;
185};
186static struct pnarg pnargs[NUM_PNARGS];
187static struct pnarg *
188pnarg_copy(char *name, char *arg)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000189{
190 char i;
adamdunkels8bb5cca2003-08-24 22:41:31 +0000191 struct pnarg *pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000192
adamdunkels8bb5cca2003-08-24 22:41:31 +0000193 pnargsptr = pnargs;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000194 /* Allocate a place in the loadernames table. */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000195 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;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000200 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000201 ++pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000202 }
203 return NULL;
204}
205
206static void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000207pnarg_free(struct pnarg *pn)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000208{
adamdunkels8bb5cca2003-08-24 22:41:31 +0000209 *(pn->name) = 0;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000210}
211#endif /* WITH_LOADER_ARCH */
212/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000213/**
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/*-----------------------------------------------------------------------------------*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000222void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000223program_handler_load(char *name, char *arg)
adamdunkels4292c862003-04-08 17:56:43 +0000224{
adamdunkelsc1272b22003-04-11 20:11:40 +0000225#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000226 struct pnarg *pnarg;
227
228 pnarg = pnarg_copy(name, arg);
229 if(pnarg != NULL) {
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000230 ek_post(id, LOADER_EVENT_DISPLAY_NAME, pnarg);
adamdunkels4a5eadf2003-08-05 22:02:52 +0000231 } else {
232 ctk_label_set_text(&errortype, "Out of memory");
233 ctk_dialog_open(&errordialog);
234 }
adamdunkels12467a72003-04-24 17:21:12 +0000235 /* ctk_redraw(); */
adamdunkels045437c2003-06-30 20:49:01 +0000236 /* ctk_window_redraw(&loadingdialog);*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000237#endif /* WITH_LOADER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000238}
adamdunkelsc1272b22003-04-11 20:11:40 +0000239
240#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000241#define RUN(prg, name, arg) program_handler_load(prg, arg)
adamdunkels4292c862003-04-08 17:56:43 +0000242#else /* WITH_LOADER_ARCH */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000243#define RUN(prg, initfunc, arg) initfunc(arg)
adamdunkels4292c862003-04-08 17:56:43 +0000244#endif /* WITH_LOADER_ARCH */
adamdunkels78c03dc2003-04-09 13:45:05 +0000245/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000246/**
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/*-----------------------------------------------------------------------------------*/
oliverschmidt533f7e22005-01-24 23:20:50 +0000254#if CTK_CONF_SCREENSAVER
adamdunkels8a8138b2003-08-09 23:30:37 +0000255void
oliverschmidt124c3ee2005-05-12 21:27:20 +0000256program_handler_setscreensaver(char *name)
adamdunkels8a8138b2003-08-09 23:30:37 +0000257{
adamdunkels15e26dd2003-08-11 22:24:20 +0000258 if(name == NULL) {
259 screensaver[0] = 0;
260 } else {
261 strncpy(screensaver, name, sizeof(screensaver));
262 }
adamdunkels8a8138b2003-08-09 23:30:37 +0000263}
oliverschmidt533f7e22005-01-24 23:20:50 +0000264#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000265/*-----------------------------------------------------------------------------------*/
adamdunkels0eeeba72004-08-20 21:32:41 +0000266static void
267make_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/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000291/*static
292 DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data)*/
293EK_EVENTHANDLER(program_handler_eventhandler, ev, data)
adamdunkels4292c862003-04-08 17:56:43 +0000294{
adamdunkelse937ded2003-10-01 07:53:57 +0000295#ifdef WITH_LOADER_ARCH
296 unsigned char err;
adamdunkelse0635172003-08-09 13:31:18 +0000297 struct dsc *dsc;
adamdunkelse937ded2003-10-01 07:53:57 +0000298#endif /* WITH_LOADER_ARCH */
299 unsigned char i;
adamdunkelse0635172003-08-09 13:31:18 +0000300 struct dsc **dscp;
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000301 /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/
302 EK_EVENTHANDLER_ARGS(ev, data);
303
304 if(ev == EK_EVENT_INIT) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000305 /* Create the menus */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000306 ctk_menu_add(&contikimenu);
307#if WITH_LOADER_ARCH
308 runmenuitem = ctk_menuitem_add(&contikimenu, "Run program...");
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000309
adamdunkels0eeeba72004-08-20 21:32:41 +0000310 make_windows();
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000311#endif /* WITH_LOADER_ARCH */
312
313
314 displayname = NULL;
315
oliverschmidt533f7e22005-01-24 23:20:50 +0000316#if CTK_CONF_SCREENSAVER
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000317 screensaver[0] = 0;
oliverschmidt533f7e22005-01-24 23:20:50 +0000318#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000319
320 } else if(ev == ctk_signal_button_activate) {
adamdunkels045437c2003-06-30 20:49:01 +0000321#ifdef WITH_LOADER_ARCH
adamdunkels4292c862003-04-08 17:56:43 +0000322 if(data == (ek_data_t)&loadbutton) {
323 ctk_window_close(&runwindow);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000324 program_handler_load(name, NULL);
adamdunkels4292c862003-04-08 17:56:43 +0000325 } else if(data == (ek_data_t)&errorokbutton) {
326 ctk_dialog_close();
adamdunkels4292c862003-04-08 17:56:43 +0000327 }
adamdunkels045437c2003-06-30 20:49:01 +0000328#endif /* WITH_LOADER_ARCH */
adamdunkelse0635172003-08-09 13:31:18 +0000329 dscp = &contikidsc[0];
330 for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) {
331 if(*dscp != NULL &&
332 data == (ek_data_t)(*dscp)->icon) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000333 RUN((*dscp)->prgname, (*dscp)->init, NULL);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000334 break;
335 }
adamdunkelse0635172003-08-09 13:31:18 +0000336 ++dscp;
337 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000338 } else if(ev == ctk_signal_menu_activate) {
adamdunkels43c3d1d2003-04-17 19:00:00 +0000339 if((struct ctk_menu *)data == &contikimenu) {
adamdunkels045437c2003-06-30 20:49:01 +0000340#if WITH_LOADER_ARCH
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000341 dsc = contikidsc[contikimenu.active];
adamdunkelse0635172003-08-09 13:31:18 +0000342 if(dsc != NULL) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000343 RUN(dsc->prgname, dsc->init, NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000344 } else if(contikimenu.active == runmenuitem) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000345 make_windows();
adamdunkelsb1a88e22004-09-09 21:15:55 +0000346 ctk_window_close(&runwindow);
adamdunkels045437c2003-06-30 20:49:01 +0000347 ctk_window_open(&runwindow);
adamdunkels46dbaed2003-07-31 23:47:30 +0000348 CTK_WIDGET_FOCUS(&runwindow, &nameentry);
adamdunkels4292c862003-04-08 17:56:43 +0000349 }
adamdunkels045437c2003-06-30 20:49:01 +0000350#else /* WITH_LOADER_ARCH */
351 if(contikidsc[contikimenu.active] != NULL) {
352 RUN(contikidsc[contikimenu.active]->prgname,
adamdunkels8bb5cca2003-08-24 22:41:31 +0000353 contikidsc[contikimenu.active]->init,
354 NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000355 }
356#endif /* WITH_LOADER_ARCH */
adamdunkels8a8138b2003-08-09 23:30:37 +0000357 }
358#if CTK_CONF_SCREENSAVER
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000359 } else if(ev == ctk_signal_screensaver_start) {
adamdunkels8a8138b2003-08-09 23:30:37 +0000360#if WITH_LOADER_ARCH
361 if(screensaver[0] != 0) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000362 program_handler_load(screensaver, NULL);
adamdunkels8a8138b2003-08-09 23:30:37 +0000363 }
364#endif /* WITH_LOADER_ARCH */
365#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000366 } else if(ev == LOADER_EVENT_DISPLAY_NAME) {
adamdunkels19539282003-08-05 23:27:23 +0000367#if WITH_LOADER_ARCH
368 if(displayname == NULL) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000369 make_windows();
370
adamdunkels8bb5cca2003-08-24 22:41:31 +0000371 ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name);
adamdunkels19539282003-08-05 23:27:23 +0000372 ctk_dialog_open(&loadingdialog);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000373 /* dispatcher_emit(loader_signal_load, data, id);*/
374 ek_post(id, LOADER_EVENT_LOAD, data);
adamdunkels19539282003-08-05 23:27:23 +0000375 displayname = data;
376 } else {
377 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000378 /* dispatcher_emit(loader_signal_display_name, data, id);*/
379 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels19539282003-08-05 23:27:23 +0000380 }
381#endif /* WITH_LOADER_ARCH */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000382 } else if(ev == LOADER_EVENT_LOAD) {
adamdunkels045437c2003-06-30 20:49:01 +0000383#if WITH_LOADER_ARCH
adamdunkels19539282003-08-05 23:27:23 +0000384 if(displayname == data) {
385 ctk_dialog_close();
386 displayname = NULL;
adamdunkels0eeeba72004-08-20 21:32:41 +0000387 log_message("Loading ", ((struct pnarg *)data)->name);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000388 err = LOADER_LOAD(((struct pnarg *)data)->name,
389 ((struct pnarg *)data)->arg);
adamdunkels19539282003-08-05 23:27:23 +0000390 if(err != LOADER_OK) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000391 make_windows();
adamdunkels506d6c42003-08-20 20:52:22 +0000392 errorfilename[0] = '"';
adamdunkels8bb5cca2003-08-24 22:41:31 +0000393 strncpy(errorfilename + 1, ((struct pnarg *)data)->name,
394 sizeof(errorfilename) - 2);
395 errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"';
adamdunkels4d2d2762003-09-04 19:34:22 +0000396 ctk_label_set_text(&errortype, (char *)errormsgs[err]);
adamdunkels19539282003-08-05 23:27:23 +0000397 ctk_dialog_open(&errordialog);
adamdunkels0eeeba72004-08-20 21:32:41 +0000398 log_message((char *)errormsgs[err], errorfilename);
adamdunkels19539282003-08-05 23:27:23 +0000399 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000400 pnarg_free(data);
adamdunkels19539282003-08-05 23:27:23 +0000401 } else {
402 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000403/* dispatcher_emit(loader_signal_display_name, data, id);*/
404 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels4292c862003-04-08 17:56:43 +0000405 }
adamdunkels045437c2003-06-30 20:49:01 +0000406#endif /* WITH_LOADEER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000407 }
408}
409/*-----------------------------------------------------------------------------------*/