Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TEST_CORE_LIMITED_IO_HPP |
| 8 | #define NFD_TEST_CORE_LIMITED_IO_HPP |
| 9 | |
| 10 | #include "core/scheduler.hpp" |
| 11 | |
| 12 | namespace nfd { |
| 13 | |
| 14 | class LimitedIo |
| 15 | { |
| 16 | public: |
| 17 | LimitedIo(); |
| 18 | |
| 19 | enum StopReason |
| 20 | { |
| 21 | NO_WORK, |
| 22 | EXCEED_OPS, |
| 23 | EXCEED_TIME |
| 24 | }; |
| 25 | |
| 26 | StopReason |
| 27 | run(int nOpsLimit, time::Duration nTimeLimit); |
| 28 | |
| 29 | void |
| 30 | afterOp(); |
| 31 | |
| 32 | private: |
| 33 | void |
| 34 | afterTimeout(); |
| 35 | |
| 36 | public: |
| 37 | static const int UNLIMITED_OPS; |
| 38 | static const time::Duration UNLIMITED_TIME; |
| 39 | |
| 40 | private: |
| 41 | bool m_isRunning; |
| 42 | int m_nOpsRemaining; |
| 43 | EventId m_timeout; |
| 44 | StopReason m_reason; |
| 45 | }; |
| 46 | |
| 47 | } // namespace nfd |
| 48 | |
| 49 | #endif // NFD_TEST_CORE_LIMITED_IO_HPP |