The Pedigree Project 0.1
PsAuxFile.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "modules/subsys/posix/PsAuxFile.h"
21
22#include "modules/drivers/x86/ps2mouse/Ps2Mouse.h"
23
24PsAuxFile::~PsAuxFile() {
25 m_MouseRegistration.reset();
26}
27
28bool PsAuxFile::initialise() {
29 // g_Ps2Mouse is a weak extern, so if nothing defines it it'll be null
30 // This could happen if the ps2mouse driver fails to load.
31 if (!g_Ps2Mouse) {
32 return false;
33 }
34
35 return g_Ps2Mouse->subscribe(subscriber, this, m_MouseRegistration);
36}
37
38uint64_t PsAuxFile::readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
39 bool bCanBlock) {
40 return m_Buffer.read(reinterpret_cast<uint8_t*>(buffer), size, bCanBlock);
41}
42
43uint64_t PsAuxFile::writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
44 bool bCanBlock) {
45 g_Ps2Mouse->write(reinterpret_cast<const char*>(buffer), size);
46 return size;
47}
48
49int PsAuxFile::select(bool bWriting, int timeout) {
50 if (bWriting) {
51 return m_Buffer.canWrite(timeout == 1) ? 1 : 0;
52 } else {
53 return m_Buffer.canRead(timeout == 1) ? 1 : 0;
54 }
55}
56
57void PsAuxFile::subscriber(void* param, const void* buffer, size_t len) {
58 reinterpret_cast<PsAuxFile*>(param)->handleIncoming(buffer, len);
59}
60
61void PsAuxFile::handleIncoming(const void* buffer, size_t len) {
62 if (m_Buffer.write(reinterpret_cast<const uint8_t*>(buffer), len, false)) {
64 }
65}
size_t write(const T *buffer, size_t count, bool block=true)
Definition Buffer.cc:103
bool canRead(bool block)
Definition Buffer.cc:525
bool canWrite(bool block)
Definition Buffer.cc:491
size_t read(T *buffer, size_t count, bool block=true)
Definition Buffer.cc:296
void dataChanged()
Definition File.cc:1364
uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition PsAuxFile.cc:38
virtual int select(bool bWriting=false, int timeout=0)
Definition PsAuxFile.cc:49
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition PsAuxFile.cc:43