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 ************************************************************/
68 #include "../head/genint1.h"
69 #include "../head/comm.h"
71 #include <netinet/in.h>
76 #define REMOTE_PATH "REMOTE"
78 #define MAXINSTANCES 256
86 char CharLine[25]="________________________";
90 /* --------------- interpreter slot -----------------*/
94 int ID; // INT identifier
95 bool remote; // Am I remote ?
96 char fullname[255],shortname[255]; // Program name
98 QSocketNotifier *notify;
99 int RInstances[MAXINSTANCES]; // IDs of my remote INT modules
100 ctx_struct p_ctx; // parent INT info
102 /*++++++++++++++++++++++++++++++++++++++++++*/
104 /*----------------- connection slot -------------*/
109 ConnectEntry(char *s) {strcpy(addr,s);};
112 /* ++++++++++++++++++++++++++++++++++++++++++ */
117 /* ---------------------------------------------------------- */
118 /* KERNEL CLASS DEFINITION */
119 /* ---------------------------------------------------------- */
121 class QKernel : public QFrame
126 QMultiLineEdit *desktop;
128 QPopupMenu *p,*p1,*p2;
130 int NodeNumber,ConType;
136 virtual void resizeEvent( QResizeEvent *ev );
138 void WriteMessage(char* msg);
152 void UnlockConsole();
153 void MessageToNode();
156 void IntMessage(int);
157 void KillInterpreter();
166 QList<InterpEntry> Interpreters;
167 QList<ConnectEntry> ConnectList;
168 QListBox *connections;
169 int Tasks; // number of working interpreters
170 int ActiveConnections; // number of connected VLPs
171 bool LOCKED,synchro,wait_for_info;
173 int lockid,unlockid,qid,cwid,
174 optid,prid,mid,msgid,toolsid,hid;
177 QSocketNotifier *Net_Notify;
183 void RunGraphModule(char*);
185 InterpEntry *findINTbySocket(int);
186 InterpEntry *findINTbyID(int);
187 InterpEntry *RunIntModule(char *ss,int r);
188 void RemoteInstance(InterpEntry*,int);
189 void CloseInstances(InterpEntry*);
193 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
197 QFont f("Helvetica",12,QFont::Bold);
198 QFont f1("Helvetica",12,QFont::Normal);
199 QFont f2("Times Roman",12,QFont::Normal);
205 sprintf(ss,"mkdir %s",REMOTE_PATH);
212 setCaption("Virtual LOGLAN Processor");
213 setBackgroundColor(white);
215 bar = new QMenuBar(this);
217 p = new QPopupMenu();
219 p->insertItem("Execute",this,SLOT(Run_Prog()));
220 p->insertItem("Kill",this,SLOT(KillInterpreter()));
221 prid = bar->insertItem("&Program",p);
222 p1 = new QPopupMenu();
223 p1->insertItem("Message",this,SLOT(MessageToNode()));
224 p1->insertSeparator();
225 p1->insertItem("Connect",this,SLOT(Connect()));
226 p1->insertItem("Disconnect",this,SLOT(Disconnect()));
227 p1->insertItem("Info",this,SLOT(Info()));
229 mid = bar->insertItem("&Machine",p1);
231 p2 = new QPopupMenu();
232 cwid = p2->insertItem("Editor",this,SLOT(Edit()));
233 hid = p2->insertItem("Help",this,SLOT(Help()));
234 p2->insertSeparator();
235 optid = p2->insertItem("Options",this,SLOT(SetOptions()));
236 msgid = p2->insertItem("Info messages",this,SLOT(SetMessages()));
237 p2->setItemChecked(msgid,TRUE);
238 p2->insertSeparator();
239 lockid = p2->insertItem("Lock console",this,SLOT(LockConsole()));
240 unlockid = p2->insertItem("Unlock console",this,SLOT(UnlockConsole()));
241 p2->setItemEnabled(unlockid,FALSE);
244 toolsid = bar->insertItem("&Tools",p2);
246 qid = bar->insertItem("&Quit",this,SLOT(QuitProc()));
249 desktop = new QMultiLineEdit(this,"desktop");
250 desktop->setAutoUpdate(TRUE);
251 desktop->setReadOnly(TRUE);
252 desktop->setFont(f1);
257 ActiveConnections = 0;
258 strcpy(LockPasswd,"");
262 Net_Notify = new QSocketNotifier(net_sock,QSocketNotifier::Read,this);
263 connect(Net_Notify,SIGNAL(activated(int)),this,SLOT(NetMessage()));
268 void QKernel::resizeEvent( QResizeEvent *ev )
270 QFrame::resizeEvent(ev);
272 desktop->setGeometry( 0,bar->height(), width(), height() - bar->height() );
278 void QKernel::n_impl()
280 QMessageBox::information(this,"Function info","This function is not implemented
285 /* ########### load configuration from file ############# */
287 void QKernel::LoadConfig()
290 char line[256],val[255];
294 WriteMessage("Cannot load configuration file!");sleep(2);exit(3);
297 f.readLine(line,256);
300 if (line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
301 strcpy(line,strtok(line,"="));
302 strcpy(val, strtok(NULL,"="));
303 if (strcmp(line,"node_number")==0) {NodeNumber = atoi(val);};
304 if (strcmp(line,"type")==0) {if (strcmp(val,"explicit")==0) ConType=1; else
306 if (strcmp(line,"host")==0) {ConnectList.append(new ConnectEntry(val));};
307 if (strcmp(line,"progdir")==0) {strcpy(progdir,val);};
308 if (strcmp(line,"homedir")==0) {strcpy(HomeDir,val);};
309 f.readLine(line,256);
313 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
316 void QKernel::Run_Prog()
319 QString s(QFileDialog::getOpenFileName(progdir,"*.log",this));
323 if (i>0) s.remove(i,4);
324 RunIntModule(s.data(),0);
332 sprintf(cmd,"%s/modules/logedit %s %s %s %s %s %s &",HomeDir,HomeDir,
333 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
340 sprintf(cmd,"%s/modules/loghelp %s/doc %s %s %s %s %s &",HomeDir,HomeDir,
341 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
346 void QKernel::RunGraphModule(char *sk)
351 sprintf(cmd,"%s/modules/loggraph %s %s %s %s %s %s",HomeDir,sk,
352 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
356 WriteMessage("Cannot connect GRAPH resources");
362 void QKernel::RunNetModule()
364 struct sockaddr_un svr;
370 sprintf(cmd,"%s/modules/lognet %s %s %s %s %s %s",HomeDir,NPATH,
371 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
374 /* -------- socket for NET module -------- */
376 sock = socket(AF_UNIX,SOCK_STREAM,0);
377 bzero(&svr,sizeof(svr));
378 svr.sun_family = AF_UNIX;
379 strcpy(svr.sun_path,NPATH);
380 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
381 bind(sock,(struct sockaddr*)&svr, len);
384 if ( system(cmd) == 0)
386 net_sock = accept(sock,(struct sockaddr*)0,(unsigned int*)0);
390 WriteMessage("NETWORK successfully connected");
391 fcntl(net_sock,F_SETFL, O_NONBLOCK|fcntl(net_sock,F_GETFL,0));
393 setsockopt(net_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
397 WriteMessage("Cannot connect NETWORK resources");
398 WriteMessage("Exiting...");
405 WriteMessage("Cannot connect NETWORK resources");
406 WriteMessage("Exiting...");
414 void QKernel::Connect()
416 QDialog d(this,"",TRUE);
417 QLabel lab(&d,"IP Address:");
419 QPushButton ob(&d,""),cb(&d,"");
422 d.setFont(QFont("Helvetica",12,QFont::Bold));
423 ob.setGeometry( 30, 60, 80, 30 );
426 lab.setGeometry( 10, 10, 60, 30 );
427 lab.setText( "Address" );
428 ed.setGeometry( 70, 10, 140, 30 );
429 cb.setGeometry( 130, 60, 80, 30 );
430 cb.setText( "Cancel" );
431 d.resize( 240, 100 );
433 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
434 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
437 m.msg_type = MSG_NET;
438 m.param.pword[0] = NET_CONNECT_TO;
439 strcpy(m.param.pstr,ed.text());
440 write(net_sock,&m,sizeof(MESSAGE));
445 void QKernel::Disconnect()
449 if (info_messages) WriteMessage("Disconnecting from virtual machine");
450 msg.msg_type = MSG_NET;
451 msg.param.pword[0] = NET_DISCONNECT;
452 write(net_sock,&msg,sizeof(MESSAGE));
455 void QKernel::QuitProc()
462 msg.msg_type = MSG_NET;
463 msg.param.pword[0] = NET_DISCONNECT;
464 write(net_sock,&msg,sizeof(MESSAGE));*/
469 msg.msg_type = MSG_NET;
470 msg.param.pword[0] = NET_EXIT;
471 write(net_sock,&msg,sizeof(MESSAGE));
472 // ::close(net_sock);
481 void QKernel::AddAddress()
483 QDialog d(this,"",TRUE);
484 QLabel lab(&d,"IP Address:");
486 QPushButton ob(&d,""),cb(&d,"");
490 ob.setGeometry( 30, 60, 80, 30 );
493 lab.setGeometry( 10, 10, 60, 30 );
494 lab.setText( "Address" );
495 ed.setGeometry( 70, 10, 140, 30 );
496 cb.setGeometry( 130, 60, 80, 30 );
497 cb.setText( "Cancel" );
498 d.resize( 240, 100 );
499 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
500 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
502 if (strcmp(ed.text(),"")!=0)
504 connections->insertItem(ed.text());
509 void QKernel::DelAddress()
513 if (connections->currentItem()!=-1)
514 connections->removeItem(connections->currentItem());
520 void QKernel::MessageToNode()
527 dlg = new QDialog(this,"Message",TRUE);
529 nodenr = new QLineEdit(dlg,"number");
530 nodenr->setGeometry( 90, 10, 50, 30 );
534 tmpQLabel = new QLabel( dlg, "Label_1" );
535 tmpQLabel->setGeometry( 10, 10, 77, 30 );
536 tmpQLabel->setText( "Node number:" );
538 tmpQLabel = new QLabel( dlg, "Label_2" );
539 tmpQLabel->setGeometry( 10, 50, 70, 30 );
540 tmpQLabel->setText( "Message:" );
543 msg = new QLineEdit( dlg, "LineEdit_1" );
544 msg->setGeometry( 80, 60, 330, 30 );
548 ob = new QPushButton( dlg, "PushButton_1" );
549 ob->setGeometry( 230, 10, 80, 30 );
550 ob->setText( "Send" );
551 ob->setDefault(TRUE);
552 cb = new QPushButton( dlg, "PushButton_2" );
553 cb->setGeometry( 330, 10, 80, 30 );
554 cb->setText( "Cancel" );
555 dlg->resize( 430, 110 );
556 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
557 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
558 dlg->setCaption("Send message to node");
562 m.msg_type = MSG_NET;
563 m.param.pword[0] = NET_PROPAGATE;
564 m.param.pword[1] = MSG_VLP;
565 m.param.pword[2] = NodeNumber;
566 m.param.pword[4] = atoi(nodenr->text());
567 m.param.pword[6] = VLP_WRITE;
568 strcpy(m.param.pstr,msg->text());
569 write(net_sock,&m,sizeof(MESSAGE));
573 void QKernel::KillInterpreter()
580 dlg = new QDialog(this,"Message",TRUE);
582 nodenr = new QLineEdit(dlg,"number");
583 nodenr->setGeometry( 90, 10, 50, 30 );
587 tmpQLabel = new QLabel( dlg, "Label_1" );
588 tmpQLabel->setGeometry( 10, 10, 77, 30 );
589 tmpQLabel->setText( "Interp. ID:" );
591 ob = new QPushButton( dlg, "PushButton_1" );
592 ob->setGeometry( 160, 10, 80, 30 );
593 ob->setText( "Kill" );
594 ob->setDefault(TRUE);
595 cb = new QPushButton( dlg, "PushButton_2" );
596 cb->setGeometry( 260, 10, 80, 30 );
597 cb->setText( "Cancel" );
598 dlg->resize( 360, 50 );
599 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
600 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
601 dlg->setCaption("Kill interpreter");
605 m.msg_type = MSG_INT;
606 m.param.pword[0] = INT_KILL;
607 pom = findINTbyID(atoi(nodenr->text()));
611 write(pom->sock,&m,sizeof(MESSAGE));
612 else WriteMessage("This is a remote instance of a program!");
614 else WriteMessage("Interpreter not found");
622 void QKernel::NetMessage()
629 cnt = read(net_sock,&msg,sizeof(MESSAGE));
630 if ( (cnt>0) && (msg.msg_type==MSG_NET))
632 switch(msg.param.pword[0])
634 case NET_CSWRITELN: WriteMessage(msg.param.pstr);break;
636 switch(msg.param.pword[1])
639 /* pom = find_link_by_ID(msg.param.pword[5]);
640 msg.msg_type = MSG_NET;
641 msg.param.pword[0] = NET_PROPAGATE;
642 send_int(pom,&msg);*/
645 switch(msg.param.pword[6])
648 QApplication::beep();
649 WriteMessage(CharLine);
650 WriteMessage("### Incoming Messsage ###");
651 sprintf(ss,"Mesg from Node %d: %s",msg.param.pword[2],msg.param.pstr);
653 WriteMessage(CharLine);
655 case VLP_REMOTE_INSTANCE:
656 sprintf(ss,"%s/%s",REMOTE_PATH,msg.param.pstr);
659 WriteMessage("Running program:");
662 pom = RunIntModule(ss,1);
665 pom->p_ctx.node = msg.param.pword[2];
666 pom->p_ctx.program_id = msg.param.pword[7];
667 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
670 case VLP_CLOSE_INSTANCE:
671 msg.msg_type = MSG_INT;
672 msg.param.pword[0] = INT_CLOSE_INSTANCE;
673 pom = findINTbyID(msg.param.pword[7]);
676 write(pom->sock,&msg,sizeof(MESSAGE));
678 m1.msg_type = MSG_VLP;
679 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
680 m1.param.pword[1] = pom->ID;
681 write(net_sock,&m1,sizeof(MESSAGE));
682 } else WriteMessage("Instance not found");
688 case NET_CONNECTIONS: ActiveConnections = msg.param.pword[1];
689 WriteMessage(msg.param.pstr);
690 if (!synchro) synchro=TRUE;
695 QString poms,poms1,poms2;
696 poms.sprintf("%s",msg.param.pstr);
697 while (poms.length()>0)
701 { poms1=poms.left(cnt);
702 poms=poms.right(poms.length()-cnt-1);
706 poms2=poms1.left(cnt);
707 poms1=poms1.right(poms1.length()-cnt-1);
708 sprintf(ss,"Node: %s Addr: %s",poms2.data(),poms1.data());
715 case NET_INFO_END:wait_for_info=FALSE;
716 WriteMessage(CharLine);
726 void QKernel::IntMessage(int sock)
732 cnt = read(sock,&msg,sizeof(MESSAGE));
733 e = findINTbySocket(sock);
734 if ( (cnt>0) && (e!=NULL))
736 switch (msg.msg_type)
739 if (msg.param.pword[0]==GRAPH_ALLOCATE)
741 RunGraphModule(msg.param.pstr);
745 write(net_sock,&msg,sizeof(MESSAGE));break;
747 switch(msg.param.pword[0])
749 case VLP_REMOTE_INSTANCE_PLEASE:
750 RemoteInstance(e,msg.param.pword[2]);
755 switch(msg.param.pword[0]){
761 m.msg_type = MSG_VLP;
762 m.param.pword[0] = VLP_INTERPRETER_DOWN;
763 m.param.pword[1] = e->ID;
764 write(net_sock,&m,sizeof(MESSAGE));
765 if (e->remote==0) CloseInstances(e);
768 Interpreters.remove(e);
772 sprintf(ss,"%s : End of program execution",msg.param.pstr);
778 msg.msg_type = MSG_INT;
779 msg.param.pword[0] = INT_CTX;
780 msg.param.pword[1] = NodeNumber;
781 msg.param.pword[2] = e->ID;
784 msg.param.pword[3] = e->p_ctx.node;
785 msg.param.pword[4] = e->p_ctx.program_id;
787 write(sock,&msg,sizeof(MESSAGE));
789 };break; /* switch param.pword[0] */
795 void QKernel::WriteMessage(char *msg)
799 desktop->getCursorPosition(&x,&y);
800 if (x>100) desktop->clear();
801 desktop->setReadOnly(FALSE);
802 desktop->append(msg);
803 desktop->setReadOnly(TRUE);
804 desktop->setCursorPosition(desktop->numLines(),1);
806 if (desktop->numLines()>100) desktop->clear();
809 void QKernel::SetMessages()
814 if ( p2->isItemChecked(msgid))
816 p2->setItemChecked(msgid,FALSE);
821 p2->setItemChecked(msgid,TRUE);
828 void QKernel::SetOptions()
830 QDialog dlg(this,"Options",TRUE);
838 progs = new QLineEdit( &dlg, "progs" );
839 progs->setGeometry( 150, 20, 180, 30 );
840 progs->setText(progdir);
843 tmpQLabel = new QLabel( &dlg, "Label_1" );
844 tmpQLabel->setGeometry( 30, 20, 120, 30 );
845 tmpQLabel->setText( "Programs directory" );
848 tmpQFrame = new QFrame( &dlg, "Frame_2" );
849 tmpQFrame->setGeometry( 10, 60, 380, 30 );
850 tmpQFrame->setFrameStyle( 52 );
852 tmpQLabel = new QLabel( &dlg, "Label_2" );
853 tmpQLabel->setGeometry( 10, 80, 340, 30 );
854 tmpQLabel->setText( "Virtual Processor properties (activated after restarting VLP):" );
858 nn = new QLineEdit( &dlg, "LineEdit_2" );
859 nn->setGeometry( 110, 110, 40, 30 );
860 sprintf(nns,"%d",NodeNumber);
863 tmpQLabel = new QLabel( &dlg, "Label_3" );
864 tmpQLabel->setGeometry( 20, 110, 90, 30 );
865 tmpQLabel->setText( "Node number:" );
867 QRadioButton *exp,*reg;
868 exp = new QRadioButton( &dlg, "RadioButton_3" );
869 exp->setGeometry( 30, 170, 100, 30 );
870 exp->setText( "Explicit" );
871 exp->setChecked( TRUE );
873 reg = new QRadioButton( &dlg, "RadioButton_4" );
874 reg->setGeometry( 30, 200, 100, 30 );
875 reg->setText( "Registration" );
876 reg->setEnabled(FALSE);
878 connections = new QListBox( &dlg, "ListBox_1" );
879 connections->setGeometry( 170, 140, 130, 100 );
880 e = ConnectList.first();
883 connections->insertItem(e->addr);
884 e = ConnectList.next();
887 tmpQLabel = new QLabel( &dlg, "Label_5" );
888 tmpQLabel->setGeometry( 170, 110, 100, 30 );
889 tmpQLabel->setText( "Connection list:" );
891 QPushButton* addbtn,*delbtn,*okbtn,*cancelbtn;
892 addbtn = new QPushButton( &dlg, "PushButton_1" );
893 addbtn->setGeometry( 310, 150, 60, 30 );
894 addbtn->setText( "Add" );
895 delbtn = new QPushButton( &dlg, "PushButton_2" );
896 delbtn->setGeometry( 310, 200, 60, 30 );
897 delbtn->setText( "Del" );
898 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddAddress()));
899 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelAddress()));
900 okbtn = new QPushButton( &dlg, "PushButton_3" );
901 okbtn->setGeometry( 80, 260, 100, 30 );
902 okbtn->setText( "Ok" );
903 okbtn->setDefault(TRUE);
904 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
905 cancelbtn->setGeometry( 210, 260, 100, 30 );
906 cancelbtn->setText( "Cancel" );
907 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
908 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
910 group = new QButtonGroup( &dlg, "ButtonGroup_1" );
911 group->setGeometry( 20, 150, 120, 90 );
912 group->setTitle( "Connection type" );
913 group->setAlignment( 1 );
915 group->insert(exp,1);
916 group->insert(reg,2);
918 dlg.resize( 400, 310 );
922 vlp_file = new QFile("vlp.cfg");
923 vlp_file->open(IO_WriteOnly);
924 sprintf(line,"progdir=%s\n",progs->text());
925 vlp_file->writeBlock(line,strlen(line));
926 strcpy(progdir,progs->text());
927 sprintf(line,"node_number=%d\n",atoi(nn->text()));
928 vlp_file->writeBlock(line,strlen(line));
929 if ( exp->isChecked())
931 sprintf(line,"type=explicit\n");
932 vlp_file->writeBlock(line,strlen(line));
933 for(i=0;i<connections->count();i++)
935 sprintf(line,"host=%s\n",connections->text(i));
936 vlp_file->writeBlock(line,strlen(line));
942 sprintf(line,"type=register\n");
943 vlp_file->writeBlock(line,strlen(line));
950 void QKernel::LockConsole()
952 QDialog d(this,"Enter password",TRUE);
953 QLabel lab(&d,"Password");
955 QPushButton ob(&d,""),cb(&d,"");
957 d.setCaption("Lock console");
958 ob.setGeometry( 30, 60, 80, 30 );
961 lab.setGeometry( 10, 10, 60, 30 );
962 lab.setText( "Password:" );
963 ed.setGeometry( 70, 10, 140, 30 );
964 ed.setEchoMode(QLineEdit::Password);
965 cb.setGeometry( 130, 60, 80, 30 );
966 cb.setText( "Cancel" );
967 d.resize( 240, 100 );
968 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
969 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
972 if (strcmp(ed.text(),"")!=0)
974 strcpy(LockPasswd,ed.text());
975 lab.setText("Retype:");
979 if (strcmp(ed.text(),LockPasswd)==0)
981 bar->setItemEnabled(qid,FALSE);
982 bar->setItemEnabled(prid,FALSE);
983 bar->setItemEnabled(mid,FALSE);
984 p2->setItemEnabled(unlockid,TRUE);
985 p2->setItemEnabled(lockid,FALSE);
986 p2->setItemEnabled(cwid,FALSE);
987 p2->setItemEnabled(optid,FALSE);
989 WriteMessage("CONSOLE LOCKED");
994 QMessageBox msg(this);
995 msg.setText("Not matching!");
996 msg.setButtonText("Close");
1001 else strcpy(LockPasswd,"");
1005 void QKernel::UnlockConsole()
1007 QDialog d(this,"Enter password",TRUE);
1008 QLabel lab(&d,"Password");
1009 QLineEdit ed(&d,"");
1010 QPushButton ob(&d,""),cb(&d,"");
1012 ob.setGeometry( 30, 60, 80, 30 );
1014 ob.setDefault(TRUE);
1015 lab.setGeometry( 10, 10, 60, 30 );
1016 lab.setText( "Password:" );
1017 ed.setGeometry( 70, 10, 140, 30 );
1018 ed.setEchoMode(QLineEdit::Password);
1019 cb.setGeometry( 130, 60, 80, 30 );
1020 cb.setText( "Cancel" );
1021 d.resize( 240, 100 );
1022 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1023 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1027 if (strcmp(ed.text(),LockPasswd)==0)
1029 bar->setItemEnabled(qid,TRUE);
1030 bar->setItemEnabled(prid,TRUE);
1031 bar->setItemEnabled(mid,TRUE);
1032 p2->setItemEnabled(unlockid,FALSE);
1033 p2->setItemEnabled(lockid,TRUE);
1034 p2->setItemEnabled(cwid,TRUE);
1035 p2->setItemEnabled(optid,TRUE);
1037 WriteMessage("CONSOLE UNLOCKED");
1042 QMessageBox msg(this);
1043 msg.setText("Wrong password!");
1044 msg.setButtonText("Close");
1051 void QKernel::InitMessage()
1053 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1058 InterpEntry *QKernel::findINTbySocket(int _id)
1061 pom = Interpreters.first();
1064 if (pom->sock == _id) break;
1065 pom = Interpreters.next();
1070 InterpEntry *QKernel::findINTbyID(int _id)
1073 pom = Interpreters.first();
1076 if (pom->ID == _id) break;
1077 pom = Interpreters.next();
1083 /* ------------------ Connect INT module -----------------*/
1085 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1088 struct sockaddr_un svr;
1094 InterpEntry *newINT;
1103 if (cf == NULL) {WriteMessage("File not found: no .ccd file");return(NULL);}
1109 if (cf == NULL) {WriteMessage("File not found: no .pcd file");return(NULL);}
1112 newINT = new InterpEntry;
1113 for(i=0;i<MAXINSTANCES;i++) newINT->RInstances[i]=-1;
1115 strcpy(b,rindex(ss,'/'));
1116 for(i=0;i<strlen(b);i++)
1120 sprintf(a,"%s : Start execution",b);
1124 newint = freeINTid; freeINTid++;
1125 newINT->ID = newint;
1126 strcpy(newINT->shortname,b);
1127 strcpy(newINT->fullname,ss);
1129 sprintf(a,"%s%d",IPATH,newint);
1130 sprintf(cmd,"%s/modules/logint %s %s",HomeDir,a,ss);
1131 if (r) strcat(cmd," r");
1132 sprintf(b," %s %s %s %s %s",myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
1137 sock = socket(AF_UNIX,SOCK_STREAM,0);
1139 bzero(&svr, sizeof(svr));
1140 svr.sun_family = AF_UNIX;
1141 strcpy(svr.sun_path,a);
1142 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1143 bind(sock,(struct sockaddr*)&svr, len);
1146 newINT->sock = accept(sock,(struct sockaddr*)0,(unsigned int *)0);
1153 fcntl(newINT->sock,F_SETFL,
1154 O_NONBLOCK|fcntl(newINT->sock,F_GETFL,0));
1156 setsockopt(newINT->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
1157 if (r) newINT->remote = 1;else newINT->remote=0;
1159 bzero(&msg,sizeof(MESSAGE));
1160 msg.msg_type = MSG_VLP;
1161 msg.param.pword[0] = VLP_REGINT;
1162 msg.param.pword[1] = newINT->ID;
1163 sprintf(msg.param.pstr,"logi%d.net",newint);
1164 write(net_sock,&msg,sizeof(MESSAGE));
1166 Interpreters.append(newINT);
1167 newINT->notify = new QSocketNotifier(newINT->sock,QSocketNotifier::Read);
1168 connect(newINT->notify,SIGNAL(activated(int)),this,SLOT(IntMessage(int)));
1169 if (info_messages) WriteMessage("INTERPRETER successfully connected");
1172 else WriteMessage("Cannot connect interpreter");
1178 /* ---------------------------------------------------------*/
1179 /* Allocate remote instance */
1181 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1187 m.msg_type = MSG_NET;
1188 m.param.pword[0] = NET_NODE_EXIST;
1189 m.param.pword[1] = on;
1190 m.param.pword[2] = interp->ID;
1191 write(net_sock,&m,sizeof(MESSAGE));
1192 bzero(&m,sizeof(MESSAGE));
1193 while( (m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST) )
1194 read(net_sock,&m,sizeof(MESSAGE));
1196 if (m.param.pword[1]==1) /* means node exists */
1198 m.msg_type = MSG_NET;
1199 m.param.pword[0] = NET_TRANSMIT_CODE;
1200 m.param.pword[1] = interp->ID;
1201 m.param.pword[2] = on;
1202 strcpy(m.param.pstr,interp->fullname);
1203 write(net_sock,&m,sizeof(MESSAGE));
1205 Net_Notify->setEnabled(FALSE);
1206 while ( (m.msg_type != MSG_NET) || (m.param.pword[0]!=NET_TRANSMITTED) )
1207 read(net_sock,&m,sizeof(MESSAGE));
1210 m.msg_type = MSG_NET;
1211 m.param.pword[0] = NET_PROPAGATE;
1212 m.param.pword[1] = MSG_VLP;
1213 m.param.pword[2] = NodeNumber;
1214 m.param.pword[3] = 0;
1215 m.param.pword[4] = on;
1216 m.param.pword[5] = 0;
1217 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1218 m.param.pword[7] = interp->ID;
1219 strcpy(m.param.pstr,interp->shortname);
1220 write(net_sock,&m,sizeof(MESSAGE));
1222 read(net_sock,&m,sizeof(MESSAGE));
1225 if ( (m.param.pword[0]==NET_PROPAGATE) && (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK))
1227 interp->RInstances[on] = m.param.pword[7];
1230 read(net_sock,&m,sizeof(MESSAGE));
1233 Net_Notify->setEnabled(TRUE);
1235 /*bzero(&m,sizeof(MESSAGE));*/
1236 m.msg_type = MSG_VLP;
1237 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1238 m.param.pword[1] = interp->RInstances[on];
1239 write(interp->sock,&m,sizeof(MESSAGE));
1241 else /* There is no such a node! */
1243 sprintf(s,"Warning: Node number %d not found!",on);
1245 WriteMessage("Allocating O-process on the local node");
1246 bzero(&m,sizeof(MESSAGE));
1247 m.msg_type = MSG_VLP;
1248 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1249 m.param.pword[1] = interp->ID;
1250 write(interp->sock,&m,sizeof(MESSAGE));
1255 /*-----------------------------------------------*/
1256 /* Close all remote instances */
1258 void QKernel::CloseInstances(InterpEntry *e)
1263 if (info_messages) WriteMessage("Closing remote instances");
1264 for(i=0;i<MAXINSTANCES;i++)
1265 if (e->RInstances[i]>=0)
1267 msg.msg_type = MSG_NET;
1268 msg.param.pword[0] = NET_PROPAGATE;
1269 msg.param.pword[1] = MSG_VLP;
1270 msg.param.pword[2] = NodeNumber;
1271 msg.param.pword[4] = i;
1272 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1273 msg.param.pword[7] = e->RInstances[i];
1274 write(net_sock,&msg,sizeof(MESSAGE));
1279 void QKernel::Info()
1283 WriteMessage(CharLine);
1284 WriteMessage("### Virtual Machine Information ###");
1285 m.msg_type = MSG_NET;
1286 m.param.pword[0]=NET_GET_INFO;
1287 write(net_sock,&m,sizeof(MESSAGE));
1288 wait_for_info = TRUE;
1291 #include "kernel.moc"
1293 int main( int argc, char **argv )
1296 for(i=0;i<5;i++) strcpy(myargs[i],"");
1297 for(i=1;i<argc;i++) strcpy(myargs[i-1],argv[i]);
1299 app = new QApplication(argc,argv);
1300 app->setStyle(WindowsStyle);
1302 app->setMainWidget( &draw);