Skip to content

Commit

Permalink
#3: Mechanism to control the crunchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-slusarenko committed Mar 2, 2018
1 parent 4df2369 commit d026bb5
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 61 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BIN=./bin

SOURCES_CRUNCHER= src/mainCruncher.cpp \
src/cruncher.cpp \
src/control.cpp \
src/differentStrings.cpp \
src/exception.cpp \
src/fileOps.cpp \
Expand Down
26 changes: 26 additions & 0 deletions db/control.dbm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
CAUTION: Do not modify this file unless you know what you are doing.
Unexpected results may occur if the code is changed deliberately.
-->
<dbmodel pgmodeler-ver="0.8.1" last-position="1,0" last-zoom="1"
default-schema="public" default-owner="postgres">
<database name="new_database">
</database>

<schema name="public" protected="true" fill-color="#e1e1e1" sql-disabled="true">
</schema>

<table name="command">
<schema name="public"/>
<role name="postgres"/>
<position x="117" y="77"/>
<column name="run" not-null="true">
<type name="bool"/>
</column>
<column name="active" not-null="true">
<type name="bool"/>
</column>
</table>

</dbmodel>
27 changes: 27 additions & 0 deletions db/control.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Database generated with pgModeler (PostgreSQL Database Modeler).
-- pgModeler version: 0.8.1
-- PostgreSQL version: 9.4
-- Project Site: pgmodeler.com.br
-- Model Author: ---


-- Database creation must be done outside an multicommand file.
-- These commands were put in this file only for convenience.
-- -- object: new_database | type: DATABASE --
-- -- DROP DATABASE IF EXISTS new_database;
-- CREATE DATABASE new_database
-- ;
-- -- ddl-end --
--

-- object: public.command | type: TABLE --
-- DROP TABLE IF EXISTS public.command CASCADE;
CREATE TABLE public.command(
run bool NOT NULL,
active bool NOT NULL
);
-- ddl-end --
ALTER TABLE public.command OWNER TO postgres;
-- ddl-end --


7 changes: 7 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const int DOMAIN_NO_INSERT = 0;
const int DOMAIN_INSERT_SAME = 1;
const int DOMAIN_INSERT_ALL = 2;

/**
* Database IDs.
**/

const int DB_TEXT_SEARCH = 7;
const int DB_CONTROL = 11;

/**
* String literals.
**/
Expand Down
56 changes: 56 additions & 0 deletions include/control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/***********************************************************************
* T R O K A M
* Fair Search Engine
*
* Copyright (C) 2018, Nicolas Slusarenko
* [email protected]
*
* This file is part of Trokam.
*
* Trokam is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Trokam is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Trokam. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/

#ifndef TROKAM_CONTROL_H
#define TROKAM_CONTROL_H

/// C++
#include <string>

/// Boost
#include <boost/scoped_ptr.hpp>

/// Trokam
#include "reporting.h"
#include "options.h"
#include "postgresql.h"

namespace Trokam
{
class Control
{
public:

Control(const Trokam::Options &value);
bool run();
bool active();

private:

Trokam::Options settings;
Trokam::Postgresql db;
Trokam::Reporting msg;
};
}

#endif /// TROKAM_INFOSTORE_H
5 changes: 3 additions & 2 deletions include/cruncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ namespace Trokam

private:

// int index;

int count;
Trokam::Options settings;
Trokam::InfoStore storage;
Trokam::Reporting msg;

void process();

void action(const int &index,
const int &error);
};
Expand Down
13 changes: 13 additions & 0 deletions include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ namespace Trokam
std::string dbName() const;
std::string dbUser() const;
std::string dbPass() const;

std::string controlHost() const;
std::string controlName() const;
std::string controlUser() const;
std::string controlPass() const;

std::string workingDir() const;
std::string seedsFile() const;
std::string contentDir() const;
Expand All @@ -55,10 +61,17 @@ namespace Trokam
void deleteWorkingDirectory();

private:

std::string optDbHost;
std::string optDbName;
std::string optDbUser;
std::string optDbPass;

std::string optControlHost;
std::string optControlName;
std::string optControlUser;
std::string optControlPass;

std::string optWorkingDir;
std::string optSeedsFile;
std::string optContentDir;
Expand Down
16 changes: 13 additions & 3 deletions include/postgresql.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,24 @@ namespace Trokam
{
public:

Postgresql(const Trokam::Options &value);
// Postgresql(const Trokam::Options &value);
Postgresql(const Trokam::Options &value,
const int &id);

~Postgresql();

void execSql(const std::string &sentence);
void execSql(const std::string &sentence, boost::scoped_ptr<pqxx::result> &answer);

void execSql(const std::string &sentence,
boost::scoped_ptr<pqxx::result> &answer);

void execSql(std::vector<std::string> &bundle);

static void extract(const boost::scoped_ptr<pqxx::result> &answer, int &value);
static void extract(const boost::scoped_ptr<pqxx::result> &answer,
int &value);

static void extract(const boost::scoped_ptr<pqxx::result> &answer,
bool &value);

private:

Expand Down
65 changes: 65 additions & 0 deletions src/control.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***********************************************************************
* T R O K A M
* Fair Search Engine
*
* Copyright (C) 2018, Nicolas Slusarenko
* [email protected]
*
* This file is part of Trokam.
*
* Trokam is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Trokam is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Trokam. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/

/// C++
#include <string>
#include <iostream>

/// Trokam
#include "common.h"
#include "control.h"

Trokam::Control::Control(const Trokam::Options &value): settings(value),
db(value, DB_CONTROL),
msg(value)
{}

bool Trokam::Control::run()
{
bool state= false;

std::string sentence;
sentence= "SELECT run ";
sentence+= "FROM command ";

boost::scoped_ptr<pqxx::result> answer;
db.execSql(sentence, answer);
Trokam::Postgresql::extract(answer, state);

return state;
}

bool Trokam::Control::active()
{
bool state= false;

std::string sentence;
sentence= "SELECT active ";
sentence+= "FROM command ";

boost::scoped_ptr<pqxx::result> answer;
db.execSql(sentence, answer);
Trokam::Postgresql::extract(answer, state);

return state;
}
Loading

0 comments on commit d026bb5

Please sign in to comment.