blob: 4c1f18a2fad277d05ebee482637d007b15568e93 [file] [log] [blame]
adamdunkels4292c862003-04-08 17:56:43 +00001/*
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 *
adamdunkels76771722003-04-28 23:20:57 +000035 * $Id: processes.c,v 1.5 2003/04/28 23:20:57 adamdunkels Exp $
adamdunkels4292c862003-04-08 17:56:43 +000036 *
37 */
38
39#include "ctk.h"
40#include "dispatcher.h"
41#include "loader.h"
42
adamdunkels8bb556e2003-04-09 19:25:37 +000043#define MAX_PROCESSLABELS 13
adamdunkels4292c862003-04-08 17:56:43 +000044static struct ctk_window processwindow;
adamdunkels8bb556e2003-04-09 19:25:37 +000045static unsigned char ids[MAX_PROCESSLABELS][4];
adamdunkels4292c862003-04-08 17:56:43 +000046static struct ctk_label processidlabels[MAX_PROCESSLABELS];
47static struct ctk_label processnamelabels[MAX_PROCESSLABELS];
48
49static struct ctk_button processupdatebutton =
adamdunkels8bb556e2003-04-09 19:25:37 +000050 {CTK_BUTTON(0, 14, 6, "Update")};
adamdunkels4292c862003-04-08 17:56:43 +000051static struct ctk_button processclosebutton =
adamdunkels8bb556e2003-04-09 19:25:37 +000052 {CTK_BUTTON(13, 14, 5, "Close")};
adamdunkels4292c862003-04-08 17:56:43 +000053
adamdunkels78c03dc2003-04-09 13:45:05 +000054static DISPATCHER_SIGHANDLER(processes_sighandler, s, data);
adamdunkels4292c862003-04-08 17:56:43 +000055static struct dispatcher_proc p =
56 {DISPATCHER_PROC("Process listing", NULL, processes_sighandler, NULL)};
57static ek_id_t id;
58
59/*-----------------------------------------------------------------------------------*/
60static void
61update_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];
adamdunkels8bb556e2003-04-09 19:25:37 +000072 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;
adamdunkels4292c862003-04-08 17:56:43 +000079 CTK_LABEL_NEW(&processidlabels[j],
adamdunkels8bb556e2003-04-09 19:25:37 +000080 0, j + 1, 3, 1, idsptr);
adamdunkels4292c862003-04-08 17:56:43 +000081 CTK_WIDGET_ADD(&processwindow, &processidlabels[j]);
82
83 CTK_LABEL_NEW(&processnamelabels[j],
adamdunkels8bb556e2003-04-09 19:25:37 +000084 4, j + 1, 16, 1, p->name);
adamdunkels4292c862003-04-08 17:56:43 +000085 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/*-----------------------------------------------------------------------------------*/
97LOADER_INIT_FUNC(processes_init)
98{
99 if(id == EK_ID_NONE) {
100 id = dispatcher_start(&p);
101
adamdunkels8bb556e2003-04-09 19:25:37 +0000102 ctk_window_new(&processwindow, 20, 15, "Processes");
adamdunkels4292c862003-04-08 17:56:43 +0000103 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/*-----------------------------------------------------------------------------------*/
111static void
adamdunkels0137b442003-04-08 23:27:33 +0000112processes_quit(void)
adamdunkels4292c862003-04-08 17:56:43 +0000113{
114 dispatcher_exit(&p);
115 id = EK_ID_NONE;
116 LOADER_UNLOAD();
adamdunkels4292c862003-04-08 17:56:43 +0000117}
118/*-----------------------------------------------------------------------------------*/
adamdunkels78c03dc2003-04-09 13:45:05 +0000119static
120DISPATCHER_SIGHANDLER(processes_sighandler, s, data)
adamdunkels4292c862003-04-08 17:56:43 +0000121{
adamdunkels78c03dc2003-04-09 13:45:05 +0000122 DISPATCHER_SIGHANDLER_ARGS(s, data);
adamdunkels4292c862003-04-08 17:56:43 +0000123 if(s == ctk_signal_button_activate) {
124 if(data == (ek_data_t)&processupdatebutton) {
125 ctk_window_clear(&processwindow);
126 update_processwindow();
adamdunkels76771722003-04-28 23:20:57 +0000127 ctk_window_redraw(&processwindow);
adamdunkels4292c862003-04-08 17:56:43 +0000128 } else if(data == (ek_data_t)&processclosebutton) {
129 ctk_window_close(&processwindow);
adamdunkels0137b442003-04-08 23:27:33 +0000130 processes_quit();
131 ctk_redraw();
adamdunkels4292c862003-04-08 17:56:43 +0000132 }
133 } else if(s == ctk_signal_window_close &&
134 data == (ek_data_t)&processwindow) {
adamdunkels0137b442003-04-08 23:27:33 +0000135 processes_quit();
adamdunkels4292c862003-04-08 17:56:43 +0000136 }
137}
138/*-----------------------------------------------------------------------------------*/