blob: 93645c55c4183c464335c0ca33172e44d013a2da [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 *
adamdunkelsb1a3d232003-06-30 20:48:10 +000035 * $Id: processes.c,v 1.6 2003/06/30 20:48:10 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
adamdunkelsb1a3d232003-06-30 20:48:10 +000066 /* 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] = ' ';
adamdunkels4292c862003-04-08 17:56:43 +000075 }
adamdunkelsb1a3d232003-06-30 20:48:10 +000076 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 }
adamdunkels4292c862003-04-08 17:56:43 +000088
89 CTK_WIDGET_ADD(&processwindow, &processupdatebutton);
90 CTK_WIDGET_ADD(&processwindow, &processclosebutton);
91 CTK_WIDGET_FOCUS(&processwindow, &processupdatebutton);
92}
93/*-----------------------------------------------------------------------------------*/
94LOADER_INIT_FUNC(processes_init)
95{
96 if(id == EK_ID_NONE) {
97 id = dispatcher_start(&p);
98
adamdunkels8bb556e2003-04-09 19:25:37 +000099 ctk_window_new(&processwindow, 20, 15, "Processes");
adamdunkels4292c862003-04-08 17:56:43 +0000100 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/*-----------------------------------------------------------------------------------*/
108static void
adamdunkels0137b442003-04-08 23:27:33 +0000109processes_quit(void)
adamdunkels4292c862003-04-08 17:56:43 +0000110{
111 dispatcher_exit(&p);
112 id = EK_ID_NONE;
113 LOADER_UNLOAD();
adamdunkels4292c862003-04-08 17:56:43 +0000114}
115/*-----------------------------------------------------------------------------------*/
adamdunkels78c03dc2003-04-09 13:45:05 +0000116static
117DISPATCHER_SIGHANDLER(processes_sighandler, s, data)
adamdunkels4292c862003-04-08 17:56:43 +0000118{
adamdunkels78c03dc2003-04-09 13:45:05 +0000119 DISPATCHER_SIGHANDLER_ARGS(s, data);
adamdunkels4292c862003-04-08 17:56:43 +0000120 if(s == ctk_signal_button_activate) {
121 if(data == (ek_data_t)&processupdatebutton) {
122 ctk_window_clear(&processwindow);
123 update_processwindow();
adamdunkels76771722003-04-28 23:20:57 +0000124 ctk_window_redraw(&processwindow);
adamdunkels4292c862003-04-08 17:56:43 +0000125 } else if(data == (ek_data_t)&processclosebutton) {
126 ctk_window_close(&processwindow);
adamdunkels0137b442003-04-08 23:27:33 +0000127 processes_quit();
adamdunkelsb1a3d232003-06-30 20:48:10 +0000128 /* ctk_desktop_redraw(processwindow.desktop); */
adamdunkels4292c862003-04-08 17:56:43 +0000129 }
130 } else if(s == ctk_signal_window_close &&
131 data == (ek_data_t)&processwindow) {
adamdunkels0137b442003-04-08 23:27:33 +0000132 processes_quit();
adamdunkels4292c862003-04-08 17:56:43 +0000133 }
134}
135/*-----------------------------------------------------------------------------------*/