aboutsummaryrefslogtreecommitdiff
path: root/desktop-utilities/lumina-terminal/TtyProcess.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2016-03-10 10:28:24 -0500
committerKen Moore <moorekou@gmail.com>2016-03-10 10:28:24 -0500
commita7e8db95a2a576b8afed2c21346747a350485090 (patch)
treea153eb939391ebf47e1f15608b86ef0786296c10 /desktop-utilities/lumina-terminal/TtyProcess.cpp
parentNow we can send input back to the TTY (diff)
downloadlumina-a7e8db95a2a576b8afed2c21346747a350485090.tar.gz
lumina-a7e8db95a2a576b8afed2c21346747a350485090.tar.bz2
lumina-a7e8db95a2a576b8afed2c21346747a350485090.zip
Finish cleaning up the TTY Process class, and get it setup for close notifications as well. Now the TTY Process thing is finished, just need to fix up the binary data display on the widget side of things.
Diffstat (limited to 'desktop-utilities/lumina-terminal/TtyProcess.cpp')
-rw-r--r--desktop-utilities/lumina-terminal/TtyProcess.cpp72
1 files changed, 55 insertions, 17 deletions
diff --git a/desktop-utilities/lumina-terminal/TtyProcess.cpp b/desktop-utilities/lumina-terminal/TtyProcess.cpp
index e0375410..b3c6aebc 100644
--- a/desktop-utilities/lumina-terminal/TtyProcess.cpp
+++ b/desktop-utilities/lumina-terminal/TtyProcess.cpp
@@ -1,24 +1,17 @@
#include "TtyProcess.h"
-//Standard C library functions for PTY access/setup
-#include <stdlib.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <signal.h>
-
-TTYProcess::TTYProcess(QObject *parent) : QFile(parent){
- childProc = 0;
+TTYProcess::TTYProcess(QObject *parent) : QObject(parent){
+ childProc = 0;
+ sn = 0;
+ ttyfd = 0;
}
TTYProcess::~TTYProcess(){
- kill(childProc, SIGKILL);
+ closeTTY(); //make sure everything is closed properly
}
// === PUBLIC ===
-bool TTYProcess::startTTY(int &retfd, QString prog, QStringList args){
+bool TTYProcess::startTTY(QString prog, QStringList args){
//Turn the program/arguments into C-compatible arrays
char cprog[prog.length()]; strcpy(cprog, prog.toLocal8Bit().data());
char *cargs[args.length()+2];
@@ -44,12 +37,28 @@ bool TTYProcess::startTTY(int &retfd, QString prog, QStringList args){
if(tmp<0){ return false; } //error
else{
childProc = tmp;
- this->setFileName( ptsname(FD) );
- retfd = FD;
+ //Load the file for close notifications
+ //TO-DO
+ //Watch the socket for activity
+ sn= new QSocketNotifier(FD, QSocketNotifier::Read);
+ sn->setEnabled(true);
+ connect(sn, SIGNAL(activated(int)), this, SLOT(checkStatus(int)) );
ttyfd = FD;
qDebug() << " - PTY:" << ptsname(FD);
- return this->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
- //return true;
+ return true;
+ }
+}
+
+void TTYProcess::closeTTY(){
+ int junk;
+ if(0==waitpid(childProc, &junk, WNOHANG)){
+ kill(childProc, SIGKILL);
+ }
+ if(ttyfd!=0 && sn!=0){
+ sn->setEnabled(false);
+ ::close(ttyfd);
+ ttyfd = 0;
+ emit processClosed();
}
}
@@ -58,6 +67,20 @@ void TTYProcess::writeTTY(QByteArray output){
qDebug() << "Wrote:" << written;
}
+QByteArray TTYProcess::readTTY(){
+ QByteArray BA;
+ if(sn==0){ return BA; } //not setup yet
+ char buffer[64];
+ ssize_t rtot = read(sn->socket(),&buffer,64);
+ buffer[rtot]='\0';
+ BA = QByteArray(buffer, rtot);
+ return BA;
+}
+
+bool TTYProcess::isOpen(){
+ return (ttyfd!=0);
+}
+
// === PRIVATE ===
pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
//Returns: -1 for errors, positive value (file descriptor) for the master side of the TTY to watch
@@ -101,3 +124,18 @@ pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
//MASTER thread (or error)
return PID;
}
+
+// === PRIVATE SLOTS ===
+void TTYProcess::checkStatus(int sock){
+ //This is run when the socket gets activated
+ if(sock!=ttyfd){
+
+ }
+ //Make sure the child PID is still active
+ int junk;
+ if(0!=waitpid(childProc, &junk, WNOHANG)){
+ this->closeTTY(); //clean up everything else
+ }else{
+ emit readyRead();
+ }
+}
bgstack15