1 /**************************************************************
3 Copyright (C) 1997 Oskar Swida
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 NOTE: This software is using the free software license of
23 the QT library v.1.30 from Troll Tech AS.
24 See the file LICENSE.QT.
27 To contact the author, write:
28 e-mail: swida@aragorn.pb.bialystok.pl
30 ************************************************************/
32 #include <QtGui/QApplication>
33 #include <QtGui/QMainWindow>
34 #include <QtGui/QTextEdit>
35 #include <QtGui/QMenuBar>
36 #include <QtGui/QMessageBox>
37 #include <QtGui/QFileDialog>
38 #include <QtGui/QDialog>
39 #include <QtCore/QString>
40 #include <QtGui/QLabel>
41 #include <QtGui/QLineEdit>
42 #include <QtGui/QPushButton>
43 #include <QtGui/QRadioButton>
44 #include <QtGui/QGroupBox>
45 #include <QtGui/QVBoxLayout>
46 #include <QtCore/QList>
47 #include <QtGui/QListWidget>
50 #include <QtCore/QSocketNotifier>
51 #include <QtGui/QCloseEvent>
52 #include <QtCore/QDir>
53 #include <QtCore/QProcess>
62 #include <netinet/in.h>
64 #include <libconfig.h>
68 #include "ui/kernelwindow.h"
71 #include "kill_interpreter_dialog.h"
72 #include "connect_dialog.h"
74 /* File resides in top directory (where are Makefiles)*/
75 #include "../../config.h"
78 char CharLine[25] = "________________________";
81 * Event invoked on program close.
82 * Closes application. Displays additional window to confirm exit.
84 void QKernel::closeEvent(QCloseEvent * e)
89 on_actionQuit_triggered();
93 void QKernel::setLocked(bool locked)
97 actionQuit->setDisabled(locked);
99 actionExecute->setDisabled(locked);
100 actionKill->setDisabled(locked);
101 actionMessage->setDisabled(locked);
102 actionConnect->setDisabled(locked);
103 actionDisconnect->setDisabled(locked);
104 actionInfo->setDisabled(locked);
107 /* Enable only menu entry for unlocking */
108 actionEditor->setDisabled(locked);
109 actionOptions->setDisabled(locked);
110 actionLock_console->setDisabled(locked);
111 actionUnlock_console->setDisabled(!locked);
115 * Kernel program constructor.
116 * Prepares everything to work.
118 QKernel::QKernel(int argc, char **argv)
122 QString arg0(argv[0]);
124 homeDir = QDir(arg0);
129 for(i = 0; (i < 5) && (i < argc-1); i++) {
130 strcpy(myargs[i], "");
132 strcpy(myargs[i], argv[i+1]);
136 QDir q(getRemoteDir());
139 q.mkpath(getRemoteDir());
142 info_messages = TRUE;
143 wait_for_info = FALSE;
145 setWindowTitle(PACKAGE_NAME);
151 ActiveConnections = 0;
152 strcpy(LockPasswd, "");
153 loadConfig(getConfigFilePath());
156 Net_Notify = new QSocketNotifier(net_sock, QSocketNotifier::Read, this);
157 connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
160 QString QKernel::getConfigFilePath()
162 return homeDir.absoluteFilePath("vlp.cfg");
165 const char * QKernel::getHomeDir()
167 return homeDir.absolutePath().toStdString().c_str();
170 const char * QKernel::getRemoteDir()
172 return homeDir.absoluteFilePath(REMOTE_PATH).toStdString().c_str();
175 const char * QKernel::getNetModuleSocket()
177 return homeDir.absoluteFilePath(NPATH).toStdString().c_str();
180 const char * QKernel::getGraphModuleSocket()
182 return homeDir.absoluteFilePath(GPATH).toStdString().c_str();
185 void QKernel::loadConfig(const QString & fname)
187 loadConfig(fname.toStdString().c_str());
190 * Loads configuration from the given file.
191 * @param fname Filename of the configuration file.
193 void QKernel::loadConfig(const char * fname)
196 config_setting_t *setting;
198 /* Hack for checking if file exists without using external libs.*/
200 FILE * file = fopen(fname, "rt");
202 fprintf(stderr, "Error: Cannot load configuration file: %s!\n",
206 /* File exists, so file has been locked. Release it. */
210 /* Read the file. If there is an error, report it and exit. */
211 if (!config_read(&cfg, file)) {
212 fprintf(stderr, "%s! In file %s, line %d\n",
213 config_error_text(&cfg),
214 config_error_file(&cfg),
215 config_error_line(&cfg));
216 config_destroy(&cfg);
221 setting = config_lookup(&cfg, "node_number");
223 NodeNumber = config_setting_get_int(setting);
225 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
226 "Warning", fname, "node_number");
227 config_destroy(&cfg);
232 setting = config_lookup(&cfg, "type");
234 /* same as strcmp(..) == 0 */
235 if (!strcmp(config_setting_get_string(setting), "explicit")) {
241 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
242 "Warning", fname, "type");
245 setting = config_lookup(&cfg, "host");
247 switch(config_setting_type(setting)) {
248 /* TODO: Deprecated. Made for back compatibility. */
249 case CONFIG_TYPE_STRING:
250 ConnectList.append(new ConnectEntry((char*)
251 config_setting_get_string(setting)));
253 case CONFIG_TYPE_ARRAY: {
254 int size = config_setting_length(setting);
255 for (int i = 0; i < size; i++) {
256 ConnectList.append(new ConnectEntry((char*)
257 config_setting_get_string_elem(setting,
263 fprintf(stderr, "%s! In file %s, bad entry type for %s."
264 " Will not be read.\n",
265 "Error", fname, "host");
268 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
269 "Warning", fname, "host");
272 setting = config_lookup(&cfg, "progdir");
274 strncpy(progdir, config_setting_get_string(setting), 256);
276 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
277 "Warning", fname, "progdir");
280 config_destroy(&cfg);
286 * Additional window id displayed to set which code to execute.
288 void QKernel::on_actionExecute_triggered()
291 QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
294 i = s.indexOf(".log");
299 // @TODO: if no interpreter is running will result in killing app
300 RunIntModule((char*)s.toAscii().data(), 0);
305 * Invokes editor program
307 void QKernel::on_actionEditor_triggered()
309 QString program = getHomeDir();
310 program += "/modules/logedit";
314 if (execl(program.toStdString().c_str(),
323 WriteMessage("Executing logedit failed!");
327 WriteMessage("fork(logedit) failed!");
328 WriteMessage("Exiting...");
330 on_actionQuit_triggered();
336 * Invokes help program
338 void QKernel::on_actionHelp_triggered()
340 QString program = getHomeDir();
341 program += "/modules/loghelp";
343 QString docDir = getHomeDir();
348 if (execl(program.toStdString().c_str(),
349 docDir.toStdString().c_str(),
358 WriteMessage("Executing loghelp failed!");
362 WriteMessage("fork(loghelp) failed!");
363 WriteMessage("Exiting...");
365 on_actionQuit_triggered();
371 * Invokes graphics module
373 void QKernel::RunGraphModule(char *sk)
377 QString program = getHomeDir();
378 program += "/modules/loggraph";
382 if (execl(program.toStdString().c_str(),
383 program.toStdString().c_str(),
393 WriteMessage("Executing loggraph failed!");
394 WriteMessage("Exiting...");
396 on_actionQuit_triggered();
400 WriteMessage("fork(loggraph) failed!");
401 WriteMessage("Exiting...");
403 on_actionQuit_triggered();
411 void QKernel::RunNetModule()
413 struct sockaddr_un svr;
418 QString program = getHomeDir();
419 program += "/modules/lognet";
423 if (execl(program.toStdString().c_str(),
424 program.toStdString().c_str(),
425 getNetModuleSocket(),
426 getConfigFilePath().toStdString().c_str(),
435 WriteMessage("Executing lognet failed!");
436 WriteMessage("Exiting...");
438 on_actionQuit_triggered();
442 WriteMessage("fork(lognet) failed!");
443 WriteMessage("Exiting...");
445 on_actionQuit_triggered();
449 /* -------- socket for NET module -------- */
450 unlink(getNetModuleSocket());
451 sock = socket(AF_UNIX, SOCK_STREAM, 0);
452 bzero(&svr, sizeof(svr));
453 svr.sun_family = AF_UNIX;
454 strcpy(svr.sun_path, getNetModuleSocket());
455 len = strlen(svr.sun_path) + sizeof(svr.sun_family);
456 bind(sock, (struct sockaddr*)&svr, len);
459 net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
462 WriteMessage("NETWORK successfully connected");
463 fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock, F_GETFL, 0));
465 setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
467 WriteMessage("Cannot connect NETWORK resources");
468 WriteMessage("Exiting...");
470 on_actionQuit_triggered();
475 * Connects to the specified address
476 * Additional window is displayed to connect to the specified address
478 void QKernel::on_actionConnect_triggered()
482 ConnectDialog dialog(this);
483 dialog.setWindowTitle("IP Address:");
486 m.msg_type = MSG_NET;
487 m.param.pword[0] = NET_CONNECT_TO;
488 strcpy(m.param.pstr, dialog.getAddress().toStdString().c_str());
489 write(net_sock, &m, sizeof(MESSAGE));
494 * Disconnects from virtual machine
496 void QKernel::on_actionDisconnect_triggered()
501 WriteMessage("Disconnecting from virtual machine");
503 msg.msg_type = MSG_NET;
504 msg.param.pword[0] = NET_DISCONNECT;
505 write(net_sock, &msg, sizeof(MESSAGE));
509 * Quits process. Closes VLP. Shows additional window to confirm exit.
511 void QKernel::on_actionQuit_triggered()
515 QMessageBox::StandardButton response = QMessageBox::question(this,
518 QMessageBox::Ok | QMessageBox::Cancel
522 if (response == QMessageBox::Cancel) {
526 msg.msg_type = MSG_NET;
527 msg.param.pword[0] = NET_DISCONNECT;
528 write(net_sock, &msg, sizeof(MESSAGE));*/
531 msg.msg_type = MSG_NET;
532 msg.param.pword[0] = NET_EXIT;
533 write(net_sock, &msg, sizeof(MESSAGE));
534 /* ::close(net_sock);*/
535 QApplication::instance()->quit();
539 * Sends message to node.
540 * Additional window is displayed to set Node Number of node where send message,
541 * and textfield to enter message.
543 void QKernel::on_actionMessage_triggered()
549 dlg = new QDialog(this, Qt::Dialog);
550 dlg->setWindowTitle("Send message to node");
552 nodenr = new QLineEdit("number", dlg);
553 nodenr->setGeometry(90, 10, 50, 30);
557 tmpQLabel = new QLabel("Node number:", dlg);
558 tmpQLabel->setGeometry(10, 10, 77, 30);
560 tmpQLabel = new QLabel("Message:", dlg);
561 tmpQLabel->setGeometry(10, 50, 70, 30);
564 msg = new QLineEdit("", dlg);
565 msg->setGeometry(80, 60, 330, 30);
568 ob = new QPushButton("Send", dlg);
569 ob->setGeometry(230, 10, 80, 30);
570 ob->setDefault(TRUE);
573 cb = new QPushButton("Cancel", dlg);
574 cb->setGeometry(330, 10, 80, 30);
575 dlg->resize(430, 110);
576 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
577 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
580 m.msg_type = MSG_NET;
581 m.param.pword[0] = NET_PROPAGATE;
582 m.param.pword[1] = MSG_VLP;
583 m.param.pword[2] = NodeNumber;
584 m.param.pword[4] = atoi(nodenr->text().toAscii().data());
585 m.param.pword[6] = VLP_WRITE;
586 strcpy(m.param.pstr, msg->text().toAscii().data());
587 write(net_sock, &m, sizeof(MESSAGE));
593 * Additional window is displayed to get ID of interpreter which should be
596 void QKernel::on_actionKill_triggered()
598 KillInterpreterDialog dialog(this);
599 dialog.setWindowTitle("Kill interpreter");
602 InterpEntry *interpreter;
605 m.msg_type = MSG_INT;
606 m.param.pword[0] = INT_KILL;
607 interpreter = findINTbyID(dialog.getInterpreterId());
608 if (interpreter != NULL) {
609 if (!(interpreter->remote))
610 write(interpreter->sock, &m, sizeof(MESSAGE));
612 WriteMessage("This is a remote instance of a program!");
615 WriteMessage("Interpreter not found");
621 * Sends message to the net module.
623 void QKernel::NetMessage()
626 /* TODO: It has to be rewritten */
632 cnt = read(net_sock, &msg, sizeof(MESSAGE));
633 if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
634 switch(msg.param.pword[0]) {
636 WriteMessage(msg.param.pstr);
639 switch(msg.param.pword[1]) {
641 /* pom = find_link_by_ID(msg.param.pword[5]);
642 msg.msg_type = MSG_NET;
643 msg.param.pword[0] = NET_PROPAGATE;
644 send_int(pom, &msg);*/
647 switch(msg.param.pword[6]) {
649 QApplication::beep();
650 WriteMessage(CharLine);
652 "### Incoming Messsage ###");
653 sprintf(ss, "Mesg from Node %d: %s",
657 WriteMessage(CharLine);
659 case VLP_REMOTE_INSTANCE:
660 sprintf(ss, "%s/%s", getRemoteDir(),
664 WriteMessage("Running program:");
667 pom = RunIntModule(ss, 1);
669 pom->p_ctx.node = msg.param.pword[2];
670 pom->p_ctx.program_id =
672 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
675 case VLP_CLOSE_INSTANCE:
676 msg.msg_type = MSG_INT;
677 msg.param.pword[0] = INT_CLOSE_INSTANCE;
678 pom = findINTbyID(msg.param.pword[7]);
680 write(pom->sock, &msg,
683 m1.msg_type = MSG_VLP;
684 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
685 m1.param.pword[1] = pom->ID;
689 WriteMessage("Instance not found");
695 case NET_CONNECTIONS:
696 ActiveConnections = msg.param.pword[1];
697 WriteMessage(msg.param.pstr);
702 /* TODO: It has to be rewritten */
704 QString poms, poms1, poms2;
705 poms.sprintf("%s", msg.param.pstr);
706 while (poms.length() > 0) {
707 cnt = poms.indexOf(';');
709 poms1 = poms.left(cnt);
710 poms = poms.right(poms.length() - cnt - 1);
711 cnt = poms1.indexOf('=');
713 poms2 = poms1.left(cnt);
714 poms1 = poms1.right(poms1.length() - cnt - 1);
715 sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
723 wait_for_info = FALSE;
724 WriteMessage(CharLine);
731 * Sends message to the interpreter program.
732 * @param sock Interpreter socket to whom the message will be send.
734 void QKernel::IntMessage(int sock)
740 cnt = read(sock, &msg, sizeof(MESSAGE));
741 e = findINTbySocket(sock);
742 if ((cnt > 0) && (e != NULL)) {
743 switch (msg.msg_type) {
745 if (msg.param.pword[0] == GRAPH_ALLOCATE) {
746 RunGraphModule(msg.param.pstr);
750 write(net_sock, &msg, sizeof(MESSAGE));
753 switch(msg.param.pword[0]) {
754 case VLP_REMOTE_INSTANCE_PLEASE:
755 RemoteInstance(e, msg.param.pword[2]);
760 switch(msg.param.pword[0]) {
765 m.msg_type = MSG_VLP;
766 m.param.pword[0] = VLP_INTERPRETER_DOWN;
767 m.param.pword[1] = e->ID;
768 write(net_sock, &m, sizeof(MESSAGE));
773 /* TODO: Check this */
774 Interpreters.removeOne(e);
778 sprintf(ss, "%s : End of program "
779 "execution", msg.param.pstr);
784 msg.msg_type = MSG_INT;
785 msg.param.pword[0] = INT_CTX;
786 msg.param.pword[1] = NodeNumber;
787 msg.param.pword[2] = e->ID;
789 msg.param.pword[3] = e->p_ctx.node;
793 write(sock, &msg, sizeof(MESSAGE));
802 * Writes message to kernel logger.
803 * @parame msg String with message to log
805 void QKernel::WriteMessage(char *msg)
809 x = desktop->textCursor().blockNumber();
810 y = desktop->textCursor().columnNumber();
816 desktop->setReadOnly(FALSE);
817 desktop->append(msg);
818 desktop->setReadOnly(TRUE);
820 QTextCursor tmpCursor = desktop->textCursor();
821 tmpCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
822 desktop->setTextCursor(tmpCursor);
826 if (desktop->document()->blockCount() > 100) {
832 * Adds checkbox to menu item. If it is checked additional info messages are
835 void QKernel::on_actionInfo_messages_triggered()
837 if (toolsMenu != NULL) {
838 info_messages = actionInfo_messages->isChecked();
839 actionInfo_messages->setChecked(info_messages);
844 * Allows to set options in GUI window.
845 * Additional window is displayed to set kernel options which are saved in
846 * vlp.cfg file in kernel executable directory.
848 void QKernel::on_actionOptions_triggered()
850 OptionsDialog optionsDialog(getConfigFilePath(), this);
851 if (optionsDialog.exec()) {
852 optionsDialog.saveConfig(getConfigFilePath());
854 loadConfig(getConfigFilePath());
859 * Locks kernel program.
860 * Additional window is displayed to enter password and retype it. If both are
861 * same kernel window is locked.
863 void QKernel::on_actionLock_console_triggered()
865 LockDialog lockDialog(this);
867 if (lockDialog.exec()) {
868 QString password = lockDialog.getPassword();
869 if (lockDialog.getPassword().size() > 0) {
870 strcpy(LockPasswd, password.toStdString().c_str());
873 if (lockDialog.exec()) {
874 password = lockDialog.getPassword();
875 if (password == LockPasswd) {
877 WriteMessage("CONSOLE LOCKED");
879 QMessageBox msg(this);
880 msg.setText("Not matching!");
881 msg.setButtonText(0, "Close");
883 strcpy(LockPasswd, "");
886 strcpy(LockPasswd, "");
893 * Unlocks kernel program.
894 * Additional window is displayed to enter password. If it is correct, kernel
897 void QKernel::on_actionUnlock_console_triggered()
899 LockDialog lockDialog(this);
901 if (lockDialog.exec()) {
902 QString password = lockDialog.getPassword();
903 if (strcmp(password.toStdString().c_str(), LockPasswd) == 0) {
905 WriteMessage("CONSOLE UNLOCKED");
907 QMessageBox msg(this);
908 msg.setText("Wrong password!");
909 msg.setButtonText(0, "Close");
916 * Writes init message in kernel
918 void QKernel::InitMessage()
920 WriteMessage("\n " PACKAGE_STRING ": READY \n");
924 * Finds Interpreter by its socket
925 * @param _id ID of the socket
926 * @return returns pointer to the found interpreter slot. NULL otherwise
928 InterpEntry *QKernel::findINTbySocket(int _id)
930 InterpEntry *pom = NULL;
932 for (int i = 0; i < Interpreters.size(); i++) {
933 if (Interpreters.at(i)->sock == _id) {
934 pom = Interpreters.at(i);
943 * Finds Interpreter by its ID.
944 * @param _id ID of the interpreter
945 * @return returns pointer to the found interpreter slot. NULL otherwise
947 InterpEntry *QKernel::findINTbyID(int _id)
949 InterpEntry *pom = NULL;
951 for (int i = 0; i < Interpreters.size(); i++) {
952 if (Interpreters.at(i)->ID == _id) {
953 pom = Interpreters.at(i);
963 * Connects interpreter
964 * @param ss full filepath with filename but without extension of the loglan
966 * @param r Interpreter execution mode. 0 if it will be local instance, 1 if
968 * @return Returns pointer to newly created interpreter slot, or NULL on error.
970 InterpEntry *QKernel::RunIntModule(char *ss, int r)
973 struct sockaddr_un svr;
980 InterpEntry *newINT = NULL;
986 WriteMessage("File not found: no .ccd file");
995 WriteMessage("File not found: no .pcd file");
1000 newINT = new InterpEntry;
1001 for(i = 0; i < MAXINSTANCES; i++)
1002 newINT->RInstances[i] =- 1;
1004 strcpy(b, rindex(ss, '/'));
1005 for(i = 0; i < strlen(b); i++)
1007 if (info_messages) {
1008 sprintf(a, "%s : Start execution", b);
1014 newINT->ID = newint;
1015 strcpy(newINT->shortname, b);
1016 strcpy(newINT->fullname, ss);
1018 sprintf(a, "%s%d", IPATH, newint);
1019 sprintf(cmd, "%s/modules/logint %s %s",
1026 sprintf(b, " %s %s %s %s %s",
1027 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
1031 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1033 bzero(&svr, sizeof(svr));
1034 svr.sun_family = AF_UNIX;
1035 strcpy(svr.sun_path, a);
1036 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1037 bind(sock, (struct sockaddr*)&svr, len);
1040 newINT->sock = accept(sock, (struct sockaddr*)0, (unsigned int *)0);
1043 if (newINT->sock > 0) {
1044 fcntl(newINT->sock, F_SETFL,
1045 O_NONBLOCK|fcntl(newINT->sock, F_GETFL, 0));
1047 setsockopt(newINT->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
1054 bzero(&msg, sizeof(MESSAGE));
1055 msg.msg_type = MSG_VLP;
1056 msg.param.pword[0] = VLP_REGINT;
1057 msg.param.pword[1] = newINT->ID;
1058 sprintf(msg.param.pstr, "logi%d.net", newint);
1059 write(net_sock, &msg, sizeof(MESSAGE));
1061 Interpreters.append(newINT);
1062 newINT->notify = new QSocketNotifier(newINT->sock,
1063 QSocketNotifier::Read);
1064 connect(newINT->notify, SIGNAL(activated(int)), this,
1065 SLOT(IntMessage(int)));
1067 WriteMessage("INTERPRETER successfully connected");
1069 WriteMessage("Cannot connect interpreter");
1076 * Allocates remote instance of interpreter
1077 * @param interp Interpreter slot
1078 * @param on Node Number
1080 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1085 m.msg_type = MSG_NET;
1086 m.param.pword[0] = NET_NODE_EXIST;
1087 m.param.pword[1] = on;
1088 m.param.pword[2] = interp->ID;
1089 write(net_sock, &m, sizeof(MESSAGE));
1090 bzero(&m, sizeof(MESSAGE));
1091 while((m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST))
1092 read(net_sock, &m, sizeof(MESSAGE));
1094 /* means node exists */
1095 if (m.param.pword[1] == 1) {
1096 m.msg_type = MSG_NET;
1097 m.param.pword[0] = NET_TRANSMIT_CODE;
1098 m.param.pword[1] = interp->ID;
1099 m.param.pword[2] = on;
1100 strcpy(m.param.pstr, interp->fullname);
1101 write(net_sock, &m, sizeof(MESSAGE));
1103 Net_Notify->setEnabled(FALSE);
1104 while ((m.msg_type != MSG_NET) ||
1105 (m.param.pword[0] != NET_TRANSMITTED))
1106 read(net_sock, &m, sizeof(MESSAGE));
1108 m.msg_type = MSG_NET;
1109 m.param.pword[0] = NET_PROPAGATE;
1110 m.param.pword[1] = MSG_VLP;
1111 m.param.pword[2] = NodeNumber;
1112 m.param.pword[3] = 0;
1113 m.param.pword[4] = on;
1114 m.param.pword[5] = 0;
1115 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1116 m.param.pword[7] = interp->ID;
1117 strcpy(m.param.pstr, interp->shortname);
1118 write(net_sock, &m, sizeof(MESSAGE));
1120 read(net_sock, &m, sizeof(MESSAGE));
1122 if ((m.param.pword[0] == NET_PROPAGATE) &&
1123 (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK)) {
1124 interp->RInstances[on] = m.param.pword[7];
1127 read(net_sock, &m, sizeof(MESSAGE));
1130 Net_Notify->setEnabled(TRUE);
1132 /*bzero(&m, sizeof(MESSAGE));*/
1133 m.msg_type = MSG_VLP;
1134 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1135 m.param.pword[1] = interp->RInstances[on];
1136 write(interp->sock, &m, sizeof(MESSAGE));
1137 } else { /* There is no such a node! */
1138 sprintf(s, "Warning: Node number %d not found!", on);
1140 WriteMessage("Allocating O-process on the local node");
1141 bzero(&m, sizeof(MESSAGE));
1142 m.msg_type = MSG_VLP;
1143 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1144 m.param.pword[1] = interp->ID;
1145 write(interp->sock, &m, sizeof(MESSAGE));
1150 * Closes all remote instances
1152 void QKernel::CloseInstances(InterpEntry *e)
1158 WriteMessage("Closing remote instances");
1160 for(i=0; i < MAXINSTANCES; i++)
1161 if (e->RInstances[i]>=0) {
1162 msg.msg_type = MSG_NET;
1163 msg.param.pword[0] = NET_PROPAGATE;
1164 msg.param.pword[1] = MSG_VLP;
1165 msg.param.pword[2] = NodeNumber;
1166 msg.param.pword[4] = i;
1167 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1168 msg.param.pword[7] = e->RInstances[i];
1169 write(net_sock, &msg, sizeof(MESSAGE));
1174 * Displays information about virtual machine
1176 void QKernel::on_actionInfo_triggered()
1180 WriteMessage(CharLine);
1181 WriteMessage("### Virtual Machine Information ###");
1182 m.msg_type = MSG_NET;
1183 m.param.pword[0] = NET_GET_INFO;
1184 write(net_sock, &m, sizeof(MESSAGE));
1185 wait_for_info = TRUE;
1189 * Program main function
1190 * All program arguments but the first one (argv[0]: program name) are saved and
1191 * passed to all dependent programs on their invocation.
1192 * @param argc Number of program arguments
1193 * @param argv Program arguments
1195 int main(int argc, char **argv)
1199 QApplication * app = new QApplication(argc, argv);
1200 QKernel kernel(argc, argv);
1202 kernel.InitMessage();