Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 : #ifndef INCLUDED_SD_SOURCE_UI_REMOTECONTROL_BUFFEREDSTREAMSOCKET_HXX
10 : #define INCLUDED_SD_SOURCE_UI_REMOTECONTROL_BUFFEREDSTREAMSOCKET_HXX
11 :
12 : #include "IBluetoothSocket.hxx"
13 : #include <osl/socket.hxx>
14 : #include <vector>
15 :
16 : #define CHARSET RTL_TEXTENCODING_UTF8
17 : #define MAX_LINE_LENGTH 20000
18 :
19 : namespace sd
20 : {
21 :
22 : /**
23 : * [A wrapper for an osl StreamSocket to allow reading lines.]
24 : *
25 : * Currently wraps either an osl StreamSocket or a standard c socket,
26 : * allowing reading and writing for our purposes. Should eventually be
27 : * returned to being a StreamSocket wrapper if/when Bluetooth is
28 : * integrated into osl Sockets.
29 : */
30 0 : class BufferedStreamSocket :
31 : public IBluetoothSocket,
32 : private ::osl::StreamSocket
33 : {
34 : public:
35 : /**
36 : * Create a BufferedStreamSocket on top of an
37 : * osl::StreamSocket.
38 : */
39 : BufferedStreamSocket( const osl::StreamSocket &aSocket );
40 : /**
41 : * Create a BufferedStreamSocket on top of a POSIX or WinSock socket.
42 : */
43 : BufferedStreamSocket( int aSocket );
44 : BufferedStreamSocket( const BufferedStreamSocket &aSocket );
45 : /**
46 : * Blocks until a line is read.
47 : * Returns whatever the last call of recv returned, i.e. 0 or less
48 : * if there was a problem in communications.
49 : */
50 : virtual sal_Int32 readLine( OString& aLine ) SAL_OVERRIDE;
51 :
52 : virtual sal_Int32 write( const void* pBuffer, sal_uInt32 n ) SAL_OVERRIDE;
53 :
54 : virtual void close() SAL_OVERRIDE;
55 :
56 : void getPeerAddr(osl::SocketAddr&);
57 : private:
58 : sal_Int32 aRet, aRead;
59 : std::vector<char> aBuffer;
60 : int mSocket;
61 : bool usingCSocket;
62 : };
63 : }
64 :
65 : #endif // INCLUDED_SD_SOURCE_UI_REMOTECONTROL_BUFFEREDSTREAMSOCKET_HXX
66 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|