Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
cf35e49
Added template files
Sermelyan Oct 30, 2019
bf7a138
Added codecov
Sermelyan Oct 30, 2019
6e5686a
add queue header and tests
Greenader Nov 8, 2019
7e28275
delete Foo
Greenader Nov 9, 2019
9ede2a8
delete comment
Greenader Nov 9, 2019
e435813
delete spaces
Greenader Nov 9, 2019
3d58e35
delete resize()
Greenader Nov 9, 2019
e4f5634
fufSuze rename
Greenader Nov 9, 2019
03f979b
add realization
Greenader Nov 17, 2019
7ffe36d
add spaces for goodread
Greenader Nov 17, 2019
4ca7c12
algo header, realisation and 1 test
Greenader Nov 17, 2019
fa6cce5
add 4 tests
Greenader Nov 17, 2019
3768fca
work with syntax
Greenader Nov 17, 2019
53f1f96
add const & in functions
Greenader Nov 23, 2019
6b7fe9e
syntax
Greenader Nov 23, 2019
b0b7d75
temporary
Sermelyan Dec 1, 2019
f75eb52
proto fix
Sermelyan Dec 1, 2019
e2dacca
proto and boost fix
Sermelyan Dec 1, 2019
044c62f
proto and boost fix
Sermelyan Dec 1, 2019
ba29d41
start API work
Greenader Dec 1, 2019
a309c7d
proto and boost fix
Sermelyan Dec 1, 2019
18af76c
proto and boost fix
Sermelyan Dec 1, 2019
2ad71a6
cmake fixes
Sermelyan Dec 1, 2019
a350d44
proto & boost fixes
Sermelyan Dec 1, 2019
c94069f
proto & boost fixes
Sermelyan Dec 1, 2019
5e46ebe
proto & boost fixes
Sermelyan Dec 1, 2019
f746c36
proto & boost fixes
Sermelyan Dec 1, 2019
5a009e8
proto & boost fixes
Sermelyan Dec 1, 2019
5c0809a
proto & boost fixes
Sermelyan Dec 1, 2019
4bd2a0d
proto & boost fixes
Sermelyan Dec 1, 2019
a367fe7
proto & boost fixes
Sermelyan Dec 1, 2019
cb68e16
proto & boost fixes
Sermelyan Dec 1, 2019
e524a8c
proto & boost fixes
Sermelyan Dec 1, 2019
c5d8b89
add boost and get data from pythonSever
Greenader Dec 1, 2019
a733201
add realization an python server
Greenader Dec 2, 2019
ed5ed6c
add realization and python server
Greenader Dec 2, 2019
3838154
add tests and python start
Greenader Dec 2, 2019
eb1117b
config..
AlekseySirmais7 Dec 2, 2019
e79f051
add sudo for conf
AlekseySirmais7 Dec 2, 2019
79790f0
conf
AlekseySirmais7 Dec 2, 2019
ae46496
add utf-8
AlekseySirmais7 Dec 2, 2019
9aa4c22
&
AlekseySirmais7 Dec 2, 2019
8190d76
delete cout
Greenader Dec 2, 2019
c137078
delete spaces
Greenader Dec 2, 2019
b93b0a1
Merge branch 'workerAPI' of https://github.com/Sermelyan/GProject int…
Greenader Dec 2, 2019
439314b
start work newAlg
Greenader Dec 5, 2019
66c0448
corrections
Greenader Dec 5, 2019
72e1d53
жадный обход
Greenader Dec 5, 2019
76bacce
testes and echo server
Sermelyan Dec 7, 2019
c2f6fa0
Style fix for data
Sermelyan Dec 7, 2019
94701e4
Realization
Sermelyan Dec 7, 2019
8b25a2e
...
Greenader Dec 7, 2019
f422dc2
Merge branch 'rk3' into queue
AlekseySirmais7 Dec 7, 2019
2d54bd5
Merge pull request #11 from Sermelyan/queue
AlekseySirmais7 Dec 7, 2019
97c212e
prepare for merge
Sermelyan Dec 7, 2019
2383320
Merge branch 'rk3' into algorithm
AlekseySirmais7 Dec 7, 2019
4f1ff78
Merge pull request #13 from Sermelyan/algorithm
AlekseySirmais7 Dec 7, 2019
c965346
1
S4ll7 Dec 8, 2019
d67f40a
2
S4ll7 Dec 8, 2019
7b40c90
Merge pull request #17 from Sermelyan/Worker
S4ll7 Dec 8, 2019
43fa800
add alex code from workerAPI
AlekseySirmais7 Dec 8, 2019
ba783d4
add alex cpp from workerAPI
AlekseySirmais7 Dec 8, 2019
6384aa6
Update worker.hpp
S4ll7 Dec 8, 2019
3701095
Update worker.cpp
S4ll7 Dec 8, 2019
951702b
proto fixes
Sermelyan Dec 9, 2019
6abd6ff
proto fixes
Sermelyan Dec 9, 2019
4e93368
proto fixes
Sermelyan Dec 9, 2019
8997fa1
proto fixes
Sermelyan Dec 9, 2019
a4732cf
proto fixes
Sermelyan Dec 9, 2019
9a06c0e
proto fixes
Sermelyan Dec 9, 2019
8d5e7d4
proto fixes
Sermelyan Dec 9, 2019
16b24be
proto fixes
Sermelyan Dec 9, 2019
5ee88f6
Merge branch 'rk3' into server
Sermelyan Dec 9, 2019
3b27b3e
Merge pull request #18 from Sermelyan/server
Sermelyan Dec 9, 2019
083021a
build fixes
Sermelyan Dec 9, 2019
c083808
add Algotest from algorithm
AlekseySirmais7 Dec 13, 2019
2d51aa4
add testAPI from workerAPI
AlekseySirmais7 Dec 13, 2019
3494362
add testQueue from Queue
AlekseySirmais7 Dec 13, 2019
f632d8e
realization
Dec 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.vscode
cmake-build-debug
build
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

