1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Update the Driver.DriverInit method signature to accept an io.Writer

Drivers can use the writer as an argument to kfmt.Fprintf to log
additional output during their initialization.
This commit is contained in:
Achilleas Anagnostopoulos 2017-07-08 20:19:28 +01:00
parent da279cf3ff
commit 3485523cdc
5 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,9 @@
package device
import "gopheros/kernel"
import (
"gopheros/kernel"
"io"
)
// Driver is an interface implemented by all drivers.
type Driver interface {
@ -10,8 +13,10 @@ type Driver interface {
// DriverVersion returns the driver version.
DriverVersion() (major uint16, minor uint16, patch uint16)
// DriverInit initializes the device driver.
DriverInit() *kernel.Error
// DriverInit initializes the device driver. If the driver init code
// needs to log some output, it can use the supplied io.Writer in
// conjunction with a call to kfmt.Fprint.
DriverInit(io.Writer) *kernel.Error
}
// ProbeFn is a function that scans for the presence of a particular

View File

@ -258,7 +258,7 @@ func (t *VT) DriverVersion() (uint16, uint16, uint16) {
}
// DriverInit initializes this driver.
func (t *VT) DriverInit() *kernel.Error { return nil }
func (t *VT) DriverInit(_ io.Writer) *kernel.Error { return nil }
func probeForVT() device.Driver {
return NewVT(DefaultTabWidth, DefaultScrollback)

View File

@ -324,7 +324,7 @@ func TestVtSetState(t *testing.T) {
func TestVTDriverInterface(t *testing.T) {
var dev device.Driver = NewVT(0, 0)
if err := dev.DriverInit(); err != nil {
if err := dev.DriverInit(nil); err != nil {
t.Fatal(err)
}

View File

@ -6,6 +6,7 @@ import (
"gopheros/kernel/cpu"
"gopheros/kernel/hal/multiboot"
"image/color"
"io"
"reflect"
"unsafe"
)
@ -197,7 +198,7 @@ func (cons *VgaTextConsole) DriverVersion() (uint16, uint16, uint16) {
}
// DriverInit initializes this driver.
func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil }
func (cons *VgaTextConsole) DriverInit(_ io.Writer) *kernel.Error { return nil }
// probeForVgaTextConsole checks for the presence of a vga text console.
func probeForVgaTextConsole() device.Driver {

View File

@ -311,7 +311,7 @@ func TestVgaTextSetPaletteColor(t *testing.T) {
func TestVgaTextDriverInterface(t *testing.T) {
var dev device.Driver = NewVgaTextConsole(80, 25, 0)
if err := dev.DriverInit(); err != nil {
if err := dev.DriverInit(nil); err != nil {
t.Fatal(err)
}