Changed the breakpoint system to use the afore-mentioned system.
[aesalon.git] / src / gui / Program.cpp
blobe994e55b47e53890f2ebf1f0a080a8c2f0345405
1 #include <QSettings>
2 #include <unistd.h>
4 #include "Program.h"
5 #include "MainWindow.h"
6 #include "misc/String.h"
7 #include "platform/PlatformException.h"
9 namespace Aesalon {
10 namespace GUI {
12 ProgramSocketThread::ProgramSocketThread(Misc::SmartPointer<Platform::TCPSocket> socket,
13 Misc::SmartPointer<Platform::Memory> memory) : socket(socket), memory(memory) {
16 void ProgramSocketThread::run() {
17 while(socket->is_valid()) {
18 std::cout << "ProgramSocketThread: checking data . . ." << std::endl;
19 std::cout << "Received \"" << socket->get_data() << "\"" << std::endl;
20 this->msleep(500);
22 this->exit(0);
25 Program::Program() {
26 QSettings settings;
28 arguments = settings.value("Program/arguments").toString().toStdString();
29 executable = settings.value("Program/executable").toString().toStdString();
30 port = settings.value("Program/port").toInt();
31 in_xterm = settings.value("Program/in-xterm").toBool();
33 arguments = Misc::StreamAsString() << settings.value("Core/aesalon-path").toString().toStdString()
34 << " --use-port " << port << " " << executable << " " << arguments;
36 Platform::ArgumentList argument_list;
38 argument_list.from_string(arguments + " ");
40 /*bi_pipe = new Platform::BidirectionalPipe(argument_list, true);*/
41 pid_t pid = fork();
42 if(pid == 0) {
43 std::cout << "in child, execv'ing . . ." << std::endl;
44 std::cout << "\targument_list[0]: \"" << argument_list.get_argument(0) << "\"\n";
45 std::cout << "\targument_list[1]: \"" << argument_list.get_argument(1) << "\"\n";
46 std::cout << "\targument_list[2]: \"" << argument_list.get_argument(2) << "\"\n";
47 std::cout << "\targument_list[3]: \"" << argument_list.get_argument(3) << "\"\n";
48 std::cout << "\targument_list[4]: \"" << argument_list.get_argument(4) << "\"\n";
49 execv(argument_list.get_argument(0).c_str(), argument_list.get_as_argv());
50 throw Misc::Exception("Couldn't execute file . . .");
53 memory = new Platform::Memory();
55 socket = NULL;
56 while(!socket.is_valid()) {
57 try {
58 socket = new Platform::TCPSocket("127.0.0.1", port);
60 catch(Platform::PlatformException pe) {
61 socket = NULL;
65 socket_thread = new ProgramSocketThread(socket, memory);
66 socket_thread->start(QThread::HighPriority);
69 } // namespace GUI
70 } // namespace Aesalon