generic handle class for the console.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <platform/openfirmware/openfirmware.h>
|
||||
#include <util/kernel_cpp.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef HANDLE_H
|
||||
#define HANDLE_H
|
||||
|
||||
|
||||
#include <boot/vfs.h>
|
||||
|
||||
|
||||
#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 */
|
||||
Reference in New Issue
Block a user