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