mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 15:55:46 +00:00
Add GUI Support
This commit is contained in:
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#if defined(GEKKO)
|
||||
|
||||
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
|
||||
#elif !defined(_WIN32) && !defined(__ANDROID__) && !defined(__SWITCH__)
|
||||
#elif !defined(_WIN32) && !defined(__ANDROID__) && !defined(__SWITCH__) && !defined(__PS2__)
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Tesses::Framework::Streams {
|
||||
free(addresses);
|
||||
|
||||
|
||||
#elif defined(__ANDROID__) || defined(__SWITCH__)
|
||||
#elif defined(__ANDROID__) || defined(__SWITCH__) || defined(__PS2__)
|
||||
|
||||
#else
|
||||
struct ifaddrs *ifAddrStruct = NULL;
|
||||
@@ -181,7 +181,12 @@ namespace Tesses::Framework::Streams {
|
||||
{
|
||||
memset(addr,0,sizeof(struct sockaddr_storage));
|
||||
uint8_t ip[16];
|
||||
|
||||
#if defined(__PS2__)
|
||||
if(inet_aton(str.c_str(),ip) == 1)
|
||||
#else
|
||||
if(inet_pton(AF_INET,str.c_str(),ip)==1)
|
||||
#endif
|
||||
{
|
||||
struct sockaddr_in* inAddr = (struct sockaddr_in*)addr;
|
||||
inAddr->sin_family = AF_INET;
|
||||
@@ -521,25 +526,46 @@ namespace Tesses::Framework::Streams {
|
||||
{
|
||||
return this->success;
|
||||
}
|
||||
NetworkStream::NetworkStream(bool ipV6,bool datagram)
|
||||
NetworkStream::NetworkStream(SocketType type)
|
||||
{
|
||||
this->endOfStream=false;
|
||||
this->owns = true;
|
||||
this->success=false;
|
||||
if(ipV6)
|
||||
switch(type)
|
||||
{
|
||||
#if defined(AF_INET6)
|
||||
this->sock = NETWORK_SOCKET(AF_INET6, datagram ? SOCK_DGRAM : SOCK_STREAM, 0);
|
||||
if(this->sock >= 0) this->success=true;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(AF_INET)
|
||||
this->sock = NETWORK_SOCKET(AF_INET, datagram ? SOCK_DGRAM : SOCK_STREAM, 0);
|
||||
if(this->sock >= 0) this->success=true;
|
||||
case SocketType::ST_IPv4_TCP:
|
||||
#if defined(AF_INET)
|
||||
this->sock = NETWORK_SOCKET(AF_INET,SOCK_STREAM, 0);
|
||||
|
||||
#endif
|
||||
break;
|
||||
case SocketType::ST_IPv4_UDP:
|
||||
#if defined(AF_INET)
|
||||
this->sock = NETWORK_SOCKET(AF_INET,SOCK_DGRAM, 0);
|
||||
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SocketType::ST_IPv6_TCP:
|
||||
#if defined(AF_INET6)
|
||||
this->sock = NETWORK_SOCKET(AF_INET6,SOCK_STREAM, 0);
|
||||
|
||||
#endif
|
||||
break;
|
||||
case SocketType::ST_IPv6_UDP:
|
||||
#if defined(AF_INET6)
|
||||
this->sock = NETWORK_SOCKET(AF_INET6,SOCK_DGRAM, 0);
|
||||
|
||||
#endif
|
||||
break;
|
||||
case SocketType::ST_UNIX:
|
||||
#if defined(AF_UNIX)
|
||||
this->sock = NETWORK_SOCKET(AF_UNIX,SOCK_DGRAM, 0);
|
||||
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if(this->sock >= 0) this->success=true;
|
||||
}
|
||||
NetworkStream::NetworkStream(std::string ipOrFqdn, uint16_t port, bool datagram, bool broadcast, bool supportIPv6)
|
||||
{
|
||||
@@ -672,7 +698,7 @@ namespace Tesses::Framework::Streams {
|
||||
ip = StringifyIP((struct sockaddr*)&storage);
|
||||
port = getPort((struct sockaddr*)&storage);
|
||||
|
||||
return new NetworkStream(s,true);
|
||||
return new NetworkStream((int32_t)s,(bool)true);
|
||||
}
|
||||
size_t NetworkStream::Read(uint8_t* buff, size_t sz)
|
||||
{
|
||||
@@ -797,7 +823,7 @@ bool NetworkStream::CanWrite() {
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkStream::NetworkStream(bool ipV6,bool datagram)
|
||||
NetworkStream::NetworkStream(SocketType type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
132
src/Streams/PtyStream.cpp
Normal file
132
src/Streams/PtyStream.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "TessesFramework/Streams/PtyStream.hpp"
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
#include <pty.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#endif
|
||||
namespace Tesses::Framework::Streams {
|
||||
PtyStream::PtyStream(WindowSize windowSize,std::string filename, std::vector<std::string> args, std::vector<std::string> env)
|
||||
{
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
this->wS = windowSize;
|
||||
this->eos=false;
|
||||
winsize sz;
|
||||
sz.ws_col =(unsigned short)windowSize.Columns;
|
||||
sz.ws_row = (unsigned short)windowSize.Rows;
|
||||
sz.ws_xpixel = (unsigned short)windowSize.Width;
|
||||
sz.ws_ypixel = (unsigned short)windowSize.Height;
|
||||
termios ios;
|
||||
cfmakeraw(&ios);
|
||||
|
||||
pid= forkpty(&this->socket,NULL,&ios,&sz);
|
||||
if(pid == -1)
|
||||
{
|
||||
this->eos=true;
|
||||
}
|
||||
if(pid == 0)
|
||||
{
|
||||
char** argv = new char*[args.size()+1];
|
||||
argv[args.size()]=NULL;
|
||||
char** envp = new char*[env.size()+1];
|
||||
envp[env.size()]=NULL;
|
||||
|
||||
for(size_t i = 0; i < args.size();i++)
|
||||
{
|
||||
argv[i] = (char*)args[i].c_str();
|
||||
}
|
||||
for(size_t i = 0; i < env.size();i++)
|
||||
{
|
||||
envp[i] = (char*)env[i].c_str();
|
||||
}
|
||||
|
||||
if(execve(filename.c_str(),argv,envp) == -1)
|
||||
{
|
||||
perror("execve returned -1");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
int flags = fcntl(this->socket, F_GETFL, 0);
|
||||
if(flags == -1) {
|
||||
perror("fcntl F_GETFL");
|
||||
this->eos=true;
|
||||
return;
|
||||
}
|
||||
flags |= O_NONBLOCK;
|
||||
|
||||
flags=fcntl(this->socket,F_SETFL,flags);
|
||||
if(flags == -1) {
|
||||
perror("fcntl F_SETFL");
|
||||
|
||||
this->eos=true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
bool PtyStream::EndOfStream()
|
||||
{
|
||||
return this->eos;
|
||||
}
|
||||
bool PtyStream::CanRead()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool PtyStream::CanWrite()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
size_t PtyStream::Read(uint8_t* buff, size_t sz)
|
||||
{
|
||||
if(this->eos) return 0;
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
auto res = read(this->socket, buff,sz);
|
||||
|
||||
if(res == -1)
|
||||
{
|
||||
if(errno != EAGAIN && errno != EWOULDBLOCK)
|
||||
this->eos=true;
|
||||
return 0;
|
||||
}
|
||||
return (size_t)res;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
size_t PtyStream::Write(const uint8_t* buff, size_t sz)
|
||||
{
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
auto res = write(this->socket, buff,sz);
|
||||
return res;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
WindowSize PtyStream::GetWindowSize()
|
||||
{
|
||||
return this->wS;
|
||||
}
|
||||
void PtyStream::Resize(WindowSize windowSize)
|
||||
{
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
this->wS = windowSize;
|
||||
winsize sz;
|
||||
sz.ws_col =(unsigned short)windowSize.Columns;
|
||||
sz.ws_row = (unsigned short)windowSize.Rows;
|
||||
sz.ws_xpixel = (unsigned short)windowSize.Width;
|
||||
sz.ws_ypixel = (unsigned short)windowSize.Height;
|
||||
|
||||
ioctl(this->socket,TIOCSWINSZ,&sz);
|
||||
#endif
|
||||
}
|
||||
PtyStream::~PtyStream()
|
||||
{
|
||||
this->eos=true;
|
||||
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32)
|
||||
close(this->socket);
|
||||
|
||||
kill((pid_t)this->pid,SIGHUP);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user