graph_manager.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * @file tests/dtss/graph_manager.hpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef TESTS_DTSS_GRAPH_MANAGER_HPP
  26. #define TESTS_DTSS_GRAPH_MANAGER_HPP 1
  27. #include <paradevs/kernel/dtss/Coordinator.hpp>
  28. #include <paradevs/kernel/dtss/GraphManager.hpp>
  29. #include <paradevs/kernel/dtss/Simulator.hpp>
  30. #include <tests/dtss/models.hpp>
  31. namespace paradevs { namespace tests { namespace dtss {
  32. template < class SchedulerHandle >
  33. struct Policy
  34. {
  35. const common::Bag < common::DoubleTime, SchedulerHandle >& bag() const
  36. { return _bag; }
  37. virtual void operator()(
  38. common::DoubleTime::type /* t */,
  39. const common::ExternalEvent < common::DoubleTime,
  40. SchedulerHandle >& event,
  41. common::DoubleTime::type /* tl */,
  42. common::DoubleTime::type /* tn */)
  43. {
  44. _bag.clear();
  45. _bag.push_back(event);
  46. }
  47. private:
  48. common::Bag < common::DoubleTime, SchedulerHandle > _bag;
  49. };
  50. template < class SchedulerHandle >
  51. class OnlyOneGraphManager :
  52. public paradevs::dtss::GraphManager < common::DoubleTime,
  53. SchedulerHandle,
  54. paradevs::common::NoParameters >
  55. {
  56. public:
  57. OnlyOneGraphManager(common::Coordinator < common::DoubleTime,
  58. SchedulerHandle >* coordinator,
  59. const paradevs::common::NoParameters& parameters) :
  60. paradevs::dtss::GraphManager < common::DoubleTime, SchedulerHandle,
  61. paradevs::common::NoParameters >(
  62. coordinator, parameters),
  63. a("a", 1, common::NoParameters())
  64. {
  65. OnlyOneGraphManager < SchedulerHandle >::add_child(&a);
  66. }
  67. virtual ~OnlyOneGraphManager()
  68. { }
  69. private:
  70. paradevs::dtss::Simulator < common::DoubleTime, A < SchedulerHandle >,
  71. SchedulerHandle > a;
  72. };
  73. template < class SchedulerHandle >
  74. class TwoGraphManager :
  75. public paradevs::dtss::GraphManager < common::DoubleTime,
  76. SchedulerHandle,
  77. paradevs::common::NoParameters >
  78. {
  79. public:
  80. TwoGraphManager(common::Coordinator < common::DoubleTime,
  81. SchedulerHandle >* coordinator,
  82. const paradevs::common::NoParameters& parameters) :
  83. paradevs::dtss::GraphManager < common::DoubleTime, SchedulerHandle,
  84. paradevs::common::NoParameters >(
  85. coordinator, parameters),
  86. a("a", 1, common::NoParameters()), b("b", 1, common::NoParameters())
  87. {
  88. TwoGraphManager < SchedulerHandle >::add_child(&a);
  89. TwoGraphManager < SchedulerHandle >::add_child(&b);
  90. a.add_out_port("out");
  91. b.add_in_port("in");
  92. TwoGraphManager < SchedulerHandle >::add_link(&a, "out", &b, "in");
  93. }
  94. virtual ~TwoGraphManager()
  95. { }
  96. private:
  97. paradevs::dtss::Simulator < common::DoubleTime, A < SchedulerHandle >,
  98. SchedulerHandle > a;
  99. paradevs::dtss::Simulator < common::DoubleTime, B < SchedulerHandle >,
  100. SchedulerHandle > b;
  101. };
  102. } } } // namespace paradevs tests dtss
  103. #endif