From 3485523cdc6b7a5c943e1001a1b32645f6c523dc Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Sat, 8 Jul 2017 20:19:28 +0100 Subject: [PATCH] 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. --- src/gopheros/device/driver.go | 11 ++++++++--- src/gopheros/device/tty/vt.go | 2 +- src/gopheros/device/tty/vt_test.go | 2 +- src/gopheros/device/video/console/vga_text.go | 3 ++- src/gopheros/device/video/console/vga_text_test.go | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gopheros/device/driver.go b/src/gopheros/device/driver.go index aec2c38..15a6316 100644 --- a/src/gopheros/device/driver.go +++ b/src/gopheros/device/driver.go @@ -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 diff --git a/src/gopheros/device/tty/vt.go b/src/gopheros/device/tty/vt.go index ba48be0..9acadf3 100644 --- a/src/gopheros/device/tty/vt.go +++ b/src/gopheros/device/tty/vt.go @@ -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) diff --git a/src/gopheros/device/tty/vt_test.go b/src/gopheros/device/tty/vt_test.go index b1bf40f..066d25f 100644 --- a/src/gopheros/device/tty/vt_test.go +++ b/src/gopheros/device/tty/vt_test.go @@ -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) } diff --git a/src/gopheros/device/video/console/vga_text.go b/src/gopheros/device/video/console/vga_text.go index d30291d..f5be66b 100644 --- a/src/gopheros/device/video/console/vga_text.go +++ b/src/gopheros/device/video/console/vga_text.go @@ -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 { diff --git a/src/gopheros/device/video/console/vga_text_test.go b/src/gopheros/device/video/console/vga_text_test.go index 0c81441..3d5cb25 100644 --- a/src/gopheros/device/video/console/vga_text_test.go +++ b/src/gopheros/device/video/console/vga_text_test.go @@ -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) }