summaryrefslogtreecommitdiff
path: root/Kernel/TTY/ConsoleManagement.h
blob: ed890d85a9cde3ed053b9e949c519b610e7ad16c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Types.h>
#include <Kernel/Library/NonnullLockRefPtr.h>
#include <Kernel/Library/NonnullLockRefPtrVector.h>
#include <Kernel/TTY/VirtualConsole.h>

namespace Kernel {

class ConsoleManagement {
    friend class VirtualConsole;

public:
    ConsoleManagement();

    static constexpr size_t s_max_virtual_consoles = 6;

    static bool is_initialized();
    static ConsoleManagement& the();

    void switch_to(unsigned);
    void initialize();

    void resolution_was_changed();

    void switch_to_debug() { switch_to(1); }

    NonnullLockRefPtr<VirtualConsole> first_tty() const { return m_consoles[0]; }
    NonnullLockRefPtr<VirtualConsole> debug_tty() const { return m_consoles[1]; }

    RecursiveSpinlock& tty_write_lock() { return m_tty_write_lock; }

private:
    NonnullLockRefPtrVector<VirtualConsole, s_max_virtual_consoles> m_consoles;
    VirtualConsole* m_active_console { nullptr };
    Spinlock m_lock { LockRank::None };
    RecursiveSpinlock m_tty_write_lock { LockRank::None };
};

};