Line data Source code
1 :
2 : /* Copyright (c) 2007-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This file is part of Collage <https://github.com/Eyescale/Collage>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef CO_BUFFER_CONNECTION_H
21 : #define CO_BUFFER_CONNECTION_H
22 :
23 : #include <co/connection.h> // base class
24 : #include <lunchbox/types.h>
25 :
26 : namespace co
27 : {
28 : namespace detail
29 : {
30 : class BufferConnection;
31 : }
32 :
33 : /** A proxy connection buffering outgoing data into a memory buffer. */
34 : class BufferConnection : public Connection
35 : {
36 : public:
37 : /** Construct a new buffer connection. @version 1.0 */
38 : CO_API BufferConnection();
39 :
40 : /** Destruct this buffer connection. @version 1.0 */
41 : CO_API virtual ~BufferConnection();
42 :
43 : /**
44 : * Flush the accumulated data, sending it to the given connection.
45 : * @version 1.0
46 : */
47 : CO_API void sendBuffer(ConnectionPtr connection);
48 :
49 : /** @return the internal data buffer. @version 1.0 */
50 : CO_API const lunchbox::Bufferb& getBuffer() const;
51 :
52 : /** @return the internal data buffer. @version 1.0 */
53 : CO_API lunchbox::Bufferb& getBuffer();
54 :
55 : /** @return the size of the accumulated data. @version 1.0 */
56 : CO_API uint64_t getSize() const;
57 :
58 : protected:
59 : /** @internal */
60 : //@{
61 0 : void readNB(void*, const uint64_t) override { LBDONTCALL; }
62 0 : int64_t readSync(void*, const uint64_t, const bool) override
63 : {
64 0 : LBDONTCALL;
65 0 : return -1;
66 : }
67 : CO_API int64_t write(const void* buffer, const uint64_t bytes) override;
68 :
69 0 : Notifier getNotifier() const override
70 : {
71 0 : LBDONTCALL;
72 0 : return 0;
73 : }
74 : //@}
75 :
76 : private:
77 : detail::BufferConnection* const _impl;
78 : };
79 :
80 : typedef lunchbox::RefPtr<BufferConnection> BufferConnectionPtr;
81 : typedef lunchbox::RefPtr<const BufferConnection> ConstBufferConnectionPtr;
82 : }
83 :
84 : #endif // CO_BUFFER_CONNECTION_H
|