Fix warnings related to const char* -> char* conversion
[vlp.git] / src / kernel / kernel.cpp
index dbe7359f70f52144984ead9eb6d0db03c4e99f4a..4db3eeeecd5950c3600cfc1c6fa3f7ae5389af18 100644 (file)
@@ -71,6 +71,8 @@
 #include "kill_interpreter_dialog.h"
 #include "connect_dialog.h"
 
+#include "vlp/config.h"
+
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
 
@@ -139,7 +141,7 @@ QKernel::QKernel(int argc, char **argv)
                q.mkpath(getRemoteDir());
        }
 
-       info_messages = TRUE;
+       info_messages = actionInfo_messages->isChecked();
        wait_for_info = FALSE;
 
        setWindowTitle(PACKAGE_NAME);
@@ -150,11 +152,15 @@ QKernel::QKernel(int argc, char **argv)
        freeINTid = 1;
        ActiveConnections = 0;
        strcpy(LockPasswd, "");
+
        loadConfig(getConfigFilePath());
+
        RunNetModule();
 
        Net_Notify = new QSocketNotifier(net_sock, QSocketNotifier::Read, this);
        connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
+
+       WriteMessage("\n " PACKAGE_STRING ": READY \n");
 }
 
 QString QKernel::getConfigFilePath()
@@ -192,93 +198,19 @@ void QKernel::loadConfig(const QString & fname)
  */
 void QKernel::loadConfig(const char * fname)
 {
-       config_t cfg;
-       config_setting_t *setting;
+       loglan::vlp::Config config;
+       if(config.load(fname)) {
+               NodeNumber = config.getNodeNumber();
+               ConType = config.getConnectionType();
 
-       /* Hack for checking if file exists without using external libs.*/
 
-       FILE * file = fopen(fname, "rt");
-       if (!file) {
-               fprintf(stderr, "Error: Cannot load configuration file: %s!\n", 
-                                                                       fname);
-               exit(3);
-       }
-       /* File exists, so file has been locked. Release it. */
-
-       config_init(&cfg);
-
-       /* Read the file. If there is an error, report it and exit. */
-       if (!config_read(&cfg, file)) {
-               fprintf(stderr, "%s! In file %s, line %d\n", 
-                       config_error_text(&cfg), 
-                       config_error_file(&cfg), 
-                       config_error_line(&cfg));
-               config_destroy(&cfg);
-               fclose(file);
-               exit(3);
-       }
-
-       setting = config_lookup(&cfg, "node_number");
-       if (setting) {
-               NodeNumber = config_setting_get_int(setting);
-       } else {
-               fprintf(stderr, "%s! In file %s, '%s' was not found.\n", 
-                                       "Warning", fname, "node_number");
-               config_destroy(&cfg);
-               fclose(file);
-               exit(3);
-       }
-
-       setting = config_lookup(&cfg, "type");
-       if (setting) {
-               /* same as strcmp(..) == 0 */
-               if (!strcmp(config_setting_get_string(setting), "explicit")) {
-                       ConType = 1;
-               } else {
-                       ConType = 2;
+               std::vector<std::string> hosts = config.getHosts();
+               for (int i = 0; i < hosts.size(); i++) {
+                       ConnectList.append(new ConnectEntry(hosts[i].c_str()));
                }
-       } else {
-               fprintf(stderr, "%s! In file %s, '%s' was not found.\n", 
-                                               "Warning", fname, "type");
-       }
 
-       setting = config_lookup(&cfg, "host");
-       if (setting) {
-               switch(config_setting_type(setting)) {
-               /* TODO: Deprecated. Made for back compatibility. */
-               case CONFIG_TYPE_STRING:
-                       ConnectList.append(new ConnectEntry((char*)
-                                       config_setting_get_string(setting)));
-                       break;
-               case CONFIG_TYPE_ARRAY: {
-                       int size = config_setting_length(setting);
-                       for (int i = 0; i < size; i++) {
-                               ConnectList.append(new ConnectEntry((char*)
-                                       config_setting_get_string_elem(setting,
-                                                                       i)));
-                       }
-                       break;
-               }
-               default:
-                       fprintf(stderr, "%s! In file %s, bad entry type for %s."
-                                                       " Will not be read.\n", 
-                                                       "Error", fname, "host");
-               }
-       } else {
-               fprintf(stderr, "%s! In file %s, '%s' was not found.\n", 
-                                               "Warning", fname, "host");
-       }
-
-       setting = config_lookup(&cfg, "progdir");
-       if (setting){
-               strncpy(progdir, config_setting_get_string(setting), 256);
-       } else {
-               fprintf(stderr, "%s! In file %s, '%s' was not found.\n", 
-                                               "Warning", fname, "progdir");
+               strncpy(progdir, config.getProgramDir(), 256);
        }
-
-       config_destroy(&cfg);
-       fclose(file);
 }
 
 /**
@@ -802,7 +734,7 @@ void QKernel::IntMessage(int sock)
  * Writes message to kernel logger.
  * @parame msg String with message to log
  */
-void QKernel::WriteMessage(char *msg)
+void QKernel::WriteMessage(const char *msg)
 {
        int x;
        int y;
@@ -912,14 +844,6 @@ void QKernel::on_actionUnlock_console_triggered()
        }
 }
 
-/**
- * Writes init message in kernel
- */
-void QKernel::InitMessage()
-{
-       WriteMessage("\n " PACKAGE_STRING ": READY \n");
-}
-
 /**
  * Finds Interpreter by its socket
  * @param _id ID of the socket
@@ -1199,7 +1123,6 @@ int main(int argc, char **argv)
        QApplication * app = new QApplication(argc, argv);
        QKernel kernel(argc, argv);
        kernel.show();
-       kernel.InitMessage();
        
        return app->exec();
 }