bin_logker_SOURCES = \
src/kernel/kernel.cpp \
src/kernel/kernel.moc.cpp \
- src/kernel/lock.cpp
+ src/kernel/lock.cpp \
+ src/kernel/options.cpp \
+ src/kernel/options.moc.cpp
bin_logker_CPPFLAGS = $(bin_logker_CFLAGS)
-bin_logker_LDADD = $(bin_logker_LIBS)
+bin_logker_LDADD = $(bin_logker_LIBS) -lconfig++
bin_logkerdir = src/kernel
bin_logker_HEADERS = \
src/kernel/kernel.h \
- src/kernel/lock.h
-src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/kernelwindow.h src/kernel/lock_dialog.h
+ src/kernel/lock.h \
+ src/kernel/options.h
+src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/kernelwindow.h src/kernel/lock_dialog.h src/kernel/optionsdialog.h
moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp
+ moc-qt4 src/kernel/options.h -o src/kernel/options.moc.cpp
# $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc
src/kernel/kernelwindow.h:
src/kernel/lock_dialog.h:
uic src/kernel/lock_dialog.ui -o src/kernel/lock_dialog.h
+src/kernel/optionsdialog.h:
+ uic src/kernel/optionsdialog.ui -o src/kernel/optionsdialog.h
+
clean-logker-extra:
rm -f src/kernel/*.moc
+ rm -f src/kernel/*.moc.cpp
rm -f src/kernel/kernelwindow.h
rm -f src/kernel/lock_dialog.h
+ rm -f src/kernel/optionsdialog.h
rm -f bin/logker
bin_logint_SOURCES = \
#include "kernel.h"
#include "kernelwindow.h"
#include "lock.h"
+#include "options.h"
/* File resides in top directory (where are Makefiles)*/
#include "../../config.h"
{
MESSAGE msg;
- QMessageBox::StandardButton response;
- response = QMessageBox::question(this, "Close VLP", "Terminate VLP ?",
- QMessageBox::Ok | QMessageBox::Cancel);
+ QMessageBox::StandardButton response = QMessageBox::question(this,
+ "Close VLP",
+ "Terminate VLP ?",
+ QMessageBox::Ok | QMessageBox::Cancel
+ );
if (response == QMessageBox::Cancel) {
QApplication::instance()->quit();
}
-/**
- * Adds IP address to the configuration.
- * Additional window is displayed to add address to the list
- */
-void QKernel::AddAddress()
-{
- QDialog d(this, Qt::Dialog);
- QLabel lab("IP Address:", &d);
- QLineEdit ed("", &d);
- QPushButton ob("", &d);
- QPushButton cb("", &d);
-
- if (connections) {
- ob.setGeometry(30, 60, 80, 30);
- ob.setText("Ok");
- ob.setDefault(TRUE);
- lab.setGeometry(10, 10, 60, 30);
- lab.setText("Address");
- ed.setGeometry(70, 10, 140, 30);
- cb.setGeometry(130, 60, 80, 30);
- cb.setText("Cancel");
- d.resize(240, 100);
- connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
- connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
- if (d.exec())
- if (strcmp(ed.text().toAscii().data(), "") != 0) {
- connections->addItem(ed.text());
- }
- }
-}
-
-/**
- * Deletes current address from available connections.
- */
-void QKernel::DelAddress()
-{
- if (connections) {
- if (connections->currentRow() != -1) {
- /* TODO: Checki if this work correctly after porting */
- connections->removeItemWidget(connections->currentItem());
- }
- }
-}
-
/**
* Sends message to node.
* Additional window is displayed to set Node Number of node where send message,
cnt = poms1.indexOf('=');
if (cnt != -1) {
poms2 = poms1.left(cnt);
- poms1 = poms1.right(
- poms1.length() -
- cnt - 1);
- sprintf(ss, "Node: %s Addr: %s", poms2.data(), poms1.data());
+ poms1 = poms1.right(poms1.length() - cnt - 1);
+ sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
WriteMessage(ss);
}
}
void QKernel::on_actionInfo_messages_triggered()
{
if (toolsMenu != NULL) {
- actionInfo_messages->setChecked(!actionInfo_messages->isChecked());
-// actionInfo_messages->toggle();
- info_messages = actionInfo_messages->isChecked();
- fprintf(stderr, "Info is checked? %s\n", actionInfo_messages->isChecked() ? "yes" : "no");
+ info_messages = !actionInfo_messages->isChecked();
+ actionInfo_messages->setChecked(info_messages);
+ fprintf(stderr, "Info is checked? %s\n", info_messages ? "yes" : "no");
}
-// menuBar()->repaint();
}
/**
*/
void QKernel::on_actionOptions_triggered()
{
- QDialog dlg(this, Qt::Dialog);
- dlg.setWindowTitle("Options");
- ConnectEntry *e;
- unsigned int i;
-
- QLineEdit* progs;
- progs = new QLineEdit(progdir, &dlg);
- progs->setGeometry(150, 20, 180, 30);
-
- QLabel* tmpQLabel;
- tmpQLabel = new QLabel("Programs directory", &dlg);
- tmpQLabel->setGeometry(30, 20, 120, 30);
-
- QFrame* tmpQFrame;
- tmpQFrame = new QFrame(&dlg);
- tmpQFrame->setGeometry(10, 60, 380, 30);
- tmpQFrame->setFrameStyle(52);
-
- tmpQLabel = new QLabel("Virtual Processor properties (activated after "
- "restarting VLP):", &dlg);
- tmpQLabel->setGeometry(10, 80, 340, 30);
-
- QLineEdit *nn;
- char nns[256];
- sprintf(nns, "%d", NodeNumber);
- nn = new QLineEdit(nns, &dlg);
- nn->setGeometry(110, 110, 40, 30);
-
- tmpQLabel = new QLabel("Node number:", &dlg);
- tmpQLabel->setGeometry(20, 110, 90, 30);
-
- QRadioButton *exp, *reg;
- exp = new QRadioButton("Explicit", &dlg);
- exp->setGeometry(30, 170, 100, 30);
- exp->setChecked(TRUE);
-
- reg = new QRadioButton("Registration", &dlg);
- reg->setGeometry(30, 200, 100, 30);
- reg->setEnabled(FALSE);
-
- connections = new QListWidget(&dlg);
- connections->setGeometry(170, 140, 130, 100);
-
- for (int i = 0; i < ConnectList.size(); i++) {
- e = ConnectList.at(i);
- connections->addItem(e->addr);
- }
-
- tmpQLabel = new QLabel("Connection list:", &dlg);
- tmpQLabel->setGeometry(170, 110, 100, 30);
-
- QPushButton *addbtn;
- QPushButton *delbtn;
- QPushButton *okbtn;
- QPushButton *cancelbtn;
- addbtn = new QPushButton("Add", &dlg);
- addbtn->setGeometry(310, 150, 60, 30);
- connect(addbtn, SIGNAL(clicked()), this, SLOT(AddAddress()));
-
- delbtn = new QPushButton("Del", &dlg);
- delbtn->setGeometry(310, 200, 60, 30);
- connect(delbtn, SIGNAL(clicked()), this, SLOT(DelAddress()));
-
- okbtn = new QPushButton("Ok", &dlg);
- okbtn->setGeometry(80, 260, 100, 30);
- okbtn->setDefault(TRUE);
- connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
- cancelbtn = new QPushButton("Cancel", &dlg);
- cancelbtn->setGeometry(210, 260, 100, 30);
- connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- QGroupBox* group;
- group = new QGroupBox("Connection type", &dlg);
- group->setGeometry(20, 150, 120, 90);
- group->setAlignment(Qt::AlignLeft);
- group->lower();
-
- QVBoxLayout *vbox = new QVBoxLayout();
- vbox->addWidget(exp);
- vbox->addWidget(reg);
- vbox->addStretch(1);
- group->setLayout(vbox);
-
- dlg.resize(400, 310);
- if (dlg.exec()) {
- config_t cfg;
- config_setting_t *root;
- config_setting_t *setting;
- config_init(&cfg);
-
- root = config_root_setting(&cfg);
-
- setting = config_setting_add(root, "progdir",
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting, progs->text().toAscii().data());
- strcpy(progdir, progs->text().toAscii().data());
-
- setting = config_setting_add(root, "node_number",
- CONFIG_TYPE_INT);
- config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
-
- setting = config_setting_add(root, "homedir",
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting, HomeDir);
-
- setting = config_setting_add(root, "type",
- CONFIG_TYPE_STRING);
- if (exp->isChecked()) {
- config_setting_set_string(setting, "explicit");
-
- config_setting_t *hosts = NULL;
- hosts = config_setting_add(root, "host",
- CONFIG_TYPE_ARRAY);
- for(i = 0; i < connections->count(); i++) {
- setting = config_setting_add(hosts, NULL,
- CONFIG_TYPE_STRING);
- config_setting_set_string(setting,
- connections->item(i)->text().toAscii().data());
- }
- } else {
- config_setting_set_string(setting, "register");
- }
-
- if (!config_write_file(&cfg, "vlp.cfg")) {
- fprintf(stderr, "Error while writing to file: %s.\n",
- "vlp.cfg");
- }
- config_destroy(&cfg);
+ OptionsDialog optionsDialog(this);
+ if (optionsDialog.exec()) {
+ optionsDialog.saveConfig("vlp.cfg");
+ LoadConfig("vlp.cfg");
}
}
{
char a[256], b[255];
struct sockaddr_un svr;
- int len, sock, i, on;
+ int len, sock, on;
+ unsigned int i;
int newint=-1;
char cmd[255];
FILE *cf;
public slots:
void n_impl();
- void AddAddress();
- void DelAddress();
void NetMessage();
void IntMessage(int);
private:
QList<InterpEntry*> Interpreters;
QList<ConnectEntry*> ConnectList;
- QListWidget *connections;
/**
* number of working interpreters
#include "lock.h"
LockDialog::LockDialog(QWidget * parent)
- : QDialog(parent)
+ : QDialog(parent, Qt::Dialog)
{
setupUi(this);
}
--- /dev/null
+#include <QtGui/QDialog>
+#include <libconfig.h>
+
+#include "options.h"
+
+OptionsDialog::OptionsDialog(QWidget * parent)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ loadConfig("vlp.cfg");
+}
+
+OptionsDialog::~OptionsDialog()
+{
+}
+
+/**
+ * Adds IP address to the configuration.
+ * Additional window is displayed to add address to the list
+ */
+void OptionsDialog::on_addConnectionButton_clicked()
+{
+ QDialog d(this, Qt::Dialog);
+ QLabel lab("IP Address:", &d);
+ QLineEdit ed("", &d);
+ QPushButton ob("", &d);
+ QPushButton cb("", &d);
+
+ if (connections) {
+ ob.setGeometry(30, 60, 80, 30);
+ ob.setText("Ok");
+ ob.setDefault(TRUE);
+ lab.setGeometry(10, 10, 60, 30);
+ lab.setText("Address");
+ ed.setGeometry(70, 10, 140, 30);
+ cb.setGeometry(130, 60, 80, 30);
+ cb.setText("Cancel");
+ d.resize(240, 100);
+ connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
+ connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
+ if (d.exec())
+ if (strcmp(ed.text().toAscii().data(), "") != 0) {
+ connections->addItem(ed.text());
+ }
+ }
+}
+
+/**
+ * Deletes current address from available connections.
+ */
+void OptionsDialog::on_delConnectionButton_clicked()
+{
+ if (connections->currentRow() != -1) {
+ connections->takeItem(connections->currentRow());
+ }
+}
+
+/**
+ * Loads configuration from the given file.
+ *
+ * @see QKernel::LoadConfig
+ *
+ * @param fname Filename of the configuration file.
+ */
+void OptionsDialog::loadConfig(char * fname)
+{
+ config_t cfg;
+ config_setting_t *setting;
+ const char *str;
+
+ /* 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->setValue(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")) {
+ explicitConnectionMode->setEnabled(true);
+ registrationConnectionMode->setDisabled(true);
+ } else {
+ registrationConnectionMode->setEnabled(true);
+ explicitConnectionMode->setDisabled(true);
+ }
+ } 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:
+ connections->addItem(config_setting_get_string(setting));
+ break;
+ case CONFIG_TYPE_ARRAY: {
+ int size = config_setting_length(setting);
+ for (int i = 0; i < size; i++) {
+ connections->addItem(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){
+ programsDirectory->setText(config_setting_get_string(setting));
+ } else {
+ fprintf(stderr, "%s! In file %s, '%s' was not found.\n", "Warning", fname, "progdir");
+ }
+
+ setting = config_lookup(&cfg, "homedir");
+ if (setting) {
+ homeDir = config_setting_get_string(setting);
+ } else {
+ fprintf(stderr, "%s! In file %s, '%s' was not found.\n", "Warning", fname, "homedir");
+ }
+
+ config_destroy(&cfg);
+ fclose(file);
+}
+
+void OptionsDialog::saveConfig(char * fname)
+{
+ config_t cfg;
+ config_setting_t *root;
+ config_setting_t *setting;
+ config_init(&cfg);
+
+ root = config_root_setting(&cfg);
+
+ setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
+ config_setting_set_string(setting, programsDirectory->text().toStdString().c_str());
+
+ setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
+ config_setting_set_int(setting, nodeNumber->value());
+
+ setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
+ config_setting_set_string(setting, homeDir);
+
+ setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
+ if (explicitConnectionMode->isChecked()) {
+ config_setting_set_string(setting, "explicit");
+
+ config_setting_t *hosts = NULL;
+ hosts = config_setting_add(root, "host", CONFIG_TYPE_ARRAY);
+ for(int i = 0; i < connections->count(); i++) {
+ setting = config_setting_add(hosts, NULL, CONFIG_TYPE_STRING);
+ config_setting_set_string(setting, connections->item(i)->text().toStdString().c_str());
+ }
+ } else {
+ config_setting_set_string(setting, "register");
+ }
+
+ if (!config_write_file(&cfg, fname)) {
+ fprintf(stderr, "Error while writing to file: %s.\n", fname);
+ }
+ config_destroy(&cfg);
+}
--- /dev/null
+#ifndef _VLP_KERNEL_OPTIONS_H
+#define _VLP_KERNEL_OPTIONS_H
+
+#include <QtGui/QDialog>
+
+#include "optionsdialog.h"
+
+/**
+ * Options Dialog class
+ */
+class OptionsDialog : public QDialog, private Ui::OptionsDialog {
+ Q_OBJECT
+public:
+ OptionsDialog(QWidget * parent = 0);
+ ~OptionsDialog();
+
+ void saveConfig(char * fname);
+
+private:
+ QString homeDir;
+
+ void loadConfig(char * fname);
+
+private slots:
+ void on_addConnectionButton_clicked();
+ void on_delConnectionButton_clicked();
+};
+
+#endif /* _VLP_KERNEL_OPTIONS_H */
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>OptionsDialog</class>
+ <widget class="QDialog" name="OptionsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>554</width>
+ <height>297</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Options</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Programs directory</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="programsDirectory">
+ <property name="text">
+ <string>./</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Virtual Processor properties (activated after restarting VLP):</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Node number:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="nodeNumber">
+ <property name="maximum">
+ <number>9999</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Connection type</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <item>
+ <widget class="QRadioButton" name="explicitConnectionMode">
+ <property name="text">
+ <string>Explicit</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="registrationConnectionMode">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Registration</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Connection list:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="connections"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QPushButton" name="addConnectionButton">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="delConnectionButton">
+ <property name="text">
+ <string>Del</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>OptionsDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>OptionsDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>