PageRenderTime 38ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/streams/scheduler.h

http://github.com/mozy/mordor
C Header | 85 lines | 76 code | 8 blank | 1 comment | 1 complexity | 90df311b1097aff62420ddf43651d4f2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_SCHEDULER_STREAM_H__
  2. #define __MORDOR_SCHEDULER_STREAM_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include "filter.h"
  5. #include "mordor/scheduler.h"
  6. namespace Mordor {
  7. class SchedulerStream : public FilterStream
  8. {
  9. public:
  10. SchedulerStream(Stream::ptr parent, bool own = true)
  11. : FilterStream(parent, own),
  12. m_closeScheduler(NULL),
  13. m_ioScheduler(NULL),
  14. m_seekScheduler(NULL),
  15. m_sizeScheduler(NULL),
  16. m_truncateScheduler(NULL),
  17. m_flushScheduler(NULL)
  18. {}
  19. Scheduler *closeScheduler() { return m_closeScheduler; }
  20. void closeScheduler(Scheduler *scheduler) { m_closeScheduler = scheduler; }
  21. Scheduler *ioScheduler() { return m_ioScheduler; }
  22. void ioScheduler(Scheduler *scheduler) { m_ioScheduler = scheduler; }
  23. Scheduler *seekScheduler() { return m_seekScheduler; }
  24. void seekScheduler(Scheduler *scheduler) { m_seekScheduler = scheduler; }
  25. Scheduler *sizeScheduler() { return m_sizeScheduler; }
  26. void sizeScheduler(Scheduler *scheduler) { m_sizeScheduler = scheduler; }
  27. Scheduler *truncateScheduler() { return m_truncateScheduler; }
  28. void truncateScheduler(Scheduler *scheduler) { m_truncateScheduler = scheduler; }
  29. Scheduler *flushScheduler() { return m_flushScheduler; }
  30. void flushScheduler(Scheduler *scheduler) { m_flushScheduler = scheduler; }
  31. void close(CloseType type = BOTH)
  32. {
  33. if (ownsParent()) {
  34. SchedulerSwitcher switcher(m_closeScheduler);
  35. parent()->close(type);
  36. }
  37. }
  38. size_t read(Buffer &b, size_t len)
  39. {
  40. SchedulerSwitcher switcher(m_ioScheduler);
  41. return parent()->read(b, len);
  42. }
  43. size_t write(const Buffer &b, size_t len)
  44. {
  45. SchedulerSwitcher switcher(m_ioScheduler);
  46. return parent()->write(b, len);
  47. }
  48. long long seek(long long offset, Anchor anchor = BEGIN)
  49. {
  50. SchedulerSwitcher switcher(m_seekScheduler);
  51. return parent()->seek(offset, anchor);
  52. }
  53. long long size()
  54. {
  55. SchedulerSwitcher switcher(m_sizeScheduler);
  56. return parent()->size();
  57. }
  58. void truncate(long long size)
  59. {
  60. SchedulerSwitcher switcher(m_truncateScheduler);
  61. parent()->truncate(size);
  62. }
  63. void flush(bool flushParent = true)
  64. {
  65. SchedulerSwitcher switcher(m_flushScheduler);
  66. parent()->flush(flushParent);
  67. }
  68. private:
  69. Scheduler *m_closeScheduler;
  70. Scheduler *m_ioScheduler;
  71. Scheduler *m_seekScheduler;
  72. Scheduler *m_sizeScheduler;
  73. Scheduler *m_truncateScheduler;
  74. Scheduler *m_flushScheduler;
  75. };
  76. }
  77. #endif