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 #include "modules/drivers/x86/ps2mouse/Ps2Mouse.h"
22 
23 bool PsAuxFile::initialise()
24 {
25  // g_Ps2Mouse is a weak extern, so if nothing defines it it'll be null
26  // This could happen if the ps2mouse driver fails to load.
27  if (!g_Ps2Mouse)
28  {
29  return false;
30  }
31 
32  g_Ps2Mouse->subscribe(subscriber, this);
33  return true;
34 }
35 
37  uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock)
38 {
39  return m_Buffer.read(reinterpret_cast<uint8_t *>(buffer), size, bCanBlock);
40 }
41 
43  uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock)
44 {
45  g_Ps2Mouse->write(reinterpret_cast<const char *>(buffer), size);
46  return size;
47 }
48 
49 int PsAuxFile::select(bool bWriting, int timeout)
50 {
51  if (bWriting)
52  {
53  return m_Buffer.canWrite(timeout == 1) ? 1 : 0;
54  }
55  else
56  {
57  return m_Buffer.canRead(timeout == 1) ? 1 : 0;
58  }
59 }
60 
61 void PsAuxFile::subscriber(void *param, const void *buffer, size_t len)
62 {
63  reinterpret_cast<PsAuxFile *>(param)->handleIncoming(buffer, len);
64 }
65 
66 void PsAuxFile::handleIncoming(const void *buffer, size_t len)
67 {
68  if (m_Buffer.write(reinterpret_cast<const uint8_t *>(buffer), len, false))
69  {
70  dataChanged();
71  }
72 }
bool canRead(bool block)
Definition: Buffer.cc:437
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: PsAuxFile.cc:42
bool canWrite(bool block)
Definition: Buffer.cc:409
size_t read(T *buffer, size_t count, bool block=true)
Definition: Buffer.cc:236
virtual int select(bool bWriting=false, int timeout=0)
Definition: PsAuxFile.cc:49
void dataChanged()
Definition: File.cc:654
uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: PsAuxFile.cc:36
size_t write(const T *buffer, size_t count, bool block=true)
Definition: Buffer.cc:64