Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ddcb12d
Added net interfaces
Oct 10, 2018
f1563a2
Modified gitignore
Oct 29, 2018
187c1c3
modified architecture, added packet tests
Oct 29, 2018
22174fa
packet tests repaired
Oct 29, 2018
b9b8902
modified architecture
Nov 19, 2018
9c1e54b
Added gitignore
Nov 19, 2018
eb73346
Clean Clion autogenerated
Nov 19, 2018
d231b11
now compiling
Nov 19, 2018
d8f1197
added calling methods logic
Nov 20, 2018
b4efdc7
edited return types for receive, boost::serialize
Nov 22, 2018
8a4b535
added client logic, reorganized boost inclusion
Nov 23, 2018
cf0a0d3
added server logic
Nov 24, 2018
dcf1268
cmake repaired
Dec 1, 2018
7769dde
added send_to for server
Dec 1, 2018
8db4d63
repaired cmake boost
Dec 1, 2018
8560767
added declarations of static members in sources
Dec 1, 2018
0c7b8a7
total code refactor
Dec 2, 2018
4d7ea3a
fixed errors
Dec 2, 2018
3f7c9d8
fixed SubSock destructor error
Dec 2, 2018
8ce52a2
fixed SubSock destructor error
Dec 2, 2018
384b94d
moved from unique_ptr to shared_ptr
Dec 3, 2018
dc77c93
moved from shared_ptr to raw pointers
Dec 3, 2018
1ad84c9
deleted priority mutexes
Dec 3, 2018
4c18d46
added logs
Dec 3, 2018
ae03588
ip log repaired
Dec 3, 2018
96199d2
boost find log added
Dec 3, 2018
b472cb3
logs removed
Dec 3, 2018
0c32f8e
repaired message borders
Dec 15, 2018
f7d4075
added pseudo sleep between two sends, moved to shared_ptr
Dec 16, 2018
782e5b3
added WAIT_TIME_BETWEEN_SEND
Dec 16, 2018
d001dbb
code refactor
Dec 17, 2018
68bbb4b
fixed small error
Dec 17, 2018
b6ae22b
removed friends, Nagle
Dec 21, 2018
28e8aaa
fixed bad synchronization error
Dec 21, 2018
5b899b3
fixed deserializable error: no return statement
Dec 21, 2018
f484869
added test
Dec 23, 2018
0498cfc
Modified gitignore
Dec 23, 2018
cc0ba47
Added CI
Dec 23, 2018
a294c18
removed extra dependency
Dec 23, 2018
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
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2

jobs:
build:
docker:
- image: "serega753/cpp_project:actual"
working_directory: /app/TP_CPP_PROJECT
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: cd
command: 'cd /app/TP_CPP_PROJECT'
- run:
name: cp cmake
command: 'cp /app/net_cmake/CMakeLists.txt /app/TP_CPP_PROJECT/Net/'
- run:
name: Creating Build Files
command: 'cmake Net/CMakeLists.txt && cd Net/ && make'
- run:
name: testing
command: '/app/TP_CPP_PROJECT/Net/net_tests'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app
Net/CMakeLists.txt
Net/cmake-build-debug*
Net/.idea*
16 changes: 16 additions & 0 deletions Net/include/AbstractClientNetObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_ABSTRACTCLIENTNETOBJECT_H
#define NET_ABSTRACTCLIENTNETOBJECT_H

#include "AbstractNetObject.h"

class AbstractClientNetObject : public AbstractNetObject
{

};


#endif //NET_ABSTRACTCLIENTNETOBJECT_H
19 changes: 19 additions & 0 deletions Net/include/AbstractNetObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_ABSTRACTNETOBJECT_H
#define NET_ABSTRACTNETOBJECT_H

#include "Serializable.h"

class AbstractNetObject
{
public:
virtual void send(Serializable* serializable) = 0;
virtual std::vector<std::shared_ptr<Serializable>> receive() = 0;
virtual void work() = 0;
};


#endif //NET_ABSTRACTNETOBJECT_H
18 changes: 18 additions & 0 deletions Net/include/AbstractServerNetObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_ABSTRACTSERVERNETOBJECT_H
#define NET_ABSTRACTSERVERNETOBJECT_H


#include "AbstractNetObject.h"

class AbstractServerNetObject :public AbstractNetObject
{
public:
virtual void send(Serializable* serializable, int player_number) = 0;
};


#endif //NET_ABSTRACTSERVERNETOBJECT_H
33 changes: 33 additions & 0 deletions Net/include/ClientNetObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_CLIENTNETOBJECT_H
#define NET_CLIENTNETOBJECT_H

#include <map>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше было бы не использовать map, а инкапсулировать эту структуру данных в отдельном классе

#include "AbstractClientNetObject.h"
#include "DefaultAbstractFactory.h"
#include "noncopyable.h"

class ClientNetObjectImpl;

class ClientNetObject : public AbstractClientNetObject, public noncopyable
{
public:
ClientNetObject(std::string ip, uint port, std::map<std::string, DefaultAbstractFactory*> _map,
std::string startobj_string,
std::string endobj_string,
size_t type_length, int wait_time);
~ClientNetObject();

void send(Serializable *serializable) override;
std::vector<std::shared_ptr<Serializable>> receive() override;
void work() override;

private:
ClientNetObjectImpl *impl;
};


