Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client #3

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9ef9705
added classes and methods prototypes
kaverhovsky Nov 12, 2020
87ddd0e
added tests and reworked code
kaverhovsky Nov 12, 2020
37715c5
fixed blank.yml
kaverhovsky Nov 12, 2020
7fc3ae4
fixed blank.yml 2
kaverhovsky Nov 12, 2020
db999d7
fixed blank.yml 3
kaverhovsky Nov 12, 2020
82bde25
fixed blank.yml 4
kaverhovsky Nov 12, 2020
6531e16
fixed blank.yml 5
kaverhovsky Nov 12, 2020
ebfa8db
fixed blank.yml 6
kaverhovsky Nov 12, 2020
24227bb
fixed blank.yml 7
kaverhovsky Nov 12, 2020
076bc9e
removed old Cmakelist
kaverhovsky Nov 12, 2020
b8fd891
fixed blank.yml 8
kaverhovsky Nov 12, 2020
225299d
some changes
kaverhovsky Nov 12, 2020
6de03f0
some changes2
kaverhovsky Nov 12, 2020
985dd79
tried to implement code
kaverhovsky Dec 10, 2020
3339e88
changed blank.yml
kaverhovsky Dec 10, 2020
8dc195d
deleted request manager
kaverhovsky Dec 10, 2020
f00d935
implemented json-like serializator
kaverhovsky Dec 23, 2020
82043c9
added boost parser and moved send and recieve to presenter
kaverhovsky Dec 24, 2020
f14559e
changed consoleView
kaverhovsky Dec 24, 2020
c099009
login handler
kaverhovsky Dec 24, 2020
255bc0d
add link handler
kaverhovsky Dec 24, 2020
837acb2
changed connect
kaverhovsky Dec 24, 2020
5043f2d
-comms
kaverhovsky Dec 24, 2020
8a30a02
--
kaverhovsky Dec 24, 2020
d90ec82
----
kaverhovsky Dec 24, 2020
20ed769
------
kaverhovsky Dec 24, 2020
fe5ff7a
improved creating and removing rooms
kaverhovsky Dec 26, 2020
db3d341
improved adding users and links
kaverhovsky Dec 27, 2020
c9caa36
recieving files
kaverhovsky Dec 27, 2020
d03341a
rec
kaverhovsky Dec 27, 2020
a4f47cf
fixed serialization
kaverhovsky Dec 27, 2020
2fb9365
debug try
kaverhovsky Dec 27, 2020
7f9d74c
getting room from server
kaverhovsky Dec 28, 2020
64cf698
new commit
kaverhovsky Dec 28, 2020
f80127f
new
kaverhovsky Dec 28, 2020
ea87c45
new2
kaverhovsky Dec 28, 2020
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
70 changes: 70 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI_client

on:
push:
branches: [ client ]
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: install cppcheck
run: sudo apt-get install -y cppcheck

- name: install valgrind
run: sudo apt install valgrind

- name: install gcovr and lcov
run: |
sudo apt install gcovr
sudo apt install lcov

- name: run cppcheck
run: cd client/src && cppcheck *.cpp

- name: build
run: |
cd client
mkdir build
cd build
cmake ..
make

#- name: test socket
# run: |
# cd client/build
# valgrind --leak-check=full ./test/socket_tests

#- name: test response
# run: |
# cd client/build
# valgrind --leak-check=full ./test/response_tests

#- name: test request
# run: |
# cd client/build
# valgrind --leak-check=full ./test/request_tests

#- name: test client
# run: |
# cd client/build
# valgrind --leak-check=full ./test/client_tests

#- name: test application
# run: |
# cd client/build
# valgrind --leak-check=full ./test/application_tests
Comment on lines +36 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

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

обычно CI запускает один скрипт, а какие тесты запускать/не запускать задаются конфигом и/или уже на уровне этого скрипта


- name: coverage
run: |
cd client/build
make gcov
make lcov
- name: archive code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-report_linear
path: client/build/test/lcoverage
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build/
.vscode/

# Prerequisites
*.d

Expand Down
10 changes: 10 additions & 0 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.16.3)

project(link_share)



add_subdirectory(src)

enable_testing()
#add_subdirectory(test)
24 changes: 24 additions & 0 deletions client/include/client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <netinet/in.h>
#include <string>

#include "socket.hpp"
#include "socket.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

между первой и второй? :)




