The Pedigree Project  0.1
ConsoleSlave.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 "Console.h"
21 #include "ConsoleDefines.h"
22 #include "pedigree/kernel/processor/types.h"
23 #include "pedigree/kernel/utilities/Buffer.h"
24 #include "pedigree/kernel/utilities/String.h"
25 
26 class Filesystem;
27 
28 extern const char defaultControl[MAX_CONTROL_CHAR];
29 
30 ConsoleSlaveFile::ConsoleSlaveFile(
31  size_t consoleNumber, String consoleName, Filesystem *pFs)
32  : ConsoleFile(consoleNumber, consoleName, pFs)
33 {
34 }
35 
37  uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock)
38 {
39  uint64_t nBytes =
40  m_Buffer.read(reinterpret_cast<char *>(buffer), size, bCanBlock);
41  if (!nBytes)
42  {
43  return 0;
44  }
45 
46  size_t endSize = processInput(reinterpret_cast<char *>(buffer), nBytes);
47 
48  return endSize;
49 }
50 
52  uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock)
53 {
54  // Send straight to the master.
55  m_pOther->inject(reinterpret_cast<char *>(buffer), size, bCanBlock);
56 
57  return size;
58 }
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: ConsoleSlave.cc:51
size_t read(T *buffer, size_t count, bool block=true)
Definition: Buffer.cc:236
Definition: String.h:49
size_t processInput(char *buf, size_t len)
Input processing.
ConsoleFile * m_pOther
Other side of the console.
Definition: Console.h:135
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: ConsoleSlave.cc:36
void inject(char *buf, size_t len, bool canBlock)
inject - inject bytes into the ring buffer