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 "kernelwindow.h"
72 /* File resides in top directory (where are Makefiles)*/
73 #include "../../config.h"
76 char CharLine[25] = "________________________";
79 * Event invoked on program close.
80 * Closes application. Displays additional window to confirm exit.
82 void QKernel::closeEvent(QCloseEvent * e)
87 on_actionQuit_triggered();
91 void QKernel::setLocked(bool locked)
95 actionQuit->setDisabled(locked);
97 actionExecute->setDisabled(locked);
98 actionKill->setDisabled(locked);
99 actionMessage->setDisabled(locked);
100 actionConnect->setDisabled(locked);
101 actionDisconnect->setDisabled(locked);
102 actionInfo->setDisabled(locked);
105 /* Enable only menu entry for unlocking */
106 actionEditor->setDisabled(locked);
107 actionOptions->setDisabled(locked);
108 actionLock_console->setDisabled(locked);
109 actionUnlock_console->setDisabled(!locked);
113 * Kernel program constructor.
114 * Prepares everything to work.
116 QKernel::QKernel(int argc, char **argv)
120 QString arg0(argv[0]);
122 homeDir = QDir(arg0);
127 for(i = 0; (i < 5) && (i < argc-1); i++) {
128 strcpy(myargs[i], "");
130 strcpy(myargs[i], argv[i+1]);
134 QDir q(getRemoteDir());
137 q.mkpath(getRemoteDir());
140 info_messages = TRUE;
141 wait_for_info = FALSE;
143 setWindowTitle(PACKAGE_NAME);
149 ActiveConnections = 0;
150 strcpy(LockPasswd, "");
151 loadConfig(getConfigFilePath());
154 Net_Notify = new QSocketNotifier(net_sock, QSocketNotifier::Read, this);
155 connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
158 QString QKernel::getConfigFilePath()
160 return homeDir.absoluteFilePath("vlp.cfg");
163 const char * QKernel::getHomeDir()
165 return homeDir.absolutePath().toStdString().c_str();
168 const char * QKernel::getRemoteDir()
170 return homeDir.absoluteFilePath(REMOTE_PATH).toStdString().c_str();
173 const char * QKernel::getNetModuleSocket()
175 return homeDir.absoluteFilePath(NPATH).toStdString().c_str();
178 const char * QKernel::getGraphModuleSocket()
180 return homeDir.absoluteFilePath(GPATH).toStdString().c_str();
183 void QKernel::loadConfig(const QString & fname)
185 loadConfig(fname.toStdString().c_str());
188 * Loads configuration from the given file.
189 * @param fname Filename of the configuration file.
191 void QKernel::loadConfig(const char * fname)
193 fprintf(stderr, "2: %s\n", fname);
195 config_setting_t *setting;
197 /* Hack for checking if file exists without using external libs.*/
199 FILE * file = fopen(fname, "rt");
201 fprintf(stderr, "Error: Cannot load configuration file: %s!\n",
205 /* File exists, so file has been locked. Release it. */
209 /* Read the file. If there is an error, report it and exit. */
210 if (!config_read(&cfg, file)) {
211 fprintf(stderr, "%s! In file %s, line %d\n",
212 config_error_text(&cfg),
213 config_error_file(&cfg),
214 config_error_line(&cfg));
215 config_destroy(&cfg);
220 setting = config_lookup(&cfg, "node_number");
222 NodeNumber = config_setting_get_int(setting);
224 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
225 "Warning", fname, "node_number");
226 config_destroy(&cfg);
231 setting = config_lookup(&cfg, "type");
233 /* same as strcmp(..) == 0 */
234 if (!strcmp(config_setting_get_string(setting), "explicit")) {
240 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
241 "Warning", fname, "type");
244 setting = config_lookup(&cfg, "host");
246 switch(config_setting_type(setting)) {
247 /* TODO: Deprecated. Made for back compatibility. */
248 case CONFIG_TYPE_STRING:
249 ConnectList.append(new ConnectEntry((char*)
250 config_setting_get_string(setting)));
252 case CONFIG_TYPE_ARRAY: {
253 int size = config_setting_length(setting);
254 for (int i = 0; i < size; i++) {
255 ConnectList.append(new ConnectEntry((char*)
256 config_setting_get_string_elem(setting,
262 fprintf(stderr, "%s! In file %s, bad entry type for %s."
263 " Will not be read.\n",
264 "Error", fname, "host");
267 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
268 "Warning", fname, "host");
271 setting = config_lookup(&cfg, "progdir");
273 strncpy(progdir, config_setting_get_string(setting), 256);
275 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
276 "Warning", fname, "progdir");
279 config_destroy(&cfg);
285 * Additional window id displayed to set which code to execute.
287 void QKernel::on_actionExecute_triggered()
290 QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
293 i = s.indexOf(".log");
298 RunIntModule((char*)s.toAscii().data(), 0);
303 * Invokes editor program
305 void QKernel::on_actionEditor_triggered()
307 QString program = getHomeDir();
308 program += "/modules/logedit";
312 if (execl(program.toStdString().c_str(),
321 WriteMessage("Executing logedit failed!");
327 * Invokes help program
329 void QKernel::on_actionHelp_triggered()
331 QString program = getHomeDir();
332 program += "/modules/loghelp";
334 QString docDir = getHomeDir();
339 if (execl(program.toStdString().c_str(),
340 docDir.toStdString().c_str(),
349 WriteMessage("Executing loghelp failed!");
355 * Invokes graphics module
357 void QKernel::RunGraphModule(char *sk)
361 QString program = getHomeDir();
362 program += "/modules/loggraph";
365 if (execl(program.toStdString().c_str(),
366 program.toStdString().c_str(),
376 WriteMessage("Executing loggraph failed!");
377 WriteMessage("Exiting...");
379 on_actionQuit_triggered();
383 WriteMessage("fork(loggraph) failed!");
384 WriteMessage("Exiting...");
386 on_actionQuit_triggered();
394 void QKernel::RunNetModule()
396 struct sockaddr_un svr;
401 QString program = getHomeDir();
402 program += "/modules/lognet";
406 if (execl(program.toStdString().c_str(),
407 program.toStdString().c_str(),
408 getNetModuleSocket(),
409 getConfigFilePath().toStdString().c_str(),
418 WriteMessage("Executing lognet failed!");
419 WriteMessage("Exiting...");
421 on_actionQuit_triggered();
425 WriteMessage("fork(lognet) failed!");
426 WriteMessage("Exiting...");
428 on_actionQuit_triggered();
432 /* -------- socket for NET module -------- */
433 unlink(getNetModuleSocket());
434 sock = socket(AF_UNIX, SOCK_STREAM, 0);
435 bzero(&svr, sizeof(svr));
436 svr.sun_family = AF_UNIX;
437 strcpy(svr.sun_path, getNetModuleSocket());
438 len = strlen(svr.sun_path) + sizeof(svr.sun_family);
439 bind(sock, (struct sockaddr*)&svr, len);
442 net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
445 WriteMessage("NETWORK successfully connected");
446 fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock, F_GETFL, 0));
448 setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
450 WriteMessage("Cannot connect NETWORK resources");
451 WriteMessage("Exiting...");
453 on_actionQuit_triggered();
458 * Connects to the specified address
459 * Additional window is displayed to connect to the specified address
461 void QKernel::on_actionConnect_triggered()
463 QDialog d(this, Qt::Dialog);
464 QLabel lab("IP Address:", &d);
465 QLineEdit ed("", &d);
466 QPushButton ob("", &d);
467 QPushButton cb("", &d);
470 ob.setGeometry(30, 60, 80, 30);
473 lab.setGeometry(10, 10, 60, 30);
474 lab.setText("Address");
475 ed.setGeometry(70, 10, 140, 30);
476 cb.setGeometry(130, 60, 80, 30);
477 cb.setText("Cancel");
480 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
481 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
483 m.msg_type = MSG_NET;
484 m.param.pword[0] = NET_CONNECT_TO;
485 strcpy(m.param.pstr, ed.text().toAscii().data());
486 write(net_sock, &m, sizeof(MESSAGE));
491 * Disconnects from virtual machine
493 void QKernel::on_actionDisconnect_triggered()
498 WriteMessage("Disconnecting from virtual machine");
500 msg.msg_type = MSG_NET;
501 msg.param.pword[0] = NET_DISCONNECT;
502 write(net_sock, &msg, sizeof(MESSAGE));
506 * Quits process. Closes VLP. Shows additional window to confirm exit.
508 void QKernel::on_actionQuit_triggered()
512 QMessageBox::StandardButton response = QMessageBox::question(this,
515 QMessageBox::Ok | QMessageBox::Cancel
519 if (response == QMessageBox::Cancel) {
523 msg.msg_type = MSG_NET;
524 msg.param.pword[0] = NET_DISCONNECT;
525 write(net_sock, &msg, sizeof(MESSAGE));*/
528 msg.msg_type = MSG_NET;
529 msg.param.pword[0] = NET_EXIT;
530 write(net_sock, &msg, sizeof(MESSAGE));
531 /* ::close(net_sock);*/
532 QApplication::instance()->quit();
536 * Sends message to node.
537 * Additional window is displayed to set Node Number of node where send message,
538 * and textfield to enter message.
540 void QKernel::on_actionMessage_triggered()
546 dlg = new QDialog(this, Qt::Dialog);
547 dlg->setWindowTitle("Send message to node");
549 nodenr = new QLineEdit("number", dlg);
550 nodenr->setGeometry(90, 10, 50, 30);
554 tmpQLabel = new QLabel("Node number:", dlg);
555 tmpQLabel->setGeometry(10, 10, 77, 30);
557 tmpQLabel = new QLabel("Message:", dlg);
558 tmpQLabel->setGeometry(10, 50, 70, 30);
561 msg = new QLineEdit("", dlg);
562 msg->setGeometry(80, 60, 330, 30);
565 ob = new QPushButton("Send", dlg);
566 ob->setGeometry(230, 10, 80, 30);
567 ob->setDefault(TRUE);
570 cb = new QPushButton("Cancel", dlg);
571 cb->setGeometry(330, 10, 80, 30);
572 dlg->resize(430, 110);
573 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
574 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
577 m.msg_type = MSG_NET;
578 m.param.pword[0] = NET_PROPAGATE;
579 m.param.pword[1] = MSG_VLP;
580 m.param.pword[2] = NodeNumber;
581 m.param.pword[4] = atoi(nodenr->text().toAscii().data());
582 m.param.pword[6] = VLP_WRITE;
583 strcpy(m.param.pstr, msg->text().toAscii().data());
584 write(net_sock, &m, sizeof(MESSAGE));
590 * Additional window is displayed to get ID of interpreter which should be
593 void QKernel::on_actionKill_triggered()
600 dlg = new QDialog(this, Qt::Dialog);
601 dlg->setWindowTitle("Kill interpreter");
603 nodenr = new QLineEdit("", dlg);
604 nodenr->setGeometry(90, 10, 50, 30);
606 QLabel * tmpQLabel = new QLabel("Interp. ID:", dlg);
607 tmpQLabel->setGeometry(10, 10, 77, 30);
609 QPushButton * ob = new QPushButton("Kill", dlg);
610 ob->setGeometry( 160, 10, 80, 30);
611 ob->setDefault(TRUE);
613 QPushButton * cb = new QPushButton("Cancel", dlg);
614 cb->setGeometry(260, 10, 80, 30);
615 dlg->resize(360, 50);
617 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
618 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
621 m.msg_type = MSG_INT;
622 m.param.pword[0] = INT_KILL;
623 pom = findINTbyID(atoi(nodenr->text().toAscii().data()));
626 write(pom->sock, &m, sizeof(MESSAGE));
628 WriteMessage("This is a remote instance of "
632 WriteMessage("Interpreter not found");
638 * Sends message to the net module.
640 void QKernel::NetMessage()
643 /* TODO: It has to be rewritten */
649 cnt = read(net_sock, &msg, sizeof(MESSAGE));
650 if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
651 switch(msg.param.pword[0]) {
653 WriteMessage(msg.param.pstr);
656 switch(msg.param.pword[1]) {
658 /* pom = find_link_by_ID(msg.param.pword[5]);
659 msg.msg_type = MSG_NET;
660 msg.param.pword[0] = NET_PROPAGATE;
661 send_int(pom, &msg);*/
664 switch(msg.param.pword[6]) {
666 QApplication::beep();
667 WriteMessage(CharLine);
669 "### Incoming Messsage ###");
670 sprintf(ss, "Mesg from Node %d: %s",
674 WriteMessage(CharLine);
676 case VLP_REMOTE_INSTANCE:
677 sprintf(ss, "%s/%s", getRemoteDir(),
681 WriteMessage("Running program:");
684 pom = RunIntModule(ss, 1);
686 pom->p_ctx.node = msg.param.pword[2];
687 pom->p_ctx.program_id =
689 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
692 case VLP_CLOSE_INSTANCE:
693 msg.msg_type = MSG_INT;
694 msg.param.pword[0] = INT_CLOSE_INSTANCE;
695 pom = findINTbyID(msg.param.pword[7]);
697 write(pom->sock, &msg,
700 m1.msg_type = MSG_VLP;
701 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
702 m1.param.pword[1] = pom->ID;
706 WriteMessage("Instance not found");
712 case NET_CONNECTIONS:
713 ActiveConnections = msg.param.pword[1];
714 WriteMessage(msg.param.pstr);
719 /* TODO: It has to be rewritten */
721 QString poms, poms1, poms2;
722 poms.sprintf("%s", msg.param.pstr);
723 while (poms.length() > 0) {
724 cnt = poms.indexOf(';');
726 poms1 = poms.left(cnt);
727 poms = poms.right(poms.length() - cnt - 1);
728 cnt = poms1.indexOf('=');
730 poms2 = poms1.left(cnt);
731 poms1 = poms1.right(poms1.length() - cnt - 1);
732 sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
740 wait_for_info = FALSE;
741 WriteMessage(CharLine);
748 * Sends message to the interpreter program.
749 * @param sock Interpreter socket to whom the message will be send.
751 void QKernel::IntMessage(int sock)
757 cnt = read(sock, &msg, sizeof(MESSAGE));
758 e = findINTbySocket(sock);
759 if ((cnt > 0) && (e != NULL)) {
760 switch (msg.msg_type) {
762 if (msg.param.pword[0] == GRAPH_ALLOCATE) {
763 RunGraphModule(msg.param.pstr);
767 write(net_sock, &msg, sizeof(MESSAGE));
770 switch(msg.param.pword[0]) {
771 case VLP_REMOTE_INSTANCE_PLEASE:
772 RemoteInstance(e, msg.param.pword[2]);
777 switch(msg.param.pword[0]) {
782 m.msg_type = MSG_VLP;
783 m.param.pword[0] = VLP_INTERPRETER_DOWN;
784 m.param.pword[1] = e->ID;
785 write(net_sock, &m, sizeof(MESSAGE));
790 /* TODO: Check this */
791 Interpreters.removeOne(e);
795 sprintf(ss, "%s : End of program "
796 "execution", msg.param.pstr);
801 msg.msg_type = MSG_INT;
802 msg.param.pword[0] = INT_CTX;
803 msg.param.pword[1] = NodeNumber;
804 msg.param.pword[2] = e->ID;
806 msg.param.pword[3] = e->p_ctx.node;
810 write(sock, &msg, sizeof(MESSAGE));
819 * Writes message to kernel logger.
820 * @parame msg String with message to log
822 void QKernel::WriteMessage(char *msg)
826 x = desktop->textCursor().blockNumber();
827 y = desktop->textCursor().columnNumber();
833 desktop->setReadOnly(FALSE);
834 desktop->append(msg);
835 desktop->setReadOnly(TRUE);
837 QTextCursor tmpCursor = desktop->textCursor();
838 tmpCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
839 desktop->setTextCursor(tmpCursor);
843 if (desktop->document()->blockCount() > 100) {
849 * Adds checkbox to menu item. If it is checked additional info messages are
852 void QKernel::on_actionInfo_messages_triggered()
854 if (toolsMenu != NULL) {
855 info_messages = !actionInfo_messages->isChecked();
856 actionInfo_messages->setChecked(info_messages);
857 fprintf(stderr, "Info is checked? %s\n", info_messages ? "yes" : "no");
862 * Allows to set options in GUI window.
863 * Additional window is displayed to set kernel options which are saved in
864 * vlp.cfg file in kernel executable directory.
866 void QKernel::on_actionOptions_triggered()
868 OptionsDialog optionsDialog(getConfigFilePath(), this);
869 if (optionsDialog.exec()) {
870 optionsDialog.saveConfig(getConfigFilePath());
872 loadConfig(getConfigFilePath());
877 * Locks kernel program.
878 * Additional window is displayed to enter password and retype it. If both are
879 * same kernel window is locked.
881 void QKernel::on_actionLock_console_triggered()
883 LockDialog lockDialog(this);
885 if (lockDialog.exec()) {
886 QString password = lockDialog.getPassword();
887 if (lockDialog.getPassword().size() > 0) {
888 strcpy(LockPasswd, password.toAscii().data());
891 if (lockDialog.exec()) {
892 password = lockDialog.getPassword();
893 if (password == LockPasswd) {
895 WriteMessage("CONSOLE LOCKED");
897 QMessageBox msg(this);
898 msg.setText("Not matching!");
899 msg.setButtonText(0, "Close");
901 strcpy(LockPasswd, "");
904 strcpy(LockPasswd, "");
911 * Unlocks kernel program.
912 * Additional window is displayed to enter password. If it is correct, kernel
915 void QKernel::on_actionUnlock_console_triggered()
917 QDialog d(this, Qt::Dialog);
918 d.setWindowTitle("Enter password");
920 QLabel lab("Password:", &d);
921 lab.setGeometry(10, 10, 60, 30);
923 QLineEdit ed("", &d);
924 ed.setGeometry(70, 10, 140, 30);
925 ed.setEchoMode(QLineEdit::Password);
927 QPushButton ob("Ok", &d);
928 ob.setGeometry(30, 60, 80, 30);
930 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
932 QPushButton cb("Cancel", &d);
933 cb.setGeometry(130, 60, 80, 30);
934 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
939 if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
941 WriteMessage("CONSOLE UNLOCKED");
943 QMessageBox msg(this);
944 msg.setText("Wrong password!");
945 msg.setButtonText(0, "Close");
952 * Writes init message in kernel
954 void QKernel::InitMessage()
956 WriteMessage("\n " PACKAGE_STRING ": READY \n");
960 * Finds Interpreter by its socket
961 * @param _id ID of the socket
962 * @return returns pointer to the found interpreter slot. NULL otherwise
964 InterpEntry *QKernel::findINTbySocket(int _id)
966 InterpEntry *pom = NULL;
968 for (int i = 0; i < Interpreters.size(); i++) {
969 if (Interpreters.at(i)->sock == _id) {
970 pom = Interpreters.at(i);
979 * Finds Interpreter by its ID.
980 * @param _id ID of the interpreter
981 * @return returns pointer to the found interpreter slot. NULL otherwise
983 InterpEntry *QKernel::findINTbyID(int _id)
985 InterpEntry *pom = NULL;
987 for (int i = 0; i < Interpreters.size(); i++) {
988 if (Interpreters.at(i)->ID == _id) {
989 pom = Interpreters.at(i);
999 * Connects interpreter
1000 * @param ss full filepath with filename but without extension of the loglan
1002 * @param r Interpreter execution mode. 0 if it will be local instance, 1 if
1004 * @return Returns pointer to newly created interpreter slot, or NULL on error.
1006 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1008 char a[256], b[255];
1009 struct sockaddr_un svr;
1016 InterpEntry *newINT = NULL;
1022 WriteMessage("File not found: no .ccd file");
1031 WriteMessage("File not found: no .pcd file");
1036 newINT = new InterpEntry;
1037 for(i = 0; i < MAXINSTANCES; i++)
1038 newINT->RInstances[i] =- 1;
1040 strcpy(b, rindex(ss, '/'));
1041 for(i = 0; i < strlen(b); i++)
1043 if (info_messages) {
1044 sprintf(a, "%s : Start execution", b);
1050 newINT->ID = newint;
1051 strcpy(newINT->shortname, b);
1052 strcpy(newINT->fullname, ss);
1054 sprintf(a, "%s%d", IPATH, newint);
1055 sprintf(cmd, "%s/modules/logint %s %s",
1062 sprintf(b, " %s %s %s %s %s",
1063 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
1067 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1069 bzero(&svr, sizeof(svr));
1070 svr.sun_family = AF_UNIX;
1071 strcpy(svr.sun_path, a);
1072 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1073 bind(sock, (struct sockaddr*)&svr, len);
1076 newINT->sock = accept(sock, (struct sockaddr*)0, (unsigned int *)0);
1079 if (newINT->sock > 0) {
1080 fcntl(newINT->sock, F_SETFL,
1081 O_NONBLOCK|fcntl(newINT->sock, F_GETFL, 0));
1083 setsockopt(newINT->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
1090 bzero(&msg, sizeof(MESSAGE));
1091 msg.msg_type = MSG_VLP;
1092 msg.param.pword[0] = VLP_REGINT;
1093 msg.param.pword[1] = newINT->ID;
1094 sprintf(msg.param.pstr, "logi%d.net", newint);
1095 write(net_sock, &msg, sizeof(MESSAGE));
1097 Interpreters.append(newINT);
1098 newINT->notify = new QSocketNotifier(newINT->sock,
1099 QSocketNotifier::Read);
1100 connect(newINT->notify, SIGNAL(activated(int)), this,
1101 SLOT(IntMessage(int)));
1103 WriteMessage("INTERPRETER successfully connected");
1105 WriteMessage("Cannot connect interpreter");
1112 * Allocates remote instance of interpreter
1113 * @param interp Interpreter slot
1114 * @param on Node Number
1116 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1121 m.msg_type = MSG_NET;
1122 m.param.pword[0] = NET_NODE_EXIST;
1123 m.param.pword[1] = on;
1124 m.param.pword[2] = interp->ID;
1125 write(net_sock, &m, sizeof(MESSAGE));
1126 bzero(&m, sizeof(MESSAGE));
1127 while((m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST))
1128 read(net_sock, &m, sizeof(MESSAGE));
1130 /* means node exists */
1131 if (m.param.pword[1] == 1) {
1132 m.msg_type = MSG_NET;
1133 m.param.pword[0] = NET_TRANSMIT_CODE;
1134 m.param.pword[1] = interp->ID;
1135 m.param.pword[2] = on;
1136 strcpy(m.param.pstr, interp->fullname);
1137 write(net_sock, &m, sizeof(MESSAGE));
1139 Net_Notify->setEnabled(FALSE);
1140 while ((m.msg_type != MSG_NET) ||
1141 (m.param.pword[0] != NET_TRANSMITTED))
1142 read(net_sock, &m, sizeof(MESSAGE));
1144 m.msg_type = MSG_NET;
1145 m.param.pword[0] = NET_PROPAGATE;
1146 m.param.pword[1] = MSG_VLP;
1147 m.param.pword[2] = NodeNumber;
1148 m.param.pword[3] = 0;
1149 m.param.pword[4] = on;
1150 m.param.pword[5] = 0;
1151 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1152 m.param.pword[7] = interp->ID;
1153 strcpy(m.param.pstr, interp->shortname);
1154 write(net_sock, &m, sizeof(MESSAGE));
1156 read(net_sock, &m, sizeof(MESSAGE));
1158 if ((m.param.pword[0] == NET_PROPAGATE) &&
1159 (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK)) {
1160 interp->RInstances[on] = m.param.pword[7];
1163 read(net_sock, &m, sizeof(MESSAGE));
1166 Net_Notify->setEnabled(TRUE);
1168 /*bzero(&m, sizeof(MESSAGE));*/
1169 m.msg_type = MSG_VLP;
1170 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1171 m.param.pword[1] = interp->RInstances[on];
1172 write(interp->sock, &m, sizeof(MESSAGE));
1173 } else { /* There is no such a node! */
1174 sprintf(s, "Warning: Node number %d not found!", on);
1176 WriteMessage("Allocating O-process on the local node");
1177 bzero(&m, sizeof(MESSAGE));
1178 m.msg_type = MSG_VLP;
1179 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1180 m.param.pword[1] = interp->ID;
1181 write(interp->sock, &m, sizeof(MESSAGE));
1186 * Closes all remote instances
1188 void QKernel::CloseInstances(InterpEntry *e)
1194 WriteMessage("Closing remote instances");
1196 for(i=0; i < MAXINSTANCES; i++)
1197 if (e->RInstances[i]>=0) {
1198 msg.msg_type = MSG_NET;
1199 msg.param.pword[0] = NET_PROPAGATE;
1200 msg.param.pword[1] = MSG_VLP;
1201 msg.param.pword[2] = NodeNumber;
1202 msg.param.pword[4] = i;
1203 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1204 msg.param.pword[7] = e->RInstances[i];
1205 write(net_sock, &msg, sizeof(MESSAGE));
1210 * Displays information about virtual machine
1212 void QKernel::on_actionInfo_triggered()
1216 WriteMessage(CharLine);
1217 WriteMessage("### Virtual Machine Information ###");
1218 m.msg_type = MSG_NET;
1219 m.param.pword[0] = NET_GET_INFO;
1220 write(net_sock, &m, sizeof(MESSAGE));
1221 wait_for_info = TRUE;
1225 * Program main function
1226 * All program arguments but the first one (argv[0]: program name) are saved and
1227 * passed to all dependent programs on their invocation.
1228 * @param argc Number of program arguments
1229 * @param argv Program arguments
1231 int main(int argc, char **argv)
1235 QApplication * app = new QApplication(argc, argv);
1236 QKernel kernel(argc, argv);
1238 kernel.InitMessage();