2019-01-15 08:30:19 +03:00
|
|
|
#include "SlavePTY.h"
|
|
|
|
#include "MasterPTY.h"
|
2019-01-30 02:49:20 +03:00
|
|
|
#include "DevPtsFS.h"
|
2019-01-31 07:55:30 +03:00
|
|
|
#include <Kernel/Process.h>
|
2019-01-15 08:30:19 +03:00
|
|
|
|
2019-01-16 04:11:50 +03:00
|
|
|
SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
|
2019-01-15 08:30:19 +03:00
|
|
|
: TTY(11, index)
|
2019-01-16 04:11:50 +03:00
|
|
|
, m_master(master)
|
2019-01-15 08:30:19 +03:00
|
|
|
, m_index(index)
|
|
|
|
{
|
2019-01-31 07:55:30 +03:00
|
|
|
set_uid(current->uid());
|
|
|
|
set_gid(current->gid());
|
2019-01-30 02:49:20 +03:00
|
|
|
DevPtsFS::the().register_slave_pty(*this);
|
2019-01-15 10:49:24 +03:00
|
|
|
set_size(80, 25);
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SlavePTY::~SlavePTY()
|
|
|
|
{
|
2019-01-30 21:05:59 +03:00
|
|
|
dbgprintf("~SlavePTY(%u)\n", m_index);
|
2019-01-30 02:49:20 +03:00
|
|
|
DevPtsFS::the().unregister_slave_pty(*this);
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
String SlavePTY::tty_name() const
|
|
|
|
{
|
2019-01-30 18:28:51 +03:00
|
|
|
return String::format("/dev/pts/%u", m_index);
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SlavePTY::on_master_write(const byte* buffer, size_t size)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
emit(buffer[i]);
|
|
|
|
}
|
|
|
|
|
2019-02-05 15:09:01 +03:00
|
|
|
ssize_t SlavePTY::on_tty_write(const byte* data, size_t size)
|
2019-01-15 08:30:19 +03:00
|
|
|
{
|
2019-02-05 15:09:01 +03:00
|
|
|
return m_master->on_slave_write(data, size);
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
2019-01-15 11:17:22 +03:00
|
|
|
|
2019-01-25 02:13:54 +03:00
|
|
|
bool SlavePTY::can_write(Process&) const
|
2019-01-15 11:17:22 +03:00
|
|
|
{
|
2019-01-30 21:05:59 +03:00
|
|
|
return m_master->can_write_from_slave();
|
2019-01-15 11:17:22 +03:00
|
|
|
}
|
2019-01-30 20:26:19 +03:00
|
|
|
|
2019-02-05 14:27:32 +03:00
|
|
|
bool SlavePTY::can_read(Process& process) const
|
|
|
|
{
|
|
|
|
if (m_master->is_closed())
|
|
|
|
return true;
|
|
|
|
return TTY::can_read(process);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t SlavePTY::read(Process& process, byte* buffer, size_t size)
|
|
|
|
{
|
|
|
|
if (m_master->is_closed())
|
|
|
|
return 0;
|
|
|
|
return TTY::read(process, buffer, size);
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:26:19 +03:00
|
|
|
void SlavePTY::close()
|
|
|
|
{
|
2019-01-30 21:05:59 +03:00
|
|
|
m_master->notify_slave_closed(Badge<SlavePTY>());
|
2019-01-30 20:26:19 +03:00
|
|
|
}
|