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;
36 struct statuslog_entry {
37 struct status *status;
38 struct list_item list;
47 struct statuslog_screen {
48 struct text_screen text_scr;
51 struct statuslog *statuslog_init(struct cui *cui)
55 sl = talloc(cui, struct statuslog);
56 sl->truncated = false;
58 list_init(&sl->status);
63 void statuslog_append_steal(struct cui *cui, struct statuslog *statuslog,
64 struct status *status)
66 struct statuslog_entry *entry;
68 entry = talloc(statuslog, struct statuslog_entry);
69 entry->status = status;
70 talloc_steal(statuslog, status);
72 list_add_tail(&statuslog->status, &entry->list);
74 if (statuslog->n_status >= max_status_entry) {
75 list_remove(&statuslog->status.head);
76 statuslog->truncated = true;
77 statuslog->n_status--;
80 statuslog->n_status++;
82 if (cui->statuslog_screen) {
83 text_screen_append_line(&cui->statuslog_screen->text_scr,
84 "%s", status->message);
85 text_screen_draw(&cui->statuslog_screen->text_scr);
89 struct statuslog_screen *statuslog_screen_init(struct cui *cui,
90 void (*on_exit)(struct cui *))
92 struct statuslog_screen *screen;
93 struct statuslog_entry *entry;
96 screen = talloc_zero(cui, struct statuslog_screen);
98 title = _("Petitboot status log");
100 text_screen_init(&screen->text_scr, cui, title, on_exit);
101 list_for_each_entry(&cui->statuslog->status, entry, list) {
102 text_screen_append_line(&screen->text_scr, "%s",
103 entry->status->message);
105 text_screen_draw(&screen->text_scr);
110 struct nc_scr *statuslog_screen_scr(struct statuslog_screen *screen)
112 return text_screen_scr(&screen->text_scr);