From eb53cd839cbf1b3c9c506e1653d1b0489f42fb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 10 Jan 2008 21:08:08 +0000 Subject: [PATCH] generic handle class for the console. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23353 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../boot/platform/atari_m68k/Handle.cpp | 84 +++++++++++++++++++ src/system/boot/platform/atari_m68k/Handle.h | 34 ++++++++ 2 files changed, 118 insertions(+) create mode 100644 src/system/boot/platform/atari_m68k/Handle.cpp create mode 100644 src/system/boot/platform/atari_m68k/Handle.h diff --git a/src/system/boot/platform/atari_m68k/Handle.cpp b/src/system/boot/platform/atari_m68k/Handle.cpp new file mode 100644 index 0000000000..1fffe29c52 --- /dev/null +++ b/src/system/boot/platform/atari_m68k/Handle.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + +#include "Handle.h" +#include "toscalls." + +Handle::Handle(int handle, bool takeOwnership) + : + fHandle((int16)handle), + fOwnHandle(takeOwnership) +{ +} + + +Handle::Handle(void) + : + fHandle(DEV_CONSOLE) +{ +} + + +Handle::~Handle() +{ + //if (fOwnHandle) + // of_close(fHandle); +} + + +void +Handle::SetHandle(int handle, bool takeOwnership) +{ + //if (fHandle && fOwnHandle) + // of_close(fHandle); + + fHandle = (int16)handle; + fOwnHandle = takeOwnership; +} + + +ssize_t +Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +{ + const char *string = (const char *)buffer; + + // can't seek + for (i = 0; i < bufferSize; i++) { + if (Bconstat(fHandle) == 0) + return i; + Bconin(fHandle, string[i]); + } + + return bufferSize; +} + + +ssize_t +Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +{ + const char *string = (const char *)buffer; + + // can't seek + for (i = 0; i < bufferSize; i++) { + Bconout(fHandle, string[i]); + } + + return bufferSize; +} + + +off_t +Handle::Size() const +{ + // ToDo: fix this! + return 1024LL * 1024 * 1024 * 1024; + // 1024 GB +} + diff --git a/src/system/boot/platform/atari_m68k/Handle.h b/src/system/boot/platform/atari_m68k/Handle.h new file mode 100644 index 0000000000..0832dfc63a --- /dev/null +++ b/src/system/boot/platform/atari_m68k/Handle.h @@ -0,0 +1,34 @@ +/* + * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef HANDLE_H +#define HANDLE_H + + +#include + + +#ifdef __cplusplus + +class Handle : public ConsoleNode { + public: + Handle(int handle, bool takeOwnership = true); + Handle(); + virtual ~Handle(); + + void SetHandle(int handle, bool takeOwnership = true); + + virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); + virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); + + virtual off_t Size() const; + + protected: + int16 fHandle; + bool fOwnHandle; +}; + +#endif /* __cplusplus */ + +#endif /* HANDLE_H */