genode/repos/demo/src/server/nitlog/main.cc

509 lines
12 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Nitpicker-based logging service
* \author Norman Feske
* \date 2006-09-18
*/
/*
* Copyright (C) 2006-2017 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
#include <util/arg_string.h>
#include <base/component.h>
#include <base/heap.h>
2011-12-22 16:19:25 +01:00
#include <base/rpc_server.h>
#include <base/session_label.h>
2011-12-22 16:19:25 +01:00
#include <root/component.h>
#include <log_session/log_session.h>
#include <nitpicker_session/connection.h>
#include <timer_session/connection.h>
#include <input/event.h>
#include <os/pixel_rgb565.h>
2011-12-22 16:19:25 +01:00
/*
* Nitpicker's graphics backend
*/
#include <nitpicker_gfx/box_painter.h>
#include <nitpicker_gfx/tff_font.h>
2011-12-22 16:19:25 +01:00
enum { LOG_W = 80 }; /* number of visible characters per line */
enum { LOG_H = 25 }; /* number of lines of log window */
typedef Text_painter::Font Font;
typedef Genode::Surface_base::Point Point;
typedef Genode::Surface_base::Area Area;
typedef Genode::Surface_base::Rect Rect;
typedef Genode::Color Color;
2011-12-22 16:19:25 +01:00
/*
* Builtin font
2011-12-22 16:19:25 +01:00
*/
extern char _binary_mono_tff_start[];
2011-12-22 16:19:25 +01:00
namespace Nitlog {
class Session_component;
class Root;
struct Main;
using namespace Genode;
}
/**
* Pixel-type-independent interface to graphics backend
*/
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
struct Canvas_base : Genode::Interface
{
virtual void draw_string(Point, Font const &, Color, char const *) = 0;
virtual void draw_box(Rect, Color) = 0;
};
/**
* Pixel-type-specific graphics backend
*/
template <typename PT>
class Canvas : public Canvas_base
{
private:
Genode::Surface<PT> _surface;
public:
Canvas(PT *base, Area size) : _surface(base, size) { }
void clip(Rect rect) { _surface.clip(rect); }
void draw_string(Point p, Font const &font, Color color,
char const *sstr)
{
Text_painter::paint(_surface, Text_painter::Position(p.x(), p.y()),
font, color, sstr);
}
void draw_box(Rect rect, Color color)
{
Box_painter::paint(_surface, rect, color);
}
};
2011-12-22 16:19:25 +01:00
class Log_entry
{
private:
typedef Genode::Color Color;
2011-12-22 16:19:25 +01:00
char _label[64];
char _text[LOG_W];
char _attr[LOG_W];
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
Color _color { };
int _label_len = 0;
int _text_len = 0;
int _id = 0;
2011-12-22 16:19:25 +01:00
public:
/**
* Constructors
*
* The default constructor is used to build an array of log entries.
*/
Log_entry() { }
Log_entry(Genode::Color color, const char *label, const char *log_text, const char *log_attr, int id):
2011-12-22 16:19:25 +01:00
_color(color), _id(id)
{
Genode::strncpy(_label, label, sizeof(_label));
Genode::strncpy(_text, log_text, sizeof(_text));
_label_len = Genode::strlen(_label);
_text_len = Genode::strlen(_text);
/* replace line feed at the end of the text with a blank */
if (_text_len > 0 && _text[_text_len - 1] == '\n')
_text[_text_len - 1] = ' ';
Genode::memcpy(_attr, log_attr, _text_len);
}
/**
* Draw entry
*
* An entry consists of a label and text. The argument 'new_section'
* marks a transition of output from one session to another. This
* information is used to separate sessions visually.
*/
void draw(Canvas_base &canvas, Font const &font, int y, int new_section = false)
2011-12-22 16:19:25 +01:00
{
2013-12-28 20:14:29 +01:00
Color label_fgcol = Color(Genode::min(255, _color.r + 200),
Genode::min(255, _color.g + 200),
Genode::min(255, _color.b + 200));
2011-12-22 16:19:25 +01:00
Color label_bgcol = Color(_color.r, _color.g, _color.b);
Color text_fgcol = Color(180, 180, 180);
Color text_bgcol = Color(_color.r / 2, _color.g / 2, _color.b / 2);
/* calculate label dimensions */
int label_w = font.string_width(_label).decimal();
int label_h = font.bounding_box().h();
2011-12-22 16:19:25 +01:00
if (new_section) {
canvas.draw_box(Rect(Point(1, y), Area(label_w + 2, label_h - 1)), label_bgcol);
canvas.draw_string(Point(1, y - 1), font, label_fgcol, _label);
canvas.draw_box(Rect(Point(1, y + label_h - 1), Area(label_w + 2, 1)), Color(0, 0, 0));
canvas.draw_box(Rect(Point(label_w + 2, y), Area(1, label_h - 1)), _color);
canvas.draw_box(Rect(Point(label_w + 3, y), Area(1, label_h - 1)), Color(0, 0, 0));
canvas.draw_box(Rect(Point(label_w + 4, y), Area(1000, label_h)), text_bgcol);
canvas.draw_box(Rect(Point(label_w + 4, y), Area(1000, 1)), Color(0, 0, 0));
2011-12-22 16:19:25 +01:00
} else
canvas.draw_box(Rect(Point(1, y), Area(1000, label_h)), text_bgcol);
2011-12-22 16:19:25 +01:00
/* draw log text */
canvas.draw_string(Point(label_w + 6, y), font, text_fgcol, _text);
2011-12-22 16:19:25 +01:00
}
/**
* Accessors
*/
int label_len() { return _label_len; }
int id() { return _id; }
};
class Log_window
{
private:
Canvas_base &_canvas;
Font const &_font;
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
Log_entry _entries[LOG_H]; /* log entries */
int _dst_entry = 0; /* destination entry for next write */
int _view_pos = 0; /* current view port on the entry array */
bool _scroll = false; /* scroll mode (when text hits bottom) */
char _attr[LOG_W]; /* character attribute buffer */
bool _dirty = true; /* schedules the log window for a redraw */
Genode::Lock _dirty_lock { };
2011-12-22 16:19:25 +01:00
public:
/**
* Constructor
*/
Log_window(Canvas_base &canvas, Font const &font)
: _canvas(canvas), _font(font) { }
2011-12-22 16:19:25 +01:00
/**
* Write log entry
*
* \param color base color for highlighting the session.
* \param sid unique ID of the log session. This ID is used to
* determine section transitions in the log output.
*/
void write(Genode::Color color, const char *label,
const char *log_text, int sid)
2011-12-22 16:19:25 +01:00
{
_entries[_dst_entry] = Log_entry(color, label, log_text, _attr, sid);
if (_scroll)
_view_pos++;
/* cycle through log entries */
_dst_entry = (_dst_entry + 1) % LOG_H;
/* start scrolling when the dst entry wraps for the first time */
if (_dst_entry == 0)
_scroll = true;
/* schedule log window for redraw */
Genode::Lock::Guard lock_guard(_dirty_lock);
_dirty |= 1;
}
/**
* Draw log window
*
* \retval true drawing operations had been performed
*/
bool draw()
{
{
Genode::Lock::Guard lock_guard(_dirty_lock);
if (!_dirty) return false;
_dirty = false;
}
int line_h = _font.bounding_box().h();
2011-12-22 16:19:25 +01:00
int curr_session_id = -1;
for (int i = 0, y = 0; i < LOG_H; i++, y += line_h) {
Log_entry *le = &_entries[(i + _view_pos) % LOG_H];
le->draw(_canvas, _font, y, curr_session_id != le->id());
2011-12-22 16:19:25 +01:00
curr_session_id = le->id();
}
return true;
}
};
class Nitlog::Session_component : public Rpc_object<Log_session>
2011-12-22 16:19:25 +01:00
{
private:
2011-12-22 16:19:25 +01:00
Log_window &_log_window;
2011-12-22 16:19:25 +01:00
Session_label const _label;
2011-12-22 16:19:25 +01:00
int const _id;
2011-12-22 16:19:25 +01:00
static int _bit(int v, int bit_num) { return (v >> bit_num) & 1; }
/**
* Compute session color
2011-12-22 16:19:25 +01:00
*/
static Color _session_color(int id)
2011-12-22 16:19:25 +01:00
{
int const scale = 32;
int const offset = 64;
2011-12-22 16:19:25 +01:00
int r = (_bit(id, 3) + 2*_bit(id, 0))*scale + offset;
int g = (_bit(id, 4) + 2*_bit(id, 1))*scale + offset;
int b = (_bit(id, 5) + 2*_bit(id, 2))*scale + offset;
2011-12-22 16:19:25 +01:00
return Color(r, g, b);
}
2011-12-22 16:19:25 +01:00
Color const _color = _session_color(_id);
2011-12-22 16:19:25 +01:00
public:
2011-12-22 16:19:25 +01:00
/**
* Constructor
*/
Session_component(Session_label const &label,
Log_window &log_window, int &cnt)
:
_log_window(log_window), _label(label), _id(cnt++)
{ }
2011-12-22 16:19:25 +01:00
/***************************
** Log session interface **
***************************/
size_t write(String const &log_text)
2011-12-22 16:19:25 +01:00
{
if (!log_text.valid_string()) {
error("corrupted string");
2011-12-22 16:19:25 +01:00
return 0;
}
_log_window.write(_color, _label.string(), log_text.string(), _id);
return strlen(log_text.string());
2011-12-22 16:19:25 +01:00
}
};
class Nitlog::Root : public Root_component<Session_component>
2011-12-22 16:19:25 +01:00
{
private:
Log_window &_log_window;
/* session counter, used as a key to generate session colors */
int _session_cnt = 0;
2011-12-22 16:19:25 +01:00
protected:
Session_component *_create_session(const char *args)
2011-12-22 16:19:25 +01:00
{
log("create log session args: ", args);
2011-12-22 16:19:25 +01:00
return new (md_alloc())
Session_component(label_from_args(args),
_log_window, _session_cnt);
2011-12-22 16:19:25 +01:00
}
public:
/**
* Constructor
*/
Root(Entrypoint &ep, Allocator &md_alloc, Log_window &log_window)
2011-12-22 16:19:25 +01:00
:
Root_component<Session_component>(ep, md_alloc),
_log_window(log_window)
{ }
2011-12-22 16:19:25 +01:00
};
class Log_view
{
private:
Nitpicker::Session_client &_nitpicker;
Nitpicker::Point _pos;
Nitpicker::Area _size;
Nitpicker::Session::View_handle _handle;
2011-12-22 16:19:25 +01:00
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
typedef Nitpicker::Session::Command Command;
typedef Nitpicker::Session::View_handle View_handle;
2011-12-22 16:19:25 +01:00
public:
Log_view(Nitpicker::Session_client &nitpicker, Nitpicker::Rect geometry)
2011-12-22 16:19:25 +01:00
:
_nitpicker(nitpicker),
_pos(geometry.p1()),
_size(geometry.area()),
_handle(nitpicker.create_view())
2011-12-22 16:19:25 +01:00
{
move(_pos);
top();
2011-12-22 16:19:25 +01:00
}
void top()
{
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
_nitpicker.enqueue<Command::To_front>(_handle, View_handle());
_nitpicker.execute();
2011-12-22 16:19:25 +01:00
}
void move(Nitpicker::Point pos)
2011-12-22 16:19:25 +01:00
{
_pos = pos;
Nitpicker::Rect rect(_pos, _size);
_nitpicker.enqueue<Command::Geometry>(_handle, rect);
_nitpicker.execute();
2011-12-22 16:19:25 +01:00
}
Nitpicker::Point pos() const { return _pos; }
2011-12-22 16:19:25 +01:00
};
struct Nitlog::Main
2011-12-22 16:19:25 +01:00
{
Env &_env;
2011-12-22 16:19:25 +01:00
Tff_font::Static_glyph_buffer<4096> _glyph_buffer { };
Tff_font _font { _binary_mono_tff_start, _glyph_buffer };
2011-12-22 16:19:25 +01:00
/* calculate size of log view in pixels */
unsigned const _win_w = _font.bounding_box().w() * LOG_W + 2;
unsigned const _win_h = _font.bounding_box().h() * LOG_H + 2;
2011-12-22 16:19:25 +01:00
/* init sessions to the required external services */
Nitpicker::Connection _nitpicker { _env };
Timer::Connection _timer { _env };
2011-12-22 16:19:25 +01:00
void _init_nitpicker_buffer()
{
_nitpicker.buffer(Framebuffer::Mode(_win_w, _win_h,
Framebuffer::Mode::RGB565), false);
}
bool const _nitpicker_buffer_initialized = (_init_nitpicker_buffer(), true);
2011-12-22 16:19:25 +01:00
Sliced_heap _sliced_heap { _env.ram(), _env.rm() };
2011-12-22 16:19:25 +01:00
/* create log window */
Attached_dataspace _fb_ds { _env.rm(), _nitpicker.framebuffer()->dataspace() };
Canvas<Pixel_rgb565> _canvas { _fb_ds.local_addr<Pixel_rgb565>(),
::Area(_win_w, _win_h) };
2011-12-22 16:19:25 +01:00
Log_window _log_window { _canvas, _font };
void _init_canvas()
{
/*
* We clip a border of one pixel off the canvas. This way, the
* border remains unaffected by the drawing operations and
* acts as an outline for the log window.
*/
_canvas.clip(::Rect(::Point(1, 1), ::Area(_win_w - 2, _win_h - 2)));
}
bool const _canvas_initialized = (_init_canvas(), true);
2011-12-22 16:19:25 +01:00
/* create view for log window */
Nitpicker::Rect const _view_geometry { Nitpicker::Point(20, 20),
Nitpicker::Area(_win_w, _win_h) };
Log_view _view { _nitpicker, _view_geometry };
2011-12-22 16:19:25 +01:00
/* create root interface for service */
Root _root { _env.ep(), _sliced_heap, _log_window };
2011-12-22 16:19:25 +01:00
Attached_dataspace _ev_ds { _env.rm(), _nitpicker.input()->dataspace() };
2011-12-22 16:19:25 +01:00
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
Nitpicker::Point _old_mouse_pos { };
unsigned _key_cnt = 0;
2011-12-22 16:19:25 +01:00
Signal_handler<Main> _input_handler {
_env.ep(), *this, &Main::_handle_input };
void _handle_input()
{
Input::Event const *ev_buf = _ev_ds.local_addr<Input::Event const>();
2011-12-22 16:19:25 +01:00
for (int i = 0, num_ev = _nitpicker.input()->flush(); i < num_ev; i++) {
2011-12-22 16:19:25 +01:00
Input::Event const &ev = ev_buf[i];
2011-12-22 16:19:25 +01:00
if (ev.type() == Input::Event::PRESS) _key_cnt++;
if (ev.type() == Input::Event::RELEASE) _key_cnt--;
2011-12-22 16:19:25 +01:00
Nitpicker::Point mouse_pos(ev.ax(), ev.ay());
2011-12-22 16:19:25 +01:00
/* move view */
if (ev.type() == Input::Event::MOTION && _key_cnt > 0)
_view.move(_view.pos() + mouse_pos - _old_mouse_pos);
2011-12-22 16:19:25 +01:00
/* find selected view and bring it to front */
if (ev.type() == Input::Event::PRESS && _key_cnt == 1)
_view.top();
2011-12-22 16:19:25 +01:00
_old_mouse_pos = mouse_pos;
2011-12-22 16:19:25 +01:00
}
}
Signal_handler<Main> _timer_handler {
_env.ep(), *this, &Main::_handle_timer };
void _handle_timer()
{
if (_log_window.draw())
_nitpicker.framebuffer()->refresh(0, 0, _win_w, _win_h);
}
Main(Env &env) : _env(env)
{
/* announce service at our parent */
_env.parent().announce(_env.ep().manage(_root));
_timer.sigh(_timer_handler);
_timer.trigger_periodic(20*1000);
_nitpicker.input()->sigh(_input_handler);
}
};
void Component::construct(Genode::Env &env)
{
static Nitlog::Main main(env);
}