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>
70 #include "../head/comm.h"
72 #include <netinet/in.h>
77 #define REMOTE_PATH "REMOTE"
79 #define MAXINSTANCES 256
87 char CharLine[25]="________________________";
91 /* --------------- interpreter slot -----------------*/
95 int ID; // INT identifier
96 bool remote; // Am I remote ?
97 char fullname[255],shortname[255]; // Program name
99 QSocketNotifier *notify;
100 int RInstances[MAXINSTANCES]; // IDs of my remote INT modules
101 ctx_struct p_ctx; // parent INT info
103 /*++++++++++++++++++++++++++++++++++++++++++*/
105 /*----------------- connection slot -------------*/
110 ConnectEntry(char *s) {strcpy(addr,s);};
113 /* ++++++++++++++++++++++++++++++++++++++++++ */
118 /* ---------------------------------------------------------- */
119 /* KERNEL CLASS DEFINITION */
120 /* ---------------------------------------------------------- */
122 class QKernel : public QFrame
127 QMultiLineEdit *desktop;
129 QPopupMenu *p,*p1,*p2;
131 int NodeNumber,ConType;
137 virtual void resizeEvent( QResizeEvent *ev );
139 void WriteMessage(char* msg);
153 void UnlockConsole();
154 void MessageToNode();
157 void IntMessage(int);
158 void KillInterpreter();
165 virtual void closeEvent ( QCloseEvent * e );
168 QList<InterpEntry> Interpreters;
169 QList<ConnectEntry> ConnectList;
170 QListBox *connections;
171 int Tasks; // number of working interpreters
172 int ActiveConnections; // number of connected VLPs
173 bool LOCKED,synchro,wait_for_info;
175 int lockid,unlockid,qid,cwid,
176 optid,prid,mid,msgid,toolsid,hid;
179 QSocketNotifier *Net_Notify;
185 void RunGraphModule(char*);
187 InterpEntry *findINTbySocket(int);
188 InterpEntry *findINTbyID(int);
189 InterpEntry *RunIntModule(char *ss,int r);
190 void RemoteInstance(InterpEntry*,int);
191 void CloseInstances(InterpEntry*);
195 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
197 void QKernel::closeEvent ( QCloseEvent * e ) {
203 QFont f("Helvetica",10,QFont::Bold);
204 QFont f1("Helvetica",10,QFont::Normal);
205 QFont f2("Times Roman",10,QFont::Normal);
211 sprintf(ss,"mkdir %s",REMOTE_PATH);
218 setCaption("Virtual LOGLAN Processor");
219 setBackgroundColor(white);
221 bar = new QMenuBar(this);
223 p = new QPopupMenu();
225 p->insertItem("Execute",this,SLOT(Run_Prog()));
226 p->insertItem("Kill",this,SLOT(KillInterpreter()));
227 prid = bar->insertItem("&Program",p);
228 p1 = new QPopupMenu();
229 p1->insertItem("Message",this,SLOT(MessageToNode()));
230 p1->insertSeparator();
231 p1->insertItem("Connect",this,SLOT(Connect()));
232 p1->insertItem("Disconnect",this,SLOT(Disconnect()));
233 p1->insertItem("Info",this,SLOT(Info()));
235 mid = bar->insertItem("&Machine",p1);
237 p2 = new QPopupMenu();
238 cwid = p2->insertItem("Editor",this,SLOT(Edit()));
239 hid = p2->insertItem("Help",this,SLOT(Help()));
240 p2->insertSeparator();
241 optid = p2->insertItem("Options",this,SLOT(SetOptions()));
242 msgid = p2->insertItem("Info messages",this,SLOT(SetMessages()));
243 p2->setItemChecked(msgid,TRUE);
244 p2->insertSeparator();
245 lockid = p2->insertItem("Lock console",this,SLOT(LockConsole()));
246 unlockid = p2->insertItem("Unlock console",this,SLOT(UnlockConsole()));
247 p2->setItemEnabled(unlockid,FALSE);
250 toolsid = bar->insertItem("&Tools",p2);
252 qid = bar->insertItem("&Quit",this,SLOT(QuitProc()));
255 desktop = new QMultiLineEdit(this,"desktop");
256 desktop->setAutoUpdate(TRUE);
257 desktop->setReadOnly(TRUE);
258 desktop->setFont(f1);
263 ActiveConnections = 0;
264 strcpy(LockPasswd,"");
268 Net_Notify = new QSocketNotifier(net_sock,QSocketNotifier::Read,this);
269 connect(Net_Notify,SIGNAL(activated(int)),this,SLOT(NetMessage()));
274 void QKernel::resizeEvent( QResizeEvent *ev )
276 QFrame::resizeEvent(ev);
278 desktop->setGeometry( 0,bar->height(), width(), height() - bar->height() );
284 void QKernel::n_impl()
286 QMessageBox::information(this,"Function info","This function is not implemented yet...","Ok");
290 /* ########### load configuration from file ############# */
292 void QKernel::LoadConfig()
301 WriteMessage("Cannot load configuration file!");sleep(2);exit(3);
304 br = f.readLine(line,256);
307 QStringList l = QStringList::split("=",line,FALSE);
308 QStringList::Iterator it = l.begin();
312 val = val.stripWhiteSpace();
313 if (line == "node_number") {NodeNumber = val.toInt();};
314 if (line == "type") {if (val=="explicit") ConType=1; else
316 if (line == "host" ) {ConnectList.append(new ConnectEntry((char*)val.ascii()));};
317 if (line == "progdir") { strcpy(progdir,val.ascii());};
318 if (line == "homedir") { strcpy(HomeDir,val.ascii());};
319 br = f.readLine(line,256);
323 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
326 void QKernel::Run_Prog()
329 QString s(QFileDialog::getOpenFileName(progdir,"*.log",this));
333 if (i>0) s.remove(i,4);
334 RunIntModule((char*)s.ascii(),0);
342 sprintf(cmd,"%s/modules/logedit %s %s %s %s %s %s &",HomeDir,HomeDir,
343 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
350 sprintf(cmd,"%s/modules/loghelp %s/doc %s %s %s %s %s &",HomeDir,HomeDir,
351 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
356 void QKernel::RunGraphModule(char *sk)
361 sprintf(cmd,"%s/modules/loggraph %s %s %s %s %s %s",HomeDir,sk,
362 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
366 WriteMessage("Cannot connect GRAPH resources");
372 void QKernel::RunNetModule()
374 struct sockaddr_un svr;
380 sprintf(cmd,"%s/modules/lognet %s %s %s %s %s %s",HomeDir,NPATH,
381 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
384 /* -------- socket for NET module -------- */
386 sock = socket(AF_UNIX,SOCK_STREAM,0);
387 bzero(&svr,sizeof(svr));
388 svr.sun_family = AF_UNIX;
389 strcpy(svr.sun_path,NPATH);
390 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
391 bind(sock,(struct sockaddr*)&svr, len);
394 if ( system(cmd) == 0)
396 net_sock = accept(sock,(struct sockaddr*)0,(unsigned int*)0);
400 WriteMessage("NETWORK successfully connected");
401 fcntl(net_sock,F_SETFL, O_NONBLOCK|fcntl(net_sock,F_GETFL,0));
403 setsockopt(net_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
407 WriteMessage("Cannot connect NETWORK resources");
408 WriteMessage("Exiting...");
415 WriteMessage("Cannot connect NETWORK resources");
416 WriteMessage("Exiting...");
424 void QKernel::Connect()
426 QDialog d(this,"",TRUE);
427 QLabel lab(&d,"IP Address:");
429 QPushButton ob(&d,""),cb(&d,"");
432 d.setFont(QFont("Helvetica",12,QFont::Bold));
433 ob.setGeometry( 30, 60, 80, 30 );
436 lab.setGeometry( 10, 10, 60, 30 );
437 lab.setText( "Address" );
438 ed.setGeometry( 70, 10, 140, 30 );
439 cb.setGeometry( 130, 60, 80, 30 );
440 cb.setText( "Cancel" );
441 d.resize( 240, 100 );
443 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
444 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
447 m.msg_type = MSG_NET;
448 m.param.pword[0] = NET_CONNECT_TO;
449 strcpy(m.param.pstr,ed.text());
450 write(net_sock,&m,sizeof(MESSAGE));
455 void QKernel::Disconnect()
459 if (info_messages) WriteMessage("Disconnecting from virtual machine");
460 msg.msg_type = MSG_NET;
461 msg.param.pword[0] = NET_DISCONNECT;
462 write(net_sock,&msg,sizeof(MESSAGE));
465 void QKernel::QuitProc()
469 if ( QMessageBox::question(this,"Close VLP","Terminate VLP ?",QMessageBox::Yes,QMessageBox::No,0) == QMessageBox::No ) return;
473 msg.msg_type = MSG_NET;
474 msg.param.pword[0] = NET_DISCONNECT;
475 write(net_sock,&msg,sizeof(MESSAGE));*/
480 msg.msg_type = MSG_NET;
481 msg.param.pword[0] = NET_EXIT;
482 write(net_sock,&msg,sizeof(MESSAGE));
483 // ::close(net_sock);
492 void QKernel::AddAddress()
494 QDialog d(this,"",TRUE);
495 QLabel lab(&d,"IP Address:");
497 QPushButton ob(&d,""),cb(&d,"");
501 ob.setGeometry( 30, 60, 80, 30 );
504 lab.setGeometry( 10, 10, 60, 30 );
505 lab.setText( "Address" );
506 ed.setGeometry( 70, 10, 140, 30 );
507 cb.setGeometry( 130, 60, 80, 30 );
508 cb.setText( "Cancel" );
509 d.resize( 240, 100 );
510 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
511 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
513 if (strcmp(ed.text(),"")!=0)
515 connections->insertItem(ed.text());
520 void QKernel::DelAddress()
524 if (connections->currentItem()!=-1)
525 connections->removeItem(connections->currentItem());
531 void QKernel::MessageToNode()
538 dlg = new QDialog(this,"Message",TRUE);
540 nodenr = new QLineEdit(dlg,"number");
541 nodenr->setGeometry( 90, 10, 50, 30 );
545 tmpQLabel = new QLabel( dlg, "Label_1" );
546 tmpQLabel->setGeometry( 10, 10, 77, 30 );
547 tmpQLabel->setText( "Node number:" );
549 tmpQLabel = new QLabel( dlg, "Label_2" );
550 tmpQLabel->setGeometry( 10, 50, 70, 30 );
551 tmpQLabel->setText( "Message:" );
554 msg = new QLineEdit( dlg, "LineEdit_1" );
555 msg->setGeometry( 80, 60, 330, 30 );
559 ob = new QPushButton( dlg, "PushButton_1" );
560 ob->setGeometry( 230, 10, 80, 30 );
561 ob->setText( "Send" );
562 ob->setDefault(TRUE);
563 cb = new QPushButton( dlg, "PushButton_2" );
564 cb->setGeometry( 330, 10, 80, 30 );
565 cb->setText( "Cancel" );
566 dlg->resize( 430, 110 );
567 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
568 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
569 dlg->setCaption("Send message to node");
573 m.msg_type = MSG_NET;
574 m.param.pword[0] = NET_PROPAGATE;
575 m.param.pword[1] = MSG_VLP;
576 m.param.pword[2] = NodeNumber;
577 m.param.pword[4] = atoi(nodenr->text());
578 m.param.pword[6] = VLP_WRITE;
579 strcpy(m.param.pstr,msg->text());
580 write(net_sock,&m,sizeof(MESSAGE));
584 void QKernel::KillInterpreter()
591 dlg = new QDialog(this,"Message",TRUE);
593 nodenr = new QLineEdit(dlg,"number");
594 nodenr->setGeometry( 90, 10, 50, 30 );
598 tmpQLabel = new QLabel( dlg, "Label_1" );
599 tmpQLabel->setGeometry( 10, 10, 77, 30 );
600 tmpQLabel->setText( "Interp. ID:" );
602 ob = new QPushButton( dlg, "PushButton_1" );
603 ob->setGeometry( 160, 10, 80, 30 );
604 ob->setText( "Kill" );
605 ob->setDefault(TRUE);
606 cb = new QPushButton( dlg, "PushButton_2" );
607 cb->setGeometry( 260, 10, 80, 30 );
608 cb->setText( "Cancel" );
609 dlg->resize( 360, 50 );
610 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
611 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
612 dlg->setCaption("Kill interpreter");
616 m.msg_type = MSG_INT;
617 m.param.pword[0] = INT_KILL;
618 pom = findINTbyID(atoi(nodenr->text()));
622 write(pom->sock,&m,sizeof(MESSAGE));
623 else WriteMessage("This is a remote instance of a program!");
625 else WriteMessage("Interpreter not found");
633 void QKernel::NetMessage()
640 cnt = read(net_sock,&msg,sizeof(MESSAGE));
641 if ( (cnt>0) && (msg.msg_type==MSG_NET))
643 switch(msg.param.pword[0])
645 case NET_CSWRITELN: WriteMessage(msg.param.pstr);break;
647 switch(msg.param.pword[1])
650 /* pom = find_link_by_ID(msg.param.pword[5]);
651 msg.msg_type = MSG_NET;
652 msg.param.pword[0] = NET_PROPAGATE;
653 send_int(pom,&msg);*/
656 switch(msg.param.pword[6])
659 QApplication::beep();
660 WriteMessage(CharLine);
661 WriteMessage("### Incoming Messsage ###");
662 sprintf(ss,"Mesg from Node %d: %s",msg.param.pword[2],msg.param.pstr);
664 WriteMessage(CharLine);
666 case VLP_REMOTE_INSTANCE:
667 sprintf(ss,"%s/%s",REMOTE_PATH,msg.param.pstr);
670 WriteMessage("Running program:");
673 pom = RunIntModule(ss,1);
676 pom->p_ctx.node = msg.param.pword[2];
677 pom->p_ctx.program_id = msg.param.pword[7];
678 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
681 case VLP_CLOSE_INSTANCE:
682 msg.msg_type = MSG_INT;
683 msg.param.pword[0] = INT_CLOSE_INSTANCE;
684 pom = findINTbyID(msg.param.pword[7]);
687 write(pom->sock,&msg,sizeof(MESSAGE));
689 m1.msg_type = MSG_VLP;
690 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
691 m1.param.pword[1] = pom->ID;
692 write(net_sock,&m1,sizeof(MESSAGE));
693 } else WriteMessage("Instance not found");
699 case NET_CONNECTIONS: ActiveConnections = msg.param.pword[1];
700 WriteMessage(msg.param.pstr);
701 if (!synchro) synchro=TRUE;
706 QString poms,poms1,poms2;
707 poms.sprintf("%s",msg.param.pstr);
708 while (poms.length()>0)
712 { poms1=poms.left(cnt);
713 poms=poms.right(poms.length()-cnt-1);
717 poms2=poms1.left(cnt);
718 poms1=poms1.right(poms1.length()-cnt-1);
719 sprintf(ss,"Node: %s Addr: %s",poms2.data(),poms1.data());
726 case NET_INFO_END:wait_for_info=FALSE;
727 WriteMessage(CharLine);
737 void QKernel::IntMessage(int sock)
743 cnt = read(sock,&msg,sizeof(MESSAGE));
744 e = findINTbySocket(sock);
745 if ( (cnt>0) && (e!=NULL))
747 switch (msg.msg_type)
750 if (msg.param.pword[0]==GRAPH_ALLOCATE)
752 RunGraphModule(msg.param.pstr);
756 write(net_sock,&msg,sizeof(MESSAGE));break;
758 switch(msg.param.pword[0])
760 case VLP_REMOTE_INSTANCE_PLEASE:
761 RemoteInstance(e,msg.param.pword[2]);
766 switch(msg.param.pword[0]){
772 m.msg_type = MSG_VLP;
773 m.param.pword[0] = VLP_INTERPRETER_DOWN;
774 m.param.pword[1] = e->ID;
775 write(net_sock,&m,sizeof(MESSAGE));
776 if (e->remote==0) CloseInstances(e);
779 Interpreters.remove(e);
783 sprintf(ss,"%s : End of program execution",msg.param.pstr);
789 msg.msg_type = MSG_INT;
790 msg.param.pword[0] = INT_CTX;
791 msg.param.pword[1] = NodeNumber;
792 msg.param.pword[2] = e->ID;
795 msg.param.pword[3] = e->p_ctx.node;
796 msg.param.pword[4] = e->p_ctx.program_id;
798 write(sock,&msg,sizeof(MESSAGE));
800 };break; /* switch param.pword[0] */
806 void QKernel::WriteMessage(char *msg)
810 desktop->getCursorPosition(&x,&y);
811 if (x>100) desktop->clear();
812 desktop->setReadOnly(FALSE);
813 desktop->append(msg);
814 desktop->setReadOnly(TRUE);
815 desktop->setCursorPosition(desktop->numLines(),1);
817 if (desktop->numLines()>100) desktop->clear();
820 void QKernel::SetMessages()
825 if ( p2->isItemChecked(msgid))
827 p2->setItemChecked(msgid,FALSE);
832 p2->setItemChecked(msgid,TRUE);
839 void QKernel::SetOptions()
841 QDialog dlg(this,"Options",TRUE);
849 progs = new QLineEdit( &dlg, "progs" );
850 progs->setGeometry( 150, 20, 180, 30 );
851 progs->setText(progdir);
854 tmpQLabel = new QLabel( &dlg, "Label_1" );
855 tmpQLabel->setGeometry( 30, 20, 120, 30 );
856 tmpQLabel->setText( "Programs directory" );
859 tmpQFrame = new QFrame( &dlg, "Frame_2" );
860 tmpQFrame->setGeometry( 10, 60, 380, 30 );
861 tmpQFrame->setFrameStyle( 52 );
863 tmpQLabel = new QLabel( &dlg, "Label_2" );
864 tmpQLabel->setGeometry( 10, 80, 340, 30 );
865 tmpQLabel->setText( "Virtual Processor properties (activated after restarting VLP):" );
869 nn = new QLineEdit( &dlg, "LineEdit_2" );
870 nn->setGeometry( 110, 110, 40, 30 );
871 sprintf(nns,"%d",NodeNumber);
874 tmpQLabel = new QLabel( &dlg, "Label_3" );
875 tmpQLabel->setGeometry( 20, 110, 90, 30 );
876 tmpQLabel->setText( "Node number:" );
878 QRadioButton *exp,*reg;
879 exp = new QRadioButton( &dlg, "RadioButton_3" );
880 exp->setGeometry( 30, 170, 100, 30 );
881 exp->setText( "Explicit" );
882 exp->setChecked( TRUE );
884 reg = new QRadioButton( &dlg, "RadioButton_4" );
885 reg->setGeometry( 30, 200, 100, 30 );
886 reg->setText( "Registration" );
887 reg->setEnabled(FALSE);
889 connections = new QListBox( &dlg, "ListBox_1" );
890 connections->setGeometry( 170, 140, 130, 100 );
891 e = ConnectList.first();
894 connections->insertItem(e->addr);
895 e = ConnectList.next();
898 tmpQLabel = new QLabel( &dlg, "Label_5" );
899 tmpQLabel->setGeometry( 170, 110, 100, 30 );
900 tmpQLabel->setText( "Connection list:" );
902 QPushButton* addbtn,*delbtn,*okbtn,*cancelbtn;
903 addbtn = new QPushButton( &dlg, "PushButton_1" );
904 addbtn->setGeometry( 310, 150, 60, 30 );
905 addbtn->setText( "Add" );
906 delbtn = new QPushButton( &dlg, "PushButton_2" );
907 delbtn->setGeometry( 310, 200, 60, 30 );
908 delbtn->setText( "Del" );
909 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddAddress()));
910 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelAddress()));
911 okbtn = new QPushButton( &dlg, "PushButton_3" );
912 okbtn->setGeometry( 80, 260, 100, 30 );
913 okbtn->setText( "Ok" );
914 okbtn->setDefault(TRUE);
915 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
916 cancelbtn->setGeometry( 210, 260, 100, 30 );
917 cancelbtn->setText( "Cancel" );
918 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
919 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
921 group = new QButtonGroup( &dlg, "ButtonGroup_1" );
922 group->setGeometry( 20, 150, 120, 90 );
923 group->setTitle( "Connection type" );
924 group->setAlignment( 1 );
926 group->insert(exp,1);
927 group->insert(reg,2);
929 dlg.resize( 400, 310 );
933 vlp_file = new QFile("vlp.cfg");
934 vlp_file->open(IO_WriteOnly);
935 sprintf(line,"progdir=%s\n",progs->text().ascii());
936 vlp_file->writeBlock(line,strlen(line));
937 strcpy(progdir,progs->text());
938 sprintf(line,"node_number=%d\n",atoi(nn->text()));
939 vlp_file->writeBlock(line,strlen(line));
940 if ( exp->isChecked())
942 sprintf(line,"type=explicit\n");
943 vlp_file->writeBlock(line,strlen(line));
944 for(i=0;i<connections->count();i++)
946 sprintf(line,"host=%s\n",connections->text(i).ascii());
947 vlp_file->writeBlock(line,strlen(line));
953 sprintf(line,"type=register\n");
954 vlp_file->writeBlock(line,strlen(line));
961 void QKernel::LockConsole()
963 QDialog d(this,"Enter password",TRUE);
964 QLabel lab(&d,"Password");
966 QPushButton ob(&d,""),cb(&d,"");
968 d.setCaption("Lock console");
969 ob.setGeometry( 30, 60, 80, 30 );
972 lab.setGeometry( 10, 10, 60, 30 );
973 lab.setText( "Password:" );
974 ed.setGeometry( 70, 10, 140, 30 );
975 ed.setEchoMode(QLineEdit::Password);
976 cb.setGeometry( 130, 60, 80, 30 );
977 cb.setText( "Cancel" );
978 d.resize( 240, 100 );
979 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
980 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
983 if (strcmp(ed.text(),"")!=0)
985 strcpy(LockPasswd,ed.text());
986 lab.setText("Retype:");
990 if (strcmp(ed.text(),LockPasswd)==0)
992 bar->setItemEnabled(qid,FALSE);
993 bar->setItemEnabled(prid,FALSE);
994 bar->setItemEnabled(mid,FALSE);
995 p2->setItemEnabled(unlockid,TRUE);
996 p2->setItemEnabled(lockid,FALSE);
997 p2->setItemEnabled(cwid,FALSE);
998 p2->setItemEnabled(optid,FALSE);
1000 WriteMessage("CONSOLE LOCKED");
1005 QMessageBox msg(this);
1006 msg.setText("Not matching!");
1007 msg.setButtonText(0,"Close");
1012 else strcpy(LockPasswd,"");
1016 void QKernel::UnlockConsole()
1018 QDialog d(this,"Enter password",TRUE);
1019 QLabel lab(&d,"Password");
1020 QLineEdit ed(&d,"");
1021 QPushButton ob(&d,""),cb(&d,"");
1023 ob.setGeometry( 30, 60, 80, 30 );
1025 ob.setDefault(TRUE);
1026 lab.setGeometry( 10, 10, 60, 30 );
1027 lab.setText( "Password:" );
1028 ed.setGeometry( 70, 10, 140, 30 );
1029 ed.setEchoMode(QLineEdit::Password);
1030 cb.setGeometry( 130, 60, 80, 30 );
1031 cb.setText( "Cancel" );
1032 d.resize( 240, 100 );
1033 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1034 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1038 if (strcmp(ed.text(),LockPasswd)==0)
1040 bar->setItemEnabled(qid,TRUE);
1041 bar->setItemEnabled(prid,TRUE);
1042 bar->setItemEnabled(mid,TRUE);
1043 p2->setItemEnabled(unlockid,FALSE);
1044 p2->setItemEnabled(lockid,TRUE);
1045 p2->setItemEnabled(cwid,TRUE);
1046 p2->setItemEnabled(optid,TRUE);
1048 WriteMessage("CONSOLE UNLOCKED");
1053 QMessageBox msg(this);
1054 msg.setText("Wrong password!");
1055 msg.setButtonText(0,"Close");
1062 void QKernel::InitMessage()
1064 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1069 InterpEntry *QKernel::findINTbySocket(int _id)
1072 pom = Interpreters.first();
1075 if (pom->sock == _id) break;
1076 pom = Interpreters.next();
1081 InterpEntry *QKernel::findINTbyID(int _id)
1084 pom = Interpreters.first();
1087 if (pom->ID == _id) break;
1088 pom = Interpreters.next();
1094 /* ------------------ Connect INT module -----------------*/
1096 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1099 struct sockaddr_un svr;
1105 InterpEntry *newINT;
1114 if (cf == NULL) {WriteMessage("File not found: no .ccd file");return(NULL);}
1120 if (cf == NULL) {WriteMessage("File not found: no .pcd file");return(NULL);}
1123 newINT = new InterpEntry;
1124 for(i=0;i<MAXINSTANCES;i++) newINT->RInstances[i]=-1;
1126 strcpy(b,rindex(ss,'/'));
1127 for(i=0;i<strlen(b);i++)
1131 sprintf(a,"%s : Start execution",b);
1135 newint = freeINTid; freeINTid++;
1136 newINT->ID = newint;
1137 strcpy(newINT->shortname,b);
1138 strcpy(newINT->fullname,ss);
1140 sprintf(a,"%s%d",IPATH,newint);
1141 sprintf(cmd,"%s/modules/logint %s %s",HomeDir,a,ss);
1142 if (r) strcat(cmd," r");
1143 sprintf(b," %s %s %s %s %s",myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
1148 sock = socket(AF_UNIX,SOCK_STREAM,0);
1150 bzero(&svr, sizeof(svr));
1151 svr.sun_family = AF_UNIX;
1152 strcpy(svr.sun_path,a);
1153 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1154 bind(sock,(struct sockaddr*)&svr, len);
1157 newINT->sock = accept(sock,(struct sockaddr*)0,(unsigned int *)0);
1164 fcntl(newINT->sock,F_SETFL,
1165 O_NONBLOCK|fcntl(newINT->sock,F_GETFL,0));
1167 setsockopt(newINT->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
1168 if (r) newINT->remote = 1;else newINT->remote=0;
1170 bzero(&msg,sizeof(MESSAGE));
1171 msg.msg_type = MSG_VLP;
1172 msg.param.pword[0] = VLP_REGINT;
1173 msg.param.pword[1] = newINT->ID;
1174 sprintf(msg.param.pstr,"logi%d.net",newint);
1175 write(net_sock,&msg,sizeof(MESSAGE));
1177 Interpreters.append(newINT);
1178 newINT->notify = new QSocketNotifier(newINT->sock,QSocketNotifier::Read);
1179 connect(newINT->notify,SIGNAL(activated(int)),this,SLOT(IntMessage(int)));
1180 if (info_messages) WriteMessage("INTERPRETER successfully connected");
1183 else WriteMessage("Cannot connect interpreter");
1189 /* ---------------------------------------------------------*/
1190 /* Allocate remote instance */
1192 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1198 m.msg_type = MSG_NET;
1199 m.param.pword[0] = NET_NODE_EXIST;
1200 m.param.pword[1] = on;
1201 m.param.pword[2] = interp->ID;
1202 write(net_sock,&m,sizeof(MESSAGE));
1203 bzero(&m,sizeof(MESSAGE));
1204 while( (m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST) )
1205 read(net_sock,&m,sizeof(MESSAGE));
1207 if (m.param.pword[1]==1) /* means node exists */
1209 m.msg_type = MSG_NET;
1210 m.param.pword[0] = NET_TRANSMIT_CODE;
1211 m.param.pword[1] = interp->ID;
1212 m.param.pword[2] = on;
1213 strcpy(m.param.pstr,interp->fullname);
1214 write(net_sock,&m,sizeof(MESSAGE));
1216 Net_Notify->setEnabled(FALSE);
1217 while ( (m.msg_type != MSG_NET) || (m.param.pword[0]!=NET_TRANSMITTED) )
1218 read(net_sock,&m,sizeof(MESSAGE));
1221 m.msg_type = MSG_NET;
1222 m.param.pword[0] = NET_PROPAGATE;
1223 m.param.pword[1] = MSG_VLP;
1224 m.param.pword[2] = NodeNumber;
1225 m.param.pword[3] = 0;
1226 m.param.pword[4] = on;
1227 m.param.pword[5] = 0;
1228 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1229 m.param.pword[7] = interp->ID;
1230 strcpy(m.param.pstr,interp->shortname);
1231 write(net_sock,&m,sizeof(MESSAGE));
1233 read(net_sock,&m,sizeof(MESSAGE));
1236 if ( (m.param.pword[0]==NET_PROPAGATE) && (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK))
1238 interp->RInstances[on] = m.param.pword[7];
1241 read(net_sock,&m,sizeof(MESSAGE));
1244 Net_Notify->setEnabled(TRUE);
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->RInstances[on];
1250 write(interp->sock,&m,sizeof(MESSAGE));
1252 else /* There is no such a node! */
1254 sprintf(s,"Warning: Node number %d not found!",on);
1256 WriteMessage("Allocating O-process on the local node");
1257 bzero(&m,sizeof(MESSAGE));
1258 m.msg_type = MSG_VLP;
1259 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1260 m.param.pword[1] = interp->ID;
1261 write(interp->sock,&m,sizeof(MESSAGE));
1266 /*-----------------------------------------------*/
1267 /* Close all remote instances */
1269 void QKernel::CloseInstances(InterpEntry *e)
1274 if (info_messages) WriteMessage("Closing remote instances");
1275 for(i=0;i<MAXINSTANCES;i++)
1276 if (e->RInstances[i]>=0)
1278 msg.msg_type = MSG_NET;
1279 msg.param.pword[0] = NET_PROPAGATE;
1280 msg.param.pword[1] = MSG_VLP;
1281 msg.param.pword[2] = NodeNumber;
1282 msg.param.pword[4] = i;
1283 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1284 msg.param.pword[7] = e->RInstances[i];
1285 write(net_sock,&msg,sizeof(MESSAGE));
1290 void QKernel::Info()
1294 WriteMessage(CharLine);
1295 WriteMessage("### Virtual Machine Information ###");
1296 m.msg_type = MSG_NET;
1297 m.param.pword[0]=NET_GET_INFO;
1298 write(net_sock,&m,sizeof(MESSAGE));
1299 wait_for_info = TRUE;
1302 #include "kernel.moc"
1304 int main( int argc, char **argv )
1307 for(i=0;i<5;i++) strcpy(myargs[i],"");
1308 for(i=1;i<argc;i++) strcpy(myargs[i-1],argv[i]);
1310 app = new QApplication(argc,argv);
1311 app->setStyle(new QWindowsStyle());
1313 app->setMainWidget( &draw);