blob: c892e6dc75f9adcc04362624abd28e7ef494d72e [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 *
oliverschmidt533f7e22005-01-24 23:20:50 +000046 * $Id: program-handler.c,v 1.27 2005/01/24 23:20:50 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
64/* Menus */
65static struct ctk_menu contikimenu;
adamdunkels4292c862003-04-08 17:56:43 +000066
adamdunkels4d2d2762003-09-04 19:34:22 +000067#define MAX_NUMDSCS 10
68
69static struct dsc *contikidsc[MAX_NUMDSCS];
adamdunkels43c3d1d2003-04-17 19:00:00 +000070static unsigned char contikidsclast = 0;
adamdunkels4292c862003-04-08 17:56:43 +000071
adamdunkels045437c2003-06-30 20:49:01 +000072#if WITH_LOADER_ARCH
adamdunkels43c3d1d2003-04-17 19:00:00 +000073/* "Run..." window */
adamdunkels4292c862003-04-08 17:56:43 +000074static struct ctk_window runwindow;
adamdunkels43c3d1d2003-04-17 19:00:00 +000075static unsigned char runmenuitem;
adamdunkels4292c862003-04-08 17:56:43 +000076static struct ctk_label namelabel =
77 {CTK_LABEL(0, 0, 13, 1, "Program name:")};
adamdunkels4292c862003-04-08 17:56:43 +000078static char name[31];
79static struct ctk_textentry nameentry =
adamdunkelsdc57fb02003-04-10 07:05:18 +000080 {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)};
adamdunkels4292c862003-04-08 17:56:43 +000081static struct ctk_button loadbutton =
adamdunkelsdc57fb02003-04-10 07:05:18 +000082 {CTK_BUTTON(10, 2, 4, "Load")};
adamdunkels4292c862003-04-08 17:56:43 +000083
adamdunkels045437c2003-06-30 20:49:01 +000084static struct ctk_window loadingdialog;
85static struct ctk_label loadingmsg =
86 {CTK_LABEL(0, 0, 8, 1, "Starting")};
87static struct ctk_label loadingname =
88 {CTK_LABEL(9, 0, 16, 1, name)};
89
90static struct ctk_window errordialog;
91static struct ctk_label errormsg =
92 {CTK_LABEL(0, 1, 22, 1, "Error loading program:")};
adamdunkels506d6c42003-08-20 20:52:22 +000093static char errorfilename[22];
adamdunkels8a8138b2003-08-09 23:30:37 +000094static struct ctk_label errorfilelabel =
adamdunkels506d6c42003-08-20 20:52:22 +000095 {CTK_LABEL(0, 3, 22, 1, errorfilename)};
adamdunkels045437c2003-06-30 20:49:01 +000096static struct ctk_label errortype =
adamdunkels8a8138b2003-08-09 23:30:37 +000097 {CTK_LABEL(4, 5, 16, 1, "")};
adamdunkels045437c2003-06-30 20:49:01 +000098static struct ctk_button errorokbutton =
adamdunkels8a8138b2003-08-09 23:30:37 +000099 {CTK_BUTTON(9, 7, 2, "Ok")};
adamdunkels045437c2003-06-30 20:49:01 +0000100
101
102#endif /* WITH_LOADER_ARCH */
103
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000104/*static DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data);
adamdunkels4292c862003-04-08 17:56:43 +0000105static struct dispatcher_proc p =
adamdunkelsc1272b22003-04-11 20:11:40 +0000106 {DISPATCHER_PROC("Program handler", NULL, program_handler_sighandler, NULL)};
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000107 static ek_id_t id;*/
108EK_EVENTHANDLER(program_handler_eventhandler, ev, data);
109EK_PROCESS(p, "Program handler", EK_PRIO_NORMAL,
110 program_handler_eventhandler, NULL, NULL);
111static ek_id_t id = EK_ID_NONE;
adamdunkels4292c862003-04-08 17:56:43 +0000112
113
adamdunkels4d2d2762003-09-04 19:34:22 +0000114static const char * const errormsgs[] = {
adamdunkels4292c862003-04-08 17:56:43 +0000115 "Ok",
116 "Read error",
117 "Header error",
118 "OS error",
119 "Data format error",
adamdunkels46dbaed2003-07-31 23:47:30 +0000120 "Out of memory",
adamdunkels4d2d2762003-09-04 19:34:22 +0000121 "File not found",
122 "No loader"
adamdunkels4292c862003-04-08 17:56:43 +0000123};
124
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000125#define LOADER_EVENT_LOAD 1
126#define LOADER_EVENT_DISPLAY_NAME 2
adamdunkels19539282003-08-05 23:27:23 +0000127
128static char *displayname;
adamdunkels4292c862003-04-08 17:56:43 +0000129
oliverschmidt533f7e22005-01-24 23:20:50 +0000130#if CTK_CONF_SCREENSAVER
adamdunkels8a8138b2003-08-09 23:30:37 +0000131static char screensaver[20];
oliverschmidt533f7e22005-01-24 23:20:50 +0000132#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000133
adamdunkels43c3d1d2003-04-17 19:00:00 +0000134/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000135/**
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/*-----------------------------------------------------------------------------------*/
adamdunkels43c3d1d2003-04-17 19:00:00 +0000147void
148program_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) {
adamdunkels4d2d2762003-09-04 19:34:22 +0000154 CTK_ICON_ADD(dsc->icon, id);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000155 }
156}
adamdunkels4292c862003-04-08 17:56:43 +0000157/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000158/**
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/*-----------------------------------------------------------------------------------*/
adamdunkels4292c862003-04-08 17:56:43 +0000166void
167program_handler_init(void)
168{
adamdunkels0eeeba72004-08-20 21:32:41 +0000169 id = ek_start(&p);
170 ctk_menu_new(&contikimenu, "Contiki");
adamdunkels4292c862003-04-08 17:56:43 +0000171}
172/*-----------------------------------------------------------------------------------*/
adamdunkels4a5eadf2003-08-05 22:02:52 +0000173#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000174#define NUM_PNARGS 6
adamdunkels4a5eadf2003-08-05 22:02:52 +0000175#define NAMELEN 16
adamdunkels8bb5cca2003-08-24 22:41:31 +0000176struct pnarg {
177 char name[NAMELEN];
178 char *arg;
179};
180static struct pnarg pnargs[NUM_PNARGS];
181static struct pnarg *
182pnarg_copy(char *name, char *arg)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000183{
184 char i;
adamdunkels8bb5cca2003-08-24 22:41:31 +0000185 struct pnarg *pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000186
adamdunkels8bb5cca2003-08-24 22:41:31 +0000187 pnargsptr = pnargs;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000188 /* Allocate a place in the loadernames table. */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000189 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;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000194 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000195 ++pnargsptr;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000196 }
197 return NULL;
198}
199
200static void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000201pnarg_free(struct pnarg *pn)
adamdunkels4a5eadf2003-08-05 22:02:52 +0000202{
adamdunkels8bb5cca2003-08-24 22:41:31 +0000203 *(pn->name) = 0;
adamdunkels4a5eadf2003-08-05 22:02:52 +0000204}
205#endif /* WITH_LOADER_ARCH */
206/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000207/**
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/*-----------------------------------------------------------------------------------*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000216void
adamdunkels8bb5cca2003-08-24 22:41:31 +0000217program_handler_load(char *name, char *arg)
adamdunkels4292c862003-04-08 17:56:43 +0000218{
adamdunkelsc1272b22003-04-11 20:11:40 +0000219#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000220 struct pnarg *pnarg;
221
222 pnarg = pnarg_copy(name, arg);
223 if(pnarg != NULL) {
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000224 ek_post(id, LOADER_EVENT_DISPLAY_NAME, pnarg);
adamdunkels4a5eadf2003-08-05 22:02:52 +0000225 } else {
226 ctk_label_set_text(&errortype, "Out of memory");
227 ctk_dialog_open(&errordialog);
228 }
adamdunkels12467a72003-04-24 17:21:12 +0000229 /* ctk_redraw(); */
adamdunkels045437c2003-06-30 20:49:01 +0000230 /* ctk_window_redraw(&loadingdialog);*/
adamdunkelsc1272b22003-04-11 20:11:40 +0000231#endif /* WITH_LOADER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000232}
adamdunkelsc1272b22003-04-11 20:11:40 +0000233
234#ifdef WITH_LOADER_ARCH
adamdunkels8bb5cca2003-08-24 22:41:31 +0000235#define RUN(prg, name, arg) program_handler_load(prg, arg)
adamdunkels4292c862003-04-08 17:56:43 +0000236#else /* WITH_LOADER_ARCH */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000237#define RUN(prg, initfunc, arg) initfunc(arg)
adamdunkels4292c862003-04-08 17:56:43 +0000238#endif /* WITH_LOADER_ARCH */
adamdunkels78c03dc2003-04-09 13:45:05 +0000239/*-----------------------------------------------------------------------------------*/
adamdunkels35298692003-08-31 22:16:49 +0000240/**
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/*-----------------------------------------------------------------------------------*/
oliverschmidt533f7e22005-01-24 23:20:50 +0000248#if CTK_CONF_SCREENSAVER
adamdunkels8a8138b2003-08-09 23:30:37 +0000249void
250program_handler_screensaver(char *name)
251{
adamdunkels15e26dd2003-08-11 22:24:20 +0000252 if(name == NULL) {
253 screensaver[0] = 0;
254 } else {
255 strncpy(screensaver, name, sizeof(screensaver));
256 }
adamdunkels8a8138b2003-08-09 23:30:37 +0000257}
oliverschmidt533f7e22005-01-24 23:20:50 +0000258#endif /* CTK_CONF_SCREENSAVER */
adamdunkels8a8138b2003-08-09 23:30:37 +0000259/*-----------------------------------------------------------------------------------*/
adamdunkels0eeeba72004-08-20 21:32:41 +0000260static void
261make_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/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000285/*static
286 DISPATCHER_SIGHANDLER(program_handler_sighandler, s, data)*/
287EK_EVENTHANDLER(program_handler_eventhandler, ev, data)
adamdunkels4292c862003-04-08 17:56:43 +0000288{
adamdunkelse937ded2003-10-01 07:53:57 +0000289#ifdef WITH_LOADER_ARCH
290 unsigned char err;
adamdunkelse0635172003-08-09 13:31:18 +0000291 struct dsc *dsc;
adamdunkelse937ded2003-10-01 07:53:57 +0000292#endif /* WITH_LOADER_ARCH */
293 unsigned char i;
adamdunkelse0635172003-08-09 13:31:18 +0000294 struct dsc **dscp;
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000295 /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/
296 EK_EVENTHANDLER_ARGS(ev, data);
297
298 if(ev == EK_EVENT_INIT) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000299 /* Create the menus */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000300 ctk_menu_add(&contikimenu);
301#if WITH_LOADER_ARCH
302 runmenuitem = ctk_menuitem_add(&contikimenu, "Run program...");
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000303
adamdunkels0eeeba72004-08-20 21:32:41 +0000304 make_windows();
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000305#endif /* WITH_LOADER_ARCH */
306
307
308 displayname = NULL;
309
oliverschmidt533f7e22005-01-24 23:20:50 +0000310#if CTK_CONF_SCREENSAVER
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000311 screensaver[0] = 0;
oliverschmidt533f7e22005-01-24 23:20:50 +0000312#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000313
314 } else if(ev == ctk_signal_button_activate) {
adamdunkels045437c2003-06-30 20:49:01 +0000315#ifdef WITH_LOADER_ARCH
adamdunkels4292c862003-04-08 17:56:43 +0000316 if(data == (ek_data_t)&loadbutton) {
317 ctk_window_close(&runwindow);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000318 program_handler_load(name, NULL);
adamdunkels4292c862003-04-08 17:56:43 +0000319 } else if(data == (ek_data_t)&errorokbutton) {
320 ctk_dialog_close();
adamdunkels4292c862003-04-08 17:56:43 +0000321 }
adamdunkels045437c2003-06-30 20:49:01 +0000322#endif /* WITH_LOADER_ARCH */
adamdunkelse0635172003-08-09 13:31:18 +0000323 dscp = &contikidsc[0];
324 for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) {
325 if(*dscp != NULL &&
326 data == (ek_data_t)(*dscp)->icon) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000327 RUN((*dscp)->prgname, (*dscp)->init, NULL);
adamdunkels43c3d1d2003-04-17 19:00:00 +0000328 break;
329 }
adamdunkelse0635172003-08-09 13:31:18 +0000330 ++dscp;
331 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000332 } else if(ev == ctk_signal_menu_activate) {
adamdunkels43c3d1d2003-04-17 19:00:00 +0000333 if((struct ctk_menu *)data == &contikimenu) {
adamdunkels045437c2003-06-30 20:49:01 +0000334#if WITH_LOADER_ARCH
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000335 dsc = contikidsc[contikimenu.active];
adamdunkelse0635172003-08-09 13:31:18 +0000336 if(dsc != NULL) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000337 RUN(dsc->prgname, dsc->init, NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000338 } else if(contikimenu.active == runmenuitem) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000339 make_windows();
adamdunkelsb1a88e22004-09-09 21:15:55 +0000340 ctk_window_close(&runwindow);
adamdunkels045437c2003-06-30 20:49:01 +0000341 ctk_window_open(&runwindow);
adamdunkels46dbaed2003-07-31 23:47:30 +0000342 CTK_WIDGET_FOCUS(&runwindow, &nameentry);
adamdunkels4292c862003-04-08 17:56:43 +0000343 }
adamdunkels045437c2003-06-30 20:49:01 +0000344#else /* WITH_LOADER_ARCH */
345 if(contikidsc[contikimenu.active] != NULL) {
346 RUN(contikidsc[contikimenu.active]->prgname,
adamdunkels8bb5cca2003-08-24 22:41:31 +0000347 contikidsc[contikimenu.active]->init,
348 NULL);
adamdunkels045437c2003-06-30 20:49:01 +0000349 }
350#endif /* WITH_LOADER_ARCH */
adamdunkels8a8138b2003-08-09 23:30:37 +0000351 }
352#if CTK_CONF_SCREENSAVER
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000353 } else if(ev == ctk_signal_screensaver_start) {
adamdunkels8a8138b2003-08-09 23:30:37 +0000354#if WITH_LOADER_ARCH
355 if(screensaver[0] != 0) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000356 program_handler_load(screensaver, NULL);
adamdunkels8a8138b2003-08-09 23:30:37 +0000357 }
358#endif /* WITH_LOADER_ARCH */
359#endif /* CTK_CONF_SCREENSAVER */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000360 } else if(ev == LOADER_EVENT_DISPLAY_NAME) {
adamdunkels19539282003-08-05 23:27:23 +0000361#if WITH_LOADER_ARCH
362 if(displayname == NULL) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000363 make_windows();
364
adamdunkels8bb5cca2003-08-24 22:41:31 +0000365 ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name);
adamdunkels19539282003-08-05 23:27:23 +0000366 ctk_dialog_open(&loadingdialog);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000367 /* dispatcher_emit(loader_signal_load, data, id);*/
368 ek_post(id, LOADER_EVENT_LOAD, data);
adamdunkels19539282003-08-05 23:27:23 +0000369 displayname = data;
370 } else {
371 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000372 /* dispatcher_emit(loader_signal_display_name, data, id);*/
373 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels19539282003-08-05 23:27:23 +0000374 }
375#endif /* WITH_LOADER_ARCH */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000376 } else if(ev == LOADER_EVENT_LOAD) {
adamdunkels045437c2003-06-30 20:49:01 +0000377#if WITH_LOADER_ARCH
adamdunkels19539282003-08-05 23:27:23 +0000378 if(displayname == data) {
379 ctk_dialog_close();
380 displayname = NULL;
adamdunkels0eeeba72004-08-20 21:32:41 +0000381 log_message("Loading ", ((struct pnarg *)data)->name);
adamdunkels8bb5cca2003-08-24 22:41:31 +0000382 err = LOADER_LOAD(((struct pnarg *)data)->name,
383 ((struct pnarg *)data)->arg);
adamdunkels19539282003-08-05 23:27:23 +0000384 if(err != LOADER_OK) {
adamdunkels0eeeba72004-08-20 21:32:41 +0000385 make_windows();
adamdunkels506d6c42003-08-20 20:52:22 +0000386 errorfilename[0] = '"';
adamdunkels8bb5cca2003-08-24 22:41:31 +0000387 strncpy(errorfilename + 1, ((struct pnarg *)data)->name,
388 sizeof(errorfilename) - 2);
389 errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"';
adamdunkels4d2d2762003-09-04 19:34:22 +0000390 ctk_label_set_text(&errortype, (char *)errormsgs[err]);
adamdunkels19539282003-08-05 23:27:23 +0000391 ctk_dialog_open(&errordialog);
adamdunkels0eeeba72004-08-20 21:32:41 +0000392 log_message((char *)errormsgs[err], errorfilename);
adamdunkels19539282003-08-05 23:27:23 +0000393 }
adamdunkels8bb5cca2003-08-24 22:41:31 +0000394 pnarg_free(data);
adamdunkels19539282003-08-05 23:27:23 +0000395 } else {
396 /* Try again. */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000397/* dispatcher_emit(loader_signal_display_name, data, id);*/
398 ek_post(id, LOADER_EVENT_DISPLAY_NAME, data);
adamdunkels4292c862003-04-08 17:56:43 +0000399 }
adamdunkels045437c2003-06-30 20:49:01 +0000400#endif /* WITH_LOADEER_ARCH */
adamdunkels4292c862003-04-08 17:56:43 +0000401 }
402}
403/*-----------------------------------------------------------------------------------*/