#include "kill_interpreter_dialog.h"
#include "connect_dialog.h"
+#include "vlp/config.h"
+
/* File resides in top directory (where are Makefiles)*/
#include "../../config.h"
+namespace loglan {
+namespace vlp {
+
char CharLine[25] = "________________________";
/**
q.mkpath(getRemoteDir());
}
- info_messages = TRUE;
+ info_messages = actionInfo_messages->isChecked();
wait_for_info = FALSE;
setWindowTitle(PACKAGE_NAME);
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()
*/
void QKernel::loadConfig(const char * fname)
{
- config_t cfg;
- config_setting_t *setting;
-
- /* 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);
- }
+ loglan::vlp::Config config;
+ if(config.load(fname)) {
+ NodeNumber = config.getNodeNumber();
+ ConType = config.getConnectionType();
- 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 (unsigned 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");
+ strncpy(progdir, config.getProgramDir(), 256);
}
-
- 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");
- }
-
- config_destroy(&cfg);
- fclose(file);
}
/**
*/
void QKernel::on_actionExecute_triggered()
{
- int i;
QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
if (!s.isNull()) {
- i = s.indexOf(".log");
+ int i = s.indexOf(".log");
if (i > 0)
s.remove(i, 4);
*/
void QKernel::RunGraphModule(char *sk)
{
- char cmd[255];
-
QString program = getHomeDir();
program += "/modules/loggraph";
KillInterpreterDialog dialog(this);
dialog.setWindowTitle("Kill interpreter");
- MESSAGE m;
- InterpEntry *interpreter;
-
if (dialog.exec()) {
+ MESSAGE m;
m.msg_type = MSG_INT;
m.param.pword[0] = INT_KILL;
+
+ InterpEntry *interpreter;
interpreter = findINTbyID(dialog.getInterpreterId());
+
if (interpreter != NULL) {
- if (!(interpreter->remote))
+ if (!(interpreter->remote)) {
write(interpreter->sock, &m, sizeof(MESSAGE));
- else
+ }
+ else {
WriteMessage("This is a remote instance of a program!");
+ }
}
else {
WriteMessage("Interpreter not found");
/* TODO: It has to be rewritten */
MESSAGE msg;
int cnt;
- char ss[255];
InterpEntry *pom;
cnt = read(net_sock, &msg, sizeof(MESSAGE));
if ((cnt > 0) && (msg.msg_type == MSG_NET)) {
+ char ss[255];
+
switch(msg.param.pword[0]) {
case NET_CSWRITELN:
WriteMessage(msg.param.pstr);
* 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;
+// int y;
x = desktop->textCursor().blockNumber();
- y = desktop->textCursor().columnNumber();
+// y = desktop->textCursor().columnNumber();
if (x > 100) {
desktop->clear();
}
}
-/**
- * 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
{
InterpEntry *pom = NULL;
- for (int i = 0; i < Interpreters.size(); i++) {
- if (Interpreters.at(i)->sock == _id) {
- pom = Interpreters.at(i);
+ for (auto interpreter : Interpreters) {
+ if (interpreter->sock == _id) {
+ pom = interpreter;
break;
}
}
{
InterpEntry *pom = NULL;
- for (int i = 0; i < Interpreters.size(); i++) {
- if (Interpreters.at(i)->ID == _id) {
- pom = Interpreters.at(i);
+ for (auto interpreter : Interpreters) {
+ if (interpreter->ID == _id) {
+ pom = interpreter;
break;
}
}
void QKernel::RemoteInstance(InterpEntry *interp, int on)
{
MESSAGE m;
- char s[255];
m.msg_type = MSG_NET;
m.param.pword[0] = NET_NODE_EXIST;
m.param.pword[1] = interp->RInstances[on];
write(interp->sock, &m, sizeof(MESSAGE));
} else { /* There is no such a node! */
+ char s[255];
sprintf(s, "Warning: Node number %d not found!", on);
WriteMessage(s);
WriteMessage("Allocating O-process on the local node");
wait_for_info = TRUE;
}
+}
+}
+
/**
* Program main function
* All program arguments but the first one (argv[0]: program name) are saved and
XInitThreads();
QApplication * app = new QApplication(argc, argv);
- QKernel kernel(argc, argv);
+ loglan::vlp::QKernel kernel(argc, argv);
kernel.show();
- kernel.InitMessage();
return app->exec();
-}
+}
\ No newline at end of file