************************************************************/
-
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QTextEdit>
#include <qcursor.h>
#include <QtCore/QSocketNotifier>
#include <QtGui/QCloseEvent>
-#include <qdir.h>
+#include <QtCore/QDir>
+#include <QtCore/QProcess>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <libconfig.h>
+#include <X11/Xlib.h>
#include "kernel.h"
-
+#include "ui/KernelWindow.h"
+#include "ConnectDialog.h"
+#include "KillDialog.h"
+#include "LockDialog.h"
+#include "OptionsDialog.h"
+#include "MessageDialog.h"
+
+#include "vlp/config.h"
+#include "vlp/QtConfigurationFinder.h"
+#include "vlp/exception/ConfigFileNotFound.h"
+
+#include <sys/prctl.h>
/* File resides in top directory (where are Makefiles)*/
#include "../../config.h"
-char CharLine[25] = "________________________";
-char myargs[5][255];
+namespace loglan {
+namespace vlp {
-//QApplication *app;
+char CharLine[25] = "________________________";
/**
* Event invoked on program close.
e->ignore();
if (!LOCKED) {
- QuitProc();
+ on_actionQuit_triggered();
}
}
{
LOCKED = locked;
- quitAction->setDisabled(locked);
- programExecuteAction->setDisabled(locked);
- programKillAction->setDisabled(locked);
- machineMessageAction->setDisabled(locked);
- machineConnectAction->setDisabled(locked);
- machineDisconnectAction->setDisabled(locked);
- machineInfoAction->setDisabled(locked);
+ actionQuit->setDisabled(locked);
+
+ actionExecute->setDisabled(locked);
+ actionKill->setDisabled(locked);
+ actionMessage->setDisabled(locked);
+ actionConnect->setDisabled(locked);
+ actionDisconnect->setDisabled(locked);
+ actionInfo->setDisabled(locked);
+
/* Enable only menu entry for unlocking */
- toolsEditorAction->setDisabled(locked);
- toolsOptionsAction->setDisabled(locked);
- toolsLockAction->setDisabled(locked);
- toolsUnlockAction->setEnabled(locked);
+ actionEditor->setDisabled(locked);
+ actionOptions->setDisabled(locked);
+ actionLock_console->setDisabled(locked);
+ actionUnlock_console->setDisabled(!locked);
}
/**
* Kernel program constructor.
* Prepares everything to work.
*/
-QKernel::QKernel()
+QKernel::QKernel(int argc, char **argv)
{
- QDir q(REMOTE_PATH);
- char ss[255];
+ setupUi(this);
+
+ int i;
+ for(i = 0; (i < 5) && (i < argc-1); i++) {
+ strcpy(myargs[i], "");
+ if (i < argc) {
+ strcpy(myargs[i], argv[i+1]);
+ }
+ }
+
+ loglan::vlp::QtConfigurationFinder configFinder;
+ configFinder.initSearchDirs();
+
+ QDir q(getRemoteDir());
if (!q.exists()) {
- sprintf(ss, "mkdir %s", REMOTE_PATH);
- system(ss);
- }
+ q.mkpath(getRemoteDir());
+ }
- info_messages = TRUE;
+ info_messages = actionInfo_messages->isChecked();
wait_for_info = FALSE;
setWindowTitle(PACKAGE_NAME);
- QMenu * programMenu = NULL;
- programMenu = menuBar()->addMenu("&Program");
- programExecuteAction = programMenu->addAction("Execute", this, SLOT(Run_Prog()));
- programKillAction = programMenu->addAction("Kill", this, SLOT(KillInterpreter()));
-
- machineMenu = menuBar()->addMenu("&Machine");
- machineMessageAction = machineMenu->addAction("Message", this, SLOT(MessageToNode()));
- machineMenu->addSeparator();
- machineConnectAction = machineMenu->addAction("Connect", this, SLOT(Connect()));
- machineDisconnectAction = machineMenu->addAction("Disconnect", this, SLOT(Disconnect()));
- machineInfoAction = machineMenu->addAction("Info", this, SLOT(Info()));
-
- toolsMenu = menuBar()->addMenu("&Tools");
- toolsEditorAction = toolsMenu->addAction("Editor", this, SLOT(Edit()));
- toolsMenu->addAction("Help", this, SLOT(Help()));
- toolsMenu->addSeparator();
- toolsOptionsAction = toolsMenu->addAction("Options", this, SLOT(SetOptions()));
- toolsInfoAction = toolsMenu->addAction("Info messages", this, SLOT(SetMessages()));
- toolsInfoAction->setCheckable(TRUE);
- toolsInfoAction->setChecked(TRUE);
- toolsMenu->addSeparator();
- toolsLockAction = toolsMenu->addAction("Lock console", this, SLOT(LockConsole()));
- toolsUnlockAction = toolsMenu->addAction("Unlock console", this,
- SLOT(UnlockConsole()));
- toolsUnlockAction->setDisabled(TRUE);
LOCKED = FALSE;
- quitAction = menuBar()->addAction("&Quit", this, SLOT(QuitProc()));
-
- desktop = new QTextEdit(this);
- desktop->setReadOnly(TRUE);
- QVBoxLayout * layout = new QVBoxLayout();
- layout->setContentsMargins (3, 0, 3, 0);
- layout->addWidget(desktop);
- QWidget *window = new QWidget();
- window->setLayout(layout);
- setCentralWidget(window);
-
- resize(400, 200);
Tasks = 0;
freeINTid = 1;
ActiveConnections = 0;
strcpy(LockPasswd, "");
- LoadConfig("vlp.cfg");
+
+ loadConfig(configFinder.findConfig().c_str());
+
RunNetModule();
Net_Notify = new QSocketNotifier(net_sock, QSocketNotifier::Read, this);
connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
+
+ WriteMessage("\n " PACKAGE_STRING ": READY \n");
}
-/**
- * Event invoked on resizing kernel application window.
- * @copydoc QWidget::resizeEvent(QResizeEvent*)
- */
-void QKernel::resizeEvent(QResizeEvent *ev)
+QString QKernel::getConfigFilePath()
{
-// QFrame::resizeEvent(ev);
-// if (desktop)
-// desktop->setGeometry(0, bar->height(), width(),
-// height() - bar->height());
+ return homeDir.absoluteFilePath("vlp.cfg");
}
-/**
- * Displays window with information about not implemented functionality.
- */
-void QKernel::n_impl()
+const char * QKernel::getHomeDir()
+{
+ return homeDir.absolutePath().toStdString().c_str();
+}
+
+const char * QKernel::getRemoteDir()
{
- QMessageBox::information(this, "Function info", "This function is not "
- "implemented yet...", "Ok");
+ return homeDir.absoluteFilePath(REMOTE_PATH).toStdString().c_str();
}
+const char * QKernel::getNetModuleSocket()
+{
+ return homeDir.absoluteFilePath(NPATH).toStdString().c_str();
+}
+
+const char * QKernel::getGraphModuleSocket()
+{
+ return homeDir.absoluteFilePath(GPATH).toStdString().c_str();
+}
+
+void QKernel::loadConfig(const QString & fname)
+{
+ loadConfig(fname.toStdString().c_str());
+}
/**
* Loads configuration from the given file.
* @param fname Filename of the configuration file.
*/
-void QKernel::LoadConfig(char * fname)
+void QKernel::loadConfig(const char * fname)
{
- config_t cfg;
- config_setting_t *setting;
- const char *str;
-
- /* Hack for checking if file exists without using external libs.*/
- FILE * file = fopen(fname, "rt");
- if (!file) {
- fprintf(stderr, "Error: Cannot load configuration file %s!\n",
- fname);
- exit(3);
- }
- /* File exists, so file has been locked. Release it. */
-
- config_init(&cfg);
-
- /* Read the file. If there is an error, report it and exit. */
- if (!config_read(&cfg, file)) {
- fprintf(stderr, "%s! In file %s, line %d\n",
- config_error_text(&cfg),
- config_error_file(&cfg),
- config_error_line(&cfg));
- config_destroy(&cfg);
- fclose(file);
- exit(3);
- }
+ loglan::vlp::Config config;
+ if(config.load(fname)) {
+ NodeNumber = config.getNodeNumber();
+ ConType = config.getConnectionType();
- setting = config_lookup(&cfg, "node_number");
- if (setting) {
- NodeNumber = config_setting_get_int(setting);
- } else {
- fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
- "Warning", fname, "node_number");
- config_destroy(&cfg);
- fclose(file);
- exit(3);
- }
- setting = config_lookup(&cfg, "type");
- if (setting) {
- /* same as strcmp(..) == 0 */
- if (!strcmp(config_setting_get_string(setting), "explicit")) {
- ConType = 1;
- } else {
- ConType = 2;
+ std::vector<std::string> hosts = config.getHosts();
+ for (unsigned int i = 0; i < hosts.size(); i++) {
+ ConnectList.append(new ConnectEntry(hosts[i].c_str()));
}
- } else {
- fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
- "Warning", fname, "type");
- }
- setting = config_lookup(&cfg, "host");
- if (setting) {
- switch(config_setting_type(setting)) {
- /* TODO: Deprecated. Made for back compatibility. */
- case CONFIG_TYPE_STRING:
- ConnectList.append(new ConnectEntry((char*)
- config_setting_get_string(setting)));
- break;
- case CONFIG_TYPE_ARRAY: {
- int size = config_setting_length(setting);
- for (int i = 0; i < size; i++) {
- ConnectList.append(new ConnectEntry((char*)
- config_setting_get_string_elem(setting,
- i)));
- }
- break;
- }
- default:
- fprintf(stderr, "%s! In file %s, bad entry type for %s."
- " Will not be read.\n",
- "Error", fname, "host");
- }
- } else {
- fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
- "Warning", fname, "host");
- }
+ strncpy(progdir, config.getProgramDir(), 256);
- setting = config_lookup(&cfg, "progdir");
- if (setting){
- strncpy(progdir, config_setting_get_string(setting), 256);
- } else {
- fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
- "Warning", fname, "progdir");
- }
-
- setting = config_lookup(&cfg, "homedir");
- if (setting) {
- strncpy(HomeDir, config_setting_get_string(setting), 255);
- } else {
- fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
- "Warning", fname, "homedir");
+ homeDir = QDir(QCoreApplication::applicationDirPath());
}
-
- config_destroy(&cfg);
- fclose(file);
}
/**
* Executes program.
* Additional window id displayed to set which code to execute.
*/
-void QKernel::Run_Prog()
+void QKernel::on_actionExecute_triggered()
{
- int i;
QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
if (!s.isNull()) {
- i = s.indexOf(".log");
+ int i = s.indexOf(".log");
if (i > 0)
s.remove(i, 4);
+ // @TODO: if no interpreter is running will result in killing app
RunIntModule((char*)s.toAscii().data(), 0);
}
}
/**
* Invokes editor program
*/
-void QKernel::Edit()
+void QKernel::on_actionEditor_triggered()
{
- char cmd[255];
- sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir,
- myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
- system(cmd);
+ QString program = getHomeDir();
+ program += "/modules/logedit";
+
+ fprintf(stderr, "Run EDIT Module: %s, %s\n", program.toStdString().c_str(), getHomeDir());
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (execl(program.toStdString().c_str(),
+ "logedit",
+ getHomeDir(),
+ myargs[0],
+ myargs[1],
+ myargs[2],
+ myargs[3],
+ myargs[4],
+ NULL
+ ) == -1) {
+ WriteMessage("Executing logedit failed!");
+ }
+ }
+ else if (pid < 0) {
+ WriteMessage("fork(logedit) failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ exit(3);
+ }
}
/**
* Invokes help program
*/
-void QKernel::Help()
+void QKernel::on_actionHelp_triggered()
{
- char cmd[255];
- sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir,
- HomeDir, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
- system(cmd);
+ QString program = getHomeDir();
+ program += "/modules/loghelp";
+
+ QString docDir = getHomeDir();
+ docDir += "/doc";
+
+ fprintf(stderr, "Run HELP Module: %s, %s\n", program.toStdString().c_str(), docDir.toStdString().c_str());
+
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (execl(program.toStdString().c_str(),
+ "loghelp",
+ docDir.toStdString().c_str(),
+ myargs[0],
+ myargs[1],
+ myargs[2],
+ myargs[3],
+ myargs[4],
+ NULL
+ ) == -1) {
+
+ WriteMessage("Executing loghelp failed!");
+ }
+ }
+ else if (pid < 0) {
+ WriteMessage("fork(loghelp) failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ exit(3);
+ }
}
/**
*/
void QKernel::RunGraphModule(char *sk)
{
- char cmd[255];
-
- sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s &", HomeDir,
- sk, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
-
- if (system(cmd) != 0)
- WriteMessage("Cannot connect GRAPH resources");
+ QString program = getHomeDir();
+ program += "/modules/loggraph";
+
+ fprintf(stderr, "Run GRAPH Module: %s, %s\n", program.toStdString().c_str(), sk);
+
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (execl(program.toStdString().c_str(),
+ "loggraph",
+ sk,
+ myargs[0],
+ myargs[1],
+ myargs[2],
+ myargs[3],
+ myargs[4],
+ NULL
+ ) == -1) {
+
+ WriteMessage("Executing loggraph failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ }
+ }
+ else if (pid < 0) {
+ WriteMessage("fork(loggraph) failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ exit(3);
+ }
}
/**
*/
void QKernel::RunNetModule()
{
+
struct sockaddr_un svr;
- int len, on;
+ int len;
+ int on;
int sock;
- char cmd[255];
- sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s &", HomeDir,
- NPATH, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
+
+ QString program = getHomeDir();
+ program += "/modules/lognet";
+
+ fprintf(stderr, "Run NET Module: %s, %s %s\n", program.toStdString().c_str(), getNetModuleSocket(), getConfigFilePath().toStdString().c_str());
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (execl(program.toStdString().c_str(),
+ "lognet",
+ getNetModuleSocket(),
+ getConfigFilePath().toStdString().c_str(),
+ myargs[0],
+ myargs[1],
+ myargs[2],
+ myargs[3],
+ myargs[4],
+ NULL
+ ) == -1) {
+
+ WriteMessage("Executing lognet failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ }
+ }
+ else if (pid < 0) {
+ WriteMessage("fork(lognet) failed!");
+ WriteMessage("Exiting...");
+ sleep(2);
+ on_actionQuit_triggered();
+ exit(3);
+ }
/* -------- socket for NET module -------- */
- unlink(NPATH);
+ unlink(getNetModuleSocket());
sock = socket(AF_UNIX, SOCK_STREAM, 0);
bzero(&svr, sizeof(svr));
svr.sun_family = AF_UNIX;
- strcpy(svr.sun_path, NPATH);
+ strcpy(svr.sun_path, getNetModuleSocket());
len = strlen(svr.sun_path) + sizeof(svr.sun_family);
- bind(sock, (struct sockaddr*)&svr, len);
+ bind(sock, (struct sockaddr*)&svr, len);
listen(sock, 5);
- if (system(cmd) == 0) {
- net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
- // close(sock);
- if (net_sock != 0) {
- WriteMessage("NETWORK successfully connected");
- fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock,
- F_GETFL, 0));
- on=1;
- setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY,
- (char*)&on, sizeof(on));
- } else {
- WriteMessage("Cannot connect NETWORK resources");
- WriteMessage("Exiting...");
- sleep(2);
- QuitProc();
- }
- /* system OK */
+ net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
+ // close(sock);
+ if (net_sock != 0) {
+ WriteMessage("NETWORK successfully connected");
+ fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock, F_GETFL, 0));
+ on = 1;
+ setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
} else {
WriteMessage("Cannot connect NETWORK resources");
WriteMessage("Exiting...");
sleep(2);
- QuitProc();
+ on_actionQuit_triggered();
}
}
* Connects to the specified address
* Additional window is displayed to connect to the specified address
*/
-void QKernel::Connect()
+void QKernel::on_actionConnect_triggered()
{
- QDialog d(this, Qt::Dialog);
- QLabel lab("IP Address:", &d);
- QLineEdit ed("", &d);
- QPushButton ob("", &d);
- QPushButton cb("", &d);
MESSAGE m;
- ob.setGeometry(30, 60, 80, 30);
- ob.setText("Ok");
- ob.setDefault(TRUE);
- lab.setGeometry(10, 10, 60, 30);
- lab.setText("Address");
- ed.setGeometry(70, 10, 140, 30);
- cb.setGeometry(130, 60, 80, 30);
- cb.setText("Cancel");
- d.resize(240, 100);
-
- connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
- connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
- if (d.exec()) {
+ dialog::ConnectDialog dialog(this);
+
+ if (dialog.exec()) {
m.msg_type = MSG_NET;
m.param.pword[0] = NET_CONNECT_TO;
- strcpy(m.param.pstr, ed.text().toAscii().data());
- write(net_sock, &m, sizeof(MESSAGE));
+ strcpy(m.param.pstr, dialog.getAddress().toStdString().c_str());
+ write(net_sock, &m, sizeof(MESSAGE));
}
}
/**
* Disconnects from virtual machine
*/
-void QKernel::Disconnect()
+void QKernel::on_actionDisconnect_triggered()
{
MESSAGE msg;
/**
* Quits process. Closes VLP. Shows additional window to confirm exit.
*/
-void QKernel::QuitProc()
+void QKernel::on_actionQuit_triggered()
{
MESSAGE msg;
- QMessageBox::StandardButton response;
- response = QMessageBox::question(this, "Close VLP", "Terminate VLP ?",
- QMessageBox::Ok | QMessageBox::Cancel);
+ QMessageBox::StandardButton response = QMessageBox::question(this,
+ "Close VLP",
+ "Terminate VLP ?",
+ QMessageBox::Ok | QMessageBox::Cancel
+ );
if (response == QMessageBox::Cancel) {
QApplication::instance()->quit();
}
-/**
- * Adds IP address to the configuration.
- * Additional window is displayed to add address to the list
- */
-void QKernel::AddAddress()
-{
- QDialog d(this, Qt::Dialog);
- QLabel lab("IP Address:", &d);
- QLineEdit ed("", &d);
- QPushButton ob("", &d);
- QPushButton cb("", &d);
-
- if (connections) {
- ob.setGeometry(30, 60, 80, 30);
- ob.setText("Ok");
- ob.setDefault(TRUE);
- lab.setGeometry(10, 10, 60, 30);
- lab.setText("Address");
- ed.setGeometry(70, 10, 140, 30);
- cb.setGeometry(130, 60, 80, 30);
- cb.setText("Cancel");
- d.resize(240, 100);
- connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
- connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
- if (d.exec())
- if (strcmp(ed.text().toAscii().data(), "") != 0) {
- connections->addItem(ed.text());
- }
- }
-}
-
-/**
- * Deletes current address from available connections.
- */
-void QKernel::DelAddress()
-{
- if (connections) {
- if (connections->currentRow() != -1) {
- /* TODO: Checki if this work correctly after porting */
- connections->removeItemWidget(connections->currentItem());
- }
- }
-}
-
/**
* Sends message to node.
* Additional window is displayed to set Node Number of node where send message,
* and textfield to enter message.
*/
-void QKernel::MessageToNode()
+void QKernel::on_actionMessage_triggered()
{
- QDialog *dlg;
- QLineEdit *nodenr;
+ dialog::MessageDialog dialog(this);
MESSAGE m;
- dlg = new QDialog(this, Qt::Dialog);
- dlg->setWindowTitle("Send message to node");
-
- nodenr = new QLineEdit("number", dlg);
- nodenr->setGeometry(90, 10, 50, 30);
- nodenr->setText("");
-
- QLabel *tmpQLabel;
- tmpQLabel = new QLabel("Node number:", dlg);
- tmpQLabel->setGeometry(10, 10, 77, 30);
-
- tmpQLabel = new QLabel("Message:", dlg);
- tmpQLabel->setGeometry(10, 50, 70, 30);
-
- QLineEdit *msg;
- msg = new QLineEdit("", dlg);
- msg->setGeometry(80, 60, 330, 30);
-
- QPushButton *ob;
- ob = new QPushButton("Send", dlg);
- ob->setGeometry(230, 10, 80, 30);
- ob->setDefault(TRUE);
-
- QPushButton *cb;
- cb = new QPushButton("Cancel", dlg);
- cb->setGeometry(330, 10, 80, 30);
- dlg->resize(430, 110);
- connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
- connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
-
- if (dlg->exec()) {
+ if (dialog.exec()) {
m.msg_type = MSG_NET;
m.param.pword[0] = NET_PROPAGATE;
m.param.pword[1] = MSG_VLP;
m.param.pword[2] = NodeNumber;
- m.param.pword[4] = atoi(nodenr->text().toAscii().data());
+ m.param.pword[4] = dialog.getNodeNumber();
m.param.pword[6] = VLP_WRITE;
- strcpy(m.param.pstr, msg->text().toAscii().data());
+ strcpy(m.param.pstr, dialog.getMessage().toStdString().c_str());
write(net_sock, &m, sizeof(MESSAGE));
}
}
* Additional window is displayed to get ID of interpreter which should be
* killed.
*/
-void QKernel::KillInterpreter()
+void QKernel::on_actionKill_triggered()
{
- QDialog *dlg;
- QLineEdit *nodenr;
- MESSAGE m;
- InterpEntry *pom;
-
- dlg = new QDialog(this, Qt::Dialog);
- dlg->setWindowTitle("Kill interpreter");
-
- nodenr = new QLineEdit("", dlg);
- nodenr->setGeometry(90, 10, 50, 30);
+ dialog::KillInterpreterDialog dialog(this);
- QLabel * tmpQLabel = new QLabel("Interp. ID:", dlg);
- tmpQLabel->setGeometry(10, 10, 77, 30);
-
- QPushButton * ob = new QPushButton("Kill", dlg);
- ob->setGeometry( 160, 10, 80, 30);
- ob->setDefault(TRUE);
-
- QPushButton * cb = new QPushButton("Cancel", dlg);
- cb->setGeometry(260, 10, 80, 30);
- dlg->resize(360, 50);
-
- connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
- connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
-
- if (dlg->exec()) {
+ if (dialog.exec()) {
+ MESSAGE m;
m.msg_type = MSG_INT;
m.param.pword[0] = INT_KILL;
- pom = findINTbyID(atoi(nodenr->text().toAscii().data()));
- if (pom != NULL) {
- if (!(pom->remote))
- write(pom->sock, &m, sizeof(MESSAGE));
- else
- WriteMessage("This is a remote instance of "
- "a program!");
+
+ InterpEntry *interpreter;
+ interpreter = findINTbyID(dialog.getInterpreterId());
+
+ if (interpreter != NULL) {
+ if (!(interpreter->remote)) {
+ write(interpreter->sock, &m, sizeof(MESSAGE));
+ }
+ else {
+ WriteMessage("This is a remote instance of a program!");
+ }
}
else {
WriteMessage("Interpreter not found");
/**
* Sends message to the net module.
+ *
+ * \todo method needs to be refactored
*/
void QKernel::NetMessage()
{
/* TODO: It has to be rewritten */
MESSAGE msg;
int cnt;
- char ss[255];
InterpEntry *pom;
cnt = read(net_sock, &msg, sizeof(MESSAGE));
if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
+ char ss[255];
+
switch(msg.param.pword[0]) {
case NET_CSWRITELN:
WriteMessage(msg.param.pstr);
case VLP_WRITE:
QApplication::beep();
WriteMessage(CharLine);
- WriteMessage(
- "### Incoming Messsage ###");
- sprintf(ss, "Mesg from Node %d: %s",
- msg.param.pword[2],
- msg.param.pstr);
+ WriteMessage("### Incoming Messsage ###");
+ sprintf(ss,
+ "Mesg from Node %d: %s",
+ msg.param.pword[2],
+ msg.param.pstr
+ );
WriteMessage(ss);
WriteMessage(CharLine);
break;
case VLP_REMOTE_INSTANCE:
- sprintf(ss, "%s/%s", REMOTE_PATH,
- msg.param.pstr);
+ sprintf(ss, "%s/%s", getRemoteDir(), msg.param.pstr);
if (info_messages) {
WriteMessage("Running program:");
cnt = poms1.indexOf('=');
if (cnt != -1) {
poms2 = poms1.left(cnt);
- poms1 = poms1.right(
- poms1.length() -
- cnt - 1);
- sprintf(ss, "Node: %s Addr: %s", poms2.data(), poms1.data());
+ poms1 = poms1.right(poms1.length() - cnt - 1);
+ sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
WriteMessage(ss);
}
}
switch (msg.msg_type) {
case MSG_GRAPH:
if (msg.param.pword[0] == GRAPH_ALLOCATE) {
+ fprintf(stderr, "Running graph module with arg: %s\n", msg.param.pstr);
RunGraphModule(msg.param.pstr);
}
break;
case MSG_INT:
switch(msg.param.pword[0]) {
case INT_EXITING:
- char ss[255];
-
MESSAGE m;
m.msg_type = MSG_VLP;
m.param.pword[0] = VLP_INTERPRETER_DOWN;
delete e;
if (info_messages) {
+ char ss[255];
sprintf(ss, "%s : End of program "
"execution", msg.param.pstr);
WriteMessage(ss);
* Writes message to kernel logger.
* @parame msg String with message to log
*/
-void QKernel::WriteMessage(char *msg)
+void QKernel::WriteMessage(const char *msg)
{
int x;
- int y;
+// int y;
x = desktop->textCursor().blockNumber();
- y = desktop->textCursor().columnNumber();
+// y = desktop->textCursor().columnNumber();
if (x > 100) {
desktop->clear();
* Adds checkbox to menu item. If it is checked additional info messages are
* shown.
*/
-void QKernel::SetMessages()
+void QKernel::on_actionInfo_messages_triggered()
{
if (toolsMenu != NULL) {
- toolsInfoAction->setChecked(!toolsInfoAction->isChecked());
-// toolsInfoAction->toggle();
- info_messages = toolsInfoAction->isChecked();
- fprintf(stderr, "Info is checked? %s\n", toolsInfoAction->isChecked() ? "yes" : "no");
+ info_messages = actionInfo_messages->isChecked();
+ actionInfo_messages->setChecked(info_messages);
}
-// menuBar()->repaint();
}
/**
* Additional window is displayed to set kernel options which are saved in
* vlp.cfg file in kernel executable directory.
*/
-void QKernel::SetOptions()
+void QKernel::on_actionOptions_triggered()
{
- QDialog dlg(this, Qt::Dialog);
- dlg.setWindowTitle("Options");
- ConnectEntry *e;
- unsigned int i;
-
- QLineEdit* progs;
- progs = new QLineEdit(progdir, &dlg);
- progs->setGeometry(150, 20, 180, 30);
-
- QLabel* tmpQLabel;
- tmpQLabel = new QLabel("Programs directory", &dlg);
- tmpQLabel->setGeometry(30, 20, 120, 30);
-
- QFrame* tmpQFrame;
- tmpQFrame = new QFrame(&dlg);
- tmpQFrame->setGeometry(10, 60, 380, 30);
- tmpQFrame->setFrameStyle(52);
-
- tmpQLabel = new QLabel("Virtual Processor properties (activated after "
- "restarting VLP):", &dlg);
- tmpQLabel->setGeometry(10, 80, 340, 30);
-
- QLineEdit *nn;
- char nns[256];
- sprintf(nns, "%d", NodeNumber);
- nn = new QLineEdit(nns, &dlg);
- nn->setGeometry(110, 110, 40, 30);
-
- tmpQLabel = new QLabel("Node number:", &dlg);
- tmpQLabel->setGeometry(20, 110, 90, 30);
+ dialog::OptionsDialog optionsDialog(getConfigFilePath(), this);
+ if (optionsDialog.exec()) {
+ optionsDialog.saveConfig(getConfigFilePath());
- QRadioButton *exp, *reg;
- exp = new QRadioButton("Explicit", &dlg);
- exp->setGeometry(30, 170, 100, 30);
- exp->setChecked(TRUE);
-
- reg = new QRadioButton("Registration", &dlg);
- reg->setGeometry(30, 200, 100, 30);
- reg->setEnabled(FALSE);
-
- connections = new QListWidget(&dlg);
- connections->setGeometry(170, 140, 130, 100);
-
- for (int i = 0; i < ConnectList.size(); i++) {
- e = ConnectList.at(i);
- connections->addItem(e->addr);
- }
-
- tmpQLabel = new QLabel("Connection list:", &dlg);
- tmpQLabel->setGeometry(170, 110, 100, 30);
-
- QPushButton *addbtn;
- QPushButton *delbtn;
- QPushButton *okbtn;
- QPushButton *cancelbtn;
- addbtn = new QPushButton("Add", &dlg);
- addbtn->setGeometry(310, 150, 60, 30);
- connect(addbtn, SIGNAL(clicked()), this, SLOT(AddAddress()));
-
- delbtn = new QPushButton("Del", &dlg);
- delbtn->setGeometry(310, 200, 60, 30);
- connect(delbtn, SIGNAL(clicked()), this, SLOT(DelAddress()));
-
- okbtn = new QPushButton("Ok", &dlg);
- okbtn->setGeometry(80, 260, 100, 30);
- okbtn->setDefault(TRUE);
- connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- cancelbtn = new QPushButton("Cancel", &dlg);
- cancelbtn->setGeometry(210, 260, 100, 30);
- connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- QGroupBox* group;
- group = new QGroupBox("Connection type", &dlg);
- group->setGeometry(20, 150, 120, 90);
- group->setAlignment(Qt::AlignLeft);
- group->lower();
-
- QVBoxLayout *vbox = new QVBoxLayout();
- vbox->addWidget(exp);
- vbox->addWidget(reg);
- vbox->addStretch(1);
- group->setLayout(vbox);
-
- dlg.resize(400, 310);
- if (dlg.exec()) {
- config_t cfg;
- config_setting_t *root;
- config_setting_t *setting;
- config_init(&cfg);
-
- root = config_root_setting(&cfg);
-
- setting = config_setting_add(root, "progdir",
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting, progs->text().toAscii().data());
- strcpy(progdir, progs->text().toAscii().data());
-
- setting = config_setting_add(root, "node_number",
- CONFIG_TYPE_INT);
- config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
-
- setting = config_setting_add(root, "homedir",
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting, HomeDir);
-
- setting = config_setting_add(root, "type",
- CONFIG_TYPE_STRING);
- if (exp->isChecked()) {
- config_setting_set_string(setting, "explicit");
-
- config_setting_t *hosts = NULL;
- hosts = config_setting_add(root, "host",
- CONFIG_TYPE_ARRAY);
- for(i = 0; i < connections->count(); i++) {
- setting = config_setting_add(hosts, NULL,
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting,
- connections->item(i)->text().toAscii().data());
- }
- } else {
- config_setting_set_string(setting, "register");
- }
-
- if (!config_write_file(&cfg, "vlp.cfg")) {
- fprintf(stderr, "Error while writing to file: %s.\n",
- "vlp.cfg");
- }
- config_destroy(&cfg);
+ loadConfig(getConfigFilePath());
}
}
* Additional window is displayed to enter password and retype it. If both are
* same kernel window is locked.
*/
-void QKernel::LockConsole()
+void QKernel::on_actionLock_console_triggered()
{
- QDialog d(this, Qt::Dialog);
- d.setWindowTitle("Lock console");
-
- QPushButton ob("Ok", &d);
- ob.setGeometry(30, 60, 80, 30);
- ob.setDefault(TRUE);
- connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-
- QLabel lab("Password:", &d);
- lab.setGeometry(10, 10, 60, 30);
-
- QLineEdit ed("", &d);
- ed.setGeometry(70, 10, 140, 30);
- ed.setEchoMode(QLineEdit::Password);
-
- QPushButton cb("Cancel", &d);
- cb.setGeometry(130, 60, 80, 30);
- connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
-
- d.resize(240, 100);
-
- if (d.exec()) {
- if (strcmp(ed.text().toAscii().data(), "") != 0) {
- strcpy(LockPasswd, ed.text().toAscii().data());
- lab.setText("Retype:");
- ed.setText("");
- /*
- * Following exec(), could produce error:
- * X Error: BadWindow (invalid Window parameter) 3
- * Major opcode: 3 (X_GetWindowAttributes)
- *
- * This is not error in our code. Basing on:
- * https://bugreports.qt-project.org/browse/QTBUG-1782
- * this happens only on Qt 4.3 - 4.4.
- */
- if (d.exec()) {
- if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
+ dialog::LockDialog lockDialog(this);
+
+ if (lockDialog.exec()) {
+ QString password = lockDialog.getPassword();
+ if (lockDialog.getPassword().size() > 0) {
+ strcpy(LockPasswd, password.toStdString().c_str());
+ lockDialog.retype();
+
+ if (lockDialog.exec()) {
+ password = lockDialog.getPassword();
+ if (password == LockPasswd) {
setLocked(TRUE);
WriteMessage("CONSOLE LOCKED");
} else {
msg.setText("Not matching!");
msg.setButtonText(0, "Close");
msg.show();
+ strcpy(LockPasswd, "");
}
} else {
strcpy(LockPasswd, "");
* Additional window is displayed to enter password. If it is correct, kernel
* window is unlocked
*/
-void QKernel::UnlockConsole()
+void QKernel::on_actionUnlock_console_triggered()
{
- QDialog d(this, Qt::Dialog);
- d.setWindowTitle("Enter password");
-
- QLabel lab("Password:", &d);
- lab.setGeometry(10, 10, 60, 30);
-
- QLineEdit ed("", &d);
- ed.setGeometry(70, 10, 140, 30);
- ed.setEchoMode(QLineEdit::Password);
-
- QPushButton ob("Ok", &d);
- ob.setGeometry(30, 60, 80, 30);
- ob.setDefault(TRUE);
- connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-
- QPushButton cb("Cancel", &d);
- cb.setGeometry(130, 60, 80, 30);
- connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
-
- d.resize(240, 100);
+ dialog::LockDialog lockDialog(this);
- if (d.exec()) {
- if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
+ if (lockDialog.exec()) {
+ QString password = lockDialog.getPassword();
+ if (strcmp(password.toStdString().c_str(), LockPasswd) == 0) {
setLocked(FALSE);
WriteMessage("CONSOLE UNLOCKED");
} else {
}
}
-/**
- * Writes init message in kernel
- */
-void QKernel::InitMessage()
-{
- WriteMessage("\n " PACKAGE_STRING ": READY \n");
-}
-
/**
* Finds Interpreter by its socket
* @param _id ID of the socket
{
InterpEntry *pom = NULL;
- for (int i = 0; i < Interpreters.size(); i++) {
- if (Interpreters.at(i)->sock == _id) {
- pom = Interpreters.at(i);
+ for (auto interpreter : Interpreters) {
+ if (interpreter->sock == _id) {
+ pom = interpreter;
break;
}
}
{
InterpEntry *pom = NULL;
- for (int i = 0; i < Interpreters.size(); i++) {
- if (Interpreters.at(i)->ID == _id) {
- pom = Interpreters.at(i);
+ for (auto interpreter : Interpreters) {
+ if (interpreter->ID == _id) {
+ pom = interpreter;
break;
}
}
*/
InterpEntry *QKernel::RunIntModule(char *ss, int r)
{
+ fprintf(stderr, "Run INT Module: %s, %d\n", ss, r);
char a[256], b[255];
struct sockaddr_un svr;
- int len, sock, i, on;
+ int len, sock, on;
+ unsigned int i;
int newint=-1;
char cmd[255];
FILE *cf;
strcpy(newINT->shortname, b);
strcpy(newINT->fullname, ss);
- sprintf(a, "%s%d", IPATH, newint);
- sprintf(cmd, "%s/modules/logint %s %s", HomeDir, a, ss);
- if (r)
+ sprintf(a, "%s%d", homeDir.absoluteFilePath(IPATH).toStdString().c_str(), newint);
+ sprintf(cmd, "%s/modules/logint %s %s",
+ getHomeDir(),
+ a,
+ ss);
+ if (r) {
strcat(cmd, " r");
- sprintf(b, " %s %s %s %s %s", myargs[0], myargs[1], myargs[2],
- myargs[3], myargs[4]);
- strcat(cmd, b);
+ }
+// sprintf(b, " %s %s %s %s %s",
+// myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
+// sprintf(cmd, "%s %s", cmd, b);
+// strcat(cmd, b);
+ fprintf(stderr, "%s\n", cmd);
strcat(cmd, " &");
sock = socket(AF_UNIX, SOCK_STREAM, 0);
void QKernel::RemoteInstance(InterpEntry *interp, int on)
{
MESSAGE m;
- char s[255];
m.msg_type = MSG_NET;
m.param.pword[0] = NET_NODE_EXIST;
m.param.pword[1] = interp->RInstances[on];
write(interp->sock, &m, sizeof(MESSAGE));
} else { /* There is no such a node! */
+ char s[255];
sprintf(s, "Warning: Node number %d not found!", on);
WriteMessage(s);
WriteMessage("Allocating O-process on the local node");
/**
* Displays information about virtual machine
*/
-void QKernel::Info()
+void QKernel::on_actionInfo_triggered()
{
MESSAGE m;
wait_for_info = TRUE;
}
+}
+}
+
/**
* Program main function
* All program arguments but the first one (argv[0]: program name) are saved and
*/
int main(int argc, char **argv)
{
- int i;
- for(i = 0; i < 5; i++) {
- strcpy(myargs[i], "");
- }
- for(i = 1; i < argc; i++) {
- strcpy(myargs[i - 1], argv[i]);
- }
+ XInitThreads();
QApplication * app = new QApplication(argc, argv);
- QKernel kernel;
+ loglan::vlp::QKernel kernel(argc, argv);
kernel.show();
- kernel.InitMessage();
return app->exec();
-}
+}
\ No newline at end of file