class Client {
public:
Client(const std::string& _host, int _port);
Copy link
Collaborator

Choose a reason for hiding this comment

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

уберите _

~Client() {}
void Connect();
void Close();
void writeToServer(std::string& req);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Request - это куда более сложная структура, чем string
да и у Ваших коллег уже есть определённые структуры - согласуйте их с ними
если это GUI клиент, то непонятно, почему называется writeToServer...
интерфейс обычно работает с логикой экранов/кнопок и пр. Если у некоторых согласно поведению есть необходимость сходить за данными - они обращаются в презентер. Если у него нет состояния - он уже идёт в модель. Там может быть несколько слоёв. Например, кэш, локальная БД и если нигде уже нет - идёт на сервер. При переходе с уровня на уровень всегда можно оставить (и обычно так и делается) коллбэк, который сетит на все промежуточные слои пришедшие данные и возвращают их клиенту через публичный интерфейс

std::string readFromServer(bool* endFlag);
std::vector<char> readFileBodyFromServer(bool* endFlag);
private:
const std::string& host;
int port;
Socket sock;
};

29 changes: 29 additions & 0 deletions client/include/inputUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include <string>
#include <vector>

template<typename T, typename... Args>
void writeData(T* key);

template<typename T, typename... Args>
void writeData(T* key, Args... args);

void fillObject(std::string* str);
void fillObject(std::vector<std::string>* str);


std::string createRoomInput();
std::string deleteRoomInput();
std::string addUsersInput();
std::string deleteUsersInput();
std::string addLinkInput();
std::string deleteLinkInput();
std::string makeSnapshotInput();
std::string logInInput();
std::string signUpInput();
std::string downloadSnapshotInput();
std::string getUserRoomInput();
std::string getUserLinksInput();
std::string getLinkSnapshotsInput();

#include "inputUtils.tpp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

обычно это как раз-таки hpp...

14 changes: 14 additions & 0 deletions client/include/inputUtils.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <iostream>
Copy link
Collaborator

Choose a reason for hiding this comment

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

зачем?


template<typename T, typename... Args>
void writeData(T* key) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

зачем?
можно было с помощью sizeof... проверить размер пакета в общем шаблоне

fillObject(key);
}

template<typename T, typename... Args>
void writeData(T* key, Args... args) {
fillObject(key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

writeData(key);

writeData(args...);
Comment on lines +5 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

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

зачем выносить в отдельный файл?

}
20 changes: 20 additions & 0 deletions client/include/link.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <memory>

class LinkImpl;

class Link {
public:
Link(std::string& name, std::string& url, std::string& uuid, std::string& description);
Link(Link& link);
~Link();
std::string GetLinkName();
std::string GetLinkInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

почему возвращается не LinkInfo, а string?

std::shared_ptr<LinkImpl> getLinkImpl();
std::string GetSnapshotUuid();
void SetLinkInfo();
void AddSnapshot(const std::string& uuid);
private:
std::shared_ptr<LinkImpl> linkImpl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

обычно для этого используется unique_ptr, т.к. он "легче"

};

47 changes: 47 additions & 0 deletions client/include/model.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <memory>
#include <vector>
#include "room.hpp"
#include "userinfo.hpp"


typedef struct recFile
{
std::string name;
std::vector<char> body;
} recFile;


template <class ResponseParser>
class ModelImpl;

template <class ResponseParser>
class Model {
Copy link
Collaborator

Choose a reason for hiding this comment

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

название особо ни о чём не говорит :/

public:
Model();
~Model();
std::string GetRoomInfoStr(const std::string& roomName);
std::string GetCurrentRoomInfoStr();
std::string GetLinkInfoStr(const std::string& linkName);
std::string GetLinkSnapshotInfoStr(const std::string& linkName);
void SetUserInfo(std::shared_ptr<UserInfo> info);
std::string GetUserInfoStr();
void AddUsers(std::vector<std::string> users);
void AddSnapshotUuid(const std::string& linkname, const std::string& uuid);
void RemoveUsers(std::vector<std::string> users);
void AddLink(std::shared_ptr<Link> newLink);
void RemoveLink(const std::string& linkName);
void AddRoom(std::shared_ptr<Room> newRoom);
void RemoveRoom(const std::string& roomName);
Comment on lines +35 to +36
Copy link
Collaborator

Choose a reason for hiding this comment

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

почему добавление по указателю, а удаление по имени?
откуда берётся это имя?

std::string FormRequest(std::string& action);
void HandleResponse(std::string& response);
void HandleFile(recFile& newFile);
bool IsHandlerRecievingFiles();
bool IsServRequired();
bool IsLogin();
private:
std::shared_ptr<ModelImpl<ResponseParser>> modelImpl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unique_ptr

};

#include "model.tpp"
Loading