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 "pedigree/kernel/processor/types.h"
21#include "pedigree/kernel/utilities/Buffer.h"
22#include "pedigree/kernel/utilities/String.h"
23
24#include "Console.h"
25#include "ConsoleDefines.h"
26
27class Filesystem;
28
29extern const char defaultControl[MAX_CONTROL_CHAR];
30
31ConsoleSlaveFile::ConsoleSlaveFile(size_t consoleNumber, String consoleName, Filesystem* pFs)
32 : ConsoleSlaveFile(consoleNumber, consoleName, pFs, nullptr) {}
33
34ConsoleSlaveFile::ConsoleSlaveFile(size_t consoleNumber, String consoleName, Filesystem* pFs,
35 File* pParent)
36 : ConsoleFile(consoleNumber, consoleName, pFs, pParent) {}
37
38uint64_t ConsoleSlaveFile::readIo(ConsoleIoState& state, uint64_t size, uintptr_t buffer,
39 bool bCanBlock) {
40 uint64_t nBytes = state.input.read(reinterpret_cast<char*>(buffer), size, bCanBlock);
41 if (!nBytes) {
42 return 0;
43 }
44
46 if (m_pOther) {
48 }
49
50 size_t endSize = processInput(reinterpret_cast<char*>(buffer), nBytes);
51
52 return endSize;
53}
54
55uint64_t ConsoleSlaveFile::writeIo(ConsoleIoState& state, uint64_t size, uintptr_t buffer,
56 bool bCanBlock) {
57 if (!size || !state.output.canWrite(bCanBlock)) {
58 return 0;
59 }
60 // Publish readiness before waiting for a reader to make more room.
61 size_t amount = state.output.writeAvailable(reinterpret_cast<char*>(buffer), size);
62 changed();
63 return amount;
64}
65
66uint64_t ConsoleSlaveFile::readBytewise(uint64_t, uint64_t size, uintptr_t buffer, bool canBlock) {
67 return readEpoch(captureOpenEpoch(), size, buffer, canBlock);
68}
69
70uint64_t ConsoleSlaveFile::writeBytewise(uint64_t, uint64_t size, uintptr_t buffer, bool canBlock) {
71 return writeEpoch(captureOpenEpoch(), size, buffer, canBlock);
72}
bool canWrite(bool block)
Definition Buffer.cc:491
size_t writeAvailable(const T *buffer, size_t count, bool atomic=false)
Definition Buffer.cc:201
size_t read(T *buffer, size_t count, bool block=true)
Definition Buffer.cc:296
ConsoleFile * m_pOther
Other side of the console.
Definition Console.h:160
size_t processInput(char *buf, size_t len)
Input processing.
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition File.h:75
void dataChanged()
Definition File.cc:1452