Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Commit

Permalink
client shared_ptr change
Browse files Browse the repository at this point in the history
  • Loading branch information
HubertLegec committed Jan 6, 2016
1 parent a97f2bc commit 632045c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 41 deletions.
3 changes: 3 additions & 0 deletions client/controller/sources/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Controller::Controller(Model *model) : model(model) {

Controller::~Controller() {
delete networkController;
for (auto strategy : strategyMap) {
delete strategy.second;
}
}

void Controller::setView(View *view) {
Expand Down
44 changes: 22 additions & 22 deletions client/strategy/sources/CategoryAccessEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,46 @@ void CategoryAccessEventStrategy::serveEvent(BasicEvent *event) {
void CategoryAccessEventStrategy::createCategory(const std::string &name) const {
LOG(INFO) << "CategoryAccessEventStrategy::createCategory:\n" << "categoryName: " << name;

shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::CREATE_CATEGORY,
name);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::CREATE_CATEGORY,
name));
controller->sendMessage(msg, getServerIP(), getServerPort());
}

void CategoryAccessEventStrategy::deleteCategory(long id) const {
LOG(INFO) << "CategoryAccessEventStrategy::deleteCategory:\n" << "categoryID: " << id;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::DESTROY_CATEGORY,
id);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::DESTROY_CATEGORY,
id));
controller->sendMessage(msg, getServerIP(), getServerPort());
}

void CategoryAccessEventStrategy::signUpCategory(long id) const {
LOG(INFO) << "CategoryAccessEventStrategy::signUpCategory:\n" << "categoryID: " << id;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::JOIN_CATEGORY, id);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::JOIN_CATEGORY, id));
controller->sendMessage(msg, getServerIP(), getServerPort());
}

void CategoryAccessEventStrategy::signOutCategory(long id) const {
LOG(INFO) << "CategoryAccessEventStrategy::signOutCategory:\n" << "categoryID: " << id;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::LEFT_CATEGORY, id);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::LEFT_CATEGORY, id));
controller->sendMessage(msg, getServerIP(), getServerPort());
}

void CategoryAccessEventStrategy::joinCategory(long id) const {
LOG(INFO) << "CategoryAccessEventStrategy::joinCategory:\n" << "categoryID: " << id;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::ACTIVATE_CATEGORY,
id);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::ACTIVATE_CATEGORY,
id));
controller->sendMessage(msg, getServerIP(), getServerPort());
}

