|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Declares main application class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __SOCKETSREADER_H__ |
|
20 #define __SOCKETSREADER_H__ |
|
21 |
|
22 #include <es_sock.h> |
|
23 |
|
24 class MSocketObserver; |
|
25 |
|
26 /*! |
|
27 This class handles reading data from a socket. |
|
28 Any data read is simply passed back to the observer. |
|
29 */ |
|
30 class CSocketReader : public CActive |
|
31 { |
|
32 public: |
|
33 /*! |
|
34 Create a CSocketReader object |
|
35 @param aSocketID ID given to the socket. Used when reporting back. |
|
36 @param aObserver an observer for status reporting |
|
37 @param aInitialBufSize the initial size to use for the read buffer |
|
38 @result A pointer to the created instance of CSocketReader |
|
39 */ |
|
40 static CSocketReader* NewL(TUint aSocketID, MSocketObserver& aObserver, |
|
41 TInt aInitialBufSize); |
|
42 |
|
43 /*! |
|
44 Create a CSocketReader object |
|
45 @param aSocketID ID given to the socket. Used when reporting back. |
|
46 @param aObserver an observer for status reporting |
|
47 @param aInitialBufSize the initial size to use for the read buffer |
|
48 @result A pointer to the created instance of CSocketReader |
|
49 */ |
|
50 static CSocketReader* NewLC(TUint aSocketID, MSocketObserver& aObserver, |
|
51 TInt aInitialBufSize); |
|
52 |
|
53 /*! |
|
54 Destroy the object and release all memory objects |
|
55 */ |
|
56 ~CSocketReader(); |
|
57 |
|
58 /*! |
|
59 Initiate reading from a socket |
|
60 @param aSocket socket to read from |
|
61 @param aMTU the bluetooth maximum transmission unit for the given socket. |
|
62 */ |
|
63 void StartReadingL(RSocket* aSocket, TInt aMTU); |
|
64 |
|
65 protected: |
|
66 // from CActive |
|
67 /*! |
|
68 Cancel any outstanding operation |
|
69 */ |
|
70 void DoCancel(); |
|
71 |
|
72 /*! |
|
73 Called when operation complete |
|
74 */ |
|
75 void RunL(); |
|
76 |
|
77 private: |
|
78 /*! |
|
79 Perform the first phase of two phase construction |
|
80 @param aSocketID ID given to the socket. Used when reporting back. |
|
81 @param aObserver an observer for status reporting |
|
82 */ |
|
83 CSocketReader(TUint aSocketID, MSocketObserver& aObserver); |
|
84 |
|
85 /*! |
|
86 Perform the second phase construction of a CSocketReader |
|
87 @param aInitialBufSize the initial size to use for the read buffer |
|
88 */ |
|
89 void ConstructL(TInt aInitialBufSize); |
|
90 |
|
91 /*! |
|
92 Initiate a read from the socket. |
|
93 */ |
|
94 void IssueRead(); |
|
95 |
|
96 private: |
|
97 // Member variables |
|
98 /*! The ID of the socket being read from */ |
|
99 TUint iSocketID; |
|
100 |
|
101 /*! An observer for reporting data to */ |
|
102 MSocketObserver& iObserver; |
|
103 |
|
104 /*! Socket to read data from */ |
|
105 RSocket* iSocket; |
|
106 |
|
107 /*! Buffer for receiving data */ |
|
108 HBufC8* iBuffer; |
|
109 |
|
110 /*! Pointer to the buffer to be used when reading */ |
|
111 TPtr8 iBufferPtr; |
|
112 }; |
|
113 |
|
114 #endif // __SOCKETSREADER_H__ |