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>
75 #include "AppConfiguration.h"
80 #define REMOTE_PATH "REMOTE"
82 #define MAXINSTANCES 256
90 char CharLine[25]="________________________";
94 /* --------------- interpreter slot -----------------*/
98 int ID; // INT identifier
99 bool remote; // Am I remote ?
100 char fullname[255],shortname[255]; // Program name
102 QSocketNotifier *notify;
103 int RInstances[MAXINSTANCES]; // IDs of my remote INT modules
104 ctx_struct p_ctx; // parent INT info
106 /*++++++++++++++++++++++++++++++++++++++++++*/
108 /*----------------- connection slot -------------*/
113 ConnectEntry(char *s) {strcpy(addr,s);};
116 /* ++++++++++++++++++++++++++++++++++++++++++ */
121 /* ---------------------------------------------------------- */
122 /* KERNEL CLASS DEFINITION */
123 /* ---------------------------------------------------------- */
125 class QKernel : public QFrame
130 QMultiLineEdit *desktop;
132 QPopupMenu *p,*p1,*p2;
134 int NodeNumber,ConType;
140 virtual void resizeEvent( QResizeEvent *ev );
142 void WriteMessage(char* msg);
156 void UnlockConsole();
157 void MessageToNode();
160 void IntMessage(int);
161 void KillInterpreter();
168 virtual void closeEvent ( QCloseEvent * e );
171 QList<InterpEntry> Interpreters;
172 QList<ConnectEntry> ConnectList;
173 QListBox *connections;
174 int Tasks; // number of working interpreters
175 int ActiveConnections; // number of connected VLPs
176 bool LOCKED,synchro,wait_for_info;
178 int lockid,unlockid,qid,cwid,
179 optid,prid,mid,msgid,toolsid,hid;
182 QSocketNotifier *Net_Notify;
187 void LoadConfig(char *);
188 void RunGraphModule(char*);
190 InterpEntry *findINTbySocket(int);
191 InterpEntry *findINTbyID(int);
192 InterpEntry *RunIntModule(char *ss,int r);
193 void RemoteInstance(InterpEntry*,int);
194 void CloseInstances(InterpEntry*);
198 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
200 void QKernel::closeEvent ( QCloseEvent * e ) {
206 QFont f("Helvetica",10,QFont::Bold);
207 QFont f1("Helvetica",10,QFont::Normal);
208 QFont f2("Times Roman",10,QFont::Normal);
214 sprintf(ss,"mkdir %s",REMOTE_PATH);
221 setCaption("Virtual LOGLAN Processor");
222 setBackgroundColor(white);
224 bar = new QMenuBar(this);
226 p = new QPopupMenu();
228 p->insertItem("Execute",this,SLOT(Run_Prog()));
229 p->insertItem("Kill",this,SLOT(KillInterpreter()));
230 prid = bar->insertItem("&Program",p);
231 p1 = new QPopupMenu();
232 p1->insertItem("Message",this,SLOT(MessageToNode()));
233 p1->insertSeparator();
234 p1->insertItem("Connect",this,SLOT(Connect()));
235 p1->insertItem("Disconnect",this,SLOT(Disconnect()));
236 p1->insertItem("Info",this,SLOT(Info()));
238 mid = bar->insertItem("&Machine",p1);
240 p2 = new QPopupMenu();
241 cwid = p2->insertItem("Editor",this,SLOT(Edit()));
242 hid = p2->insertItem("Help",this,SLOT(Help()));
243 p2->insertSeparator();
244 optid = p2->insertItem("Options",this,SLOT(SetOptions()));
245 msgid = p2->insertItem("Info messages",this,SLOT(SetMessages()));
246 p2->setItemChecked(msgid,TRUE);
247 p2->insertSeparator();
248 lockid = p2->insertItem("Lock console",this,SLOT(LockConsole()));
249 unlockid = p2->insertItem("Unlock console",this,SLOT(UnlockConsole()));
250 p2->setItemEnabled(unlockid,FALSE);
253 toolsid = bar->insertItem("&Tools",p2);
255 qid = bar->insertItem("&Quit",this,SLOT(QuitProc()));
258 desktop = new QMultiLineEdit(this,"desktop");
259 desktop->setAutoUpdate(TRUE);
260 desktop->setReadOnly(TRUE);
261 desktop->setFont(f1);
266 ActiveConnections = 0;
267 strcpy(LockPasswd,"");
268 LoadConfig("vlp.cfg");
271 Net_Notify = new QSocketNotifier(net_sock,QSocketNotifier::Read,this);
272 connect(Net_Notify,SIGNAL(activated(int)),this,SLOT(NetMessage()));
277 void QKernel::resizeEvent( QResizeEvent *ev )
279 QFrame::resizeEvent(ev);
281 desktop->setGeometry( 0,bar->height(), width(), height() - bar->height() );
287 void QKernel::n_impl()
289 QMessageBox::information(this,"Function info","This function is not implemented yet...","Ok");
293 /* ########### load configuration from file ############# */
295 void QKernel::LoadConfig(char * fname)
300 /* Hack for checking if file exists without using external libs.*/
301 FILE * file = fopen(fname, "r");
303 fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname);
306 /* File exists, so file has been locked. Release it. */
311 /* Read the file. If there is an error, report it and exit. */
312 if(!config_read_file(&cfg, fname))
314 AppConfiguration::error(&cfg);
315 config_destroy(&cfg);
316 exit(3);/* from original code. */
319 if(!config_lookup_int(&cfg, "node_number", &NodeNumber))
321 AppConfiguration::error(&cfg);
322 config_destroy(&cfg);
326 if(config_lookup_string(&cfg, "type", &str)){
327 ConType = (strcmp(str, "explicit") == 0) ? 1 : 2;
330 AppConfiguration::error(&cfg);
334 if(config_lookup_string(&cfg, "host", &str)) {
335 ConnectList.append(new ConnectEntry((char*)str));
338 AppConfiguration::error(&cfg);
341 if(config_lookup_string(&cfg, "progdir", &str)){
342 strncpy(progdir, str, 256);
345 AppConfiguration::error(&cfg);
348 if(config_lookup_string(&cfg, "homedir", &str)){
349 strncpy(HomeDir, str, 255);
352 AppConfiguration::error(&cfg);
355 config_destroy(&cfg);
357 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
360 void QKernel::Run_Prog()
363 QString s(QFileDialog::getOpenFileName(progdir,"*.log",this));
367 if (i>0) s.remove(i,4);
368 RunIntModule((char*)s.ascii(),0);
376 sprintf(cmd,"%s/modules/logedit %s %s %s %s %s %s &",HomeDir,HomeDir,
377 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
384 sprintf(cmd,"%s/modules/loghelp %s/doc %s %s %s %s %s &",HomeDir,HomeDir,
385 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
390 void QKernel::RunGraphModule(char *sk)
395 sprintf(cmd,"%s/modules/loggraph %s %s %s %s %s %s",HomeDir,sk,
396 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
400 WriteMessage("Cannot connect GRAPH resources");
406 void QKernel::RunNetModule()
408 struct sockaddr_un svr;
414 sprintf(cmd,"%s/modules/lognet %s %s %s %s %s %s",HomeDir,NPATH,
415 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
418 /* -------- socket for NET module -------- */
420 sock = socket(AF_UNIX,SOCK_STREAM,0);
421 bzero(&svr,sizeof(svr));
422 svr.sun_family = AF_UNIX;
423 strcpy(svr.sun_path,NPATH);
424 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
425 bind(sock,(struct sockaddr*)&svr, len);
428 if ( system(cmd) == 0)
430 net_sock = accept(sock,(struct sockaddr*)0,(unsigned int*)0);
434 WriteMessage("NETWORK successfully connected");
435 fcntl(net_sock,F_SETFL, O_NONBLOCK|fcntl(net_sock,F_GETFL,0));
437 setsockopt(net_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
441 WriteMessage("Cannot connect NETWORK resources");
442 WriteMessage("Exiting...");
449 WriteMessage("Cannot connect NETWORK resources");
450 WriteMessage("Exiting...");
458 void QKernel::Connect()
460 QDialog d(this,"",TRUE);
461 QLabel lab(&d,"IP Address:");
463 QPushButton ob(&d,""),cb(&d,"");
466 d.setFont(QFont("Helvetica",12,QFont::Bold));
467 ob.setGeometry( 30, 60, 80, 30 );
470 lab.setGeometry( 10, 10, 60, 30 );
471 lab.setText( "Address" );
472 ed.setGeometry( 70, 10, 140, 30 );
473 cb.setGeometry( 130, 60, 80, 30 );
474 cb.setText( "Cancel" );
475 d.resize( 240, 100 );
477 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
478 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
481 m.msg_type = MSG_NET;
482 m.param.pword[0] = NET_CONNECT_TO;
483 strcpy(m.param.pstr,ed.text());
484 write(net_sock,&m,sizeof(MESSAGE));
489 void QKernel::Disconnect()
493 if (info_messages) WriteMessage("Disconnecting from virtual machine");
494 msg.msg_type = MSG_NET;
495 msg.param.pword[0] = NET_DISCONNECT;
496 write(net_sock,&msg,sizeof(MESSAGE));
499 void QKernel::QuitProc()
503 if ( QMessageBox::question(this,"Close VLP","Terminate VLP ?",QMessageBox::Yes,QMessageBox::No,0) == QMessageBox::No ) return;
507 msg.msg_type = MSG_NET;
508 msg.param.pword[0] = NET_DISCONNECT;
509 write(net_sock,&msg,sizeof(MESSAGE));*/
514 msg.msg_type = MSG_NET;
515 msg.param.pword[0] = NET_EXIT;
516 write(net_sock,&msg,sizeof(MESSAGE));
517 // ::close(net_sock);
526 void QKernel::AddAddress()
528 QDialog d(this,"",TRUE);
529 QLabel lab(&d,"IP Address:");
531 QPushButton ob(&d,""),cb(&d,"");
535 ob.setGeometry( 30, 60, 80, 30 );
538 lab.setGeometry( 10, 10, 60, 30 );
539 lab.setText( "Address" );
540 ed.setGeometry( 70, 10, 140, 30 );
541 cb.setGeometry( 130, 60, 80, 30 );
542 cb.setText( "Cancel" );
543 d.resize( 240, 100 );
544 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
545 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
547 if (strcmp(ed.text(),"")!=0)
549 connections->insertItem(ed.text());
554 void QKernel::DelAddress()
558 if (connections->currentItem()!=-1)
559 connections->removeItem(connections->currentItem());
565 void QKernel::MessageToNode()
572 dlg = new QDialog(this,"Message",TRUE);
574 nodenr = new QLineEdit(dlg,"number");
575 nodenr->setGeometry( 90, 10, 50, 30 );
579 tmpQLabel = new QLabel( dlg, "Label_1" );
580 tmpQLabel->setGeometry( 10, 10, 77, 30 );
581 tmpQLabel->setText( "Node number:" );
583 tmpQLabel = new QLabel( dlg, "Label_2" );
584 tmpQLabel->setGeometry( 10, 50, 70, 30 );
585 tmpQLabel->setText( "Message:" );
588 msg = new QLineEdit( dlg, "LineEdit_1" );
589 msg->setGeometry( 80, 60, 330, 30 );
593 ob = new QPushButton( dlg, "PushButton_1" );
594 ob->setGeometry( 230, 10, 80, 30 );
595 ob->setText( "Send" );
596 ob->setDefault(TRUE);
597 cb = new QPushButton( dlg, "PushButton_2" );
598 cb->setGeometry( 330, 10, 80, 30 );
599 cb->setText( "Cancel" );
600 dlg->resize( 430, 110 );
601 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
602 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
603 dlg->setCaption("Send message to node");
607 m.msg_type = MSG_NET;
608 m.param.pword[0] = NET_PROPAGATE;
609 m.param.pword[1] = MSG_VLP;
610 m.param.pword[2] = NodeNumber;
611 m.param.pword[4] = atoi(nodenr->text());
612 m.param.pword[6] = VLP_WRITE;
613 strcpy(m.param.pstr,msg->text());
614 write(net_sock,&m,sizeof(MESSAGE));
618 void QKernel::KillInterpreter()
625 dlg = new QDialog(this,"Message",TRUE);
627 nodenr = new QLineEdit(dlg,"number");
628 nodenr->setGeometry( 90, 10, 50, 30 );
632 tmpQLabel = new QLabel( dlg, "Label_1" );
633 tmpQLabel->setGeometry( 10, 10, 77, 30 );
634 tmpQLabel->setText( "Interp. ID:" );
636 ob = new QPushButton( dlg, "PushButton_1" );
637 ob->setGeometry( 160, 10, 80, 30 );
638 ob->setText( "Kill" );
639 ob->setDefault(TRUE);
640 cb = new QPushButton( dlg, "PushButton_2" );
641 cb->setGeometry( 260, 10, 80, 30 );
642 cb->setText( "Cancel" );
643 dlg->resize( 360, 50 );
644 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
645 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
646 dlg->setCaption("Kill interpreter");
650 m.msg_type = MSG_INT;
651 m.param.pword[0] = INT_KILL;
652 pom = findINTbyID(atoi(nodenr->text()));
656 write(pom->sock,&m,sizeof(MESSAGE));
657 else WriteMessage("This is a remote instance of a program!");
659 else WriteMessage("Interpreter not found");
667 void QKernel::NetMessage()
674 cnt = read(net_sock,&msg,sizeof(MESSAGE));
675 if ( (cnt>0) && (msg.msg_type==MSG_NET))
677 switch(msg.param.pword[0])
679 case NET_CSWRITELN: WriteMessage(msg.param.pstr);break;
681 switch(msg.param.pword[1])
684 /* pom = find_link_by_ID(msg.param.pword[5]);
685 msg.msg_type = MSG_NET;
686 msg.param.pword[0] = NET_PROPAGATE;
687 send_int(pom,&msg);*/
690 switch(msg.param.pword[6])
693 QApplication::beep();
694 WriteMessage(CharLine);
695 WriteMessage("### Incoming Messsage ###");
696 sprintf(ss,"Mesg from Node %d: %s",msg.param.pword[2],msg.param.pstr);
698 WriteMessage(CharLine);
700 case VLP_REMOTE_INSTANCE:
701 sprintf(ss,"%s/%s",REMOTE_PATH,msg.param.pstr);
704 WriteMessage("Running program:");
707 pom = RunIntModule(ss,1);
710 pom->p_ctx.node = msg.param.pword[2];
711 pom->p_ctx.program_id = msg.param.pword[7];
712 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
715 case VLP_CLOSE_INSTANCE:
716 msg.msg_type = MSG_INT;
717 msg.param.pword[0] = INT_CLOSE_INSTANCE;
718 pom = findINTbyID(msg.param.pword[7]);
721 write(pom->sock,&msg,sizeof(MESSAGE));
723 m1.msg_type = MSG_VLP;
724 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
725 m1.param.pword[1] = pom->ID;
726 write(net_sock,&m1,sizeof(MESSAGE));
727 } else WriteMessage("Instance not found");
733 case NET_CONNECTIONS: ActiveConnections = msg.param.pword[1];
734 WriteMessage(msg.param.pstr);
735 if (!synchro) synchro=TRUE;
740 QString poms,poms1,poms2;
741 poms.sprintf("%s",msg.param.pstr);
742 while (poms.length()>0)
746 { poms1=poms.left(cnt);
747 poms=poms.right(poms.length()-cnt-1);
751 poms2=poms1.left(cnt);
752 poms1=poms1.right(poms1.length()-cnt-1);
753 sprintf(ss,"Node: %s Addr: %s",poms2.data(),poms1.data());
760 case NET_INFO_END:wait_for_info=FALSE;
761 WriteMessage(CharLine);
771 void QKernel::IntMessage(int sock)
777 cnt = read(sock,&msg,sizeof(MESSAGE));
778 e = findINTbySocket(sock);
779 if ( (cnt>0) && (e!=NULL))
781 switch (msg.msg_type)
784 if (msg.param.pword[0]==GRAPH_ALLOCATE)
786 RunGraphModule(msg.param.pstr);
790 write(net_sock,&msg,sizeof(MESSAGE));break;
792 switch(msg.param.pword[0])
794 case VLP_REMOTE_INSTANCE_PLEASE:
795 RemoteInstance(e,msg.param.pword[2]);
800 switch(msg.param.pword[0]){
806 m.msg_type = MSG_VLP;
807 m.param.pword[0] = VLP_INTERPRETER_DOWN;
808 m.param.pword[1] = e->ID;
809 write(net_sock,&m,sizeof(MESSAGE));
810 if (e->remote==0) CloseInstances(e);
813 Interpreters.remove(e);
817 sprintf(ss,"%s : End of program execution",msg.param.pstr);
823 msg.msg_type = MSG_INT;
824 msg.param.pword[0] = INT_CTX;
825 msg.param.pword[1] = NodeNumber;
826 msg.param.pword[2] = e->ID;
829 msg.param.pword[3] = e->p_ctx.node;
830 msg.param.pword[4] = e->p_ctx.program_id;
832 write(sock,&msg,sizeof(MESSAGE));
834 };break; /* switch param.pword[0] */
840 void QKernel::WriteMessage(char *msg)
844 desktop->getCursorPosition(&x,&y);
845 if (x>100) desktop->clear();
846 desktop->setReadOnly(FALSE);
847 desktop->append(msg);
848 desktop->setReadOnly(TRUE);
849 desktop->setCursorPosition(desktop->numLines(),1);
851 if (desktop->numLines()>100) desktop->clear();
854 void QKernel::SetMessages()
859 if ( p2->isItemChecked(msgid))
861 p2->setItemChecked(msgid,FALSE);
866 p2->setItemChecked(msgid,TRUE);
873 void QKernel::SetOptions()
875 QDialog dlg(this,"Options",TRUE);
883 progs = new QLineEdit( &dlg, "progs" );
884 progs->setGeometry( 150, 20, 180, 30 );
885 progs->setText(progdir);
888 tmpQLabel = new QLabel( &dlg, "Label_1" );
889 tmpQLabel->setGeometry( 30, 20, 120, 30 );
890 tmpQLabel->setText( "Programs directory" );
893 tmpQFrame = new QFrame( &dlg, "Frame_2" );
894 tmpQFrame->setGeometry( 10, 60, 380, 30 );
895 tmpQFrame->setFrameStyle( 52 );
897 tmpQLabel = new QLabel( &dlg, "Label_2" );
898 tmpQLabel->setGeometry( 10, 80, 340, 30 );
899 tmpQLabel->setText( "Virtual Processor properties (activated after restarting VLP):" );
903 nn = new QLineEdit( &dlg, "LineEdit_2" );
904 nn->setGeometry( 110, 110, 40, 30 );
905 sprintf(nns,"%d",NodeNumber);
908 tmpQLabel = new QLabel( &dlg, "Label_3" );
909 tmpQLabel->setGeometry( 20, 110, 90, 30 );
910 tmpQLabel->setText( "Node number:" );
912 QRadioButton *exp,*reg;
913 exp = new QRadioButton( &dlg, "RadioButton_3" );
914 exp->setGeometry( 30, 170, 100, 30 );
915 exp->setText( "Explicit" );
916 exp->setChecked( TRUE );
918 reg = new QRadioButton( &dlg, "RadioButton_4" );
919 reg->setGeometry( 30, 200, 100, 30 );
920 reg->setText( "Registration" );
921 reg->setEnabled(FALSE);
923 connections = new QListBox( &dlg, "ListBox_1" );
924 connections->setGeometry( 170, 140, 130, 100 );
925 e = ConnectList.first();
928 connections->insertItem(e->addr);
929 e = ConnectList.next();
932 tmpQLabel = new QLabel( &dlg, "Label_5" );
933 tmpQLabel->setGeometry( 170, 110, 100, 30 );
934 tmpQLabel->setText( "Connection list:" );
936 QPushButton* addbtn,*delbtn,*okbtn,*cancelbtn;
937 addbtn = new QPushButton( &dlg, "PushButton_1" );
938 addbtn->setGeometry( 310, 150, 60, 30 );
939 addbtn->setText( "Add" );
940 delbtn = new QPushButton( &dlg, "PushButton_2" );
941 delbtn->setGeometry( 310, 200, 60, 30 );
942 delbtn->setText( "Del" );
943 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddAddress()));
944 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelAddress()));
945 okbtn = new QPushButton( &dlg, "PushButton_3" );
946 okbtn->setGeometry( 80, 260, 100, 30 );
947 okbtn->setText( "Ok" );
948 okbtn->setDefault(TRUE);
949 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
950 cancelbtn->setGeometry( 210, 260, 100, 30 );
951 cancelbtn->setText( "Cancel" );
952 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
953 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
955 group = new QButtonGroup( &dlg, "ButtonGroup_1" );
956 group->setGeometry( 20, 150, 120, 90 );
957 group->setTitle( "Connection type" );
958 group->setAlignment( 1 );
960 group->insert(exp,1);
961 group->insert(reg,2);
963 dlg.resize( 400, 310 );
967 vlp_file = new QFile("vlp.cfg");
968 vlp_file->open(IO_WriteOnly);
969 sprintf(line,"progdir=%s\n",progs->text().ascii());
970 vlp_file->writeBlock(line,strlen(line));
971 strcpy(progdir,progs->text());
972 sprintf(line,"node_number=%d\n",atoi(nn->text()));
973 vlp_file->writeBlock(line,strlen(line));
974 if ( exp->isChecked())
976 sprintf(line,"type=explicit\n");
977 vlp_file->writeBlock(line,strlen(line));
978 for(i=0;i<connections->count();i++)
980 sprintf(line,"host=%s\n",connections->text(i).ascii());
981 vlp_file->writeBlock(line,strlen(line));
987 sprintf(line,"type=register\n");
988 vlp_file->writeBlock(line,strlen(line));
995 void QKernel::LockConsole()
997 QDialog d(this,"Enter password",TRUE);
998 QLabel lab(&d,"Password");
1000 QPushButton ob(&d,""),cb(&d,"");
1002 d.setCaption("Lock console");
1003 ob.setGeometry( 30, 60, 80, 30 );
1005 ob.setDefault(TRUE);
1006 lab.setGeometry( 10, 10, 60, 30 );
1007 lab.setText( "Password:" );
1008 ed.setGeometry( 70, 10, 140, 30 );
1009 ed.setEchoMode(QLineEdit::Password);
1010 cb.setGeometry( 130, 60, 80, 30 );
1011 cb.setText( "Cancel" );
1012 d.resize( 240, 100 );
1013 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1014 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1017 if (strcmp(ed.text(),"")!=0)
1019 strcpy(LockPasswd,ed.text());
1020 lab.setText("Retype:");
1024 if (strcmp(ed.text(),LockPasswd)==0)
1026 bar->setItemEnabled(qid,FALSE);
1027 bar->setItemEnabled(prid,FALSE);
1028 bar->setItemEnabled(mid,FALSE);
1029 p2->setItemEnabled(unlockid,TRUE);
1030 p2->setItemEnabled(lockid,FALSE);
1031 p2->setItemEnabled(cwid,FALSE);
1032 p2->setItemEnabled(optid,FALSE);
1034 WriteMessage("CONSOLE LOCKED");
1039 QMessageBox msg(this);
1040 msg.setText("Not matching!");
1041 msg.setButtonText(0,"Close");
1046 else strcpy(LockPasswd,"");
1050 void QKernel::UnlockConsole()
1052 QDialog d(this,"Enter password",TRUE);
1053 QLabel lab(&d,"Password");
1054 QLineEdit ed(&d,"");
1055 QPushButton ob(&d,""),cb(&d,"");
1057 ob.setGeometry( 30, 60, 80, 30 );
1059 ob.setDefault(TRUE);
1060 lab.setGeometry( 10, 10, 60, 30 );
1061 lab.setText( "Password:" );
1062 ed.setGeometry( 70, 10, 140, 30 );
1063 ed.setEchoMode(QLineEdit::Password);
1064 cb.setGeometry( 130, 60, 80, 30 );
1065 cb.setText( "Cancel" );
1066 d.resize( 240, 100 );
1067 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1068 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1072 if (strcmp(ed.text(),LockPasswd)==0)
1074 bar->setItemEnabled(qid,TRUE);
1075 bar->setItemEnabled(prid,TRUE);
1076 bar->setItemEnabled(mid,TRUE);
1077 p2->setItemEnabled(unlockid,FALSE);
1078 p2->setItemEnabled(lockid,TRUE);
1079 p2->setItemEnabled(cwid,TRUE);
1080 p2->setItemEnabled(optid,TRUE);
1082 WriteMessage("CONSOLE UNLOCKED");
1087 QMessageBox msg(this);
1088 msg.setText("Wrong password!");
1089 msg.setButtonText(0,"Close");
1096 void QKernel::InitMessage()
1098 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1103 InterpEntry *QKernel::findINTbySocket(int _id)
1106 pom = Interpreters.first();
1109 if (pom->sock == _id) break;
1110 pom = Interpreters.next();
1115 InterpEntry *QKernel::findINTbyID(int _id)
1118 pom = Interpreters.first();
1121 if (pom->ID == _id) break;
1122 pom = Interpreters.next();
1128 /* ------------------ Connect INT module -----------------*/
1130 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1133 struct sockaddr_un svr;
1139 InterpEntry *newINT;
1148 if (cf == NULL) {WriteMessage("File not found: no .ccd file");return(NULL);}
1154 if (cf == NULL) {WriteMessage("File not found: no .pcd file");return(NULL);}
1157 newINT = new InterpEntry;
1158 for(i=0;i<MAXINSTANCES;i++) newINT->RInstances[i]=-1;
1160 strcpy(b,rindex(ss,'/'));
1161 for(i=0;i<strlen(b);i++)
1165 sprintf(a,"%s : Start execution",b);
1169 newint = freeINTid; freeINTid++;
1170 newINT->ID = newint;
1171 strcpy(newINT->shortname,b);
1172 strcpy(newINT->fullname,ss);
1174 sprintf(a,"%s%d",IPATH,newint);
1175 sprintf(cmd,"%s/modules/logint %s %s",HomeDir,a,ss);
1176 if (r) strcat(cmd," r");
1177 sprintf(b," %s %s %s %s %s",myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
1182 sock = socket(AF_UNIX,SOCK_STREAM,0);
1184 bzero(&svr, sizeof(svr));
1185 svr.sun_family = AF_UNIX;
1186 strcpy(svr.sun_path,a);
1187 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1188 bind(sock,(struct sockaddr*)&svr, len);
1191 newINT->sock = accept(sock,(struct sockaddr*)0,(unsigned int *)0);
1198 fcntl(newINT->sock,F_SETFL,
1199 O_NONBLOCK|fcntl(newINT->sock,F_GETFL,0));
1201 setsockopt(newINT->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
1202 if (r) newINT->remote = 1;else newINT->remote=0;
1204 bzero(&msg,sizeof(MESSAGE));
1205 msg.msg_type = MSG_VLP;
1206 msg.param.pword[0] = VLP_REGINT;
1207 msg.param.pword[1] = newINT->ID;
1208 sprintf(msg.param.pstr,"logi%d.net",newint);
1209 write(net_sock,&msg,sizeof(MESSAGE));
1211 Interpreters.append(newINT);
1212 newINT->notify = new QSocketNotifier(newINT->sock,QSocketNotifier::Read);
1213 connect(newINT->notify,SIGNAL(activated(int)),this,SLOT(IntMessage(int)));
1214 if (info_messages) WriteMessage("INTERPRETER successfully connected");
1217 else WriteMessage("Cannot connect interpreter");
1223 /* ---------------------------------------------------------*/
1224 /* Allocate remote instance */
1226 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1232 m.msg_type = MSG_NET;
1233 m.param.pword[0] = NET_NODE_EXIST;
1234 m.param.pword[1] = on;
1235 m.param.pword[2] = interp->ID;
1236 write(net_sock,&m,sizeof(MESSAGE));
1237 bzero(&m,sizeof(MESSAGE));
1238 while( (m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST) )
1239 read(net_sock,&m,sizeof(MESSAGE));
1241 if (m.param.pword[1]==1) /* means node exists */
1243 m.msg_type = MSG_NET;
1244 m.param.pword[0] = NET_TRANSMIT_CODE;
1245 m.param.pword[1] = interp->ID;
1246 m.param.pword[2] = on;
1247 strcpy(m.param.pstr,interp->fullname);
1248 write(net_sock,&m,sizeof(MESSAGE));
1250 Net_Notify->setEnabled(FALSE);
1251 while ( (m.msg_type != MSG_NET) || (m.param.pword[0]!=NET_TRANSMITTED) )
1252 read(net_sock,&m,sizeof(MESSAGE));
1255 m.msg_type = MSG_NET;
1256 m.param.pword[0] = NET_PROPAGATE;
1257 m.param.pword[1] = MSG_VLP;
1258 m.param.pword[2] = NodeNumber;
1259 m.param.pword[3] = 0;
1260 m.param.pword[4] = on;
1261 m.param.pword[5] = 0;
1262 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1263 m.param.pword[7] = interp->ID;
1264 strcpy(m.param.pstr,interp->shortname);
1265 write(net_sock,&m,sizeof(MESSAGE));
1267 read(net_sock,&m,sizeof(MESSAGE));
1270 if ( (m.param.pword[0]==NET_PROPAGATE) && (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK))
1272 interp->RInstances[on] = m.param.pword[7];
1275 read(net_sock,&m,sizeof(MESSAGE));
1278 Net_Notify->setEnabled(TRUE);
1280 /*bzero(&m,sizeof(MESSAGE));*/
1281 m.msg_type = MSG_VLP;
1282 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1283 m.param.pword[1] = interp->RInstances[on];
1284 write(interp->sock,&m,sizeof(MESSAGE));
1286 else /* There is no such a node! */
1288 sprintf(s,"Warning: Node number %d not found!",on);
1290 WriteMessage("Allocating O-process on the local node");
1291 bzero(&m,sizeof(MESSAGE));
1292 m.msg_type = MSG_VLP;
1293 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1294 m.param.pword[1] = interp->ID;
1295 write(interp->sock,&m,sizeof(MESSAGE));
1300 /*-----------------------------------------------*/
1301 /* Close all remote instances */
1303 void QKernel::CloseInstances(InterpEntry *e)
1308 if (info_messages) WriteMessage("Closing remote instances");
1309 for(i=0;i<MAXINSTANCES;i++)
1310 if (e->RInstances[i]>=0)
1312 msg.msg_type = MSG_NET;
1313 msg.param.pword[0] = NET_PROPAGATE;
1314 msg.param.pword[1] = MSG_VLP;
1315 msg.param.pword[2] = NodeNumber;
1316 msg.param.pword[4] = i;
1317 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1318 msg.param.pword[7] = e->RInstances[i];
1319 write(net_sock,&msg,sizeof(MESSAGE));
1324 void QKernel::Info()
1328 WriteMessage(CharLine);
1329 WriteMessage("### Virtual Machine Information ###");
1330 m.msg_type = MSG_NET;
1331 m.param.pword[0]=NET_GET_INFO;
1332 write(net_sock,&m,sizeof(MESSAGE));
1333 wait_for_info = TRUE;
1336 #include "kernel.moc"
1338 int main( int argc, char **argv )
1341 for(i=0;i<5;i++) strcpy(myargs[i],"");
1342 for(i=1;i<argc;i++) strcpy(myargs[i-1],argv[i]);
1344 app = new QApplication(argc,argv);
1345 app->setStyle(new QWindowsStyle());
1347 app->setMainWidget( &draw);