From 3490d8d1eee73348bc8ed4938d27d19d8f41660b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 28 Oct 2013 22:33:08 +0100 Subject: [PATCH] VLP-28 Moved kernel class declarations to the header file. Code refactor. --- Makefile.am | 11 +- src/global/comm.h | 3 + src/kernel/kernel.cpp | 246 +++++++++--------------------------------- src/kernel/kernel.h | 192 +++++++++++++++++++++++++++++++++ 4 files changed, 250 insertions(+), 202 deletions(-) create mode 100644 src/kernel/kernel.h diff --git a/Makefile.am b/Makefile.am index 0266450..782199d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,7 @@ bin_PROGRAMS = \ BUILT_SOURCES = \ src/graph/loggraph.moc \ src/net/lognet.moc.cpp \ - src/kernel/kernel.moc \ + src/kernel/kernel.moc.cpp \ src/edit/editor.moc.cpp \ src/lgconfig/lgconfig.moc \ src/preproc/prep.moc.cpp \ @@ -62,11 +62,14 @@ clean-lognet-extra: rm -f bin/modules/lognet rm -f bin/lognet -bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc +bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc.cpp bin_logker_CPPFLAGS = $(bin_logker_CFLAGS) bin_logker_LDADD = $(bin_logker_LIBS) -src/kernel/kernel.moc: - moc-qt4 -i src/kernel/kernel.cpp -o src/kernel/kernel.moc +bin_logkerdir = src/kernel +bin_logker_HEADERS = \ + src/kernel/kernel.h +src/kernel/kernel.moc.cpp: src/kernel/kernel.h + moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp # $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc clean-logker-extra: diff --git a/src/global/comm.h b/src/global/comm.h index b5c7f30..27e754d 100644 --- a/src/global/comm.h +++ b/src/global/comm.h @@ -1,5 +1,7 @@ /* Communication structures */ +#ifndef LOGLAN_COMM_H +#define LOGLAN_COMM_H // REDHAT DEPENDENT !!! #include @@ -176,3 +178,4 @@ typedef struct { #define TCP_BUFFER_SIZE 30*sizeof(MESSAGE); +#endif /* LOGLAN_COMM_H */ diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 969156f..d2521ab 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -58,160 +58,21 @@ #include #include "genint1.h" -#include "comm.h" #include "socu.h" #include #include +#include "kernel.h" + /* File resides in top directory (where are Makefiles)*/ #include "../../config.h" -#define GPATH "loggr" -#define IPATH "logi" -#define NPATH "logn" -#define REMOTE_PATH "REMOTE" -#define MAXINTERP 20 -#define MAXINSTANCES 256 - - -#define MESG_COL 0 -#define WARN_COL 1 -#define NORM_COL 2 - char CharLine[25] = "________________________"; char myargs[5][255]; -/** - * Interpreter slot - */ -class InterpEntry { -public: - /** Interpreter identifier */ - int ID; - /** Defines if interpreter is remote or not */ - bool remote; - /* Program name */ - char fullname[255]; - char shortname[255]; - - /* Socket */ - int sock; - QSocketNotifier *notify; - /* IDs of my remote INT modules */ - int RInstances[MAXINSTANCES]; - /* Parent interpreter info */ - ctx_struct p_ctx; -}; - -/** - * Connection slot - */ -class ConnectEntry { -public: - char addr[256]; - - ConnectEntry(char *s) { - strcpy(addr, s); - }; -}; - -QApplication *app; - -/** - * Kernel class - */ -class QKernel : public QMainWindow { - Q_OBJECT -public: - QTextEdit *desktop; - QMenuBar *bar; - QMenu *programMenu; - QMenu *machineMenu; - QMenu *toolsMenu; - char progdir[256]; - int NodeNumber; - int ConType; - - QKernel(); - - virtual void resizeEvent(QResizeEvent *ev); - - void WriteMessage(char* msg); - void InitMessage(); - -public slots: - void n_impl(); - void Run_Prog(); - void Edit(); - void Help(); - void SetOptions(); - void AddAddress(); - void DelAddress(); - void LockConsole(); - void UnlockConsole(); - void MessageToNode(); - void QuitProc(); - void NetMessage(); - void IntMessage(int); - void KillInterpreter(); - void Disconnect(); - void SetMessages(); - void Connect(); - void Info(); - -protected: - virtual void closeEvent (QCloseEvent * e); - -private: - QList Interpreters; - QList ConnectList; - QListWidget *connections; - - /** - * number of working interpreters - * @attention Currently not in use - */ - int Tasks; - - /** - * number of connected VLPs - */ - int ActiveConnections; - bool LOCKED; - bool synchro; - bool wait_for_info; - char LockPasswd[25]; - QAction * lockid; - QAction * unlockid; - QAction * qid; - QAction * cwid; - QAction * optid; - QAction * programExecuteAction; - QAction * programKillAction; - QAction * machineMessageAction; - QAction * machineConnectAction; - QAction * machineDisconnectAction; - QAction * machineInfoAction; - QAction * msgid; - QAction * hid; - - int net_sock; - int freeINTid; - QSocketNotifier *Net_Notify; - char HomeDir[255]; - bool info_messages; - - void LoadConfig(char *); - void RunGraphModule(char*); - void RunNetModule(); - InterpEntry *findINTbySocket(int); - InterpEntry *findINTbyID(int); - InterpEntry *RunIntModule(char *ss, int r); - void RemoteInstance(InterpEntry*, int); - void CloseInstances(InterpEntry*); -}; +//QApplication *app; /** * Event invoked on program close. @@ -226,6 +87,25 @@ void QKernel::closeEvent(QCloseEvent * e) } } +void QKernel::setLocked(bool locked) +{ + LOCKED = locked; + + quitAction->setDisabled(locked); + programExecuteAction->setDisabled(locked); + programKillAction->setDisabled(locked); + machineMessageAction->setDisabled(locked); + machineConnectAction->setDisabled(locked); + machineDisconnectAction->setDisabled(locked); + machineInfoAction->setDisabled(locked); + + /* Enable only menu entry for unlocking */ + toolsEditorAction->setDisabled(locked); + toolsOptionsAction->setDisabled(locked); + toolsLockAction->setDisabled(locked); + toolsUnlockAction->setEnabled(locked); +} + /** * Kernel program constructor. * Prepares everything to work. @@ -258,21 +138,21 @@ QKernel::QKernel() machineInfoAction = machineMenu->addAction("Info", this, SLOT(Info())); toolsMenu = menuBar()->addMenu("&Tools"); - cwid = toolsMenu->addAction("Editor", this, SLOT(Edit())); - hid = toolsMenu->addAction("Help", this, SLOT(Help())); + toolsEditorAction = toolsMenu->addAction("Editor", this, SLOT(Edit())); + toolsMenu->addAction("Help", this, SLOT(Help())); toolsMenu->addSeparator(); - optid = toolsMenu->addAction("Options", this, SLOT(SetOptions())); - msgid = toolsMenu->addAction("Info messages", this, SLOT(SetMessages())); - msgid->setCheckable(TRUE); - msgid->setChecked(TRUE); - toolsMenu->addSeparator(); - lockid = toolsMenu->addAction("Lock console", this, SLOT(LockConsole())); - unlockid = toolsMenu->addAction("Unlock console", this, + toolsOptionsAction = toolsMenu->addAction("Options", this, SLOT(SetOptions())); + toolsInfoAction = toolsMenu->addAction("Info messages", this, SLOT(SetMessages())); + toolsInfoAction->setCheckable(TRUE); + toolsInfoAction->setChecked(TRUE); + toolsMenu->addSeparator(); + toolsLockAction = toolsMenu->addAction("Lock console", this, SLOT(LockConsole())); + toolsUnlockAction = toolsMenu->addAction("Unlock console", this, SLOT(UnlockConsole())); - unlockid->setDisabled(TRUE); + toolsUnlockAction->setDisabled(TRUE); LOCKED = FALSE; - qid = menuBar()->addAction("&Quit", this, SLOT(QuitProc())); + quitAction = menuBar()->addAction("&Quit", this, SLOT(QuitProc())); desktop = new QTextEdit(this); desktop->setReadOnly(TRUE); @@ -345,7 +225,7 @@ void QKernel::LoadConfig(char * fname) config_error_line(&cfg)); config_destroy(&cfg); fclose(file); - exit(3);/* from original code. */ + exit(3); } setting = config_lookup(&cfg, "node_number"); @@ -455,7 +335,7 @@ void QKernel::Edit() void QKernel::Help() { char cmd[255]; - sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir, + sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir, HomeDir, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]); system(cmd); } @@ -467,9 +347,8 @@ void QKernel::RunGraphModule(char *sk) { char cmd[255]; - sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s", HomeDir, sk, - myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]); - strcat(cmd, " &"); + sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s &", HomeDir, + sk, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]); if (system(cmd) != 0) WriteMessage("Cannot connect GRAPH resources"); @@ -484,9 +363,8 @@ void QKernel::RunNetModule() int len, on; int sock; char cmd[255]; - sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s", HomeDir, NPATH, - myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]); - strcat(cmd, " &"); + sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s &", HomeDir, + NPATH, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]); /* -------- socket for NET module -------- */ unlink(NPATH); @@ -596,7 +474,7 @@ void QKernel::QuitProc() msg.param.pword[0] = NET_EXIT; write(net_sock, &msg, sizeof(MESSAGE)); /* ::close(net_sock);*/ - app->quit(); + QApplication::instance()->quit(); } /** @@ -965,15 +843,12 @@ void QKernel::WriteMessage(char *msg) void QKernel::SetMessages() { if (toolsMenu != NULL) { - if (msgid->isChecked()) { - msgid->setChecked(FALSE); - info_messages = FALSE; - } else { - msgid->setChecked(TRUE); - info_messages = TRUE; - } + toolsInfoAction->setChecked(!toolsInfoAction->isChecked()); +// toolsInfoAction->toggle(); + info_messages = toolsInfoAction->isChecked(); + fprintf(stderr, "Info is checked? %s\n", toolsInfoAction->isChecked() ? "yes" : "no"); } - /* bar->repaint(); */ +// menuBar()->repaint(); } /** @@ -1159,20 +1034,8 @@ void QKernel::LockConsole() */ if (d.exec()) { if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) { - qid->setDisabled(TRUE); - programExecuteAction->setDisabled(TRUE); - programKillAction->setDisabled(TRUE); - machineMessageAction->setDisabled(TRUE); - machineConnectAction->setDisabled(TRUE); - machineDisconnectAction->setDisabled(TRUE); - machineInfoAction->setDisabled(TRUE); - - unlockid->setEnabled(TRUE); - lockid->setDisabled(TRUE); - cwid->setDisabled(TRUE); - optid->setDisabled(TRUE); + setLocked(TRUE); WriteMessage("CONSOLE LOCKED"); - LOCKED = TRUE; } else { QMessageBox msg(this); msg.setText("Not matching!"); @@ -1216,19 +1079,8 @@ void QKernel::UnlockConsole() if (d.exec()) { if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) { - qid->setEnabled(TRUE); - programExecuteAction->setEnabled(TRUE); - programKillAction->setEnabled(TRUE); - machineMessageAction->setEnabled(TRUE); - machineConnectAction->setEnabled(TRUE); - machineDisconnectAction->setEnabled(TRUE); - machineInfoAction->setEnabled(TRUE); - unlockid->setEnabled(FALSE); - lockid->setEnabled(TRUE); - cwid->setEnabled(TRUE); - optid->setEnabled(TRUE); + setLocked(FALSE); WriteMessage("CONSOLE UNLOCKED"); - LOCKED = FALSE; } else { QMessageBox msg(this); msg.setText("Wrong password!"); @@ -1506,8 +1358,6 @@ void QKernel::Info() wait_for_info = TRUE; } -#include "kernel.moc" - /** * Program main function * All program arguments but the first one (argv[0]: program name) are saved and @@ -1525,7 +1375,7 @@ int main(int argc, char **argv) strcpy(myargs[i - 1], argv[i]); } - app = new QApplication(argc, argv); + QApplication * app = new QApplication(argc, argv); QKernel kernel; kernel.show(); kernel.InitMessage(); diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h new file mode 100644 index 0000000..168777c --- /dev/null +++ b/src/kernel/kernel.h @@ -0,0 +1,192 @@ +/************************************************************** + + Copyright (C) 1997 Oskar Swida + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + + + NOTE: This software is using the free software license of + the QT library v.1.30 from Troll Tech AS. + See the file LICENSE.QT. + + + To contact the author, write: + e-mail: swida@aragorn.pb.bialystok.pl + +************************************************************/ + +#ifndef VLP_KERNEL_H +#define VLP_KERNEL_H + +#include +#include +#include +#include + +#include "comm.h" + +#define GPATH "loggr" +#define IPATH "logi" +#define NPATH "logn" +#define REMOTE_PATH "REMOTE" +#define MAXINTERP 20 +#define MAXINSTANCES 256 + + +#define MESG_COL 0 +#define WARN_COL 1 +#define NORM_COL 2 + + +/** + * Interpreter slot + */ +class InterpEntry { +public: + /** Interpreter identifier */ + int ID; + /** Defines if interpreter is remote or not */ + bool remote; + /* Program name */ + char fullname[255]; + char shortname[255]; + + /* Socket */ + int sock; + QSocketNotifier *notify; + /* IDs of my remote INT modules */ + int RInstances[MAXINSTANCES]; + /* Parent interpreter info */ + ctx_struct p_ctx; +}; + +/** + * Connection slot + */ +class ConnectEntry { +public: + char addr[256]; + + ConnectEntry(char *s) { + strcpy(addr, s); + }; +}; + + +/** + * Kernel class + */ +class QKernel : public QMainWindow { + Q_OBJECT +public: + QTextEdit *desktop; + QMenuBar *bar; + QMenu *programMenu; + QMenu *machineMenu; + QMenu *toolsMenu; + char progdir[256]; + int NodeNumber; + int ConType; + + QKernel(); + + virtual void resizeEvent(QResizeEvent *ev); + + void WriteMessage(char* msg); + void InitMessage(); + +public slots: + void n_impl(); + void Run_Prog(); + void Edit(); + void Help(); + void SetOptions(); + void AddAddress(); + void DelAddress(); + void LockConsole(); + void UnlockConsole(); + void MessageToNode(); + void QuitProc(); + void NetMessage(); + void IntMessage(int); + void KillInterpreter(); + void Disconnect(); + void SetMessages(); + void Connect(); + void Info(); + +protected: + virtual void closeEvent (QCloseEvent * e); + +private: + QList Interpreters; + QList ConnectList; + QListWidget *connections; + + /** + * number of working interpreters + * @attention Currently not in use + */ + int Tasks; + + /** + * number of connected VLPs + */ + int ActiveConnections; + /** + * Indicates state of the Kernel Program. Is it locked or not. + */ + bool LOCKED; + bool synchro; + bool wait_for_info; + char LockPasswd[25]; + QAction * toolsEditorAction; + QAction * toolsOptionsAction; + QAction * toolsInfoAction; + QAction * programExecuteAction; + QAction * programKillAction; + QAction * machineMessageAction; + QAction * machineConnectAction; + QAction * machineDisconnectAction; + QAction * machineInfoAction; + QAction * toolsLockAction; + QAction * toolsUnlockAction; + QAction * quitAction; + + int net_sock; + int freeINTid; + QSocketNotifier *Net_Notify; + char HomeDir[255]; + bool info_messages; + + void LoadConfig(char *); + void RunGraphModule(char*); + void RunNetModule(); + InterpEntry *findINTbySocket(int); + InterpEntry *findINTbyID(int); + InterpEntry *RunIntModule(char *ss, int r); + void RemoteInstance(InterpEntry*, int); + void CloseInstances(InterpEntry*); + + /** + * Sets QKernel menu entries to the given status + * @param locked status which will be set on the menu entries. + */ + void setLocked(bool locked); +}; + +#endif /* VLP_KERNEL_H */ -- 2.30.2