From ab399101dba6ae75e9bad9d10f8276e2d031a092 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Thu, 1 Aug 2013 22:42:53 +0200 Subject: [PATCH] vlp-7 Documented kernel class. --- src/kernel/kernel.cpp | 203 ++++++++++++++++++++++++++++++++---------- 1 file changed, 156 insertions(+), 47 deletions(-) diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 9560890..b5e1cd1 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -89,13 +89,14 @@ char CharLine[25] = "________________________"; char myargs[5][255]; - -/* --------------- interpreter slot -----------------*/ +/** + * Interpreter slot + */ class InterpEntry { public: - /* INT identifier */ + /** Interpreter identifier */ int ID; - /* Am I remote ? */ + /** Defines if interpreter is remote or not */ bool remote; /* Program name */ char fullname[255]; @@ -106,12 +107,13 @@ public: QSocketNotifier *notify; /* IDs of my remote INT modules */ int RInstances[MAXINSTANCES]; - /* parent INT info */ + /* Parent interpreter info */ ctx_struct p_ctx; }; -/*++++++++++++++++++++++++++++++++++++++++++*/ -/*----------------- connection slot -------------*/ +/** + * Connection slot + */ class ConnectEntry { public: char addr[256]; @@ -121,24 +123,20 @@ public: }; }; -/* ++++++++++++++++++++++++++++++++++++++++++ */ - QApplication *app; - -/* ---------------------------------------------------------- */ -/* KERNEL CLASS DEFINITION */ -/* ---------------------------------------------------------- */ - +/** + * Kernel class + */ class QKernel : public QFrame { Q_OBJECT public: - QMultiLineEdit *desktop; - QMenuBar *bar; + QMultiLineEdit *desktop; + QMenuBar *bar; QPopupMenu *p; QPopupMenu *p1; QPopupMenu *p2; - char progdir[256]; + char progdir[256]; int NodeNumber; int ConType; @@ -216,13 +214,20 @@ private: void RemoteInstance(InterpEntry*, int); void CloseInstances(InterpEntry*); }; -/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -void QKernel::closeEvent (QCloseEvent * e) +/** + * Event invoked on program close. + * @copydoc QWidget::closeEvent(QCloseEvent*) + */ +void QKernel::closeEvent(QCloseEvent * e) { e->ignore(); } +/** + * Kernel program constructor. + * Prepares everything to work. + */ QKernel::QKernel() { QFont f("Helvetica", 10, QFont::Bold); @@ -294,6 +299,10 @@ QKernel::QKernel() connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage())); } +/** + * Event invoked on resizing kernel application window. + * @copydoc QWidget::resizeEvent(QResizeEvent*) + */ void QKernel::resizeEvent(QResizeEvent *ev) { QFrame::resizeEvent(ev); @@ -302,15 +311,19 @@ void QKernel::resizeEvent(QResizeEvent *ev) height() - bar->height()); } +/** + * Displays window with information about not implemented functionality. + */ void QKernel::n_impl() { QMessageBox::information(this, "Function info", "This function is not " "implemented yet...", "Ok"); } - -/* ########### load configuration from file ############# */ - +/** + * Loads configuration from the given file. + * @param fname Filename of the configuration file. + */ void QKernel::LoadConfig(char * fname) { config_t cfg; @@ -409,8 +422,11 @@ void QKernel::LoadConfig(char * fname) config_destroy(&cfg); fclose(file); } -/* +++++++++++++++++++++++++++++++++++++++++++++++ */ +/** + * Executes program. + * Additional window id displayed to set which code to execute. + */ void QKernel::Run_Prog() { int i; @@ -426,6 +442,9 @@ void QKernel::Run_Prog() } } +/** + * Invokes editor program + */ void QKernel::Edit() { char cmd[255]; @@ -434,6 +453,9 @@ void QKernel::Edit() system(cmd); } +/** + * Invokes help program + */ void QKernel::Help() { char cmd[255]; @@ -442,7 +464,9 @@ void QKernel::Help() system(cmd); } - +/** + * Invokes graphics module + */ void QKernel::RunGraphModule(char *sk) { char cmd[255]; @@ -455,8 +479,9 @@ void QKernel::RunGraphModule(char *sk) WriteMessage("Cannot connect GRAPH resources"); } - - +/** + * Invokes net module + */ void QKernel::RunNetModule() { struct sockaddr_un svr; @@ -502,6 +527,10 @@ void QKernel::RunNetModule() } } +/** + * Connects to the specified address + * Additional window is displayed to connect to the specified address + */ void QKernel::Connect() { QDialog d(this, "", TRUE); @@ -532,6 +561,9 @@ void QKernel::Connect() } } +/** + * Disconnects from virtual machine + */ void QKernel::Disconnect() { MESSAGE msg; @@ -544,6 +576,9 @@ void QKernel::Disconnect() write(net_sock, &msg, sizeof(MESSAGE)); } +/** + * Quits process. Closes VLP. Shows additional window to confirm exit. + */ void QKernel::QuitProc() { MESSAGE msg; @@ -568,6 +603,10 @@ void QKernel::QuitProc() } } +/** + * Adds IP address to the configuration. + * Additional window is displayed to add address to the list + */ void QKernel::AddAddress() { QDialog d(this, "", TRUE); @@ -595,6 +634,9 @@ void QKernel::AddAddress() } } +/** + * Deletes current address from available connections. + */ void QKernel::DelAddress() { if (connections) { @@ -603,6 +645,11 @@ void QKernel::DelAddress() } } +/** + * Sends message to node. + * Additional window is displayed to set Node Number of node where send message, + * and textfield to enter message. + */ void QKernel::MessageToNode() { QDialog *dlg; @@ -656,6 +703,11 @@ void QKernel::MessageToNode() } } +/** + * Kills interpreter. + * Additional window is displayed to get ID of interpreter which should be + * killed. + */ void QKernel::KillInterpreter() { QDialog *dlg; @@ -702,8 +754,9 @@ void QKernel::KillInterpreter() } } - - +/** + * Sends message to the net module. + */ void QKernel::NetMessage() { @@ -813,6 +866,10 @@ void QKernel::NetMessage() } } +/** + * Sends message to the interpreter program. + * @param sock Interpreter socket to whom the message will be send. + */ void QKernel::IntMessage(int sock) { MESSAGE msg; @@ -874,11 +931,15 @@ void QKernel::IntMessage(int sock) write(sock, &msg, sizeof(MESSAGE)); break; }; - break; /* switch param.pword[0] */ - } /* switch type */ - } /* if */ + break; + } + } } +/** + * Writes message to kernel logger. + * @parame msg String with message to log + */ void QKernel::WriteMessage(char *msg) { int x; @@ -900,6 +961,10 @@ void QKernel::WriteMessage(char *msg) } } +/** + * Adds checkbox to menu item. It it is checked additional info messages are + * shown. + */ void QKernel::SetMessages() { if (p2 != NULL) { @@ -910,10 +975,15 @@ void QKernel::SetMessages() p2->setItemChecked(msgid, TRUE); info_messages=TRUE; } - } /* !=NULL */ + } /* bar->repaint(); */ } +/** + * Allows to set options in GUI window. + * Additional window is displayed to set kernel options which are saved in + * vlp.cfg file in kernel executable directory. + */ void QKernel::SetOptions() { QDialog dlg(this, "Options", TRUE); @@ -1052,6 +1122,11 @@ void QKernel::SetOptions() } } +/** + * Locks kernel program. + * Additional window is displayed to enter password and retype it. If both are + * same kernel window is locked. + */ void QKernel::LockConsole() { QDialog d(this, "Enter password", TRUE); @@ -1104,6 +1179,11 @@ void QKernel::LockConsole() } } +/** + * Unlocks kernel program. + * Additional window is displayed to enter password. If it is correct, kernel + * window is unlocked + */ void QKernel::UnlockConsole() { QDialog d(this, "Enter password", TRUE); @@ -1146,11 +1226,19 @@ void QKernel::UnlockConsole() } } +/** + * Writes init message in kernel + */ void QKernel::InitMessage() { WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n"); } +/** + * Finds Interpreter by its socket + * @param _id ID of the socket + * @return returns pointer to the found interpreter slot + */ InterpEntry *QKernel::findINTbySocket(int _id) { InterpEntry *pom; @@ -1162,9 +1250,14 @@ InterpEntry *QKernel::findINTbySocket(int _id) pom = Interpreters.next(); } - return(pom); + return pom; } +/** + * Finds Interpreter by its ID. + * @param _id ID of the interpreter + * @return returns pointer to the found interpreter slot + */ InterpEntry *QKernel::findINTbyID(int _id) { InterpEntry *pom; @@ -1174,12 +1267,18 @@ InterpEntry *QKernel::findINTbyID(int _id) break; pom = Interpreters.next(); } - return(pom); + return pom; } -/* ------------------ Connect INT module -----------------*/ - +/** + * Connects interpreter + * @param ss full filepath with filename but without extension of the loglan + * program to run. + * @param r Interpreter execution mode. 0 if it will be local instance, 1 if + * remote + * @return Returns pointer to newly created interpreter slot, or NULL on error. + */ InterpEntry *QKernel::RunIntModule(char *ss, int r) { char a[256], b[255]; @@ -1280,9 +1379,11 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r) return newINT; } -/* ---------------------------------------------------------*/ -/* Allocate remote instance */ - +/** + * Allocates remote instance of interpreter + * @param interp Interpreter slot + * @param on Node Number + */ void QKernel::RemoteInstance(InterpEntry *interp, int on) { MESSAGE m; @@ -1352,10 +1453,9 @@ void QKernel::RemoteInstance(InterpEntry *interp, int on) } } - -/*-----------------------------------------------*/ -/* Close all remote instances */ - +/** + * Closes all remote instances + */ void QKernel::CloseInstances(InterpEntry *e) { MESSAGE msg; @@ -1377,7 +1477,9 @@ void QKernel::CloseInstances(InterpEntry *e) } } - +/** + * Displays information about virtual machine + */ void QKernel::Info() { MESSAGE m; @@ -1392,14 +1494,21 @@ void QKernel::Info() #include "kernel.moc" +/** + * Program main function + * All program arguments but the first one (argv[0]: program name) are saved and + * passed to all dependent programs on their invocation. + * @param argc Number of program arguments + * @param argv Program arguments + */ int main(int argc, char **argv) { int i; - for(i=0; i < 5; i++) { + for(i = 0; i < 5; i++) { strcpy(myargs[i], ""); } - for(i=1; i < argc; i++) { - strcpy(myargs[i-1], argv[i]); + for(i = 1; i < argc; i++) { + strcpy(myargs[i - 1], argv[i]); } app = new QApplication(argc, argv); -- 2.30.2