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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use crate::Handle;
use crate::guid::Guid;
use crate::status::Status;

use super::package::{HiiPackageKind, HiiPackageHeader, HiiPackageListHeader};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(transparent)]
pub struct HiiHandle(pub usize);

pub type HiiDatabaseNotify = extern "win64" fn (
    PackageKind: HiiPackageKind,
    PackageGuid: &Guid,
    Package: &HiiPackageHeader,
    Handle: HiiHandle,
    NotifyKind: HiiDatabaseNotifyKind
) -> Status;

#[repr(usize)]
pub enum HiiDatabaseNotifyKind {
    NewPack = 1,
    RemovePack = 2,
    ExportPack = 4,
    AddPack = 8,
}

#[repr(C)]
pub struct HiiKeyboardLayout {
    /// The length of the current keyboard layout
    pub LayoutLength: u16,
    /// The unique ID associated with this keyboard layout
    pub Guid: Guid,
    /// An offset location of the string which describes this keyboard layout, as a DescriptionStringBundle
    pub LayoutDescriptorStringOffset: u32,
    /// The number of Descriptor entries in this layout
    pub DescriptorCount: u8,
    //Descriptors: [KeyDescriptor; DescriptorCount]
}

#[repr(C)]
pub struct HiiDatabase {
    /// Adds the packages in the package list to the HII database
    pub NewPackageList: extern "win64" fn (
        &HiiDatabase,
        PackageList: &HiiPackageListHeader,
        DriverHandle: Handle,
        Handle: &mut HiiHandle
    ) -> Status,

    /// Removes a package list from the HII database
    pub RemovePackageList: extern "win64" fn (
        &HiiDatabase,
        Handle: HiiHandle
    ) -> Status,

    /// Update a package list in the HII database
    pub UpdatePackageList: extern "win64" fn (
        &HiiDatabase,
        Handle: HiiHandle,
        PackageList: &HiiPackageListHeader
    ) -> Status,

    /// Determines the handles that are currently active in the database
    pub ListPackageLists: extern "win64" fn (
        &HiiDatabase,
        PackageKind: HiiPackageKind,
        PackageGuid: &Guid,
        HandleBufferLength: &mut usize,
        Handle: *mut HiiHandle
    ) -> Status,

    /// Exports the contents of one or all package lists in the HII database into a buffer
    pub ExportPackageLists: extern "win64" fn (
        &HiiDatabase,
        Handle: HiiHandle,
        BufferSize: &mut usize,
        Buffer: &mut HiiPackageListHeader
    ) -> Status,

    /// Registers a notification function for HII database-related events
    pub RegisterPackageNotify: extern "win64" fn (
        &HiiDatabase,
        PackageKind: HiiPackageKind,
        PackageGuid: &Guid,
        PackageNotifyFn: HiiDatabaseNotify,
        NotifyKind: HiiDatabaseNotifyKind,
        NotifyHandle: &mut Handle
    ) -> Status,

    /// Removes the specified HII database package-related notification
    pub UnregisterPackageNotify: extern "win64" fn (
        &HiiDatabase,
        NotificationHandle: Handle
    ) -> Status,

    /// Retrieves a list of the keyboard layouts in the system
    pub FindKeyboardLayouts: extern "win64" fn (
        &HiiDatabase,
        KeyGuidBufferLength: &mut u16,
        KeyGuidBuffer: *mut Guid
    ) -> Status,

    /// Retrieves the requested keyboard layout
    pub GetKeyboardLayout: extern "win64" fn (
        &HiiDatabase,
        KeyGuid: &Guid,
        KeyboardLayoutLength: &mut u16,
        KeyboardLayout: *mut HiiKeyboardLayout
    ) -> Status,

    /// Sets the currently active keyboard layout
    pub SetKeyboardLayout: extern "win64" fn (
        &HiiDatabase,
        KeyGuid: &Guid
    ) -> Status,

    /// Return the EFI handle associated with a package list
    pub GetPackageListHandle: extern "win64" fn (
        &HiiDatabase,
        PackageListHandle: HiiHandle,
        DriverHandle: &mut Handle
    ) -> Status,
}