Skip to content

Commit

Permalink
Merge pull request #42 from SoPra-Team-17/FixCallbackPointer
Browse files Browse the repository at this point in the history
callback shared pointer to raw pointer
  • Loading branch information
csacro authored May 29, 2020
2 parents b619691 + 37a2ccf commit 0d983b1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ set(SOURCE
add_library(${PROJECT_NAME} SHARED ${SOURCE})
target_compile_options(${PROJECT_NAME} PRIVATE ${COMMON_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror -mtune=native -march=native)
target_link_libraries(${PROJECT_NAME}
PUBLIC SopraCommon
PRIVATE SopraNetwork
SopraCommon
SopraNetwork
$<$<CONFIG:Debug>:--coverage>)
target_include_directories(${PROJECT_NAME}
PUBLIC
Expand Down
4 changes: 2 additions & 2 deletions src/LibClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ namespace libclient {
return model->clientState.debugMessage;
}

LibClient::LibClient(std::shared_ptr<Callback> callback) : model(std::make_shared<Model>()),
network(std::move(callback), model) {}
LibClient::LibClient(Callback* callback) : model(std::make_shared<Model>()),
network(callback, model) {}

bool LibClient::setName(const std::string &name) {
if(network.getState() != Network::NetworkState::NOT_CONNECTED && network.getState() != Network::NetworkState::CONNECTED){
Expand Down
2 changes: 1 addition & 1 deletion src/LibClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace libclient {
private:
std::shared_ptr<libclient::Model> model;
public:
explicit LibClient(std::shared_ptr<Callback> callback);
explicit LibClient(Callback* callback);

libclient::Network network;

Expand Down
3 changes: 1 addition & 2 deletions src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
#include <util/UUID.hpp>

namespace libclient {
Network::Network(std::shared_ptr<Callback> c, std::shared_ptr<Model> m) : callback(std::move(c)),
model(std::move(m)) {}
Network::Network(libclient::Callback *c, std::shared_ptr<Model> m) : callback(c), model(std::move(m)) {}

void Network::onReceiveMessage(const std::string &message) {
auto json = nlohmann::json::parse(message);
Expand Down
4 changes: 2 additions & 2 deletions src/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace libclient {
PAUSE,
GAME_OVER
};
Network(std::shared_ptr<libclient::Callback> c, std::shared_ptr<libclient::Model> m);
Network(libclient::Callback *c, std::shared_ptr<libclient::Model> m);

[[nodiscard]] NetworkState getState() const;

Expand Down Expand Up @@ -65,7 +65,7 @@ namespace libclient {
bool sendReconnect();

private:
std::shared_ptr<Callback> callback;
Callback *callback;
std::shared_ptr<Model> model;
std::optional<websocket::network::WebSocketClient> webSocketClient;
NetworkState state = NetworkState::NOT_CONNECTED;
Expand Down

0 comments on commit 0d983b1

Please sign in to comment.