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 | 7677172 | 2003-04-28 23:20:57 +0000 | [diff] [blame^] | 35 | * $Id: processes.c,v 1.5 2003/04/28 23:20:57 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 | |
| 66 | i = 0; |
| 67 | j = 0; |
| 68 | do { |
| 69 | p = dispatcher_process(i); |
| 70 | if(p != NULL) { |
| 71 | idsptr = ids[j]; |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 72 | idsptr[0] = '0' + i / 100; |
| 73 | if(idsptr[0] == '0') { |
| 74 | idsptr[0] = ' '; |
| 75 | } |
| 76 | idsptr[1] = '0' + i / 10; |
| 77 | idsptr[2] = '0' + i % 10; |
| 78 | idsptr[3] = 0; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 79 | CTK_LABEL_NEW(&processidlabels[j], |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 80 | 0, j + 1, 3, 1, idsptr); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 81 | CTK_WIDGET_ADD(&processwindow, &processidlabels[j]); |
| 82 | |
| 83 | CTK_LABEL_NEW(&processnamelabels[j], |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 84 | 4, j + 1, 16, 1, p->name); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 85 | CTK_WIDGET_ADD(&processwindow, &processnamelabels[j]); |
| 86 | ++j; |
| 87 | } |
| 88 | ++i; |
| 89 | } while(i != 0); |
| 90 | |
| 91 | |
| 92 | CTK_WIDGET_ADD(&processwindow, &processupdatebutton); |
| 93 | CTK_WIDGET_ADD(&processwindow, &processclosebutton); |
| 94 | CTK_WIDGET_FOCUS(&processwindow, &processupdatebutton); |
| 95 | } |
| 96 | /*-----------------------------------------------------------------------------------*/ |
| 97 | LOADER_INIT_FUNC(processes_init) |
| 98 | { |
| 99 | if(id == EK_ID_NONE) { |
| 100 | id = dispatcher_start(&p); |
| 101 | |
adamdunkels | 8bb556e | 2003-04-09 19:25:37 +0000 | [diff] [blame] | 102 | ctk_window_new(&processwindow, 20, 15, "Processes"); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 103 | update_processwindow(); |
| 104 | |
| 105 | dispatcher_listen(ctk_signal_button_activate); |
| 106 | dispatcher_listen(ctk_signal_window_close); |
| 107 | } |
| 108 | ctk_window_open(&processwindow); |
| 109 | } |
| 110 | /*-----------------------------------------------------------------------------------*/ |
| 111 | static void |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 112 | processes_quit(void) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 113 | { |
| 114 | dispatcher_exit(&p); |
| 115 | id = EK_ID_NONE; |
| 116 | LOADER_UNLOAD(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 117 | } |
| 118 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 119 | static |
| 120 | DISPATCHER_SIGHANDLER(processes_sighandler, s, data) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 121 | { |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 122 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 123 | if(s == ctk_signal_button_activate) { |
| 124 | if(data == (ek_data_t)&processupdatebutton) { |
| 125 | ctk_window_clear(&processwindow); |
| 126 | update_processwindow(); |
adamdunkels | 7677172 | 2003-04-28 23:20:57 +0000 | [diff] [blame^] | 127 | ctk_window_redraw(&processwindow); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 128 | } else if(data == (ek_data_t)&processclosebutton) { |
| 129 | ctk_window_close(&processwindow); |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 130 | processes_quit(); |
| 131 | ctk_redraw(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 132 | } |
| 133 | } else if(s == ctk_signal_window_close && |
| 134 | data == (ek_data_t)&processwindow) { |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 135 | processes_quit(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | /*-----------------------------------------------------------------------------------*/ |