57 #include "program-handler.h"
61 static struct ctk_menu contikimenu = {
NULL,
"Contiki", 7, 0, 0};
63 #ifndef PROGRAM_HANDLER_CONF_MAX_NUMDSCS
64 #define MAX_NUMDSCS 10
66 #define MAX_NUMDSCS PROGRAM_HANDLER_CONF_MAX_NUMDSCS
69 static struct dsc *contikidsc[MAX_NUMDSCS];
70 static unsigned char contikidsclast = 0;
72 #ifndef PROGRAM_HANDLER_CONF_QUIT_MENU
75 #define QUIT_MENU PROGRAM_HANDLER_CONF_QUIT_MENU
80 static unsigned char quitmenuitem;
84 static struct ctk_label quitdialoglabel =
85 {
CTK_LABEL(2, 1, 20, 1,
"Really quit Contiki?")};
86 static struct ctk_button quityesbutton =
88 static struct ctk_button quitnobutton =
97 static unsigned char runmenuitem;
98 static struct ctk_label namelabel =
99 {
CTK_LABEL(0, 0, 13, 1,
"Program name:")};
100 static char name[31];
101 static struct ctk_textentry nameentry =
103 static struct ctk_button loadbutton =
107 static struct ctk_label loadingmsg =
109 static struct ctk_label loadingname =
113 static struct ctk_label errormsg =
114 {
CTK_LABEL(0, 1, 22, 1,
"Error loading program:")};
115 static char errorfilename[22];
116 static struct ctk_label errorfilelabel =
118 static struct ctk_label errortype =
120 static struct ctk_button errorokbutton =
123 static const char *
const errormsgs[] = {
136 #define LOADER_EVENT_LOAD 1
137 #define LOADER_EVENT_DISPLAY_NAME 2
139 PROCESS(program_handler_process,
"Program handler");
141 AUTOSTART_PROCESSES(&program_handler_process);
143 static char *displayname;
145 #if CTK_CONF_SCREENSAVER
146 char program_handler_screensaver[20];
164 unsigned char desktop)
166 contikidsc[contikidsclast++] = dsc;
183 #ifdef WITH_LOADER_ARCH
191 static struct pnarg *
192 pnarg_copy(
char *name,
char *arg)
195 struct pnarg *pnargsptr;
200 if(*(pnargsptr->name) == 0) {
201 strncpy(pnargsptr->name, name, NAMELEN);
202 pnargsptr->arg = arg;
211 pnarg_free(
struct pnarg *pn)
229 #ifdef WITH_LOADER_ARCH
232 pnarg = pnarg_copy(name, arg);
234 process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, pnarg);
237 ctk_dialog_open(&errordialog);
244 #ifdef WITH_LOADER_ARCH
245 #define RUN(prg, name, arg) program_handler_load(prg, arg)
247 #define RUN(prg, process, arg) process_start(process, arg)
258 #if CTK_CONF_SCREENSAVER
260 program_handler_setscreensaver(
char *name)
263 program_handler_screensaver[0] = 0;
265 strncpy(program_handler_screensaver, name,
sizeof(program_handler_screensaver));
270 #ifdef WITH_LOADER_ARCH
282 ctk_dialog_new(&loadingdialog, 25, 1);
286 ctk_dialog_new(&errordialog, 22, 8);
297 #ifdef WITH_LOADER_ARCH
319 #if CTK_CONF_SCREENSAVER
320 program_handler_screensaver[0] = 0;
326 #ifdef WITH_LOADER_ARCH
327 if(data == (process_data_t)&loadbutton) {
330 }
else if(data == (process_data_t)&errorokbutton) {
335 if(data == (process_data_t)&quityesbutton) {
338 }
else if(data == (process_data_t)&quitnobutton) {
342 dscp = &contikidsc[0];
343 for(i = 0; i < CTK_MAXMENUITEMS; ++i) {
346 && data == (process_data_t)(*dscp)->icon
349 RUN((*dscp)->prgname, (*dscp)->process,
NULL);
355 if((
struct ctk_menu *)data == &contikimenu) {
357 dsc = contikidsc[contikimenu.
active];
360 }
else if(contikimenu.
active == runmenuitem) {
369 contikidsc[contikimenu.
active]->process,
374 if(contikimenu.
active == quitmenuitem) {
375 ctk_dialog_new(&quitdialog, 24, 5);
380 ctk_dialog_open(&quitdialog);
384 #if CTK_CONF_SCREENSAVER
385 }
else if(ev == ctk_signal_screensaver_start) {
387 if(program_handler_screensaver[0] != 0) {
392 }
else if(ev == LOADER_EVENT_DISPLAY_NAME) {
394 if(displayname ==
NULL) {
398 ctk_dialog_open(&loadingdialog);
399 process_post(&program_handler_process, LOADER_EVENT_LOAD, data);
403 process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data);
406 }
else if(ev == LOADER_EVENT_LOAD) {
408 if(displayname == data) {
411 log_message(
"Loading ", ((
struct pnarg *)data)->name);
413 ((
struct pnarg *)data)->arg);
416 errorfilename[0] =
'"';
417 strncpy(errorfilename + 1, ((
struct pnarg *)data)->name,
418 sizeof(errorfilename) - 2);
419 errorfilename[1 + strlen(((
struct pnarg *)data)->name)] =
'"';
421 ctk_dialog_open(&errordialog);
422 log_message((
char *)errormsgs[err], errorfilename);
427 process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data);
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_button_activate
Same as ctk_signal_widget_activate.
unsigned char ctk_menuitem_add(CC_REGISTER_ARG struct ctk_menu *menu, char *name)
Adds a menu item to a menu.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
#define NUM_PNARGS
Initializes the program handler.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
unsigned char active
The currently active menu item.
#define LOADER_OK
No error.
#define PROCESS_BEGIN()
Define the beginning of a process.
void ctk_menu_add(struct ctk_menu *menu)
Add a menu to the menu bar.
#define CTK_TEXTENTRY(x, y, w, h, text, len)
Instantiating macro for the ctk_textentry widget.
#define ctk_label_set_text(l, t)
Set the text of a label.
#define NULL
The null pointer.
process_event_t ctk_signal_menu_activate
Emitted when a menu item is activated.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
The DSC program description structure.
void program_handler_add(struct dsc *dsc, char *menuname, unsigned char desktop)
Add a program to the program handler.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
CTK screen drawing module interface, ctk-draw.
Representation of an individual menu.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
void ctk_draw_init(void)
The initialization function.
Representation of a CTK window.
char * prgname
The name of the program on disk.
#define LOADER_LOAD(name, arg)
Load and execute a program.
void program_handler_load(char *name, char *arg)
Loads a program and displays a dialog telling the user about it.
#define CTK_ICON_ADD(icon, p)
Add an icon to the desktop.