PIRController.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "PIRController.hpp"
  18. #include "PIRClient.hpp"
  19. /**
  20. * Class constructor.
  21. * Param :
  22. * - pirClient_ptr model_ptr_ : PIRClient shared_ptr.
  23. **/
  24. PIRController::PIRController(PIRClientSimple& model_ptr_):
  25. model_ptr(model_ptr_),
  26. view_cli(this),
  27. logger(this)
  28. {
  29. addListenersToModel();
  30. }
  31. /**
  32. * Add listners (attribute of PIRController) to the model (model_ptr).
  33. **/
  34. void PIRController::addListenersToModel()
  35. {
  36. connectionMessage.push_back(model_ptr.addMessageListener(boost::bind(&PIRView::messageUpdate, &view_cli, _1)));
  37. connectionMessage.push_back(model_ptr.addMessageListener(boost::bind(&PIRView::messageUpdate, &logger, _1)));
  38. connectionMenu.push_back(model_ptr.addMenuListener(boost::bind(&PIRView::catalogUpdate, &view_cli, _1)));
  39. connectionMenu.push_back(model_ptr.addMenuListener(boost::bind(&PIRView::catalogUpdate, &logger, _1)));
  40. connectionWrite.push_back(model_ptr.addWriteListener(boost::bind(&PIRView::writeUpdate, &view_cli, _1)));
  41. }
  42. /**
  43. * Notify model of a client choice.
  44. * Param :
  45. * - int c : int input.
  46. **/
  47. void PIRController::notifyClientChoice(int c)
  48. {
  49. model_ptr.setChosenElement(c);
  50. }
  51. PIRController::~PIRController()
  52. {
  53. for (auto &messageView : connectionMessage)
  54. messageView.disconnect();
  55. for (auto &menuView : connectionMenu)
  56. menuView.disconnect();
  57. for (auto &writeView : connectionWrite)
  58. writeView.disconnect();
  59. }