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)
302 /* Hack for checking if file exists without using external libs.*/
303 FILE * file = fopen(fname, "r");
305 fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname);
308 /* 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)) {
336 strcpy(host, str);//FIXME: buffer overflow
337 ConnectList.append(new ConnectEntry(host));
340 AppConfiguration::error(&cfg);
343 if(config_lookup_string(&cfg, "progdir", &str)){
344 strcpy(progdir, str);//FIXME: buffer overflow
347 AppConfiguration::error(&cfg);
350 if(config_lookup_string(&cfg, "homedir", &str)){
351 strcpy(HomeDir, str);//FIXME: buffer overflow
354 AppConfiguration::error(&cfg);
357 config_destroy(&cfg);
359 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
362 void QKernel::Run_Prog()
365 QString s(QFileDialog::getOpenFileName(progdir,"*.log",this));
369 if (i>0) s.remove(i,4);
370 RunIntModule((char*)s.ascii(),0);
378 sprintf(cmd,"%s/modules/logedit %s %s %s %s %s %s &",HomeDir,HomeDir,
379 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
386 sprintf(cmd,"%s/modules/loghelp %s/doc %s %s %s %s %s &",HomeDir,HomeDir,
387 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
392 void QKernel::RunGraphModule(char *sk)
397 sprintf(cmd,"%s/modules/loggraph %s %s %s %s %s %s",HomeDir,sk,
398 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
402 WriteMessage("Cannot connect GRAPH resources");
408 void QKernel::RunNetModule()
410 struct sockaddr_un svr;
416 sprintf(cmd,"%s/modules/lognet %s %s %s %s %s %s",HomeDir,NPATH,
417 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
420 /* -------- socket for NET module -------- */
422 sock = socket(AF_UNIX,SOCK_STREAM,0);
423 bzero(&svr,sizeof(svr));
424 svr.sun_family = AF_UNIX;
425 strcpy(svr.sun_path,NPATH);
426 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
427 bind(sock,(struct sockaddr*)&svr, len);
430 if ( system(cmd) == 0)
432 net_sock = accept(sock,(struct sockaddr*)0,(unsigned int*)0);
436 WriteMessage("NETWORK successfully connected");
437 fcntl(net_sock,F_SETFL, O_NONBLOCK|fcntl(net_sock,F_GETFL,0));
439 setsockopt(net_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
443 WriteMessage("Cannot connect NETWORK resources");
444 WriteMessage("Exiting...");
451 WriteMessage("Cannot connect NETWORK resources");
452 WriteMessage("Exiting...");
460 void QKernel::Connect()
462 QDialog d(this,"",TRUE);
463 QLabel lab(&d,"IP Address:");
465 QPushButton ob(&d,""),cb(&d,"");
468 d.setFont(QFont("Helvetica",12,QFont::Bold));
469 ob.setGeometry( 30, 60, 80, 30 );
472 lab.setGeometry( 10, 10, 60, 30 );
473 lab.setText( "Address" );
474 ed.setGeometry( 70, 10, 140, 30 );
475 cb.setGeometry( 130, 60, 80, 30 );
476 cb.setText( "Cancel" );
477 d.resize( 240, 100 );
479 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
480 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
483 m.msg_type = MSG_NET;
484 m.param.pword[0] = NET_CONNECT_TO;
485 strcpy(m.param.pstr,ed.text());
486 write(net_sock,&m,sizeof(MESSAGE));
491 void QKernel::Disconnect()
495 if (info_messages) WriteMessage("Disconnecting from virtual machine");
496 msg.msg_type = MSG_NET;
497 msg.param.pword[0] = NET_DISCONNECT;
498 write(net_sock,&msg,sizeof(MESSAGE));
501 void QKernel::QuitProc()
505 if ( QMessageBox::question(this,"Close VLP","Terminate VLP ?",QMessageBox::Yes,QMessageBox::No,0) == QMessageBox::No ) return;
509 msg.msg_type = MSG_NET;
510 msg.param.pword[0] = NET_DISCONNECT;
511 write(net_sock,&msg,sizeof(MESSAGE));*/
516 msg.msg_type = MSG_NET;
517 msg.param.pword[0] = NET_EXIT;
518 write(net_sock,&msg,sizeof(MESSAGE));
519 // ::close(net_sock);
528 void QKernel::AddAddress()
530 QDialog d(this,"",TRUE);
531 QLabel lab(&d,"IP Address:");
533 QPushButton ob(&d,""),cb(&d,"");
537 ob.setGeometry( 30, 60, 80, 30 );
540 lab.setGeometry( 10, 10, 60, 30 );
541 lab.setText( "Address" );
542 ed.setGeometry( 70, 10, 140, 30 );
543 cb.setGeometry( 130, 60, 80, 30 );
544 cb.setText( "Cancel" );
545 d.resize( 240, 100 );
546 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
547 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
549 if (strcmp(ed.text(),"")!=0)
551 connections->insertItem(ed.text());
556 void QKernel::DelAddress()
560 if (connections->currentItem()!=-1)
561 connections->removeItem(connections->currentItem());
567 void QKernel::MessageToNode()
574 dlg = new QDialog(this,"Message",TRUE);
576 nodenr = new QLineEdit(dlg,"number");
577 nodenr->setGeometry( 90, 10, 50, 30 );
581 tmpQLabel = new QLabel( dlg, "Label_1" );
582 tmpQLabel->setGeometry( 10, 10, 77, 30 );
583 tmpQLabel->setText( "Node number:" );
585 tmpQLabel = new QLabel( dlg, "Label_2" );
586 tmpQLabel->setGeometry( 10, 50, 70, 30 );
587 tmpQLabel->setText( "Message:" );
590 msg = new QLineEdit( dlg, "LineEdit_1" );
591 msg->setGeometry( 80, 60, 330, 30 );
595 ob = new QPushButton( dlg, "PushButton_1" );
596 ob->setGeometry( 230, 10, 80, 30 );
597 ob->setText( "Send" );
598 ob->setDefault(TRUE);
599 cb = new QPushButton( dlg, "PushButton_2" );
600 cb->setGeometry( 330, 10, 80, 30 );
601 cb->setText( "Cancel" );
602 dlg->resize( 430, 110 );
603 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
604 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
605 dlg->setCaption("Send message to node");
609 m.msg_type = MSG_NET;
610 m.param.pword[0] = NET_PROPAGATE;
611 m.param.pword[1] = MSG_VLP;
612 m.param.pword[2] = NodeNumber;
613 m.param.pword[4] = atoi(nodenr->text());
614 m.param.pword[6] = VLP_WRITE;
615 strcpy(m.param.pstr,msg->text());
616 write(net_sock,&m,sizeof(MESSAGE));
620 void QKernel::KillInterpreter()
627 dlg = new QDialog(this,"Message",TRUE);
629 nodenr = new QLineEdit(dlg,"number");
630 nodenr->setGeometry( 90, 10, 50, 30 );
634 tmpQLabel = new QLabel( dlg, "Label_1" );
635 tmpQLabel->setGeometry( 10, 10, 77, 30 );
636 tmpQLabel->setText( "Interp. ID:" );
638 ob = new QPushButton( dlg, "PushButton_1" );
639 ob->setGeometry( 160, 10, 80, 30 );
640 ob->setText( "Kill" );
641 ob->setDefault(TRUE);
642 cb = new QPushButton( dlg, "PushButton_2" );
643 cb->setGeometry( 260, 10, 80, 30 );
644 cb->setText( "Cancel" );
645 dlg->resize( 360, 50 );
646 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
647 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
648 dlg->setCaption("Kill interpreter");
652 m.msg_type = MSG_INT;
653 m.param.pword[0] = INT_KILL;
654 pom = findINTbyID(atoi(nodenr->text()));
658 write(pom->sock,&m,sizeof(MESSAGE));
659 else WriteMessage("This is a remote instance of a program!");
661 else WriteMessage("Interpreter not found");
669 void QKernel::NetMessage()
676 cnt = read(net_sock,&msg,sizeof(MESSAGE));
677 if ( (cnt>0) && (msg.msg_type==MSG_NET))
679 switch(msg.param.pword[0])
681 case NET_CSWRITELN: WriteMessage(msg.param.pstr);break;
683 switch(msg.param.pword[1])
686 /* pom = find_link_by_ID(msg.param.pword[5]);
687 msg.msg_type = MSG_NET;
688 msg.param.pword[0] = NET_PROPAGATE;
689 send_int(pom,&msg);*/
692 switch(msg.param.pword[6])
695 QApplication::beep();
696 WriteMessage(CharLine);
697 WriteMessage("### Incoming Messsage ###");
698 sprintf(ss,"Mesg from Node %d: %s",msg.param.pword[2],msg.param.pstr);
700 WriteMessage(CharLine);
702 case VLP_REMOTE_INSTANCE:
703 sprintf(ss,"%s/%s",REMOTE_PATH,msg.param.pstr);
706 WriteMessage("Running program:");
709 pom = RunIntModule(ss,1);
712 pom->p_ctx.node = msg.param.pword[2];
713 pom->p_ctx.program_id = msg.param.pword[7];
714 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
717 case VLP_CLOSE_INSTANCE:
718 msg.msg_type = MSG_INT;
719 msg.param.pword[0] = INT_CLOSE_INSTANCE;
720 pom = findINTbyID(msg.param.pword[7]);
723 write(pom->sock,&msg,sizeof(MESSAGE));
725 m1.msg_type = MSG_VLP;
726 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
727 m1.param.pword[1] = pom->ID;
728 write(net_sock,&m1,sizeof(MESSAGE));
729 } else WriteMessage("Instance not found");
735 case NET_CONNECTIONS: ActiveConnections = msg.param.pword[1];
736 WriteMessage(msg.param.pstr);
737 if (!synchro) synchro=TRUE;
742 QString poms,poms1,poms2;
743 poms.sprintf("%s",msg.param.pstr);
744 while (poms.length()>0)
748 { poms1=poms.left(cnt);
749 poms=poms.right(poms.length()-cnt-1);
753 poms2=poms1.left(cnt);
754 poms1=poms1.right(poms1.length()-cnt-1);
755 sprintf(ss,"Node: %s Addr: %s",poms2.data(),poms1.data());
762 case NET_INFO_END:wait_for_info=FALSE;
763 WriteMessage(CharLine);
773 void QKernel::IntMessage(int sock)
779 cnt = read(sock,&msg,sizeof(MESSAGE));
780 e = findINTbySocket(sock);
781 if ( (cnt>0) && (e!=NULL))
783 switch (msg.msg_type)
786 if (msg.param.pword[0]==GRAPH_ALLOCATE)
788 RunGraphModule(msg.param.pstr);
792 write(net_sock,&msg,sizeof(MESSAGE));break;
794 switch(msg.param.pword[0])
796 case VLP_REMOTE_INSTANCE_PLEASE:
797 RemoteInstance(e,msg.param.pword[2]);
802 switch(msg.param.pword[0]){
808 m.msg_type = MSG_VLP;
809 m.param.pword[0] = VLP_INTERPRETER_DOWN;
810 m.param.pword[1] = e->ID;
811 write(net_sock,&m,sizeof(MESSAGE));
812 if (e->remote==0) CloseInstances(e);
815 Interpreters.remove(e);
819 sprintf(ss,"%s : End of program execution",msg.param.pstr);
825 msg.msg_type = MSG_INT;
826 msg.param.pword[0] = INT_CTX;
827 msg.param.pword[1] = NodeNumber;
828 msg.param.pword[2] = e->ID;
831 msg.param.pword[3] = e->p_ctx.node;
832 msg.param.pword[4] = e->p_ctx.program_id;
834 write(sock,&msg,sizeof(MESSAGE));
836 };break; /* switch param.pword[0] */
842 void QKernel::WriteMessage(char *msg)
846 desktop->getCursorPosition(&x,&y);
847 if (x>100) desktop->clear();
848 desktop->setReadOnly(FALSE);
849 desktop->append(msg);
850 desktop->setReadOnly(TRUE);
851 desktop->setCursorPosition(desktop->numLines(),1);
853 if (desktop->numLines()>100) desktop->clear();
856 void QKernel::SetMessages()
861 if ( p2->isItemChecked(msgid))
863 p2->setItemChecked(msgid,FALSE);
868 p2->setItemChecked(msgid,TRUE);
875 void QKernel::SetOptions()
877 QDialog dlg(this,"Options",TRUE);
885 progs = new QLineEdit( &dlg, "progs" );
886 progs->setGeometry( 150, 20, 180, 30 );
887 progs->setText(progdir);
890 tmpQLabel = new QLabel( &dlg, "Label_1" );
891 tmpQLabel->setGeometry( 30, 20, 120, 30 );
892 tmpQLabel->setText( "Programs directory" );
895 tmpQFrame = new QFrame( &dlg, "Frame_2" );
896 tmpQFrame->setGeometry( 10, 60, 380, 30 );
897 tmpQFrame->setFrameStyle( 52 );
899 tmpQLabel = new QLabel( &dlg, "Label_2" );
900 tmpQLabel->setGeometry( 10, 80, 340, 30 );
901 tmpQLabel->setText( "Virtual Processor properties (activated after restarting VLP):" );
905 nn = new QLineEdit( &dlg, "LineEdit_2" );
906 nn->setGeometry( 110, 110, 40, 30 );
907 sprintf(nns,"%d",NodeNumber);
910 tmpQLabel = new QLabel( &dlg, "Label_3" );
911 tmpQLabel->setGeometry( 20, 110, 90, 30 );
912 tmpQLabel->setText( "Node number:" );
914 QRadioButton *exp,*reg;
915 exp = new QRadioButton( &dlg, "RadioButton_3" );
916 exp->setGeometry( 30, 170, 100, 30 );
917 exp->setText( "Explicit" );
918 exp->setChecked( TRUE );
920 reg = new QRadioButton( &dlg, "RadioButton_4" );
921 reg->setGeometry( 30, 200, 100, 30 );
922 reg->setText( "Registration" );
923 reg->setEnabled(FALSE);
925 connections = new QListBox( &dlg, "ListBox_1" );
926 connections->setGeometry( 170, 140, 130, 100 );
927 e = ConnectList.first();
930 connections->insertItem(e->addr);
931 e = ConnectList.next();
934 tmpQLabel = new QLabel( &dlg, "Label_5" );
935 tmpQLabel->setGeometry( 170, 110, 100, 30 );
936 tmpQLabel->setText( "Connection list:" );
938 QPushButton* addbtn,*delbtn,*okbtn,*cancelbtn;
939 addbtn = new QPushButton( &dlg, "PushButton_1" );
940 addbtn->setGeometry( 310, 150, 60, 30 );
941 addbtn->setText( "Add" );
942 delbtn = new QPushButton( &dlg, "PushButton_2" );
943 delbtn->setGeometry( 310, 200, 60, 30 );
944 delbtn->setText( "Del" );
945 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddAddress()));
946 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelAddress()));
947 okbtn = new QPushButton( &dlg, "PushButton_3" );
948 okbtn->setGeometry( 80, 260, 100, 30 );
949 okbtn->setText( "Ok" );
950 okbtn->setDefault(TRUE);
951 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
952 cancelbtn->setGeometry( 210, 260, 100, 30 );
953 cancelbtn->setText( "Cancel" );
954 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
955 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
957 group = new QButtonGroup( &dlg, "ButtonGroup_1" );
958 group->setGeometry( 20, 150, 120, 90 );
959 group->setTitle( "Connection type" );
960 group->setAlignment( 1 );
962 group->insert(exp,1);
963 group->insert(reg,2);
965 dlg.resize( 400, 310 );
969 vlp_file = new QFile("vlp.cfg");
970 vlp_file->open(IO_WriteOnly);
971 sprintf(line,"progdir=%s\n",progs->text().ascii());
972 vlp_file->writeBlock(line,strlen(line));
973 strcpy(progdir,progs->text());
974 sprintf(line,"node_number=%d\n",atoi(nn->text()));
975 vlp_file->writeBlock(line,strlen(line));
976 if ( exp->isChecked())
978 sprintf(line,"type=explicit\n");
979 vlp_file->writeBlock(line,strlen(line));
980 for(i=0;i<connections->count();i++)
982 sprintf(line,"host=%s\n",connections->text(i).ascii());
983 vlp_file->writeBlock(line,strlen(line));
989 sprintf(line,"type=register\n");
990 vlp_file->writeBlock(line,strlen(line));
997 void QKernel::LockConsole()
999 QDialog d(this,"Enter password",TRUE);
1000 QLabel lab(&d,"Password");
1001 QLineEdit ed(&d,"");
1002 QPushButton ob(&d,""),cb(&d,"");
1004 d.setCaption("Lock console");
1005 ob.setGeometry( 30, 60, 80, 30 );
1007 ob.setDefault(TRUE);
1008 lab.setGeometry( 10, 10, 60, 30 );
1009 lab.setText( "Password:" );
1010 ed.setGeometry( 70, 10, 140, 30 );
1011 ed.setEchoMode(QLineEdit::Password);
1012 cb.setGeometry( 130, 60, 80, 30 );
1013 cb.setText( "Cancel" );
1014 d.resize( 240, 100 );
1015 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1016 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1019 if (strcmp(ed.text(),"")!=0)
1021 strcpy(LockPasswd,ed.text());
1022 lab.setText("Retype:");
1026 if (strcmp(ed.text(),LockPasswd)==0)
1028 bar->setItemEnabled(qid,FALSE);
1029 bar->setItemEnabled(prid,FALSE);
1030 bar->setItemEnabled(mid,FALSE);
1031 p2->setItemEnabled(unlockid,TRUE);
1032 p2->setItemEnabled(lockid,FALSE);
1033 p2->setItemEnabled(cwid,FALSE);
1034 p2->setItemEnabled(optid,FALSE);
1036 WriteMessage("CONSOLE LOCKED");
1041 QMessageBox msg(this);
1042 msg.setText("Not matching!");
1043 msg.setButtonText(0,"Close");
1048 else strcpy(LockPasswd,"");
1052 void QKernel::UnlockConsole()
1054 QDialog d(this,"Enter password",TRUE);
1055 QLabel lab(&d,"Password");
1056 QLineEdit ed(&d,"");
1057 QPushButton ob(&d,""),cb(&d,"");
1059 ob.setGeometry( 30, 60, 80, 30 );
1061 ob.setDefault(TRUE);
1062 lab.setGeometry( 10, 10, 60, 30 );
1063 lab.setText( "Password:" );
1064 ed.setGeometry( 70, 10, 140, 30 );
1065 ed.setEchoMode(QLineEdit::Password);
1066 cb.setGeometry( 130, 60, 80, 30 );
1067 cb.setText( "Cancel" );
1068 d.resize( 240, 100 );
1069 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1070 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1074 if (strcmp(ed.text(),LockPasswd)==0)
1076 bar->setItemEnabled(qid,TRUE);
1077 bar->setItemEnabled(prid,TRUE);
1078 bar->setItemEnabled(mid,TRUE);
1079 p2->setItemEnabled(unlockid,FALSE);
1080 p2->setItemEnabled(lockid,TRUE);
1081 p2->setItemEnabled(cwid,TRUE);
1082 p2->setItemEnabled(optid,TRUE);
1084 WriteMessage("CONSOLE UNLOCKED");
1089 QMessageBox msg(this);
1090 msg.setText("Wrong password!");
1091 msg.setButtonText(0,"Close");
1098 void QKernel::InitMessage()
1100 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1105 InterpEntry *QKernel::findINTbySocket(int _id)
1108 pom = Interpreters.first();
1111 if (pom->sock == _id) break;
1112 pom = Interpreters.next();
1117 InterpEntry *QKernel::findINTbyID(int _id)
1120 pom = Interpreters.first();
1123 if (pom->ID == _id) break;
1124 pom = Interpreters.next();
1130 /* ------------------ Connect INT module -----------------*/
1132 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1135 struct sockaddr_un svr;
1141 InterpEntry *newINT;
1150 if (cf == NULL) {WriteMessage("File not found: no .ccd file");return(NULL);}
1156 if (cf == NULL) {WriteMessage("File not found: no .pcd file");return(NULL);}
1159 newINT = new InterpEntry;
1160 for(i=0;i<MAXINSTANCES;i++) newINT->RInstances[i]=-1;
1162 strcpy(b,rindex(ss,'/'));
1163 for(i=0;i<strlen(b);i++)
1167 sprintf(a,"%s : Start execution",b);
1171 newint = freeINTid; freeINTid++;
1172 newINT->ID = newint;
1173 strcpy(newINT->shortname,b);
1174 strcpy(newINT->fullname,ss);
1176 sprintf(a,"%s%d",IPATH,newint);
1177 sprintf(cmd,"%s/modules/logint %s %s",HomeDir,a,ss);
1178 if (r) strcat(cmd," r");
1179 sprintf(b," %s %s %s %s %s",myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
1184 sock = socket(AF_UNIX,SOCK_STREAM,0);
1186 bzero(&svr, sizeof(svr));
1187 svr.sun_family = AF_UNIX;
1188 strcpy(svr.sun_path,a);
1189 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1190 bind(sock,(struct sockaddr*)&svr, len);
1193 newINT->sock = accept(sock,(struct sockaddr*)0,(unsigned int *)0);
1200 fcntl(newINT->sock,F_SETFL,
1201 O_NONBLOCK|fcntl(newINT->sock,F_GETFL,0));
1203 setsockopt(newINT->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
1204 if (r) newINT->remote = 1;else newINT->remote=0;
1206 bzero(&msg,sizeof(MESSAGE));
1207 msg.msg_type = MSG_VLP;
1208 msg.param.pword[0] = VLP_REGINT;
1209 msg.param.pword[1] = newINT->ID;
1210 sprintf(msg.param.pstr,"logi%d.net",newint);
1211 write(net_sock,&msg,sizeof(MESSAGE));
1213 Interpreters.append(newINT);
1214 newINT->notify = new QSocketNotifier(newINT->sock,QSocketNotifier::Read);
1215 connect(newINT->notify,SIGNAL(activated(int)),this,SLOT(IntMessage(int)));
1216 if (info_messages) WriteMessage("INTERPRETER successfully connected");
1219 else WriteMessage("Cannot connect interpreter");
1225 /* ---------------------------------------------------------*/
1226 /* Allocate remote instance */
1228 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1234 m.msg_type = MSG_NET;
1235 m.param.pword[0] = NET_NODE_EXIST;
1236 m.param.pword[1] = on;
1237 m.param.pword[2] = interp->ID;
1238 write(net_sock,&m,sizeof(MESSAGE));
1239 bzero(&m,sizeof(MESSAGE));
1240 while( (m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST) )
1241 read(net_sock,&m,sizeof(MESSAGE));
1243 if (m.param.pword[1]==1) /* means node exists */
1245 m.msg_type = MSG_NET;
1246 m.param.pword[0] = NET_TRANSMIT_CODE;
1247 m.param.pword[1] = interp->ID;
1248 m.param.pword[2] = on;
1249 strcpy(m.param.pstr,interp->fullname);
1250 write(net_sock,&m,sizeof(MESSAGE));
1252 Net_Notify->setEnabled(FALSE);
1253 while ( (m.msg_type != MSG_NET) || (m.param.pword[0]!=NET_TRANSMITTED) )
1254 read(net_sock,&m,sizeof(MESSAGE));
1257 m.msg_type = MSG_NET;
1258 m.param.pword[0] = NET_PROPAGATE;
1259 m.param.pword[1] = MSG_VLP;
1260 m.param.pword[2] = NodeNumber;
1261 m.param.pword[3] = 0;
1262 m.param.pword[4] = on;
1263 m.param.pword[5] = 0;
1264 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1265 m.param.pword[7] = interp->ID;
1266 strcpy(m.param.pstr,interp->shortname);
1267 write(net_sock,&m,sizeof(MESSAGE));
1269 read(net_sock,&m,sizeof(MESSAGE));
1272 if ( (m.param.pword[0]==NET_PROPAGATE) && (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK))
1274 interp->RInstances[on] = m.param.pword[7];
1277 read(net_sock,&m,sizeof(MESSAGE));
1280 Net_Notify->setEnabled(TRUE);
1282 /*bzero(&m,sizeof(MESSAGE));*/
1283 m.msg_type = MSG_VLP;
1284 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1285 m.param.pword[1] = interp->RInstances[on];
1286 write(interp->sock,&m,sizeof(MESSAGE));
1288 else /* There is no such a node! */
1290 sprintf(s,"Warning: Node number %d not found!",on);
1292 WriteMessage("Allocating O-process on the local node");
1293 bzero(&m,sizeof(MESSAGE));
1294 m.msg_type = MSG_VLP;
1295 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1296 m.param.pword[1] = interp->ID;
1297 write(interp->sock,&m,sizeof(MESSAGE));
1302 /*-----------------------------------------------*/
1303 /* Close all remote instances */
1305 void QKernel::CloseInstances(InterpEntry *e)
1310 if (info_messages) WriteMessage("Closing remote instances");
1311 for(i=0;i<MAXINSTANCES;i++)
1312 if (e->RInstances[i]>=0)
1314 msg.msg_type = MSG_NET;
1315 msg.param.pword[0] = NET_PROPAGATE;
1316 msg.param.pword[1] = MSG_VLP;
1317 msg.param.pword[2] = NodeNumber;
1318 msg.param.pword[4] = i;
1319 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1320 msg.param.pword[7] = e->RInstances[i];
1321 write(net_sock,&msg,sizeof(MESSAGE));
1326 void QKernel::Info()
1330 WriteMessage(CharLine);
1331 WriteMessage("### Virtual Machine Information ###");
1332 m.msg_type = MSG_NET;
1333 m.param.pword[0]=NET_GET_INFO;
1334 write(net_sock,&m,sizeof(MESSAGE));
1335 wait_for_info = TRUE;
1338 #include "kernel.moc"
1340 int main( int argc, char **argv )
1343 for(i=0;i<5;i++) strcpy(myargs[i],"");
1344 for(i=1;i<argc;i++) strcpy(myargs[i-1],argv[i]);
1346 app = new QApplication(argc,argv);
1347 app->setStyle(new QWindowsStyle());
1349 app->setMainWidget( &draw);