blob: 0b8f8b05966d99986ae4a4cfd7f0b96119cf330d [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +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. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the Contiki desktop environment
31 *
32 * $Id: memstat.c,v 1.1 2006/04/17 15:18:19 kthacker Exp $
33 *
34 */
35
36#include <stdlib.h>
37
38#include "ctk.h"
39#include "ek.h"
40#include "loader.h"
41
42static struct ctk_window window;
43static struct ctk_label freemsg =
44 {CTK_LABEL(2, 0, 12, 1, "Free memory:")};
45static char freemem[6];
46static struct ctk_label freenum =
47 {CTK_LABEL(18, 0, 5, 1, freemem)};
48
49static struct ctk_label lblockmsg =
50 {CTK_LABEL(2, 2, 14, 1, "Largest block:")};
51static char lblock[6];
52static struct ctk_label lblocknum =
53 {CTK_LABEL(18, 2, 5, 1, lblock)};
54
55const static struct ctk_button updatebutton =
56 {CTK_BUTTON(0, 4, 6, "Update")};
57const static struct ctk_button closebutton =
58 {CTK_BUTTON(17, 4, 5, "Close")};
59
60/*static DISPATCHER_SIGHANDLER(memstat_sighandler, s, data);
61static struct dispatcher_proc p =
62 {DISPATCHER_PROC("Memory statistics", NULL, memstat_sighandler, NULL)};
63 static ek_id_t id;*/
64EK_EVENTHANDLER(memstat_eventhandler, ev, data);
65EK_PROCESS(p, "Memory statistics", EK_PRIO_NORMAL,
66 memstat_eventhandler, NULL, NULL);
67static ek_id_t id = EK_ID_NONE;
68
69/*-----------------------------------------------------------------------------------*/
70static void
71update(void)
72{
73 int mem;
74
75 mem = _heapmemavail();
76 freemem[0] = (mem/10000) % 10 + '0';
77 freemem[1] = (mem/1000) % 10 + '0';
78 freemem[2] = (mem/100) % 10 + '0';
79 freemem[3] = (mem/10) % 10 + '0';
80 freemem[4] = (mem) % 10 + '0';
81
82 mem = _heapmaxavail();
83 lblock[0] = (mem/10000) % 10 + '0';
84 lblock[1] = (mem/1000) % 10 + '0';
85 lblock[2] = (mem/100) % 10 + '0';
86 lblock[3] = (mem/10) % 10 + '0';
87 lblock[4] = (mem) % 10 + '0';
88
89}
90/*-----------------------------------------------------------------------------------*/
91LOADER_INIT_FUNC(memstat_init, arg)
92{
93 arg_free(arg);
94
95 if(id == EK_ID_NONE) {
96 id = ek_start(&p);
97
98 } else {
99 ctk_window_open(&window);
100 }
101}
102/*-----------------------------------------------------------------------------------*/
103static void
104quit(void)
105{
106 ek_exit();
107 id = EK_ID_NONE;
108 LOADER_UNLOAD();
109}
110/*-----------------------------------------------------------------------------------*/
111EK_EVENTHANDLER(memstat_eventhandler, ev, data)
112{
113 EK_EVENTHANDLER_ARGS(ev, data);
114
115 if(ev == EK_EVENT_INIT) {
116 ctk_window_new(&window, 24, 5, "Memory stats");
117 /* ctk_window_move(&window, 0, 1);*/
118
119 CTK_WIDGET_ADD(&window, &freemsg);
120 CTK_WIDGET_ADD(&window, &freenum);
121
122 CTK_WIDGET_ADD(&window, &lblockmsg);
123 CTK_WIDGET_ADD(&window, &lblocknum);
124
125 CTK_WIDGET_ADD(&window, &updatebutton);
126 CTK_WIDGET_ADD(&window, &closebutton);
127
128 CTK_WIDGET_FOCUS(&window, &updatebutton);
129
130 update();
131
132 ctk_window_open(&window);
133
134 } else if(ev == ctk_signal_button_activate) {
135 if(data == (ek_data_t)&updatebutton) {
136 update();
137 ctk_window_redraw(&window);
138 } else if(data == (ek_data_t)&closebutton) {
139 ctk_window_close(&window);
140 quit();
141 }
142 } else if((ev == ctk_signal_window_close &&
143 data == (ek_data_t)&window) ||
144 ev == EK_EVENT_REQUEST_EXIT) {
145 quit();
146 }
147}
148/*-----------------------------------------------------------------------------------*/