void CategoryAccessEventStrategy::leaveCategory(long id) const {
LOG(INFO) << "CategoryAccessEventStrategy::leaveCategory:\n" << "categoryID: " << id;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::DEACTIVATE_CATEGORY,
id);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::DEACTIVATE_CATEGORY,
id));
controller->sendMessage(msg, getServerIP(), getServerPort());
}
7 changes: 3 additions & 4 deletions client/strategy/sources/ChooseMenuOptionEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void ChooseMenuOptionEventStrategy::showCategoryList() const {
if (!getModel()->isRegistered()) {
createAccount();
} else {
shared_ptr<GetMessage> toSend = make_shared<GetMessage>(getModel()->getUserId(), GetMessageType::CAT_LIST);
auto toSend = shared_ptr<GetMessage>(new GetMessage(getModel()->getUserId(), GetMessageType::CAT_LIST));
controller->setState(Controller::CATEGORY_LIST);
controller->createTimeoutThread();
controller->sendMessage(toSend, getServerIP(), getServerPort());
Expand Down Expand Up @@ -129,9 +129,8 @@ void ChooseMenuOptionEventStrategy::signUpCategory() const {
if (getModel()->isRegistered()) {
controller->setState(Controller::SIGN_UP);
controller->createTimeoutThread();
shared_ptr<GetMessage> ptr = make_shared<GetMessage>(getModel()->getUserId(), GetMessageType::CAT_LIST);
controller->getSendQueue()->push(
shared_ptr<MessageWrapper>(new MessageWrapper(ptr, getServerIP(), getServerPort())));
auto ptr = shared_ptr<GetMessage>(new GetMessage(getModel()->getUserId(), GetMessageType::CAT_LIST));
controller->sendMessage(ptr, getServerIP(), getServerPort());
} else {
createAccount();
}
Expand Down
4 changes: 3 additions & 1 deletion client/strategy/sources/ConfirmMessageEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "../headers/ConfirmMessageEventStrategy.h"
#include "../../../clientEvents/headers/ConfirmMessageEvent.h"

using namespace std;

ConfirmMessageEventStrategy::ConfirmMessageEventStrategy() : BasicEventStrategy() { }

ConfirmMessageEventStrategy::ConfirmMessageEventStrategy(Controller* controller) : BasicEventStrategy(controller) { }
Expand All @@ -17,6 +19,6 @@ void ConfirmMessageEventStrategy::serveEvent(BasicEvent *event) {

m.addConfirmation(getModel()->getUserName());
ConnectionInfo neighbour = getModel()->getLeftNeighbour(m.getCategoryId());
auto toSend = std::shared_ptr<RingMessage>(new RingMessage(m));
auto toSend = shared_ptr<RingMessage>(new RingMessage(m));
controller->sendMessage(toSend, neighbour.getIP(), neighbour.getPort());
}
8 changes: 4 additions & 4 deletions client/strategy/sources/NewMessageEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void NewMessageEventStrategy::serveEvent(BasicEvent *event) {
LOG(INFO) << "NewMessageEventStrategy::serveEvent:\n" << event->toString();

NewMessageEvent *newMessageEvent = dynamic_cast<NewMessageEvent *>(event);
shared_ptr<RingMessage> ringMsg = make_shared<RingMessage>(getModel()->getUserId(),
newMessageEvent->getCategoryID(),
newMessageEvent->getMessage());
auto ringMsg = shared_ptr<RingMessage>(new RingMessage(getModel()->getUserId(),
newMessageEvent->getCategoryID(),
newMessageEvent->getMessage()));
ConnectionInfo neighbour = getModel()->getLeftNeighbour(newMessageEvent->getCategoryID());
shared_ptr<MessageWrapper> msg = shared_ptr<MessageWrapper>(
auto msg = shared_ptr<MessageWrapper>(
new MessageWrapper(ringMsg, neighbour.getIP(), neighbour.getPort()));
sendMessage(msg);
showMainMenu();
Expand Down
16 changes: 8 additions & 8 deletions client/strategy/sources/PendingUserEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ void PendingUserEventStrategy::serveEvent(BasicEvent *event) {

void PendingUserEventStrategy::acceptUser(long categoryID, long userID) {
LOG(INFO) << "PendingUserEventStrategy::acceptUser:\ncategoryID:" << categoryID << " ; userID:" << userID;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::NEW_MEMBER_CONFIRM,
categoryID, userID);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::NEW_MEMBER_CONFIRM,
categoryID, userID));
controller->sendMessage(msg, getServerIP(), getServerPort());
getModel()->removePendingUser(categoryID, userID);
}

void PendingUserEventStrategy::rejectUser(long categoryID, long userID) {
LOG(INFO) << "PendingUserEventStrategy::rejectUser:\ncategoryID:" << categoryID << " ; userID:" << userID;
shared_ptr<CategoryManagementMessage> msg = make_shared<CategoryManagementMessage>(getModel()->getUserId(),
MessageType::NEW_MEMBER_REJECT,
categoryID, userID);
sendMessage(shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
auto msg = shared_ptr<CategoryManagementMessage>(new CategoryManagementMessage(getModel()->getUserId(),
MessageType::NEW_MEMBER_REJECT,
categoryID, userID));
controller->sendMessage(msg, getServerIP(), getServerPort());
getModel()->removePendingUser(categoryID, userID);
}
4 changes: 2 additions & 2 deletions client/strategy/sources/UserAccountEventStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void UserAccountEventStrategy::serveEvent(BasicEvent *event) {

void UserAccountEventStrategy::createAccount(const std::string &name) const {
LOG(INFO) << "CUserAccountEventStrategy::createAccount:\n" << "userName: " << name;
shared_ptr<UserManagementMessage> msg = shared_ptr<UserManagementMessage>(
auto msg = shared_ptr<UserManagementMessage>(
new UserManagementMessage(MessageType::CREATE_USER_ACCOUNT, getMyIP(), getMyPort(), name));
controller->getSendQueue()->push(
shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
Expand All @@ -44,7 +44,7 @@ void UserAccountEventStrategy::createAccount(const std::string &name) const {
void UserAccountEventStrategy::deleteAccount() const {
LOG(INFO) << "CUserAccountEventStrategy::DeleteAccount";
long id = getModel()->getUserId();
shared_ptr<UserManagementMessage> msg = shared_ptr<UserManagementMessage>(
auto msg = shared_ptr<UserManagementMessage>(
new UserManagementMessage(id, MessageType::DELETE_USER_ACCOUNT));
controller->getSendQueue()->push(
shared_ptr<MessageWrapper>(new MessageWrapper(msg, getServerIP(), getServerPort())));
Expand Down

0 comments on commit 632045c

Please sign in to comment.