language: cpp

os: linux

compiler: gcc

before_install:
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update -q
- sudo apt-get install cppcheck -y
- sudo apt-get install python3 -y
- sudo apt-get install g++-9 -y
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90
- sudo apt-get install libboost-all-dev -y
- sudo apt-get install protobuf-compiler libprotobuf-dev -y
- CMAKE_VERSION=3.15.4
- CMAKE_VERSION_DIR=v3.15
- CMAKE_OS=Linux-x86_64
- CMAKE_TAR=cmake-$CMAKE_VERSION-$CMAKE_OS.tar.gz
- CMAKE_URL=http://www.cmake.org/files/$CMAKE_VERSION_DIR/$CMAKE_TAR
- CMAKE_DIR=$(pwd)/cmake-$CMAKE_VERSION
- wget --quiet $CMAKE_URL
- mkdir -p $CMAKE_DIR
- tar --strip-components=1 -xzf $CMAKE_TAR -C $CMAKE_DIR
- export PATH=$CMAKE_DIR/bin:$PATH
- sudo pip install flask
- sudo python ./serverAPI.py &

script:
# - ./linters/run.sh --local
- mkdir build
- cd build
- cmake -j2 ../
- make -j2
- ./test
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.15)
project(GProject)

find_package(Boost COMPONENTS thread log http)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()

find_package(Protobuf)
include_directories(${PROTOBUF_INCLUDE_DIR})

include_directories(${CMAKE_CURRENT_BINARY_DIR})


configure_file(CMakeLists.txt.in
googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
execute_process(COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )

add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build)


set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")

include_directories(include)

protobuf_generate_cpp(PROTO_SRC PROTO_HEADER protobuf/structures.proto)
add_library(proto ${PROTO_HEADER} ${PROTO_SRC})

