vlp-15 Set version to 3.1. Replaced hardcoded strings with generated ones.
[vlp.git] / src / kernel / kernel.cpp
index 95608909f8cac15cb4cf9b3cc3e69996bbf2d263..16bda4f4ed2546a6526d2367b966c5ec947a69be 100644 (file)
@@ -73,6 +73,9 @@
 
 #include <libconfig.h>
 
+/* File resides in top directory (where are Makefiles)*/
+#include "../../config.h"
+
 #define GPATH "loggr"
 #define IPATH "logi"
 #define NPATH "logn"
 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 +110,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 +126,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 +217,20 @@ private:
        void RemoteInstance(InterpEntry*, int);
        void CloseInstances(InterpEntry*);
 };
-/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
-void QKernel::closeEvent (QCloseEvent * e)
+/**
+ * Event invoked on program close.
+ * Closes application. Displays additional window to confirm exit.
+ */
+void QKernel::closeEvent(QCloseEvent * e)
 {
-       e->ignore();
+       QuitProc();
 }
 
+/**
+ * Kernel program constructor.
+ * Prepares everything to work.
+ */
 QKernel::QKernel()
 {
        QFont f("Helvetica", 10, QFont::Bold);
@@ -239,7 +247,7 @@ QKernel::QKernel()
        info_messages = TRUE;
        wait_for_info = FALSE;
 
-       setCaption("Virtual LOGLAN Processor");
+       setCaption(PACKAGE_NAME);
        setBackgroundColor(white);
 
        bar = new QMenuBar(this);
@@ -294,6 +302,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 +314,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 +425,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 +445,9 @@ void QKernel::Run_Prog()
        }
 }
 
+/**
+ * Invokes editor program
+ */
 void QKernel::Edit()
 {
        char cmd[255];
@@ -434,6 +456,9 @@ void QKernel::Edit()
        system(cmd);
 }
 
+/**
+ * Invokes help program
+ */
 void QKernel::Help()
 {
        char cmd[255];
@@ -442,7 +467,9 @@ void QKernel::Help()
        system(cmd);
 }
 
-
+/**
+ * Invokes graphics module
+ */
 void QKernel::RunGraphModule(char *sk)
 {
        char cmd[255];
@@ -455,8 +482,9 @@ void QKernel::RunGraphModule(char *sk)
                WriteMessage("Cannot connect GRAPH resources");
 }
 
-
-
+/**
+ * Invokes net module
+ */
 void QKernel::RunNetModule()
 {
        struct sockaddr_un svr;
@@ -502,6 +530,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 +564,9 @@ void QKernel::Connect()
        }
 }
 
+/**
+ * Disconnects from virtual machine
+ */
 void QKernel::Disconnect()
 {
        MESSAGE msg;
@@ -544,6 +579,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 +606,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 +637,9 @@ void QKernel::AddAddress()
        }
 }
 
+/**
+ * Deletes current address from available connections.
+ */
 void QKernel::DelAddress()
 {
        if (connections) {
@@ -603,6 +648,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 +706,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 +757,9 @@ void QKernel::KillInterpreter()
        }
 }
 
-
-
+/**
+ * Sends message to the net module.
+ */
 void QKernel::NetMessage()
 {
        
@@ -813,6 +869,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 +934,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 +964,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 +978,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 +1125,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 +1182,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 +1229,19 @@ void QKernel::UnlockConsole()
        }
 }
 
+/**
+ * Writes init message in kernel
+ */
 void QKernel::InitMessage()
 {
-       WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
+       WriteMessage("\n " PACKAGE_STRING ": 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 +1253,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 +1270,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 +1382,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 +1456,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 +1480,9 @@ void QKernel::CloseInstances(InterpEntry *e)
                }
 }
 
-
+/**
+ * Displays information about virtual machine
+ */
 void QKernel::Info()
 {
        MESSAGE m;
@@ -1392,14 +1497,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);
@@ -1408,5 +1520,6 @@ int main(int argc, char **argv)
        app->setMainWidget(&kernel);
        kernel.show();
        kernel.InitMessage();
+       
        return app->exec();
 }