Commit eff3d653 authored by Stanislav Bohm's avatar Stanislav Bohm

DOC: Basic documentation added

parent aaba448c
......@@ -27,8 +27,6 @@ add_library(libloom
taskfactory.h
dictionary.cpp
dictionary.h
databuilder.cpp
databuilder.h
data.cpp
data.h
unpacking.cpp
......
/**
@file compat.h
This file provides some features from C++14.
In the current version it provides std::make_unique
*/
#ifndef LIBLOOM_COMPAT_H
#define LIBLOOM_COMPAT_H
......
......@@ -16,6 +16,7 @@ namespace loom {
class Connection;
/** Base class for handling events emited by Connection */
class ConnectionCallback
{
friend class Connection;
......@@ -23,15 +24,21 @@ public:
virtual ~ConnectionCallback();
protected:
/** New connection is established. (Not used when connection created by 'accept'). */
virtual void on_connection() { assert(0); }
/** An error has occured, error_code is from libuv. */
virtual void on_error(int error_code);
/** The connection is closed. */
virtual void on_close() = 0;
/** Raw data received */
virtual void on_data_chunk(const char *buffer, size_t size) { assert(0); }
/** Raw data finished */
virtual void on_data_finish() { assert(0); }
/** Message received */
virtual void on_message(const char *buffer, size_t size) = 0;
};
/** Class representing TCP/IP connection */
class Connection
{
public:
......@@ -51,6 +58,7 @@ public:
return state;
}
/** Set callback instance; the old one is forgotten. */
void set_callback(ConnectionCallback *callback) {
this->callback = callback;
}
......
......@@ -15,30 +15,52 @@ class Worker;
class SendBuffer;
class Connection;
/** Base class for data objects */
class Data
{
public:
virtual ~Data();
virtual std::string get_type_name() const = 0;
/** Get size of data */
virtual size_t get_size() = 0;
/** Get debugging info string */
virtual std::string get_info() = 0;
/** Get length of data (when object is not indexable then returns 0) */
virtual size_t get_length();
/** Get subobject at given index (0 ... get_length()) */
virtual std::shared_ptr<Data> get_at_index(size_t index);
/** Get subobject slice at given indices (0 ... get_length()) */
virtual std::shared_ptr<Data> get_slice(size_t from, size_t to);
/** Serialize object into send buffer */
void serialize(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
virtual void init_message(Worker &worker, loomcomm::Data &msg) const;
virtual void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr) = 0;
/** Get pointer to raw data, returns nullptr when it is not possible */
virtual char *get_raw_data(Worker &worker);
/** Returns a filename if data obeject is mapped from file, empty string otherwise */
virtual std::string get_filename() const;
protected:
/** Init serialization message */
virtual void init_message(Worker &worker, loomcomm::Data &msg) const;
/** Serialize content */
virtual void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr) = 0;
};
/** Base class for deserialization */
class DataUnpacker
{
public:
virtual ~DataUnpacker();
virtual bool init(Worker &worker, Connection &connection, const loomcomm::Data &msg) = 0;
virtual bool on_message(Connection &connection, const char *data, size_t size);
virtual void on_data_chunk(const char *data, size_t size);
......
......@@ -21,10 +21,10 @@ public:
std::shared_ptr<Data>& get_ref_at_index(size_t index);
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
std::string get_type_name() const;
private:
protected:
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
size_t length;
std::unique_ptr<std::shared_ptr<Data>[]> items;
};
......
......@@ -26,12 +26,11 @@ public:
}
std::string get_info();
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
std::string get_filename() const;
private:
protected:
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
void open();
void map(int fd, bool write);
......
......@@ -27,10 +27,9 @@ public:
std::shared_ptr<Data> get_at_index(size_t index);
std::shared_ptr<Data> get_slice(size_t from, size_t to);
protected:
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
private:
Worker &worker;
std::shared_ptr<Data> data;
size_t length;
......
......@@ -26,17 +26,16 @@ public:
}
std::string get_info();
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
//char* init_memonly(size_t size);
char* init_empty_file(Worker &worker, size_t size);
void assign_filename(Worker &worker);
void init_from_file(Worker &worker);
std::string get_filename() const;
private:
protected:
void serialize_data(Worker &worker, SendBuffer &buffer, std::shared_ptr<Data> &data_ptr);
void open(Worker &worker);
void map(int fd, bool write);
......
//#include "databuilder.h"
/*#ifndef LIBLOOM_DATABUILDER_H
#define LIBLOOM_DATABUILDER_H
#include "data.h"
#include <stdlib.h>
#include <memory>
#include <string.h>
namespace loom {
class Worker;
class Data;
class DataBuilder
{
public:
DataBuilder(Worker &worker, loom::Id id, size_t size, bool in_file)
: data(std::make_unique<Data>(id))
{
if (in_file) {
pointer = data->init_empty_file(worker, size);
} else {
pointer = data->init_memonly(size);
}
}
std::unique_ptr<Data> release_data() {
pointer = nullptr;
return std::move(data);
}
void add(const char *new_data, size_t size) {
memcpy(pointer, new_data, size);
pointer += size;
}
public:
std::unique_ptr<Data> data;
char *pointer;
};
}
#endif // LIBLOOM_DATABUILDER_H
*/
......@@ -9,6 +9,7 @@
namespace loom {
/** Container for symbols */
class Dictionary {
public:
......
......@@ -3,7 +3,6 @@
#include "loomcomm.pb.h"
#include "log.h"
#include "utils.h"
#include "databuilder.h"
#include <sstream>
......
......@@ -13,6 +13,7 @@ class Worker;
class DataBuilder;
class SendBuffer;
/** Interconnection between workers */
class InterConnection : public SimpleConnectionCallback
{
public:
......
......@@ -4,6 +4,8 @@
#include "spdlog/spdlog.h"
namespace loom {
/** Main loom log */
extern std::shared_ptr<spdlog::logger> llog;
}
......
......@@ -15,6 +15,7 @@ namespace loom {
class Data;
/** Buffer for composing data that will be send over a connection */
class SendBuffer {
public:
......
......@@ -9,6 +9,7 @@ namespace loom {
class Worker;
/** Class that repsents one task */
class Task {
public:
......
......@@ -15,6 +15,7 @@ namespace loom {
class Worker;
class TaskInstance;
/** Abstract class for creating task instances */
class TaskFactory
{
public:
......
......@@ -17,6 +17,7 @@ class Data;
typedef std::vector<std::shared_ptr<Data>*> DataVector;
/** Base class for task instance - an actual state of computation of a task */
class TaskInstance
{
public:
......
#include "rawdatatasks.h"
#include "libloom/compat.h"
#include "libloom/databuilder.h"
#include "libloom/data/rawdata.h"
#include "libloom/data/index.h"
#include "libloom/data/externfile.h"
......
......@@ -8,6 +8,7 @@
namespace loom {
/** Base class for factory producing deserializers for data types */
class UnpackFactory
{
public:
......
......@@ -19,6 +19,7 @@ namespace loom {
class Worker;
class DataUnpacker;
/** Class representing connection to the server */
class ServerConnection : public SimpleConnectionCallback {
public:
......@@ -37,7 +38,7 @@ protected:
void on_error(int error_code);
};
/** Main class of the libloom that represents whole worker */
class Worker {
friend class ServerConnection;
......
......@@ -13,9 +13,7 @@ add_library(loom-server-lib OBJECT
freshconn.cpp
freshconn.h
clientconn.cpp
clientconn.h
resendtask.cpp
resendtask.h)
clientconn.h)
target_include_directories(loom-server-lib PUBLIC ${PROJECT_SOURCE_DIR}/src)
......
......@@ -4,11 +4,12 @@
#include "libloom/connection.h"
namespace loom {
class SendBuffer;
class SendBuffer;
}
class Server;
/** Connection to client */
class ClientConnection : public loom::ConnectionCallback {
public:
ClientConnection(Server &server,
......@@ -17,10 +18,6 @@ public:
void on_message(const char *buffer, size_t size);
void on_close();
/*void send(uv_write_t *request, uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb) {
connection->send(request, bufs, nbufs, cb);
}*/
void send_buffer(loom::SendBuffer *buffer) {
connection->send_buffer(buffer);
}
......
......@@ -12,6 +12,9 @@
class Server;
class DWConnection;
/** An implementation of a simple worker that is only able
* to receive a data
*/
class DummyWorker
{
friend class DWConnection;
......
......@@ -5,6 +5,9 @@
class Server;
/**
* A new connection before registration (it is not determined if it is client or worker)
*/
class FreshConnection : public loom::ConnectionCallback {
public:
......
/*#include "resendtask.h"
#include "server.h"
#include "libloom/loomcomm.pb.h"
#include "libloom/log.h"
using namespace loom;
ResendTask::ResendTask(Server &server, std::unique_ptr<Task> task)
: TaskInstance(server.get_dummy_worker(),std::move(task)),
server(server), buffer(*this)
{
}
void ResendTask::start(DataVector &input_data)
{
assert(input_data.size() == 1);
auto data = *input_data[0];
Id id = -get_id();
llog->debug("Resending data id={} to client", id);
loomcomm::DataPrologue msg;
msg.set_id(id);
buffer.add(msg);
data->serialize(worker, buffer, data);
// loomcomm::Data msg;
// msg.set_id(id);
// msg.set_size(data->get_size());
//
// buffer.add(msg);
// buffer.add(data, data->get_data(worker), data->get_size());
auto &connection = server.get_client_connection();
connection.send_buffer(&buffer);
}
ResendTaskFactory::ResendTaskFactory(Server &server)
: TaskFactory("resend"), server(server)
{
}
std::unique_ptr<TaskInstance> ResendTaskFactory::make_instance(Worker &worker, std::unique_ptr<Task> task)
{
return std::make_unique<ResendTask>(server, std::move(task));
}
ResendTask::_SendBuffer::_SendBuffer(ResendTask &task) : task(task)
{
}
void ResendTask::_SendBuffer::on_finish(int status)
{
UV_CHECK(status);
llog->debug("Resend task id={} finished", task.get_id());
task.finish_without_data();
}
*/
/*#ifndef LOOM_SERVER_RESENDJOB_H
#define LOOM_SERVER_RESENDJOB_H
#include "libloom/taskinstance.h"
#include "libloom/taskfactory.h"
#include "libloom/sendbuffer.h"
namespace loom {
class Data;
}
class Server;
class ResendTask : public loom::TaskInstance
{
public:
class _SendBuffer : public loom::SendBuffer {
public:
_SendBuffer(ResendTask &task);
~_SendBuffer() {}
void on_finish(int status);
protected:
ResendTask &task;
};
ResendTask(Server &server, std::unique_ptr<loom::Task> task);
void start(loom::DataVector &input_data);
protected:
Server &server;
_SendBuffer buffer;
static void _on_write(uv_write_t *write_req, int status);
};
class ResendTaskFactory : public loom::TaskFactory
{
public:
ResendTaskFactory(Server &server);
std::unique_ptr<loom::TaskInstance> make_instance(loom::Worker &worker, std::unique_ptr<loom::Task> task);
private:
Server &server;
};
#endif // LOOM_SERVER_RESENDJOB_H
*/
#include "server.h"
#include "resendtask.h"
#include "libloom/compat.h"
#include "libloom/utils.h"
......
......@@ -11,6 +11,7 @@
#include <vector>
/** Main class of the server */
class Server {
public:
......
......@@ -15,6 +15,7 @@ class Plan;
class Server;
/** This class is responsible for planning tasks on workers */
class TaskManager
{
......
......@@ -11,6 +11,7 @@
class WorkerConnection;
class Server;
/** A task in the task graph in the server */
class TaskNode {
public:
......
......@@ -9,6 +9,7 @@
class Server;
class TaskNode;
/** Connection to worker */
class WorkerConnection : public loom::ConnectionCallback {
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment