1 /**************************************************************
3 Copyright (C) 1997 Oskar Swida
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 NOTE: This software is using the free software license of
23 the QT library v.1.30 from Troll Tech AS.
24 See the file LICENSE.QT.
27 To contact the author, write:
28 e-mail: swida@aragorn.pb.bialystok.pl
30 ************************************************************/
34 //#include <qwindow.h>
62 #include <qwindowsstyle.h>
72 #include <netinet/in.h>
74 #include <libconfig.h>
79 #define REMOTE_PATH "REMOTE"
81 #define MAXINSTANCES 256
89 char CharLine[25]="________________________";
93 /* --------------- interpreter slot -----------------*/
97 int ID; // INT identifier
98 bool remote; // Am I remote ?
99 char fullname[255],shortname[255]; // Program name
101 QSocketNotifier *notify;
102 int RInstances[MAXINSTANCES]; // IDs of my remote INT modules
103 ctx_struct p_ctx; // parent INT info
105 /*++++++++++++++++++++++++++++++++++++++++++*/
107 /*----------------- connection slot -------------*/
112 ConnectEntry(char *s) {strcpy(addr,s);};
115 /* ++++++++++++++++++++++++++++++++++++++++++ */
120 /* ---------------------------------------------------------- */
121 /* KERNEL CLASS DEFINITION */
122 /* ---------------------------------------------------------- */
124 class QKernel : public QFrame
129 QMultiLineEdit *desktop;
131 QPopupMenu *p,*p1,*p2;
133 int NodeNumber,ConType;
139 virtual void resizeEvent( QResizeEvent *ev );
141 void WriteMessage(char* msg);
155 void UnlockConsole();
156 void MessageToNode();
159 void IntMessage(int);
160 void KillInterpreter();
167 virtual void closeEvent ( QCloseEvent * e );
170 QList<InterpEntry> Interpreters;
171 QList<ConnectEntry> ConnectList;
172 QListBox *connections;
173 int Tasks; // number of working interpreters
174 int ActiveConnections; // number of connected VLPs
175 bool LOCKED,synchro,wait_for_info;
177 int lockid,unlockid,qid,cwid,
178 optid,prid,mid,msgid,toolsid,hid;
181 QSocketNotifier *Net_Notify;
186 void LoadConfig(char *);
187 void RunGraphModule(char*);
189 InterpEntry *findINTbySocket(int);
190 InterpEntry *findINTbyID(int);
191 InterpEntry *RunIntModule(char *ss,int r);
192 void RemoteInstance(InterpEntry*,int);
193 void CloseInstances(InterpEntry*);
197 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
199 void QKernel::closeEvent ( QCloseEvent * e ) {
205 QFont f("Helvetica",10,QFont::Bold);
206 QFont f1("Helvetica",10,QFont::Normal);
207 QFont f2("Times Roman",10,QFont::Normal);
213 sprintf(ss,"mkdir %s",REMOTE_PATH);
220 setCaption("Virtual LOGLAN Processor");
221 setBackgroundColor(white);
223 bar = new QMenuBar(this);
225 p = new QPopupMenu();
227 p->insertItem("Execute",this,SLOT(Run_Prog()));
228 p->insertItem("Kill",this,SLOT(KillInterpreter()));
229 prid = bar->insertItem("&Program",p);
230 p1 = new QPopupMenu();
231 p1->insertItem("Message",this,SLOT(MessageToNode()));
232 p1->insertSeparator();
233 p1->insertItem("Connect",this,SLOT(Connect()));
234 p1->insertItem("Disconnect",this,SLOT(Disconnect()));
235 p1->insertItem("Info",this,SLOT(Info()));
237 mid = bar->insertItem("&Machine",p1);
239 p2 = new QPopupMenu();
240 cwid = p2->insertItem("Editor",this,SLOT(Edit()));
241 hid = p2->insertItem("Help",this,SLOT(Help()));
242 p2->insertSeparator();
243 optid = p2->insertItem("Options",this,SLOT(SetOptions()));
244 msgid = p2->insertItem("Info messages",this,SLOT(SetMessages()));
245 p2->setItemChecked(msgid,TRUE);
246 p2->insertSeparator();
247 lockid = p2->insertItem("Lock console",this,SLOT(LockConsole()));
248 unlockid = p2->insertItem("Unlock console",this,SLOT(UnlockConsole()));
249 p2->setItemEnabled(unlockid,FALSE);
252 toolsid = bar->insertItem("&Tools",p2);
254 qid = bar->insertItem("&Quit",this,SLOT(QuitProc()));
257 desktop = new QMultiLineEdit(this,"desktop");
258 desktop->setAutoUpdate(TRUE);
259 desktop->setReadOnly(TRUE);
260 desktop->setFont(f1);
265 ActiveConnections = 0;
266 strcpy(LockPasswd,"");
267 LoadConfig("vlp.cfg");
270 Net_Notify = new QSocketNotifier(net_sock,QSocketNotifier::Read,this);
271 connect(Net_Notify,SIGNAL(activated(int)),this,SLOT(NetMessage()));
276 void QKernel::resizeEvent( QResizeEvent *ev )
278 QFrame::resizeEvent(ev);
280 desktop->setGeometry( 0,bar->height(), width(), height() - bar->height() );
286 void QKernel::n_impl()
288 QMessageBox::information(this,"Function info","This function is not implemented yet...","Ok");
292 /* ########### load configuration from file ############# */
294 void QKernel::LoadConfig(char * fname)
297 config_setting_t *setting;
300 /* Hack for checking if file exists without using external libs.*/
301 FILE * file = fopen(fname, "rt");
303 fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname);
306 /* File exists, so file has been locked. Release it. */
310 /* Read the file. If there is an error, report it and exit. */
311 if(!config_read(&cfg, file))
313 fprintf(stderr, "%s! In file %s, line %d\n",
314 config_error_text(&cfg),
315 config_error_file(&cfg),
316 config_error_line(&cfg));
317 config_destroy(&cfg);
319 exit(3);/* from original code. */
322 setting = config_lookup(&cfg, "node_number");
324 NodeNumber = config_setting_get_int(setting);
327 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
331 config_destroy(&cfg);
336 setting = config_lookup(&cfg, "type");
338 ConType = (strcmp(config_setting_get_string(setting), "explicit") == 0) ? 1 : 2;
341 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
347 setting = config_lookup(&cfg, "host");
349 switch(config_setting_type(setting)) {
350 case CONFIG_TYPE_STRING:/* TODO: Deprecated. Made for back compatibility. */
351 ConnectList.append(new ConnectEntry((char*)config_setting_get_string(setting)));
353 case CONFIG_TYPE_ARRAY:
354 for (int i = 0; i < config_setting_length(setting); i++) {
355 ConnectList.append(new ConnectEntry((char*)config_setting_get_string_elem(setting, i)));
359 fprintf(stderr, "%s! In file %s, bad entry type for %s. Will not be read.\n",
366 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
372 setting = config_lookup(&cfg, "progdir");
374 strncpy(progdir, config_setting_get_string(setting), 256);
377 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
383 setting = config_lookup(&cfg, "homedir");
385 strncpy(HomeDir, config_setting_get_string(setting), 255);
388 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
394 config_destroy(&cfg);
397 /* +++++++++++++++++++++++++++++++++++++++++++++++ */
400 void QKernel::Run_Prog()
403 QString s(QFileDialog::getOpenFileName(progdir,"*.log",this));
407 if (i>0) s.remove(i,4);
408 RunIntModule((char*)s.ascii(),0);
416 sprintf(cmd,"%s/modules/logedit %s %s %s %s %s %s &",HomeDir,HomeDir,
417 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
424 sprintf(cmd,"%s/modules/loghelp %s/doc %s %s %s %s %s &",HomeDir,HomeDir,
425 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
430 void QKernel::RunGraphModule(char *sk)
435 sprintf(cmd,"%s/modules/loggraph %s %s %s %s %s %s",HomeDir,sk,
436 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
440 WriteMessage("Cannot connect GRAPH resources");
446 void QKernel::RunNetModule()
448 struct sockaddr_un svr;
454 sprintf(cmd,"%s/modules/lognet %s %s %s %s %s %s",HomeDir,NPATH,
455 myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
458 /* -------- socket for NET module -------- */
460 sock = socket(AF_UNIX,SOCK_STREAM,0);
461 bzero(&svr,sizeof(svr));
462 svr.sun_family = AF_UNIX;
463 strcpy(svr.sun_path,NPATH);
464 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
465 bind(sock,(struct sockaddr*)&svr, len);
468 if ( system(cmd) == 0)
470 net_sock = accept(sock,(struct sockaddr*)0,(unsigned int*)0);
474 WriteMessage("NETWORK successfully connected");
475 fcntl(net_sock,F_SETFL, O_NONBLOCK|fcntl(net_sock,F_GETFL,0));
477 setsockopt(net_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
481 WriteMessage("Cannot connect NETWORK resources");
482 WriteMessage("Exiting...");
489 WriteMessage("Cannot connect NETWORK resources");
490 WriteMessage("Exiting...");
498 void QKernel::Connect()
500 QDialog d(this,"",TRUE);
501 QLabel lab(&d,"IP Address:");
503 QPushButton ob(&d,""),cb(&d,"");
506 d.setFont(QFont("Helvetica",12,QFont::Bold));
507 ob.setGeometry( 30, 60, 80, 30 );
510 lab.setGeometry( 10, 10, 60, 30 );
511 lab.setText( "Address" );
512 ed.setGeometry( 70, 10, 140, 30 );
513 cb.setGeometry( 130, 60, 80, 30 );
514 cb.setText( "Cancel" );
515 d.resize( 240, 100 );
517 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
518 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
521 m.msg_type = MSG_NET;
522 m.param.pword[0] = NET_CONNECT_TO;
523 strcpy(m.param.pstr,ed.text());
524 write(net_sock,&m,sizeof(MESSAGE));
529 void QKernel::Disconnect()
533 if (info_messages) WriteMessage("Disconnecting from virtual machine");
534 msg.msg_type = MSG_NET;
535 msg.param.pword[0] = NET_DISCONNECT;
536 write(net_sock,&msg,sizeof(MESSAGE));
539 void QKernel::QuitProc()
543 if ( QMessageBox::question(this,"Close VLP","Terminate VLP ?",QMessageBox::Yes,QMessageBox::No,0) == QMessageBox::No ) return;
547 msg.msg_type = MSG_NET;
548 msg.param.pword[0] = NET_DISCONNECT;
549 write(net_sock,&msg,sizeof(MESSAGE));*/
554 msg.msg_type = MSG_NET;
555 msg.param.pword[0] = NET_EXIT;
556 write(net_sock,&msg,sizeof(MESSAGE));
557 // ::close(net_sock);
566 void QKernel::AddAddress()
568 QDialog d(this,"",TRUE);
569 QLabel lab(&d,"IP Address:");
571 QPushButton ob(&d,""),cb(&d,"");
575 ob.setGeometry( 30, 60, 80, 30 );
578 lab.setGeometry( 10, 10, 60, 30 );
579 lab.setText( "Address" );
580 ed.setGeometry( 70, 10, 140, 30 );
581 cb.setGeometry( 130, 60, 80, 30 );
582 cb.setText( "Cancel" );
583 d.resize( 240, 100 );
584 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
585 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
587 if (strcmp(ed.text(),"")!=0)
589 connections->insertItem(ed.text());
594 void QKernel::DelAddress()
598 if (connections->currentItem()!=-1)
599 connections->removeItem(connections->currentItem());
605 void QKernel::MessageToNode()
612 dlg = new QDialog(this,"Message",TRUE);
614 nodenr = new QLineEdit(dlg,"number");
615 nodenr->setGeometry( 90, 10, 50, 30 );
619 tmpQLabel = new QLabel( dlg, "Label_1" );
620 tmpQLabel->setGeometry( 10, 10, 77, 30 );
621 tmpQLabel->setText( "Node number:" );
623 tmpQLabel = new QLabel( dlg, "Label_2" );
624 tmpQLabel->setGeometry( 10, 50, 70, 30 );
625 tmpQLabel->setText( "Message:" );
628 msg = new QLineEdit( dlg, "LineEdit_1" );
629 msg->setGeometry( 80, 60, 330, 30 );
633 ob = new QPushButton( dlg, "PushButton_1" );
634 ob->setGeometry( 230, 10, 80, 30 );
635 ob->setText( "Send" );
636 ob->setDefault(TRUE);
637 cb = new QPushButton( dlg, "PushButton_2" );
638 cb->setGeometry( 330, 10, 80, 30 );
639 cb->setText( "Cancel" );
640 dlg->resize( 430, 110 );
641 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
642 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
643 dlg->setCaption("Send message to node");
647 m.msg_type = MSG_NET;
648 m.param.pword[0] = NET_PROPAGATE;
649 m.param.pword[1] = MSG_VLP;
650 m.param.pword[2] = NodeNumber;
651 m.param.pword[4] = atoi(nodenr->text());
652 m.param.pword[6] = VLP_WRITE;
653 strcpy(m.param.pstr,msg->text());
654 write(net_sock,&m,sizeof(MESSAGE));
658 void QKernel::KillInterpreter()
665 dlg = new QDialog(this,"Message",TRUE);
667 nodenr = new QLineEdit(dlg,"number");
668 nodenr->setGeometry( 90, 10, 50, 30 );
672 tmpQLabel = new QLabel( dlg, "Label_1" );
673 tmpQLabel->setGeometry( 10, 10, 77, 30 );
674 tmpQLabel->setText( "Interp. ID:" );
676 ob = new QPushButton( dlg, "PushButton_1" );
677 ob->setGeometry( 160, 10, 80, 30 );
678 ob->setText( "Kill" );
679 ob->setDefault(TRUE);
680 cb = new QPushButton( dlg, "PushButton_2" );
681 cb->setGeometry( 260, 10, 80, 30 );
682 cb->setText( "Cancel" );
683 dlg->resize( 360, 50 );
684 connect(ob,SIGNAL(clicked()),dlg,SLOT(accept()));
685 connect(cb,SIGNAL(clicked()),dlg,SLOT(reject()));
686 dlg->setCaption("Kill interpreter");
690 m.msg_type = MSG_INT;
691 m.param.pword[0] = INT_KILL;
692 pom = findINTbyID(atoi(nodenr->text()));
696 write(pom->sock,&m,sizeof(MESSAGE));
697 else WriteMessage("This is a remote instance of a program!");
699 else WriteMessage("Interpreter not found");
707 void QKernel::NetMessage()
714 cnt = read(net_sock,&msg,sizeof(MESSAGE));
715 if ( (cnt>0) && (msg.msg_type==MSG_NET))
717 switch(msg.param.pword[0])
719 case NET_CSWRITELN: WriteMessage(msg.param.pstr);break;
721 switch(msg.param.pword[1])
724 /* pom = find_link_by_ID(msg.param.pword[5]);
725 msg.msg_type = MSG_NET;
726 msg.param.pword[0] = NET_PROPAGATE;
727 send_int(pom,&msg);*/
730 switch(msg.param.pword[6])
733 QApplication::beep();
734 WriteMessage(CharLine);
735 WriteMessage("### Incoming Messsage ###");
736 sprintf(ss,"Mesg from Node %d: %s",msg.param.pword[2],msg.param.pstr);
738 WriteMessage(CharLine);
740 case VLP_REMOTE_INSTANCE:
741 sprintf(ss,"%s/%s",REMOTE_PATH,msg.param.pstr);
744 WriteMessage("Running program:");
747 pom = RunIntModule(ss,1);
750 pom->p_ctx.node = msg.param.pword[2];
751 pom->p_ctx.program_id = msg.param.pword[7];
752 pom->RInstances[msg.param.pword[2]] = msg.param.pword[7];
755 case VLP_CLOSE_INSTANCE:
756 msg.msg_type = MSG_INT;
757 msg.param.pword[0] = INT_CLOSE_INSTANCE;
758 pom = findINTbyID(msg.param.pword[7]);
761 write(pom->sock,&msg,sizeof(MESSAGE));
763 m1.msg_type = MSG_VLP;
764 m1.param.pword[0] = VLP_INTERPRETER_DOWN;
765 m1.param.pword[1] = pom->ID;
766 write(net_sock,&m1,sizeof(MESSAGE));
767 } else WriteMessage("Instance not found");
773 case NET_CONNECTIONS: ActiveConnections = msg.param.pword[1];
774 WriteMessage(msg.param.pstr);
775 if (!synchro) synchro=TRUE;
780 QString poms,poms1,poms2;
781 poms.sprintf("%s",msg.param.pstr);
782 while (poms.length()>0)
786 { poms1=poms.left(cnt);
787 poms=poms.right(poms.length()-cnt-1);
791 poms2=poms1.left(cnt);
792 poms1=poms1.right(poms1.length()-cnt-1);
793 sprintf(ss,"Node: %s Addr: %s",poms2.data(),poms1.data());
800 case NET_INFO_END:wait_for_info=FALSE;
801 WriteMessage(CharLine);
811 void QKernel::IntMessage(int sock)
817 cnt = read(sock,&msg,sizeof(MESSAGE));
818 e = findINTbySocket(sock);
819 if ( (cnt>0) && (e!=NULL))
821 switch (msg.msg_type)
824 if (msg.param.pword[0]==GRAPH_ALLOCATE)
826 RunGraphModule(msg.param.pstr);
830 write(net_sock,&msg,sizeof(MESSAGE));break;
832 switch(msg.param.pword[0])
834 case VLP_REMOTE_INSTANCE_PLEASE:
835 RemoteInstance(e,msg.param.pword[2]);
840 switch(msg.param.pword[0]){
846 m.msg_type = MSG_VLP;
847 m.param.pword[0] = VLP_INTERPRETER_DOWN;
848 m.param.pword[1] = e->ID;
849 write(net_sock,&m,sizeof(MESSAGE));
850 if (e->remote==0) CloseInstances(e);
853 Interpreters.remove(e);
857 sprintf(ss,"%s : End of program execution",msg.param.pstr);
863 msg.msg_type = MSG_INT;
864 msg.param.pword[0] = INT_CTX;
865 msg.param.pword[1] = NodeNumber;
866 msg.param.pword[2] = e->ID;
869 msg.param.pword[3] = e->p_ctx.node;
870 msg.param.pword[4] = e->p_ctx.program_id;
872 write(sock,&msg,sizeof(MESSAGE));
874 };break; /* switch param.pword[0] */
880 void QKernel::WriteMessage(char *msg)
884 desktop->getCursorPosition(&x,&y);
885 if (x>100) desktop->clear();
886 desktop->setReadOnly(FALSE);
887 desktop->append(msg);
888 desktop->setReadOnly(TRUE);
889 desktop->setCursorPosition(desktop->numLines(),1);
891 if (desktop->numLines()>100) desktop->clear();
894 void QKernel::SetMessages()
899 if ( p2->isItemChecked(msgid))
901 p2->setItemChecked(msgid,FALSE);
906 p2->setItemChecked(msgid,TRUE);
913 void QKernel::SetOptions()
915 QDialog dlg(this,"Options",TRUE);
921 progs = new QLineEdit( &dlg, "progs" );
922 progs->setGeometry( 150, 20, 180, 30 );
923 progs->setText(progdir);
926 tmpQLabel = new QLabel( &dlg, "Label_1" );
927 tmpQLabel->setGeometry( 30, 20, 120, 30 );
928 tmpQLabel->setText( "Programs directory" );
931 tmpQFrame = new QFrame( &dlg, "Frame_2" );
932 tmpQFrame->setGeometry( 10, 60, 380, 30 );
933 tmpQFrame->setFrameStyle( 52 );
935 tmpQLabel = new QLabel( &dlg, "Label_2" );
936 tmpQLabel->setGeometry( 10, 80, 340, 30 );
937 tmpQLabel->setText( "Virtual Processor properties (activated after restarting VLP):" );
941 nn = new QLineEdit( &dlg, "LineEdit_2" );
942 nn->setGeometry( 110, 110, 40, 30 );
943 sprintf(nns,"%d",NodeNumber);
946 tmpQLabel = new QLabel( &dlg, "Label_3" );
947 tmpQLabel->setGeometry( 20, 110, 90, 30 );
948 tmpQLabel->setText( "Node number:" );
950 QRadioButton *exp,*reg;
951 exp = new QRadioButton( &dlg, "RadioButton_3" );
952 exp->setGeometry( 30, 170, 100, 30 );
953 exp->setText( "Explicit" );
954 exp->setChecked( TRUE );
956 reg = new QRadioButton( &dlg, "RadioButton_4" );
957 reg->setGeometry( 30, 200, 100, 30 );
958 reg->setText( "Registration" );
959 reg->setEnabled(FALSE);
961 connections = new QListBox( &dlg, "ListBox_1" );
962 connections->setGeometry( 170, 140, 130, 100 );
963 e = ConnectList.first();
966 connections->insertItem(e->addr);
967 e = ConnectList.next();
970 tmpQLabel = new QLabel( &dlg, "Label_5" );
971 tmpQLabel->setGeometry( 170, 110, 100, 30 );
972 tmpQLabel->setText( "Connection list:" );
974 QPushButton* addbtn,*delbtn,*okbtn,*cancelbtn;
975 addbtn = new QPushButton( &dlg, "PushButton_1" );
976 addbtn->setGeometry( 310, 150, 60, 30 );
977 addbtn->setText( "Add" );
978 delbtn = new QPushButton( &dlg, "PushButton_2" );
979 delbtn->setGeometry( 310, 200, 60, 30 );
980 delbtn->setText( "Del" );
981 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddAddress()));
982 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelAddress()));
983 okbtn = new QPushButton( &dlg, "PushButton_3" );
984 okbtn->setGeometry( 80, 260, 100, 30 );
985 okbtn->setText( "Ok" );
986 okbtn->setDefault(TRUE);
987 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
988 cancelbtn->setGeometry( 210, 260, 100, 30 );
989 cancelbtn->setText( "Cancel" );
990 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
991 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
993 group = new QButtonGroup( &dlg, "ButtonGroup_1" );
994 group->setGeometry( 20, 150, 120, 90 );
995 group->setTitle( "Connection type" );
996 group->setAlignment( 1 );
998 group->insert(exp,1);
999 group->insert(reg,2);
1001 dlg.resize( 400, 310 );
1006 config_setting_t *root, *setting;
1009 root = config_root_setting(&cfg);
1011 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
1012 config_setting_set_string(setting, progs->text().ascii());
1013 strcpy(progdir,progs->text());
1015 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
1016 config_setting_set_int(setting, atoi(nn->text()));
1018 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
1019 config_setting_set_string(setting, HomeDir);
1021 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
1022 if ( exp->isChecked())
1024 config_setting_set_string(setting, "explicit");
1026 config_setting_t *hosts = NULL;
1027 hosts = config_setting_add(root, "host", CONFIG_TYPE_ARRAY);
1028 for(i=0;i<connections->count();i++) {
1029 setting = config_setting_add(hosts, NULL, CONFIG_TYPE_STRING);
1030 config_setting_set_string(setting, connections->text(i).ascii());
1034 config_setting_set_string(setting, "register");
1037 if(!config_write_file(&cfg, "vlp.cfg")) {
1038 fprintf(stderr, "Error while writing to file: %s.\n", "vlp.cfg");
1040 config_destroy(&cfg);
1045 void QKernel::LockConsole()
1047 QDialog d(this,"Enter password",TRUE);
1048 QLabel lab(&d,"Password");
1049 QLineEdit ed(&d,"");
1050 QPushButton ob(&d,""),cb(&d,"");
1052 d.setCaption("Lock console");
1053 ob.setGeometry( 30, 60, 80, 30 );
1055 ob.setDefault(TRUE);
1056 lab.setGeometry( 10, 10, 60, 30 );
1057 lab.setText( "Password:" );
1058 ed.setGeometry( 70, 10, 140, 30 );
1059 ed.setEchoMode(QLineEdit::Password);
1060 cb.setGeometry( 130, 60, 80, 30 );
1061 cb.setText( "Cancel" );
1062 d.resize( 240, 100 );
1063 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1064 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1067 if (strcmp(ed.text(),"")!=0)
1069 strcpy(LockPasswd,ed.text());
1070 lab.setText("Retype:");
1074 if (strcmp(ed.text(),LockPasswd)==0)
1076 bar->setItemEnabled(qid,FALSE);
1077 bar->setItemEnabled(prid,FALSE);
1078 bar->setItemEnabled(mid,FALSE);
1079 p2->setItemEnabled(unlockid,TRUE);
1080 p2->setItemEnabled(lockid,FALSE);
1081 p2->setItemEnabled(cwid,FALSE);
1082 p2->setItemEnabled(optid,FALSE);
1084 WriteMessage("CONSOLE LOCKED");
1089 QMessageBox msg(this);
1090 msg.setText("Not matching!");
1091 msg.setButtonText(0,"Close");
1096 else strcpy(LockPasswd,"");
1100 void QKernel::UnlockConsole()
1102 QDialog d(this,"Enter password",TRUE);
1103 QLabel lab(&d,"Password");
1104 QLineEdit ed(&d,"");
1105 QPushButton ob(&d,""),cb(&d,"");
1107 ob.setGeometry( 30, 60, 80, 30 );
1109 ob.setDefault(TRUE);
1110 lab.setGeometry( 10, 10, 60, 30 );
1111 lab.setText( "Password:" );
1112 ed.setGeometry( 70, 10, 140, 30 );
1113 ed.setEchoMode(QLineEdit::Password);
1114 cb.setGeometry( 130, 60, 80, 30 );
1115 cb.setText( "Cancel" );
1116 d.resize( 240, 100 );
1117 connect(&ob,SIGNAL(clicked()),&d,SLOT(accept()));
1118 connect(&cb,SIGNAL(clicked()),&d,SLOT(reject()));
1122 if (strcmp(ed.text(),LockPasswd)==0)
1124 bar->setItemEnabled(qid,TRUE);
1125 bar->setItemEnabled(prid,TRUE);
1126 bar->setItemEnabled(mid,TRUE);
1127 p2->setItemEnabled(unlockid,FALSE);
1128 p2->setItemEnabled(lockid,TRUE);
1129 p2->setItemEnabled(cwid,TRUE);
1130 p2->setItemEnabled(optid,TRUE);
1132 WriteMessage("CONSOLE UNLOCKED");
1137 QMessageBox msg(this);
1138 msg.setText("Wrong password!");
1139 msg.setButtonText(0,"Close");
1146 void QKernel::InitMessage()
1148 WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
1153 InterpEntry *QKernel::findINTbySocket(int _id)
1156 pom = Interpreters.first();
1159 if (pom->sock == _id) break;
1160 pom = Interpreters.next();
1165 InterpEntry *QKernel::findINTbyID(int _id)
1168 pom = Interpreters.first();
1171 if (pom->ID == _id) break;
1172 pom = Interpreters.next();
1178 /* ------------------ Connect INT module -----------------*/
1180 InterpEntry *QKernel::RunIntModule(char *ss, int r)
1183 struct sockaddr_un svr;
1189 InterpEntry *newINT;
1198 if (cf == NULL) {WriteMessage("File not found: no .ccd file");return(NULL);}
1204 if (cf == NULL) {WriteMessage("File not found: no .pcd file");return(NULL);}
1207 newINT = new InterpEntry;
1208 for(i=0;i<MAXINSTANCES;i++) newINT->RInstances[i]=-1;
1210 strcpy(b,rindex(ss,'/'));
1211 for(i=0;i<strlen(b);i++)
1215 sprintf(a,"%s : Start execution",b);
1219 newint = freeINTid; freeINTid++;
1220 newINT->ID = newint;
1221 strcpy(newINT->shortname,b);
1222 strcpy(newINT->fullname,ss);
1224 sprintf(a,"%s%d",IPATH,newint);
1225 sprintf(cmd,"%s/modules/logint %s %s",HomeDir,a,ss);
1226 if (r) strcat(cmd," r");
1227 sprintf(b," %s %s %s %s %s",myargs[0],myargs[1],myargs[2],myargs[3],myargs[4]);
1232 sock = socket(AF_UNIX,SOCK_STREAM,0);
1234 bzero(&svr, sizeof(svr));
1235 svr.sun_family = AF_UNIX;
1236 strcpy(svr.sun_path,a);
1237 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
1238 bind(sock,(struct sockaddr*)&svr, len);
1241 newINT->sock = accept(sock,(struct sockaddr*)0,(unsigned int *)0);
1248 fcntl(newINT->sock,F_SETFL,
1249 O_NONBLOCK|fcntl(newINT->sock,F_GETFL,0));
1251 setsockopt(newINT->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
1252 if (r) newINT->remote = 1;else newINT->remote=0;
1254 bzero(&msg,sizeof(MESSAGE));
1255 msg.msg_type = MSG_VLP;
1256 msg.param.pword[0] = VLP_REGINT;
1257 msg.param.pword[1] = newINT->ID;
1258 sprintf(msg.param.pstr,"logi%d.net",newint);
1259 write(net_sock,&msg,sizeof(MESSAGE));
1261 Interpreters.append(newINT);
1262 newINT->notify = new QSocketNotifier(newINT->sock,QSocketNotifier::Read);
1263 connect(newINT->notify,SIGNAL(activated(int)),this,SLOT(IntMessage(int)));
1264 if (info_messages) WriteMessage("INTERPRETER successfully connected");
1267 else WriteMessage("Cannot connect interpreter");
1273 /* ---------------------------------------------------------*/
1274 /* Allocate remote instance */
1276 void QKernel::RemoteInstance(InterpEntry *interp, int on)
1282 m.msg_type = MSG_NET;
1283 m.param.pword[0] = NET_NODE_EXIST;
1284 m.param.pword[1] = on;
1285 m.param.pword[2] = interp->ID;
1286 write(net_sock,&m,sizeof(MESSAGE));
1287 bzero(&m,sizeof(MESSAGE));
1288 while( (m.msg_type!=MSG_NET) && (m.param.pword[0]!=NET_NODE_EXIST) )
1289 read(net_sock,&m,sizeof(MESSAGE));
1291 if (m.param.pword[1]==1) /* means node exists */
1293 m.msg_type = MSG_NET;
1294 m.param.pword[0] = NET_TRANSMIT_CODE;
1295 m.param.pword[1] = interp->ID;
1296 m.param.pword[2] = on;
1297 strcpy(m.param.pstr,interp->fullname);
1298 write(net_sock,&m,sizeof(MESSAGE));
1300 Net_Notify->setEnabled(FALSE);
1301 while ( (m.msg_type != MSG_NET) || (m.param.pword[0]!=NET_TRANSMITTED) )
1302 read(net_sock,&m,sizeof(MESSAGE));
1305 m.msg_type = MSG_NET;
1306 m.param.pword[0] = NET_PROPAGATE;
1307 m.param.pword[1] = MSG_VLP;
1308 m.param.pword[2] = NodeNumber;
1309 m.param.pword[3] = 0;
1310 m.param.pword[4] = on;
1311 m.param.pword[5] = 0;
1312 m.param.pword[6] = VLP_REMOTE_INSTANCE;
1313 m.param.pword[7] = interp->ID;
1314 strcpy(m.param.pstr,interp->shortname);
1315 write(net_sock,&m,sizeof(MESSAGE));
1317 read(net_sock,&m,sizeof(MESSAGE));
1320 if ( (m.param.pword[0]==NET_PROPAGATE) && (m.param.pword[6] == VLP_REMOTE_INSTANCE_OK))
1322 interp->RInstances[on] = m.param.pword[7];
1325 read(net_sock,&m,sizeof(MESSAGE));
1328 Net_Notify->setEnabled(TRUE);
1330 /*bzero(&m,sizeof(MESSAGE));*/
1331 m.msg_type = MSG_VLP;
1332 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1333 m.param.pword[1] = interp->RInstances[on];
1334 write(interp->sock,&m,sizeof(MESSAGE));
1336 else /* There is no such a node! */
1338 sprintf(s,"Warning: Node number %d not found!",on);
1340 WriteMessage("Allocating O-process on the local node");
1341 bzero(&m,sizeof(MESSAGE));
1342 m.msg_type = MSG_VLP;
1343 m.param.pword[0] = VLP_REMOTE_INSTANCE_HERE;
1344 m.param.pword[1] = interp->ID;
1345 write(interp->sock,&m,sizeof(MESSAGE));
1350 /*-----------------------------------------------*/
1351 /* Close all remote instances */
1353 void QKernel::CloseInstances(InterpEntry *e)
1358 if (info_messages) WriteMessage("Closing remote instances");
1359 for(i=0;i<MAXINSTANCES;i++)
1360 if (e->RInstances[i]>=0)
1362 msg.msg_type = MSG_NET;
1363 msg.param.pword[0] = NET_PROPAGATE;
1364 msg.param.pword[1] = MSG_VLP;
1365 msg.param.pword[2] = NodeNumber;
1366 msg.param.pword[4] = i;
1367 msg.param.pword[6] = VLP_CLOSE_INSTANCE;
1368 msg.param.pword[7] = e->RInstances[i];
1369 write(net_sock,&msg,sizeof(MESSAGE));
1374 void QKernel::Info()
1378 WriteMessage(CharLine);
1379 WriteMessage("### Virtual Machine Information ###");
1380 m.msg_type = MSG_NET;
1381 m.param.pword[0]=NET_GET_INFO;
1382 write(net_sock,&m,sizeof(MESSAGE));
1383 wait_for_info = TRUE;
1386 #include "kernel.moc"
1388 int main( int argc, char **argv )
1391 for(i=0;i<5;i++) strcpy(myargs[i],"");
1392 for(i=1;i<argc;i++) strcpy(myargs[i-1],argv[i]);
1394 app = new QApplication(argc,argv);
1395 app->setStyle(new QWindowsStyle());
1397 app->setMainWidget( &draw);