Line data Source code
1 :
2 : /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
3 : * 2012-2014, Stefan.Eilemann@epfl.ch
4 : *
5 : * This file is part of Collage <https://github.com/Eyescale/Collage>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #ifndef CO_BUFFER_H
22 : #define CO_BUFFER_H
23 :
24 : #include <co/api.h>
25 : #include <co/types.h>
26 :
27 : #include <lunchbox/buffer.h> // base class
28 : #include <lunchbox/referenced.h> // base class
29 : #include <lunchbox/thread.h> // LB_TS_VAR macro
30 :
31 :
32 : namespace co
33 : {
34 : namespace detail { class Buffer; }
35 :
36 : /**
37 : * A receive buffer for a Connection.
38 : *
39 : * The buffer does not auto-delete, that is, a BufferPtr is not a smart
40 : * pointer. Instead, the BufferListener interface notifies when a buffer is
41 : * reusable. The BufferCache uses this to recycle unreferenced buffers, i.e.,
42 : * unused by any ICommand.
43 : */
44 : class Buffer : public lunchbox::Bufferb, public lunchbox::Referenced
45 : {
46 : public:
47 : /** Construct a new buffer. @version 1.0 */
48 : CO_API Buffer( BufferListener* listener = 0 );
49 :
50 : /** Destruct this buffer. @version 1.0 */
51 : CO_API virtual ~Buffer();
52 :
53 : /** @return true if the buffer is no longer in use. @version 1.0 */
54 : CO_API bool isFree() const;
55 :
56 : void setUsed(); //!< @internal
57 :
58 : private:
59 : detail::Buffer* const _impl;
60 1107 : LB_TS_VAR( _writeThread );
61 :
62 : void notifyFree() override;
63 : };
64 :
65 : std::ostream& operator << ( std::ostream&, const Buffer& );
66 : }
67 :
68 : #endif //CO_BUFFER_H
|