TestMobility.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // Copyright (C) 2013 Opensim Ltd.
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. //
  9. // This program 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 Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. //
  17. // author: Levente Meszaros (levy@omnetpp.org)
  18. //
  19. #include "TestMobility.h"
  20. #include "TestOperation.h"
  21. namespace inet {
  22. Define_Module(TestMobility);
  23. bool TestMobility::handleOperationStage(LifecycleOperation *operation, int stage, IDoneCallback *doneCallback)
  24. {
  25. Enter_Method_Silent();
  26. if (dynamic_cast<TestNodeStartOperation *>(operation)) {
  27. if (stage == 0) {
  28. scheduleAt(simTime() + 9, &startMoving);
  29. EV << getFullPath() << " starting to move" << endl;
  30. return true;
  31. }
  32. else if (stage == 1 || stage == 3)
  33. return true;
  34. else if (stage == 2) {
  35. this->doneCallback = doneCallback;
  36. return false;
  37. }
  38. else
  39. throw cRuntimeError("Unknown stage");
  40. }
  41. else if (dynamic_cast<TestNodeShutdownOperation *>(operation)) {
  42. if (stage == 0) {
  43. scheduleAt(simTime() + 9, &stopMoving);
  44. EV << getFullPath() << " stopping to move" << endl;
  45. return true;
  46. }
  47. else if (stage == 1 || stage == 3)
  48. return true;
  49. else if (stage == 2) {
  50. this->doneCallback = doneCallback;
  51. return false;
  52. }
  53. else
  54. throw cRuntimeError("Unknown stage");
  55. }
  56. else
  57. return true;
  58. }
  59. void TestMobility::initialize(int stage)
  60. {
  61. moving = false;
  62. }
  63. void TestMobility::handleMessage(cMessage * message)
  64. {
  65. if (message == &startMoving) {
  66. moving = true;
  67. EV << getFullPath() << " moving started" << endl;
  68. doneCallback->invoke();
  69. }
  70. else if (message == &stopMoving) {
  71. moving = false;
  72. EV << getFullPath() << " moving stopped" << endl;
  73. doneCallback->invoke();
  74. }
  75. }
  76. }