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 ************************************************************/
34 //#include <qwindow.h>
62 #include <qwindowsstyle.h>
72 #include <netinet/in.h>
74 #include <libconfig.h>
79 #define REMOTE_PATH "REMOTE"
81 #define MAXINSTANCES 256
89 char CharLine[25] = "________________________";
93 /* --------------- interpreter slot -----------------*/
106 QSocketNotifier *notify;
107 /* IDs of my remote INT modules */
108 int RInstances[MAXINSTANCES];
109 /* parent INT info */
112 /*++++++++++++++++++++++++++++++++++++++++++*/
114 /*----------------- connection slot -------------*/
119 ConnectEntry(char *s) {
124 /* ++++++++++++++++++++++++++++++++++++++++++ */
129 /* ---------------------------------------------------------- */
130 /* KERNEL CLASS DEFINITION */
131 /* ---------------------------------------------------------- */
133 class QKernel : public QFrame {
136 QMultiLineEdit *desktop;
147 virtual void resizeEvent(QResizeEvent *ev);
149 void WriteMessage(char* msg);
161 void UnlockConsole();
162 void MessageToNode();
165 void IntMessage(int);
166 void KillInterpreter();
173 virtual void closeEvent (QCloseEvent * e);
176 QList<InterpEntry> Interpreters;
177 QList<ConnectEntry> ConnectList;
178 QListBox *connections;
181 * number of working interpreters
186 * number of connected VLPs
188 int ActiveConnections;
206 QSocketNotifier *Net_Notify;
210 void LoadConfig(char *);
211 void RunGraphModule(char*);
213 InterpEntry *findINTbySocket(int);
214 InterpEntry *findINTbyID(int);
215 InterpEntry *RunIntModule(char *ss, int r);
216 void RemoteInstance(InterpEntry*, int);
217 void CloseInstances(InterpEntry*);
219 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
221 void QKernel::closeEvent (QCloseEvent * e)
228 QFont f("Helvetica", 10, QFont::Bold);
229 QFont f1("Helvetica", 10, QFont::Normal);
230 QFont f2("Times Roman", 10, QFont::Normal);
235 sprintf(ss, "mkdir %s", REMOTE_PATH);
239 info_messages = TRUE;
240 wait_for_info = FALSE;
242 setCaption("Virtual LOGLAN Processor");
243 setBackgroundColor(white);
245 bar = new QMenuBar(this);
247 p = new QPopupMenu();
249 p->insertItem("Execute", this, SLOT(Run_Prog()));
250 p->insertItem("Kill", this, SLOT(KillInterpreter()));
251 prid = bar->insertItem("&Program", p);
252 p1 = new QPopupMenu();
253 p1->insertItem("Message", this, SLOT(MessageToNode()));
254 p1->insertSeparator();
255 p1->insertItem("Connect", this, SLOT(Connect()));
256 p1->insertItem("Disconnect", this, SLOT(Disconnect()));
257 p1->insertItem("Info", this, SLOT(Info()));
259 mid = bar->insertItem("&Machine", p1);
261 p2 = new QPopupMenu();
262 cwid = p2->insertItem("Editor", this, SLOT(Edit()));
263 hid = p2->insertItem("Help", this, SLOT(Help()));
264 p2->insertSeparator();
265 optid = p2->insertItem("Options", this, SLOT(SetOptions()));
266 msgid = p2->insertItem("Info messages", this, SLOT(SetMessages()));
267 p2->setItemChecked(msgid, TRUE);
268 p2->insertSeparator();
269 lockid = p2->insertItem("Lock console", this, SLOT(LockConsole()));
270 unlockid = p2->insertItem("Unlock console", this,
271 SLOT(UnlockConsole()));
272 p2->setItemEnabled(unlockid, FALSE);
275 toolsid = bar->insertItem("&Tools", p2);
277 qid = bar->insertItem("&Quit", this, SLOT(QuitProc()));
280 desktop = new QMultiLineEdit(this, "desktop");
281 desktop->setAutoUpdate(TRUE);
282 desktop->setReadOnly(TRUE);
283 desktop->setFont(f1);
288 ActiveConnections = 0;
289 strcpy(LockPasswd, "");
290 LoadConfig("vlp.cfg");
293 Net_Notify = new QSocketNotifier(net_sock, QSocketNotifier::Read, this);
294 connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
297 void QKernel::resizeEvent(QResizeEvent *ev)
299 QFrame::resizeEvent(ev);
301 desktop->setGeometry(0, bar->height(), width(),
302 height() - bar->height());
305 void QKernel::n_impl()
307 QMessageBox::information(this, "Function info", "This function is not "
308 "implemented yet...", "Ok");
312 /* ########### load configuration from file ############# */
314 void QKernel::LoadConfig(char * fname)
317 config_setting_t *setting;
320 /* Hack for checking if file exists without using external libs.*/
321 FILE * file = fopen(fname, "rt");
323 fprintf(stderr, "Error: Cannot load configuration file %s!\n",
327 /* File exists, so file has been locked. Release it. */
331 /* Read the file. If there is an error, report it and exit. */
332 if (!config_read(&cfg, file)) {
333 fprintf(stderr, "%s! In file %s, line %d\n",
334 config_error_text(&cfg),
335 config_error_file(&cfg),
336 config_error_line(&cfg));
337 config_destroy(&cfg);
339 exit(3);/* from original code. */
342 setting = config_lookup(&cfg, "node_number");
344 NodeNumber = config_setting_get_int(setting);
346 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
347 "Warning", fname, "node_number");
348 config_destroy(&cfg);
353 setting = config_lookup(&cfg, "type");
355 /* same as strcmp(..) == 0 */
356 if (!strcmp(config_setting_get_string(setting), "explicit")) {
362 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
363 "Warning", fname, "type");
366 setting = config_lookup(&cfg, "host");
368 switch(config_setting_type(setting)) {
369 /* TODO: Deprecated. Made for back compatibility. */
370 case CONFIG_TYPE_STRING:
371 ConnectList.append(new ConnectEntry((char*)
372 config_setting_get_string(setting)));
374 case CONFIG_TYPE_ARRAY:
375 int length = config_setting_length(setting);
376 for (int i = 0; i < length; i++) {
377 ConnectList.append(new ConnectEntry((char*)
378 config_setting_get_string_elem(setting,
383 fprintf(stderr, "%s! In file %s, bad entry type for %s."
384 " Will not be read.\n",
385 "Error", fname, "host");
388 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
389 "Warning", fname, "host");
392 setting = config_lookup(&cfg, "progdir");
394 strncpy(progdir, config_setting_get_string(setting), 256);
396 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
397 "Warning", fname, "progdir");
400 setting = config_lookup(&cfg, "homedir");
402 strncpy(HomeDir, config_setting_get_string(setting), 255);
404 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
405 "Warning", fname, "homedir");
408 config_destroy(&cfg);
411 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
413 void QKernel::Run_Prog()
416 QString s(QFileDialog::getOpenFileName(progdir, "*.log", this));
424 RunIntModule((char*)s.ascii(), 0);
431 sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir,
432 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
439 sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir,
440 HomeDir, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
445 void QKernel::RunGraphModule(char *sk)
449 sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s", HomeDir, sk,
450 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
453 if (system(cmd) != 0)
454 WriteMessage("Cannot connect GRAPH resources");
459 void QKernel::RunNetModule()
461 struct sockaddr_un svr;
465 sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s", HomeDir, NPATH,
466 myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
469 /* -------- socket for NET module -------- */
471 sock = socket(AF_UNIX, SOCK_STREAM, 0);
472 bzero(&svr, sizeof(svr));
473 svr.sun_family = AF_UNIX;
474 strcpy(svr.sun_path, NPATH);
475 len = strlen(svr.sun_path) + sizeof(svr.sun_family);
476 bind(sock, (struct sockaddr*)&svr, len);
479 if (system(cmd) == 0) {
480 net_sock = accept(sock, (struct sockaddr*)0, (unsigned int*)0);
483 WriteMessage("NETWORK successfully connected");
484 fcntl(net_sock, F_SETFL, O_NONBLOCK|fcntl(net_sock,
487 setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY,
488 (char*)&on, sizeof(on));
490 WriteMessage("Cannot connect NETWORK resources");
491 WriteMessage("Exiting...");
497 WriteMessage("Cannot connect NETWORK resources");
498 WriteMessage("Exiting...");
504 void QKernel::Connect()
506 QDialog d(this, "", TRUE);
507 QLabel lab(&d, "IP Address:");
508 QLineEdit ed(&d, "");
509 QPushButton ob(&d, "");
510 QPushButton cb(&d, "");
513 d.setFont(QFont("Helvetica", 12, QFont::Bold));
514 ob.setGeometry(30, 60, 80, 30);
517 lab.setGeometry(10, 10, 60, 30);
518 lab.setText("Address");
519 ed.setGeometry(70, 10, 140, 30);
520 cb.setGeometry(130, 60, 80, 30);
521 cb.setText("Cancel");
524 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
525 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
527 m.msg_type = MSG_NET;
528 m.param.pword[0] = NET_CONNECT_TO;
529 strcpy(m.param.pstr, ed.text());
530 write(net_sock, &m, sizeof(MESSAGE));
534 void QKernel::Disconnect()
539 WriteMessage("Disconnecting from virtual machine");
541 msg.msg_type = MSG_NET;
542 msg.param.pword[0] = NET_DISCONNECT;
543 write(net_sock, &msg, sizeof(MESSAGE));
546 void QKernel::QuitProc()
550 if (QMessageBox::question(this, "Close VLP", "Terminate VLP ?",
551 QMessageBox::Yes, QMessageBox::No, 0) == QMessageBox::No) {
557 msg.msg_type = MSG_NET;
558 msg.param.pword[0] = NET_DISCONNECT;
559 write(net_sock, &msg, sizeof(MESSAGE));*/
562 msg.msg_type = MSG_NET;
563 msg.param.pword[0] = NET_EXIT;
564 write(net_sock, &msg, sizeof(MESSAGE));
565 /* ::close(net_sock);*/
570 void QKernel::AddAddress()
572 QDialog d(this, "", TRUE);
573 QLabel lab(&d, "IP Address:");
574 QLineEdit ed(&d, "");
575 QPushButton ob(&d, "");
576 QPushButton cb(&d, "");
579 ob.setGeometry(30, 60, 80, 30);
582 lab.setGeometry(10, 10, 60, 30);
583 lab.setText("Address");
584 ed.setGeometry(70, 10, 140, 30);
585 cb.setGeometry(130, 60, 80, 30);
586 cb.setText("Cancel");
588 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
589 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
591 if (strcmp(ed.text(), "") != 0) {
592 connections->insertItem(ed.text());
597 void QKernel::DelAddress()
600 if (connections->currentItem() != -1)
601 connections->removeItem(connections->currentItem());
605 void QKernel::MessageToNode()
611 dlg = new QDialog(this, "Message", TRUE);
613 nodenr = new QLineEdit(dlg, "number");
614 nodenr->setGeometry(90, 10, 50, 30);
618 tmpQLabel = new QLabel(dlg, "Label_1");
619 tmpQLabel->setGeometry(10, 10, 77, 30);
620 tmpQLabel->setText("Node number:");
622 tmpQLabel = new QLabel(dlg, "Label_2");
623 tmpQLabel->setGeometry(10, 50, 70, 30);
624 tmpQLabel->setText("Message:");
627 msg = new QLineEdit(dlg, "LineEdit_1");
628 msg->setGeometry(80, 60, 330, 30);
632 ob = new QPushButton(dlg, "PushButton_1");
633 ob->setGeometry(230, 10, 80, 30);
635 ob->setDefault(TRUE);
638 cb = new QPushButton(dlg, "PushButton_2");
639 cb->setGeometry(330, 10, 80, 30);
640 cb->setText("Cancel");
641 dlg->resize(430, 110);
642 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
643 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
644 dlg->setCaption("Send message to node");
647 m.msg_type = MSG_NET;
648 m.param.pword[0] = NET_PROPAGATE;
649 m.param.pword[1] = MSG_VLP;
650 m.param.pword[2] = NodeNumber;
651 m.param.pword[4] = atoi(nodenr->text());
652 m.param.pword[6] = VLP_WRITE;
653 strcpy(m.param.pstr, msg->text());
654 write(net_sock, &m, sizeof(MESSAGE));
658 void QKernel::KillInterpreter()
665 dlg = new QDialog(this, "Message", TRUE);
667 nodenr = new QLineEdit(dlg, "number");
668 nodenr->setGeometry(90, 10, 50, 30);
672 tmpQLabel = new QLabel(dlg, "Label_1");
673 tmpQLabel->setGeometry(10, 10, 77, 30);
674 tmpQLabel->setText("Interp. ID:");
675 QPushButton* ob, *cb;
676 ob = new QPushButton(dlg, "PushButton_1");
677 ob->setGeometry( 160, 10, 80, 30);
679 ob->setDefault(TRUE);
680 cb = new QPushButton(dlg, "PushButton_2");
681 cb->setGeometry(260, 10, 80, 30);
682 cb->setText("Cancel");
683 dlg->resize(360, 50);
684 connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
685 connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
686 dlg->setCaption("Kill interpreter");
688 m.msg_type = MSG_INT;
689 m.param.pword[0] = INT_KILL;
690 pom = findINTbyID(atoi(nodenr->text()));
693 write(pom->sock, &m, sizeof(MESSAGE));
695 WriteMessage("This is a remote instance of "
699 WriteMessage("Interpreter not found");
706 void QKernel::NetMessage()
709 /* TODO: It has to be rewritten */
715 cnt = read(net_sock, &msg, sizeof(MESSAGE));
716 if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
717 switch(msg.param.pword[0]) {
719 WriteMessage(msg.param.pstr);
722 switch(msg.param.pword[1]) {
724 /* pom = find_link_by_ID(msg.param.pword[5]);
725 msg.msg_type = MSG_NET;
726 msg.param.pword[0] = NET_PROPAGATE;
727 send_int(pom, &msg);*/
730 switch(msg.param.pword[6]) {
732 QApplication::beep();
733 WriteMessage(CharLine);
735 "### Incoming Messsage ###");
736 sprintf(ss, "Mesg from Node %d: %s",
740 WriteMessage(CharLine);
742 case VLP_REMOTE_INSTANCE:
743 sprintf(ss, "%s/%s", REMOTE_PATH,
747 WriteMessage("Running program:");
750 pom = RunIntModule(ss, 1);
752 pom->p_ctx.node = msg.param.pword[2];
753 pom->p_ctx.program_id =
755 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
758 case VLP_CLOSE_INSTANCE:
759 msg.msg_type = MSG_INT;
760 msg.param.pword[0] = INT_CLOSE_INSTANCE;
761 pom = findINTbyID(msg.param.pword[7]);
763 write(pom->sock, &msg,
766 m1.msg_type = MSG_VLP;
767 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
768 m1.param.pword[1] = pom->ID;
772 WriteMessage("Instance not found");
778 case NET_CONNECTIONS:
779 ActiveConnections = msg.param.pword[1];
780 WriteMessage(msg.param.pstr);
785 /* TODO: It has to be rewritten */
787 QString poms, poms1, poms2;
788 poms.sprintf("%s", msg.param.pstr);
789 while (poms.length() > 0) {
790 cnt = poms.find(';');
792 poms1 = poms.left(cnt);
793 poms = poms.right(poms.length() - cnt - 1);
794 cnt = poms1.find('=');
796 poms2 = poms1.left(cnt);
800 sprintf(ss, "Node: %s Addr: %s", poms2.data(), poms1.data());
808 wait_for_info = FALSE;
809 WriteMessage(CharLine);
815 void QKernel::IntMessage(int sock)
821 cnt = read(sock, &msg, sizeof(MESSAGE));
822 e = findINTbySocket(sock);
823 if ((cnt > 0) && (e != NULL)) {
824 switch (msg.msg_type) {
826 if (msg.param.pword[0] == GRAPH_ALLOCATE) {
827 RunGraphModule(msg.param.pstr);
831 write(net_sock, &msg, sizeof(MESSAGE));
834 switch(msg.param.pword[0]) {
835 case VLP_REMOTE_INSTANCE_PLEASE:
836 RemoteInstance(e, msg.param.pword[2]);
841 switch(msg.param.pword[0]) {
846 m.msg_type = MSG_VLP;
847 m.param.pword[0] = VLP_INTERPRETER_DOWN;
848 m.param.pword[1] = e->ID;
849 write(net_sock, &m, sizeof(MESSAGE));
854 Interpreters.remove(e);
858 sprintf(ss, "%s : End of program "
859 "execution", msg.param.pstr);
864 msg.msg_type = MSG_INT;
865 msg.param.pword[0] = INT_CTX;
866 msg.param.pword[1] = NodeNumber;
867 msg.param.pword[2] = e->ID;
869 msg.param.pword[3] = e->p_ctx.node;
873 write(sock, &msg, sizeof(MESSAGE));
876 break; /* switch param.pword[0] */
881 void QKernel::WriteMessage(char *msg)
886 desktop->getCursorPosition(&x, &y);
891 desktop->setReadOnly(FALSE);
892 desktop->append(msg);
893 desktop->setReadOnly(TRUE);
894 desktop->setCursorPosition(desktop->numLines(), 1);
897 if (desktop->numLines() > 100) {
902 void QKernel::SetMessages()
905 if (p2->isItemChecked(msgid)) {
906 p2->setItemChecked(msgid, FALSE);
909 p2->setItemChecked(msgid, TRUE);
913 /* bar->repaint(); */
916 void QKernel::SetOptions()
918 QDialog dlg(this, "Options", TRUE);
923 progs = new QLineEdit(&dlg, "progs");
924 progs->setGeometry(150, 20, 180, 30);
925 progs->setText(progdir);
928 tmpQLabel = new QLabel(&dlg, "Label_1");
929 tmpQLabel->setGeometry(30, 20, 120, 30);
930 tmpQLabel->setText("Programs directory");
933 tmpQFrame = new QFrame(&dlg, "Frame_2");
934 tmpQFrame->setGeometry(10, 60, 380, 30);
935 tmpQFrame->setFrameStyle(52);
937 tmpQLabel = new QLabel(&dlg, "Label_2");
938 tmpQLabel->setGeometry(10, 80, 340, 30);
939 tmpQLabel->setText("Virtual Processor properties (activated after "
944 nn = new QLineEdit(&dlg, "LineEdit_2");
945 nn->setGeometry(110, 110, 40, 30);
946 sprintf(nns, "%d", NodeNumber);
949 tmpQLabel = new QLabel(&dlg, "Label_3");
950 tmpQLabel->setGeometry(20, 110, 90, 30);
951 tmpQLabel->setText("Node number:");
953 QRadioButton *exp, *reg;
954 exp = new QRadioButton(&dlg, "RadioButton_3");
955 exp->setGeometry(30, 170, 100, 30);
956 exp->setText("Explicit");
957 exp->setChecked(TRUE);
959 reg = new QRadioButton(&dlg, "RadioButton_4");
960 reg->setGeometry(30, 200, 100, 30);
961 reg->setText("Registration");
962 reg->setEnabled(FALSE);
964 connections = new QListBox(&dlg, "ListBox_1");
965 connections->setGeometry(170, 140, 130, 100);
966 e = ConnectList.first();
968 connections->insertItem(e->addr);
969 e = ConnectList.next();
972 tmpQLabel = new QLabel(&dlg, "Label_5");
973 tmpQLabel->setGeometry(170, 110, 100, 30);
974 tmpQLabel->setText("Connection list:");
979 QPushButton *cancelbtn;
980 addbtn = new QPushButton(&dlg, "PushButton_1");
981 addbtn->setGeometry(310, 150, 60, 30);
982 addbtn->setText("Add");
983 delbtn = new QPushButton(&dlg, "PushButton_2");
984 delbtn->setGeometry(310, 200, 60, 30);
985 delbtn->setText("Del");
986 connect(addbtn, SIGNAL(clicked()), this, SLOT(AddAddress()));
987 connect(delbtn, SIGNAL(clicked()), this, SLOT(DelAddress()));
988 okbtn = new QPushButton(&dlg, "PushButton_3");
989 okbtn->setGeometry(80, 260, 100, 30);
990 okbtn->setText("Ok");
991 okbtn->setDefault(TRUE);
992 cancelbtn = new QPushButton(&dlg, "PushButton_4");
993 cancelbtn->setGeometry(210, 260, 100, 30);
994 cancelbtn->setText("Cancel");
995 connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
996 connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
998 group = new QButtonGroup(&dlg, "ButtonGroup_1");
999 group->setGeometry(20, 150, 120, 90);
1000 group->setTitle("Connection type");
1001 group->setAlignment(1);
1003 group->insert(exp, 1);
1004 group->insert(reg, 2);
1006 dlg.resize(400, 310);
1009 config_setting_t *root;
1010 config_setting_t *setting;
1013 root = config_root_setting(&cfg);
1015 setting = config_setting_add(root, "progdir",
1016 CONFIG_TYPE_STRING);
1017 config_setting_set_string(setting, progs->text().ascii());
1018 strcpy(progdir, progs->text());
1020 setting = config_setting_add(root, "node_number",
1022 config_setting_set_int(setting, atoi(nn->text()));
1024 setting = config_setting_add(root, "homedir",
1025 CONFIG_TYPE_STRING);
1026 config_setting_set_string(setting, HomeDir);
1028 setting = config_setting_add(root, "type",
1029 CONFIG_TYPE_STRING);
1030 if (exp->isChecked()) {
1031 config_setting_set_string(setting, "explicit");
1033 config_setting_t *hosts = NULL;
1034 hosts = config_setting_add(root, "host",
1036 for(i = 0; i < connections->count(); i++) {
1037 setting = config_setting_add(hosts, NULL,
1038 CONFIG_TYPE_STRING);
1039 config_setting_set_string(setting,
1040 connections->text(i).ascii());
1043 config_setting_set_string(setting, "register");
1046 if (!config_write_file(&cfg, "vlp.cfg")) {
1047 fprintf(stderr, "Error while writing to file: %s.\n",
1050 config_destroy(&cfg);
1054 void QKernel::LockConsole()
1056 QDialog d(this, "Enter password", TRUE);
1057 QLabel lab(&d, "Password");
1058 QLineEdit ed(&d, "");
1059 QPushButton ob(&d, "");
1060 QPushButton cb(&d, "");
1062 d.setCaption("Lock console");
1063 ob.setGeometry(30, 60, 80, 30);
1065 ob.setDefault(TRUE);
1066 lab.setGeometry(10, 10, 60, 30);
1067 lab.setText("Password:");
1068 ed.setGeometry(70, 10, 140, 30);
1069 ed.setEchoMode(QLineEdit::Password);
1070 cb.setGeometry(130, 60, 80, 30);
1071 cb.setText("Cancel");
1073 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
1074 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
1077 if (strcmp(ed.text(), "") != 0) {
1078 strcpy(LockPasswd, ed.text());
1079 lab.setText("Retype:");
1082 if (strcmp(ed.text(), LockPasswd)==0) {
1083 bar->setItemEnabled(qid, FALSE);
1084 bar->setItemEnabled(prid, FALSE);
1085 bar->setItemEnabled(mid, FALSE);
1086 p2->setItemEnabled(unlockid, TRUE);
1087 p2->setItemEnabled(lockid, FALSE);
1088 p2->setItemEnabled(cwid, FALSE);
1089 p2->setItemEnabled(optid, FALSE);
1091 WriteMessage("CONSOLE LOCKED");
1094 QMessageBox msg(this);
1095 msg.setText("Not matching!");
1096 msg.setButtonText(0, "Close");
1100 strcpy(LockPasswd, "");
1106 void QKernel::UnlockConsole()
1108 QDialog d(this, "Enter password", TRUE);
1109 QLabel lab(&d, "Password");
1110 QLineEdit ed(&d, "");
1111 QPushButton ob(&d, "");
1112 QPushButton cb(&d, "");
1114 ob.setGeometry(30, 60, 80, 30);
1116 ob.setDefault(TRUE);
1117 lab.setGeometry(10, 10, 60, 30);
1118 lab.setText("Password:");
1119 ed.setGeometry(70, 10, 140, 30);
1120 ed.setEchoMode(QLineEdit::Password);
1121 cb.setGeometry(130, 60, 80, 30);
1122 cb.setText("Cancel");
1124 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
1125 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
1128 if (strcmp(ed.text(), LockPasswd) == 0) {
1129 bar->setItemEnabled(qid, TRUE);
1130 bar->setItemEnabled(prid, TRUE);
1131 bar->setItemEnabled(mid, TRUE);
1132 p2->setItemEnabled(unlockid, FALSE);
1133 p2->setItemEnabled(lockid, TRUE);
1134 p2->setItemEnabled(cwid, TRUE);
1135 p2->setItemEnabled(optid, TRUE);
1137 WriteMessage("CONSOLE UNLOCKED");
1140 QMessageBox msg(this);
1141 msg.setText("Wrong password!");
1142 msg.setButtonText(0, "Close");
1148 void QKernel::InitMessage()
1150 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1153 InterpEntry *QKernel::findINTbySocket(int _id)
1156 pom = Interpreters.first();
1158 while (pom != NULL) {
1159 if (pom->sock == _id)
1162 pom = Interpreters.next();
1167 InterpEntry *QKernel::findINTbyID(int _id)
1170 pom = Interpreters.first();
1171 while (pom != NULL) {
1174 pom = Interpreters.next();
1180 /* ------------------ Connect INT module -----------------*/
1182 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1184 char a[256], b[255];
1185 struct sockaddr_un svr;
1186 int len, sock, i, on;
1191 InterpEntry *newINT = NULL;
1197 WriteMessage("File not found: no .ccd file");
1206 WriteMessage("File not found: no .pcd file");
1211 newINT = new InterpEntry;
1212 for(i = 0; i < MAXINSTANCES; i++)
1213 newINT->RInstances[i] =- 1;
1215 strcpy(b, rindex(ss, '/'));
1216 for(i = 0; i < strlen(b); i++)
1218 if (info_messages) {
1219 sprintf(a, "%s : Start execution", b);
1225 newINT->ID = newint;
1226 strcpy(newINT->shortname, b);
1227 strcpy(newINT->fullname, ss);
1229 sprintf(a, "%s%d", IPATH, newint);
1230 sprintf(cmd, "%s/modules/logint %s %s", HomeDir, a, ss);
1233 sprintf(b, " %s %s %s %s %s", myargs[0], myargs[1], myargs[2],
1234 myargs[3], myargs[4]);
1238 sock = socket(AF_UNIX, SOCK_STREAM, 0);
1240 bzero(&svr, sizeof(svr));
1241 svr.sun_family = AF_UNIX;
1242 strcpy(svr.sun_path, a);
1243 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1244 bind(sock, (struct sockaddr*)&svr, len);
1247 newINT->sock = accept(sock, (struct sockaddr*)0, (unsigned int *)0);
1250 if (newINT->sock > 0) {
1251 fcntl(newINT->sock, F_SETFL,
1252 O_NONBLOCK|fcntl(newINT->sock, F_GETFL, 0));
1254 setsockopt(newINT->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
1261 bzero(&msg, sizeof(MESSAGE));
1262 msg.msg_type = MSG_VLP;
1263 msg.param.pword[0] = VLP_REGINT;
1264 msg.param.pword[1] = newINT->ID;
1265 sprintf(msg.param.pstr, "logi%d.net", newint);
1266 write(net_sock, &msg, sizeof(MESSAGE));
1268 Interpreters.append(newINT);
1269 newINT->notify = new QSocketNotifier(newINT->sock,
1270 QSocketNotifier::Read);
1271 connect(newINT->notify, SIGNAL(activated(int)), this,
1272 SLOT(IntMessage(int)));
1274 WriteMessage("INTERPRETER successfully connected");
1276 WriteMessage("Cannot connect interpreter");
1282 /* ---------------------------------------------------------*/
1283 /* Allocate remote instance */
1285 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1290 m.msg_type = MSG_NET;
1291 m.param.pword[0] = NET_NODE_EXIST;
1292 m.param.pword[1] = on;
1293 m.param.pword[2] = interp->ID;
1294 write(net_sock, &m, sizeof(MESSAGE));
1295 bzero(&m, sizeof(MESSAGE));
1296 while((m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST))
1297 read(net_sock, &m, sizeof(MESSAGE));
1299 /* means node exists */
1300 if (m.param.pword[1] == 1) {
1301 m.msg_type = MSG_NET;
1302 m.param.pword[0] = NET_TRANSMIT_CODE;
1303 m.param.pword[1] = interp->ID;
1304 m.param.pword[2] = on;
1305 strcpy(m.param.pstr, interp->fullname);
1306 write(net_sock, &m, sizeof(MESSAGE));
1308 Net_Notify->setEnabled(FALSE);
1309 while ((m.msg_type != MSG_NET) ||
1310 (m.param.pword[0] != NET_TRANSMITTED))
1311 read(net_sock, &m, sizeof(MESSAGE));
1313 m.msg_type = MSG_NET;
1314 m.param.pword[0] = NET_PROPAGATE;
1315 m.param.pword[1] = MSG_VLP;
1316 m.param.pword[2] = NodeNumber;
1317 m.param.pword[3] = 0;
1318 m.param.pword[4] = on;
1319 m.param.pword[5] = 0;
1320 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1321 m.param.pword[7] = interp->ID;
1322 strcpy(m.param.pstr, interp->shortname);
1323 write(net_sock, &m, sizeof(MESSAGE));
1325 read(net_sock, &m, sizeof(MESSAGE));
1327 if ((m.param.pword[0] == NET_PROPAGATE) &&
1328 (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK)) {
1329 interp->RInstances[on] = m.param.pword[7];
1332 read(net_sock, &m, sizeof(MESSAGE));
1335 Net_Notify->setEnabled(TRUE);
1337 /*bzero(&m, sizeof(MESSAGE));*/
1338 m.msg_type = MSG_VLP;
1339 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1340 m.param.pword[1] = interp->RInstances[on];
1341 write(interp->sock, &m, sizeof(MESSAGE));
1342 } else { /* There is no such a node! */
1343 sprintf(s, "Warning: Node number %d not found!", on);
1345 WriteMessage("Allocating O-process on the local node");
1346 bzero(&m, sizeof(MESSAGE));
1347 m.msg_type = MSG_VLP;
1348 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1349 m.param.pword[1] = interp->ID;
1350 write(interp->sock, &m, sizeof(MESSAGE));
1355 /*-----------------------------------------------*/
1356 /* Close all remote instances */
1358 void QKernel::CloseInstances(InterpEntry *e)
1364 WriteMessage("Closing remote instances");
1366 for(i=0; i < MAXINSTANCES; i++)
1367 if (e->RInstances[i]>=0) {
1368 msg.msg_type = MSG_NET;
1369 msg.param.pword[0] = NET_PROPAGATE;
1370 msg.param.pword[1] = MSG_VLP;
1371 msg.param.pword[2] = NodeNumber;
1372 msg.param.pword[4] = i;
1373 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1374 msg.param.pword[7] = e->RInstances[i];
1375 write(net_sock, &msg, sizeof(MESSAGE));
1380 void QKernel::Info()
1384 WriteMessage(CharLine);
1385 WriteMessage("### Virtual Machine Information ###");
1386 m.msg_type = MSG_NET;
1387 m.param.pword[0] = NET_GET_INFO;
1388 write(net_sock, &m, sizeof(MESSAGE));
1389 wait_for_info = TRUE;
1392 #include "kernel.moc"
1394 int main(int argc, char **argv)
1397 for(i=0; i < 5; i++) {
1398 strcpy(myargs[i], "");
1400 for(i=1; i < argc; i++) {
1401 strcpy(myargs[i-1], argv[i]);
1404 app = new QApplication(argc, argv);
1405 app->setStyle(new QWindowsStyle());
1407 app->setMainWidget(&kernel);