#endif //NET_CLIENTNETOBJECT_H
18 changes: 18 additions & 0 deletions Net/include/DefaultAbstractFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by alex on 23.11.18.
//

#ifndef NET_DEFAULTABSTRACTFACTORY_H
#define NET_DEFAULTABSTRACTFACTORY_H

#include "Serializable.h"

class DefaultAbstractFactory
{
public:
virtual std::shared_ptr<Serializable> create() = 0;
virtual ~DefaultAbstractFactory() = default;
};


#endif //NET_DEFAULTABSTRACTFACTORY_H
24 changes: 24 additions & 0 deletions Net/include/Serializable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by alex on 12.11.18.
//

#ifndef NET_SERIALIZABLE_H
#define NET_SERIALIZABLE_H

#include <string>
#include <boost/archive/text_iarchive.hpp>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нехорошо, что в общем интерфейсе Serializable задействован Boost
Boost нужно подключать на уже уровне конкретной реализации...

#include <boost/archive/text_oarchive.hpp>

struct Serializable
{
public:
virtual void serialize(boost::archive::text_oarchive& ar) = 0;

virtual void deserialize(boost::archive::text_iarchive& ar) = 0;
// virtual void serialize(boost::archive::text_iarchive& ar, const unsigned int version) = 0;
// virtual void serialize(boost::archive::text_oarchive& ar, const unsigned int version) = 0;
virtual ~Serializable() = default;
};


#endif //NET_SERIALIZABLE_H
34 changes: 34 additions & 0 deletions Net/include/ServerNetObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_SERVERNETOBJECT_H
#define NET_SERVERNETOBJECT_H


#include <map>
#include "AbstractServerNetObject.h"
#include "DefaultAbstractFactory.h"
#include "noncopyable.h"

class ServerNetObjectImpl;

class ServerNetObject : public AbstractServerNetObject, public noncopyable
{
public:
ServerNetObject(std::string ip, uint port, int player_num, std::map<std::string, DefaultAbstractFactory*> _map,
std::string startobj_string,
std::string endobj_string,
size_t type_length, int wait_time);
~ServerNetObject();

void send(Serializable *serializable) override;
std::vector<std::shared_ptr<Serializable>> receive() override;
void work() override;
void send(Serializable *serializable, int player_number) override;
private:
ServerNetObjectImpl* impl;
};


#endif //NET_SERVERNETOBJECT_H
22 changes: 22 additions & 0 deletions Net/include/noncopyable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by alex on 17.12.18.
//

#ifndef NET_NONCOPYABLE_H
#define NET_NONCOPYABLE_H


class noncopyable
{
protected:
noncopyable() = default;
~noncopyable() = default;
public:
noncopyable(noncopyable&) = delete;
noncopyable(noncopyable&&) = delete;
noncopyable& operator=(noncopyable&) = delete;
noncopyable&& operator=(noncopyable&&) = delete;
};


#endif //NET_NONCOPYABLE_H
34 changes: 34 additions & 0 deletions Net/non_public_include/SerializationOperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by alex on 23.12.18.
//

#ifndef NET_SERIALIZATIONOPERATION_H
#define NET_SERIALIZATIONOPERATION_H

#include <string>
#include <map>
#include <iostream>

#include "DefaultAbstractFactory.h"

class SerializationOperation
{
public:
SerializationOperation(std::map<std::string, DefaultAbstractFactory*> _map,
std::string startobj_string,
std::string endobj_string,
size_t type_length);

std::string serialize(Serializable* serializable) const;
std::shared_ptr<Serializable> deserialize(std::string& wrong_data_recv_buf, std::string& temp_recv_buf) const;
std::string get_endobj() const;

private:
std::map<std::string, DefaultAbstractFactory*> map;
const std::string STARTOBJ;
const std::string ENDOBJ;
const size_t TYPE_LENGTH;
};


#endif //NET_SERIALIZATIONOPERATION_H
40 changes: 40 additions & 0 deletions Net/src/ClientNetObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by alex on 17.12.18.
//

#include "../include/ClientNetObject.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

недоработали с Cmake...

#include "ClientNetObjectImpl.cpp"

ClientNetObject::ClientNetObject(
std::string ip,
uint port,
std::map<std::string, DefaultAbstractFactory*> _map,
std::string startobj_string = "STARTOBJ",
std::string endobj_string = "ENDOBJ",
size_t type_length = 3, int wait_time = 1)
{
impl = new ClientNetObjectImpl(ip, port, _map,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему не умный указатель?

startobj_string,
endobj_string,
type_length, wait_time);
}

ClientNetObject::~ClientNetObject()
{
delete impl;
}

void ClientNetObject::send(Serializable *serializable)
{
impl->send(serializable);
}

std::vector<std::shared_ptr<Serializable>> ClientNetObject::receive()
{
return impl->receive();
}

void ClientNetObject::work()
{
impl->work();
}
Loading