2 * Copyright (C) 2016 IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #if defined(HAVE_CONFIG_H)
24 #include <talloc/talloc.h>
25 #include <types/types.h>
27 #include <util/util.h>
28 #include <i18n/i18n.h>
31 #include "nc-textscreen.h"
32 #include "nc-statuslog.h"
34 static const int max_status_entry = 10000;
42 struct statuslog_screen {
43 struct text_screen text_scr;
46 struct statuslog *statuslog_init(struct cui *cui)
50 sl = talloc(cui, struct statuslog);
51 sl->truncated = false;
53 list_init(&sl->status);
58 void statuslog_append_steal(struct cui *cui, struct statuslog *statuslog,
59 struct status *status)
61 struct statuslog_entry *entry;
63 entry = talloc(statuslog, struct statuslog_entry);
64 entry->status = status;
65 talloc_steal(statuslog, status);
67 list_add_tail(&statuslog->status, &entry->list);
69 if (statuslog->n_status >= max_status_entry) {
70 list_remove(&statuslog->status.head);
71 statuslog->truncated = true;
72 statuslog->n_status--;
75 statuslog->n_status++;
77 if (cui->statuslog_screen) {
78 text_screen_append_line(&cui->statuslog_screen->text_scr,
79 "%s", status->message);
80 text_screen_draw(&cui->statuslog_screen->text_scr);
84 struct statuslog_screen *statuslog_screen_init(struct cui *cui,
85 void (*on_exit)(struct cui *))
87 struct statuslog_screen *screen;
88 struct statuslog_entry *entry;
91 screen = talloc_zero(cui, struct statuslog_screen);
93 title = _("Petitboot status log");
95 text_screen_init(&screen->text_scr, cui, title, on_exit);
96 list_for_each_entry(&cui->statuslog->status, entry, list) {
97 text_screen_append_line(&screen->text_scr, "%s",
98 entry->status->message);
100 text_screen_draw(&screen->text_scr);
105 struct nc_scr *statuslog_screen_scr(struct statuslog_screen *screen)
107 return text_screen_scr(&screen->text_scr);