add_library(algorithm STATIC src/algorithm.cpp)

add_library(queue STATIC src/queue.cpp)

add_library(server STATIC src/server.cpp)
target_link_libraries(server proto ${Boost_LIBRARIES})

#find_package (sqlite3.h)

#if (SQLITE3_FOUND)
# include_directories(${SQLITE3_INCLUDE_DIRS})
# target_link_libraries (new ${SQLITE3_LIBRARIES})
#endif (SQLITE3_FOUND)
#add_library(sqlite3 STATIC include/sqlite-autoconf-3300100/sqlite3.c)

add_library(worker STATIC src/worker.cpp)
include_directories(/usr/include)
link_directories(/usr/lib)
target_link_libraries(worker gtest gmock sqlite3)

add_executable(testServer test/testServer.cpp)
target_link_libraries(testServer gtest gmock server proto ${PROTOBUF_LIBRARY})
15 changes: 15 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# GProject
# GProject

[![Build Status](https://travis-ci.org/Sermelyan/GProject.svg?branch=template)](https://travis-ci.org/Sermelyan/GProject)

56 changes: 56 additions & 0 deletions include/algorithm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 <Alex>
*/

#ifndef INCLUDE_ALGORITHM_HPP_
#define INCLUDE_ALGORITHM_HPP_
#include <utility>
#include <vector>
#include <unordered_set>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <assert.h>

class Algorithm {

public:
typedef std::size_t dotId;
typedef std::pair<dotId, dotId> edge;
typedef std::size_t weight;

private:
typedef boost::adjacency_list <boost::listS, boost::vecS, boost::directedS,
boost::no_property,boost::property<boost::edge_weight_t, size_t> > graph_t;
typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_descriptor;

public:
Algorithm()= delete;
explicit Algorithm(const std::vector<edge> &edgeArr, const std::vector<weight> &weightArr);
~Algorithm();
Algorithm(const Algorithm&) = delete;
Algorithm(const Algorithm&&) = delete;
Algorithm& operator=(const Algorithm&) = delete;
Algorithm& operator=(const Algorithm&&) = delete;

std::vector<dotId> CalcRoute(const dotId &A, const dotId &B);

std::pair<std::vector<Algorithm::dotId>, size_t>
getRoute(dotId from, const size_t &pointsCount,
const size_t &time, const size_t &maxPlacesCount);



// delete this from algo and use from WorkerAPI
long int getWeightIndex(const size_t &pointsCount, const size_t &from, const size_t &to);

private:
void MakeGraph();
edge * edgeArr;
size_t edgeSize;
weight * weightArr;
graph_t myGraph;
const size_t MAX_PLACES = 200; // контроль (максимальное кол-во мест в пути)
};

#endif // INCLUDE_ALGORITHM_HPP_
46 changes: 46 additions & 0 deletions include/data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2019 <Copyright Owner>
*/

#include <iostream>
#include <string>
#include <utility>
#include <vector>

#ifndef INCLUDE_DATA_HPP_
#define INCLUDE_DATA_HPP_

static const unsigned MIN_IN_HOUR = 60;

typedef std::pair<double, double> Point;
typedef std::vector<Point> Points;
typedef std::vector<std::string> Filters;

struct DataIn {
Filters FilterList;
unsigned TimeLimit;
unsigned MaxDots;
Point StartPoint;
Point EndPoint;
int UserID;
DataIn() {}
DataIn(::Filters _f, unsigned _t, unsigned _md, Point _sp, Point _ep,
int _u)
: FilterList(std::move(_f)),
TimeLimit(_t),
MaxDots(_md),
StartPoint(std::move(_sp)),
EndPoint(std::move(_ep)),
UserID(_u) {}
};

struct DataOut {
Points RoutePoints;
unsigned MaxTime;
int UserID;
DataOut() {}
DataOut(Points _p, unsigned _t, int _u)
: RoutePoints(std::move(_p)), MaxTime(_t), UserID(_u) {}
};

#endif // INCLUDE_DATA_HPP_
58 changes: 58 additions & 0 deletions include/queue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 <Alex>
*/

#ifndef INCLUDE_QUEUE_HPP_
#define INCLUDE_QUEUE_HPP_

#include <queue>
#include <mutex>
#include <memory>

template <class T>
class GQueue {
public:
GQueue() = delete;
explicit GQueue(const T &element404);
~GQueue();
void push(const T &element);
T popIfNotEmpty();

GQueue(const GQueue&) = delete;
GQueue(const GQueue&&) = delete;
GQueue& operator=(const GQueue&) = delete;
GQueue& operator=(const GQueue&&) = delete;

private:
T element404;
std::unique_ptr<std::queue<T>> queue;
std::mutex GQueueMutex;
};

template <class T>
GQueue<T>::~GQueue() = default;

template <class T>
GQueue<T>::GQueue(const T &element404) {
queue.reset(new std::queue<T>);
this->element404 = element404;
}

template <class T>
void GQueue<T>::push(const T &element) {
const std::lock_guard<std::mutex> lock(GQueueMutex);
queue->push(element);
}

template <class T>
T GQueue<T>::popIfNotEmpty() {
const std::lock_guard<std::mutex> lock(GQueueMutex);
T answer = this->element404;
if (!queue->empty()) {
answer = queue->front();
queue->pop();
}
return answer;
}

#endif // INCLUDE_QUEU_HPP_
89 changes: 89 additions & 0 deletions include/server.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2019 <Copyright Owner>
*/

#include <memory>
#include <set>
#include <string>
#include <thread>
#include <utility>
#include <vector>

#include <boost/asio.hpp>
#include <boost/bind.hpp>

#include "data.hpp"
#include "queue.hpp"

#ifndef INCLUDE_SERVER_HPP_
#define INCLUDE_SERVER_HPP_

class ClientAdapter;
class Server;

class Client : std::enable_shared_from_this<Client> {
public:
int user_id;
typedef std::shared_ptr<Client> ClientPtr;

boost::asio::ip::tcp::socket &Sock();
static ClientPtr NewClient(boost::asio::io_service &io, Server &s);

void Read();
void Write(const std::string &msg);

static std::unique_ptr<DataIn> Unmarshal(const char *msg);
static std::string Marshal(const DataOut &out);

private:
explicit Client(boost::asio::io_service &io, Server &s);

boost::asio::ip::tcp::socket _socket;
Server &_server;
// std::string _read_msg;
// std::string _write_msg;

char _read_msg[4096];
std::string _write_msg;

void onRead(const boost::system::error_code &e, size_t bytes);
void onWrite(const boost::system::error_code &e, size_t bytes);
static void parseHTTP(const char *msg, const char *msg_end, std::map<std::string, std::string> &httpRequest);
};

class Server {
public:
Server(GQueue<DataIn> &in, GQueue<DataOut> &out, unsigned Port);
~Server();

void Kill();
void SendToQueue(std::unique_ptr<DataIn> data);
void StartAccept();
void StartEchoServer();
void StartServer(unsigned serviceThr = 4, unsigned queueThr = 2);

void AddWaitingClient(const Client::ClientPtr &c);
void RemoveWaitingClient(const Client::ClientPtr &c);

private:
boost::asio::io_service service;
GQueue<DataIn> &in;
GQueue<DataOut> &out;
bool alive;
unsigned port;

boost::asio::ip::tcp::acceptor acceptor;
std::vector<std::thread> threads;
std::set<Client::ClientPtr> waitingClients;
std::mutex liveMutex;
std::mutex waitingMutex;

void onAccept(const Client::ClientPtr &c,
const boost::system::error_code &e);
bool isAlive();
void GetFromQueue();

void sillyServer();
};

#endif // INCLUDE_SERVER_HPP_
Loading