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)
195 fprintf(stderr, "2: %s\n", fname);
197 config_setting_t *setting;
199 /* Hack for checking if file exists without using external libs.*/
201 FILE * file = fopen(fname, "rt");
203 fprintf(stderr, "Error: Cannot load configuration file: %s!\n",
207 /* File exists, so file has been locked. Release it. */
211 /* Read the file. If there is an error, report it and exit. */
212 if (!config_read(&cfg, file)) {
213 fprintf(stderr, "%s! In file %s, line %d\n",
214 config_error_text(&cfg),
215 config_error_file(&cfg),
216 config_error_line(&cfg));
217 config_destroy(&cfg);
222 setting = config_lookup(&cfg, "node_number");
224 NodeNumber = config_setting_get_int(setting);
226 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
227 "Warning", fname, "node_number");
228 config_destroy(&cfg);
233 setting = config_lookup(&cfg, "type");
235 /* same as strcmp(..) == 0 */
236 if (!strcmp(config_setting_get_string(setting), "explicit")) {
242 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
243 "Warning", fname, "type");
246 setting = config_lookup(&cfg, "host");
248 switch(config_setting_type(setting)) {
249 /* TODO: Deprecated. Made for back compatibility. */
250 case CONFIG_TYPE_STRING:
251 ConnectList.append(new ConnectEntry((char*)
252 config_setting_get_string(setting)));
254 case CONFIG_TYPE_ARRAY: {
255 int size = config_setting_length(setting);
256 for (int i = 0; i < size; i++) {
257 ConnectList.append(new ConnectEntry((char*)
258 config_setting_get_string_elem(setting,
264 fprintf(stderr, "%s! In file %s, bad entry type for %s."
265 " Will not be read.\n",
266 "Error", fname, "host");
269 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
270 "Warning", fname, "host");
273 setting = config_lookup(&cfg, "progdir");
275 strncpy(progdir, config_setting_get_string(setting), 256);
277 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
278 "Warning", fname, "progdir");
281 config_destroy(&cfg);
287 * Additional window id displayed to set which code to execute.
289 void QKernel::on_actionExecute_triggered()
292 QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
295 i = s.indexOf(".log");
300 // @TODO: if no interpreter is running will result in killing app
301 RunIntModule((char*)s.toAscii().data(), 0);
306 * Invokes editor program
308 void QKernel::on_actionEditor_triggered()
310 QString program = getHomeDir();
311 program += "/modules/logedit";
315 if (execl(program.toStdString().c_str(),
324 WriteMessage("Executing logedit failed!");
330 * Invokes help program
332 void QKernel::on_actionHelp_triggered()
334 QString program = getHomeDir();
335 program += "/modules/loghelp";
337 QString docDir = getHomeDir();
342 if (execl(program.toStdString().c_str(),
343 docDir.toStdString().c_str(),
352 WriteMessage("Executing loghelp failed!");
358 * Invokes graphics module
360 void QKernel::RunGraphModule(char *sk)
364 QString program = getHomeDir();
365 program += "/modules/loggraph";
368 if (execl(program.toStdString().c_str(),
369 program.toStdString().c_str(),
379 WriteMessage("Executing loggraph failed!");
380 WriteMessage("Exiting...");
382 on_actionQuit_triggered();
386 WriteMessage("fork(loggraph) failed!");
387 WriteMessage("Exiting...");
389 on_actionQuit_triggered();
397 void QKernel::RunNetModule()
399 struct sockaddr_un svr;
404 QString program = getHomeDir();
405 program += "/modules/lognet";
409 if (execl(program.toStdString().c_str(),
410 program.toStdString().c_str(),
411 getNetModuleSocket(),
412 getConfigFilePath().toStdString().c_str(),
421 WriteMessage("Executing lognet failed!");
422 WriteMessage("Exiting...");
424 on_actionQuit_triggered();
428 WriteMessage("fork(lognet) failed!");
429 WriteMessage("Exiting...");
431 on_actionQuit_triggered();
435 /* -------- socket for NET module -------- */
436 unlink(getNetModuleSocket());
437 sock = socket(AF_UNIX, SOCK_STREAM, 0);
438 bzero(&svr, sizeof(svr));
439 svr.sun_family = AF_UNIX;
440 strcpy(svr.sun_path, getNetModuleSocket());
441 len = strlen(svr.sun_path) + sizeof(svr.sun_family);
442 bind(sock, (struct sockaddr*)&svr, len);
445 net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
448 WriteMessage("NETWORK successfully connected");
449 fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock, F_GETFL, 0));
451 setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
453 WriteMessage("Cannot connect NETWORK resources");
454 WriteMessage("Exiting...");
456 on_actionQuit_triggered();
461 * Connects to the specified address
462 * Additional window is displayed to connect to the specified address
464 void QKernel::on_actionConnect_triggered()
468 ConnectDialog dialog(this);
469 dialog.setWindowTitle("IP Address:");
472 m.msg_type = MSG_NET;
473 m.param.pword[0] = NET_CONNECT_TO;
474 strcpy(m.param.pstr, dialog.getAddress().toStdString().c_str());
475 write(net_sock, &m, sizeof(MESSAGE));
480 * Disconnects from virtual machine
482 void QKernel::on_actionDisconnect_triggered()
487 WriteMessage("Disconnecting from virtual machine");
489 msg.msg_type = MSG_NET;
490 msg.param.pword[0] = NET_DISCONNECT;
491 write(net_sock, &msg, sizeof(MESSAGE));
495 * Quits process. Closes VLP. Shows additional window to confirm exit.
497 void QKernel::on_actionQuit_triggered()
501 QMessageBox::StandardButton response = QMessageBox::question(this,
504 QMessageBox::Ok | QMessageBox::Cancel
508 if (response == QMessageBox::Cancel) {
512 msg.msg_type = MSG_NET;
513 msg.param.pword[0] = NET_DISCONNECT;
514 write(net_sock, &msg, sizeof(MESSAGE));*/
517 msg.msg_type = MSG_NET;
518 msg.param.pword[0] = NET_EXIT;
519 write(net_sock, &msg, sizeof(MESSAGE));
520 /* ::close(net_sock);*/
521 QApplication::instance()->quit();
525 * Sends message to node.
526 * Additional window is displayed to set Node Number of node where send message,
527 * and textfield to enter message.
529 void QKernel::on_actionMessage_triggered()
535 dlg = new QDialog(this, Qt::Dialog);
536 dlg->setWindowTitle("Send message to node");
538 nodenr = new QLineEdit("number", dlg);
539 nodenr->setGeometry(90, 10, 50, 30);
543 tmpQLabel = new QLabel("Node number:", dlg);
544 tmpQLabel->setGeometry(10, 10, 77, 30);
546 tmpQLabel = new QLabel("Message:", dlg);
547 tmpQLabel->setGeometry(10, 50, 70, 30);
550 msg = new QLineEdit("", dlg);
551 msg->setGeometry(80, 60, 330, 30);
554 ob = new QPushButton("Send", dlg);
555 ob->setGeometry(230, 10, 80, 30);
556 ob->setDefault(TRUE);
559 cb = new QPushButton("Cancel", dlg);
560 cb->setGeometry(330, 10, 80, 30);
561 dlg->resize(430, 110);
562 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
563 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
566 m.msg_type = MSG_NET;
567 m.param.pword[0] = NET_PROPAGATE;
568 m.param.pword[1] = MSG_VLP;
569 m.param.pword[2] = NodeNumber;
570 m.param.pword[4] = atoi(nodenr->text().toAscii().data());
571 m.param.pword[6] = VLP_WRITE;
572 strcpy(m.param.pstr, msg->text().toAscii().data());
573 write(net_sock, &m, sizeof(MESSAGE));
579 * Additional window is displayed to get ID of interpreter which should be
582 void QKernel::on_actionKill_triggered()
584 KillInterpreterDialog dialog(this);
585 dialog.setWindowTitle("Kill interpreter");
588 InterpEntry *interpreter;
591 m.msg_type = MSG_INT;
592 m.param.pword[0] = INT_KILL;
593 interpreter = findINTbyID(dialog.getInterpreterId());
594 if (interpreter != NULL) {
595 if (!(interpreter->remote))
596 write(interpreter->sock, &m, sizeof(MESSAGE));
598 WriteMessage("This is a remote instance of a program!");
601 WriteMessage("Interpreter not found");
607 * Sends message to the net module.
609 void QKernel::NetMessage()
612 /* TODO: It has to be rewritten */
618 cnt = read(net_sock, &msg, sizeof(MESSAGE));
619 if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
620 switch(msg.param.pword[0]) {
622 WriteMessage(msg.param.pstr);
625 switch(msg.param.pword[1]) {
627 /* pom = find_link_by_ID(msg.param.pword[5]);
628 msg.msg_type = MSG_NET;
629 msg.param.pword[0] = NET_PROPAGATE;
630 send_int(pom, &msg);*/
633 switch(msg.param.pword[6]) {
635 QApplication::beep();
636 WriteMessage(CharLine);
638 "### Incoming Messsage ###");
639 sprintf(ss, "Mesg from Node %d: %s",
643 WriteMessage(CharLine);
645 case VLP_REMOTE_INSTANCE:
646 sprintf(ss, "%s/%s", getRemoteDir(),
650 WriteMessage("Running program:");
653 pom = RunIntModule(ss, 1);
655 pom->p_ctx.node = msg.param.pword[2];
656 pom->p_ctx.program_id =
658 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
661 case VLP_CLOSE_INSTANCE:
662 msg.msg_type = MSG_INT;
663 msg.param.pword[0] = INT_CLOSE_INSTANCE;
664 pom = findINTbyID(msg.param.pword[7]);
666 write(pom->sock, &msg,
669 m1.msg_type = MSG_VLP;
670 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
671 m1.param.pword[1] = pom->ID;
675 WriteMessage("Instance not found");
681 case NET_CONNECTIONS:
682 ActiveConnections = msg.param.pword[1];
683 WriteMessage(msg.param.pstr);
688 /* TODO: It has to be rewritten */
690 QString poms, poms1, poms2;
691 poms.sprintf("%s", msg.param.pstr);
692 while (poms.length() > 0) {
693 cnt = poms.indexOf(';');
695 poms1 = poms.left(cnt);
696 poms = poms.right(poms.length() - cnt - 1);
697 cnt = poms1.indexOf('=');
699 poms2 = poms1.left(cnt);
700 poms1 = poms1.right(poms1.length() - cnt - 1);
701 sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
709 wait_for_info = FALSE;
710 WriteMessage(CharLine);
717 * Sends message to the interpreter program.
718 * @param sock Interpreter socket to whom the message will be send.
720 void QKernel::IntMessage(int sock)
726 cnt = read(sock, &msg, sizeof(MESSAGE));
727 e = findINTbySocket(sock);
728 if ((cnt > 0) && (e != NULL)) {
729 switch (msg.msg_type) {
731 if (msg.param.pword[0] == GRAPH_ALLOCATE) {
732 RunGraphModule(msg.param.pstr);
736 write(net_sock, &msg, sizeof(MESSAGE));
739 switch(msg.param.pword[0]) {
740 case VLP_REMOTE_INSTANCE_PLEASE:
741 RemoteInstance(e, msg.param.pword[2]);
746 switch(msg.param.pword[0]) {
751 m.msg_type = MSG_VLP;
752 m.param.pword[0] = VLP_INTERPRETER_DOWN;
753 m.param.pword[1] = e->ID;
754 write(net_sock, &m, sizeof(MESSAGE));
759 /* TODO: Check this */
760 Interpreters.removeOne(e);
764 sprintf(ss, "%s : End of program "
765 "execution", msg.param.pstr);
770 msg.msg_type = MSG_INT;
771 msg.param.pword[0] = INT_CTX;
772 msg.param.pword[1] = NodeNumber;
773 msg.param.pword[2] = e->ID;
775 msg.param.pword[3] = e->p_ctx.node;
779 write(sock, &msg, sizeof(MESSAGE));
788 * Writes message to kernel logger.
789 * @parame msg String with message to log
791 void QKernel::WriteMessage(char *msg)
795 x = desktop->textCursor().blockNumber();
796 y = desktop->textCursor().columnNumber();
802 desktop->setReadOnly(FALSE);
803 desktop->append(msg);
804 desktop->setReadOnly(TRUE);
806 QTextCursor tmpCursor = desktop->textCursor();
807 tmpCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
808 desktop->setTextCursor(tmpCursor);
812 if (desktop->document()->blockCount() > 100) {
818 * Adds checkbox to menu item. If it is checked additional info messages are
821 void QKernel::on_actionInfo_messages_triggered()
823 if (toolsMenu != NULL) {
824 info_messages = actionInfo_messages->isChecked();
825 actionInfo_messages->setChecked(info_messages);
830 * Allows to set options in GUI window.
831 * Additional window is displayed to set kernel options which are saved in
832 * vlp.cfg file in kernel executable directory.
834 void QKernel::on_actionOptions_triggered()
836 OptionsDialog optionsDialog(getConfigFilePath(), this);
837 if (optionsDialog.exec()) {
838 optionsDialog.saveConfig(getConfigFilePath());
840 loadConfig(getConfigFilePath());
845 * Locks kernel program.
846 * Additional window is displayed to enter password and retype it. If both are
847 * same kernel window is locked.
849 void QKernel::on_actionLock_console_triggered()
851 LockDialog lockDialog(this);
853 if (lockDialog.exec()) {
854 QString password = lockDialog.getPassword();
855 if (lockDialog.getPassword().size() > 0) {
856 strcpy(LockPasswd, password.toStdString().c_str());
859 if (lockDialog.exec()) {
860 password = lockDialog.getPassword();
861 if (password == LockPasswd) {
863 WriteMessage("CONSOLE LOCKED");
865 QMessageBox msg(this);
866 msg.setText("Not matching!");
867 msg.setButtonText(0, "Close");
869 strcpy(LockPasswd, "");
872 strcpy(LockPasswd, "");
879 * Unlocks kernel program.
880 * Additional window is displayed to enter password. If it is correct, kernel
883 void QKernel::on_actionUnlock_console_triggered()
885 LockDialog lockDialog(this);
887 if (lockDialog.exec()) {
888 QString password = lockDialog.getPassword();
889 if (strcmp(password.toStdString().c_str(), LockPasswd) == 0) {
891 WriteMessage("CONSOLE UNLOCKED");
893 QMessageBox msg(this);
894 msg.setText("Wrong password!");
895 msg.setButtonText(0, "Close");
902 * Writes init message in kernel
904 void QKernel::InitMessage()
906 WriteMessage("\n " PACKAGE_STRING ": READY \n");
910 * Finds Interpreter by its socket
911 * @param _id ID of the socket
912 * @return returns pointer to the found interpreter slot. NULL otherwise
914 InterpEntry *QKernel::findINTbySocket(int _id)
916 InterpEntry *pom = NULL;
918 for (int i = 0; i < Interpreters.size(); i++) {
919 if (Interpreters.at(i)->sock == _id) {
920 pom = Interpreters.at(i);
929 * Finds Interpreter by its ID.
930 * @param _id ID of the interpreter
931 * @return returns pointer to the found interpreter slot. NULL otherwise
933 InterpEntry *QKernel::findINTbyID(int _id)
935 InterpEntry *pom = NULL;
937 for (int i = 0; i < Interpreters.size(); i++) {
938 if (Interpreters.at(i)->ID == _id) {
939 pom = Interpreters.at(i);
949 * Connects interpreter
950 * @param ss full filepath with filename but without extension of the loglan
952 * @param r Interpreter execution mode. 0 if it will be local instance, 1 if
954 * @return Returns pointer to newly created interpreter slot, or NULL on error.
956 InterpEntry *QKernel::RunIntModule(char *ss, int r)
959 struct sockaddr_un svr;
966 InterpEntry *newINT = NULL;
972 WriteMessage("File not found: no .ccd file");
981 WriteMessage("File not found: no .pcd file");
986 newINT = new InterpEntry;
987 for(i = 0; i < MAXINSTANCES; i++)
988 newINT->RInstances[i] =- 1;
990 strcpy(b, rindex(ss, '/'));
991 for(i = 0; i < strlen(b); i++)
994 sprintf(a, "%s : Start execution", b);
1000 newINT->ID = newint;
1001 strcpy(newINT->shortname, b);
1002 strcpy(newINT->fullname, ss);
1004 sprintf(a, "%s%d", IPATH, newint);
1005 sprintf(cmd, "%s/modules/logint %s %s",
1012 sprintf(b, " %s %s %s %s %s",
1013 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
1017 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1019 bzero(&svr, sizeof(svr));
1020 svr.sun_family = AF_UNIX;
1021 strcpy(svr.sun_path, a);
1022 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1023 bind(sock, (struct sockaddr*)&svr, len);
1026 newINT->sock = accept(sock, (struct sockaddr*)0, (unsigned int *)0);
1029 if (newINT->sock > 0) {
1030 fcntl(newINT->sock, F_SETFL,
1031 O_NONBLOCK|fcntl(newINT->sock, F_GETFL, 0));
1033 setsockopt(newINT->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
1040 bzero(&msg, sizeof(MESSAGE));
1041 msg.msg_type = MSG_VLP;
1042 msg.param.pword[0] = VLP_REGINT;
1043 msg.param.pword[1] = newINT->ID;
1044 sprintf(msg.param.pstr, "logi%d.net", newint);
1045 write(net_sock, &msg, sizeof(MESSAGE));
1047 Interpreters.append(newINT);
1048 newINT->notify = new QSocketNotifier(newINT->sock,
1049 QSocketNotifier::Read);
1050 connect(newINT->notify, SIGNAL(activated(int)), this,
1051 SLOT(IntMessage(int)));
1053 WriteMessage("INTERPRETER successfully connected");
1055 WriteMessage("Cannot connect interpreter");
1062 * Allocates remote instance of interpreter
1063 * @param interp Interpreter slot
1064 * @param on Node Number
1066 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1071 m.msg_type = MSG_NET;
1072 m.param.pword[0] = NET_NODE_EXIST;
1073 m.param.pword[1] = on;
1074 m.param.pword[2] = interp->ID;
1075 write(net_sock, &m, sizeof(MESSAGE));
1076 bzero(&m, sizeof(MESSAGE));
1077 while((m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST))
1078 read(net_sock, &m, sizeof(MESSAGE));
1080 /* means node exists */
1081 if (m.param.pword[1] == 1) {
1082 m.msg_type = MSG_NET;
1083 m.param.pword[0] = NET_TRANSMIT_CODE;
1084 m.param.pword[1] = interp->ID;
1085 m.param.pword[2] = on;
1086 strcpy(m.param.pstr, interp->fullname);
1087 write(net_sock, &m, sizeof(MESSAGE));
1089 Net_Notify->setEnabled(FALSE);
1090 while ((m.msg_type != MSG_NET) ||
1091 (m.param.pword[0] != NET_TRANSMITTED))
1092 read(net_sock, &m, sizeof(MESSAGE));
1094 m.msg_type = MSG_NET;
1095 m.param.pword[0] = NET_PROPAGATE;
1096 m.param.pword[1] = MSG_VLP;
1097 m.param.pword[2] = NodeNumber;
1098 m.param.pword[3] = 0;
1099 m.param.pword[4] = on;
1100 m.param.pword[5] = 0;
1101 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1102 m.param.pword[7] = interp->ID;
1103 strcpy(m.param.pstr, interp->shortname);
1104 write(net_sock, &m, sizeof(MESSAGE));
1106 read(net_sock, &m, sizeof(MESSAGE));
1108 if ((m.param.pword[0] == NET_PROPAGATE) &&
1109 (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK)) {
1110 interp->RInstances[on] = m.param.pword[7];
1113 read(net_sock, &m, sizeof(MESSAGE));
1116 Net_Notify->setEnabled(TRUE);
1118 /*bzero(&m, sizeof(MESSAGE));*/
1119 m.msg_type = MSG_VLP;
1120 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1121 m.param.pword[1] = interp->RInstances[on];
1122 write(interp->sock, &m, sizeof(MESSAGE));
1123 } else { /* There is no such a node! */
1124 sprintf(s, "Warning: Node number %d not found!", on);
1126 WriteMessage("Allocating O-process on the local node");
1127 bzero(&m, sizeof(MESSAGE));
1128 m.msg_type = MSG_VLP;
1129 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1130 m.param.pword[1] = interp->ID;
1131 write(interp->sock, &m, sizeof(MESSAGE));
1136 * Closes all remote instances
1138 void QKernel::CloseInstances(InterpEntry *e)
1144 WriteMessage("Closing remote instances");
1146 for(i=0; i < MAXINSTANCES; i++)
1147 if (e->RInstances[i]>=0) {
1148 msg.msg_type = MSG_NET;
1149 msg.param.pword[0] = NET_PROPAGATE;
1150 msg.param.pword[1] = MSG_VLP;
1151 msg.param.pword[2] = NodeNumber;
1152 msg.param.pword[4] = i;
1153 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1154 msg.param.pword[7] = e->RInstances[i];
1155 write(net_sock, &msg, sizeof(MESSAGE));
1160 * Displays information about virtual machine
1162 void QKernel::on_actionInfo_triggered()
1166 WriteMessage(CharLine);
1167 WriteMessage("### Virtual Machine Information ###");
1168 m.msg_type = MSG_NET;
1169 m.param.pword[0] = NET_GET_INFO;
1170 write(net_sock, &m, sizeof(MESSAGE));
1171 wait_for_info = TRUE;
1175 * Program main function
1176 * All program arguments but the first one (argv[0]: program name) are saved and
1177 * passed to all dependent programs on their invocation.
1178 * @param argc Number of program arguments
1179 * @param argv Program arguments
1181 int main(int argc, char **argv)
1185 QApplication * app = new QApplication(argc, argv);
1186 QKernel kernel(argc, argv);
1188 kernel.InitMessage();