adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop environment |
| 34 | * |
adamdunkels | b1a3d23 | 2003-06-30 20:48:10 +0000 | [diff] [blame^] | 35 | * $Id: processes.c,v 1.6 2003/06/30 20:48:10 adamdunkels Exp $ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include "ctk.h" |
| 40 | #include "dispatcher.h" |
| 41 | #include "loader.h" |
| 42 | |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 43 | #define MAX_PROCESSLABELS 13 |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 44 | static struct ctk_window processwindow; |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 45 | static unsigned char ids[MAX_PROCESSLABELS][4]; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 46 | static struct ctk_label processidlabels[MAX_PROCESSLABELS]; |
| 47 | static struct ctk_label processnamelabels[MAX_PROCESSLABELS]; |
| 48 | |
| 49 | static struct ctk_button processupdatebutton = |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 50 | {CTK_BUTTON(0, 14, 6, "Update")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 51 | static struct ctk_button processclosebutton = |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 52 | {CTK_BUTTON(13, 14, 5, "Close")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 53 | |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 54 | static DISPATCHER_SIGHANDLER(processes_sighandler, s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 55 | static struct dispatcher_proc p = |
| 56 | {DISPATCHER_PROC("Process listing", NULL, processes_sighandler, NULL)}; |
| 57 | static ek_id_t id; |
| 58 | |
| 59 | /*-----------------------------------------------------------------------------------*/ |
| 60 | static void |
| 61 | update_processwindow(void) |
| 62 | { |
| 63 | unsigned char i, j, *idsptr; |
| 64 | struct dispatcher_proc *p; |
| 65 | |
adamdunkels | b1a3d23 | 2003-06-30 20:48:10 +0000 | [diff] [blame^] | 66 | /* Step through each possible process ID and see if there is a |
| 67 | matching process. */ |
| 68 | j = 0; |
| 69 | for(p = DISPATCHER_PROCS(); p != NULL; p = p->next) { |
| 70 | idsptr = ids[j]; |
| 71 | i = p->id; |
| 72 | idsptr[0] = '0' + i / 100; |
| 73 | if(idsptr[0] == '0') { |
| 74 | idsptr[0] = ' '; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 75 | } |
adamdunkels | b1a3d23 | 2003-06-30 20:48:10 +0000 | [diff] [blame^] | 76 | idsptr[1] = '0' + i / 10; |
| 77 | idsptr[2] = '0' + i % 10; |
| 78 | idsptr[3] = 0; |
| 79 | CTK_LABEL_NEW(&processidlabels[j], |
| 80 | 0, j + 1, 3, 1, idsptr); |
| 81 | CTK_WIDGET_ADD(&processwindow, &processidlabels[j]); |
| 82 | |
| 83 | CTK_LABEL_NEW(&processnamelabels[j], |
| 84 | 4, j + 1, 16, 1, p->name); |
| 85 | CTK_WIDGET_ADD(&processwindow, &processnamelabels[j]); |
| 86 | ++j; |
| 87 | } |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 88 | |
| 89 | CTK_WIDGET_ADD(&processwindow, &processupdatebutton); |
| 90 | CTK_WIDGET_ADD(&processwindow, &processclosebutton); |
| 91 | CTK_WIDGET_FOCUS(&processwindow, &processupdatebutton); |
| 92 | } |
| 93 | /*-----------------------------------------------------------------------------------*/ |
| 94 | LOADER_INIT_FUNC(processes_init) |
| 95 | { |
| 96 | if(id == EK_ID_NONE) { |
| 97 | id = dispatcher_start(&p); |
| 98 | |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 99 | ctk_window_new(&processwindow, 20, 15, "Processes"); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 100 | update_processwindow(); |
| 101 | |
| 102 | dispatcher_listen(ctk_signal_button_activate); |
| 103 | dispatcher_listen(ctk_signal_window_close); |
| 104 | } |
| 105 | ctk_window_open(&processwindow); |
| 106 | } |
| 107 | /*-----------------------------------------------------------------------------------*/ |
| 108 | static void |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 109 | processes_quit(void) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 110 | { |
| 111 | dispatcher_exit(&p); |
| 112 | id = EK_ID_NONE; |
| 113 | LOADER_UNLOAD(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 114 | } |
| 115 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 116 | static |
| 117 | DISPATCHER_SIGHANDLER(processes_sighandler, s, data) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 118 | { |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 119 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 120 | if(s == ctk_signal_button_activate) { |
| 121 | if(data == (ek_data_t)&processupdatebutton) { |
| 122 | ctk_window_clear(&processwindow); |
| 123 | update_processwindow(); |
adamdunkels | 7677172 | 2003-04-28 23:20:57 +0000 | [diff] [blame] | 124 | ctk_window_redraw(&processwindow); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 125 | } else if(data == (ek_data_t)&processclosebutton) { |
| 126 | ctk_window_close(&processwindow); |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 127 | processes_quit(); |
adamdunkels | b1a3d23 | 2003-06-30 20:48:10 +0000 | [diff] [blame^] | 128 | /* ctk_desktop_redraw(processwindow.desktop); */ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 129 | } |
| 130 | } else if(s == ctk_signal_window_close && |
| 131 | data == (ek_data_t)&processwindow) { |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 132 | processes_quit(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | /*-----------------------------------------------------------------------------------*/ |