summaryrefslogtreecommitdiffstats
path: root/src/nfc/symbian/llcpsockettype1_symbian.h
blob: c9646a8a42814aadb51012310335059ef622a384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: http://www.qt-project.org/
**
** This file is part of the QtNfc module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef LLCPSOCKETTYPE1_SYMBIAN_H_
#define LLCPSOCKETTYPE1_SYMBIAN_H_

#include <e32base.h>
#include <nfcserver.h>                      // RNfcServer
#include <llcpconnlesslistener.h>           // MLlcpConnLessListener

/*
 *   FORWARD DECLARATIONS
 */
class COwnLlcpConnectionWrapper;
class CLlcpSenderType1;
class CLlcpReceiverType1;
class CLlcpTimer;
class CLlcpProvider;
class MLlcpConnLessTransporter;

#include <qconnectivityglobal.h>
#include "../qllcpsocket_symbian_p.h"

class MLlcpReadWriteCb
    {
public:

    /*
     * Empty Destructor.
     */
    virtual ~MLlcpReadWriteCb() {};

    /*
     * Called
     */
    virtual void ReceiveComplete(TInt aError) = 0;
    virtual void WriteComplete(TInt aError, TInt aSize) = 0;
    };

/*
 *  CLASS DECLARATION for CLlcpSocketType1 (ConnectLess Tran).
 */
class CLlcpSocketType1 : public CBase,
                         public MLlcpConnLessListener,
                         public MLlcpReadWriteCb
   {
public:
   /*
    * Creates a new CLlcpSocketType1 object.
    */
   static CLlcpSocketType1* NewL(QLlcpSocketPrivate&);

   /*
    * Creates a new CLlcpSocketType1 object.
    */
   static CLlcpSocketType1* NewLC(QLlcpSocketPrivate&);

   /*
    * Destructor
    */
   ~CLlcpSocketType1();

public:
   TInt StartWriteDatagram(const TDesC8& aData,TUint8 portNum);
   TInt ReadDatagram(TDes8& aData);
   TInt ReadDatagram(TDes8& aData, TUint8& aRemotePortNum);
   TBool Bind(TUint8 portNum);

   /*
       Returns true if at least one datagram is waiting to be read;
       otherwise returns false.
   */
   TBool HasPendingDatagrams() const;
   TInt64 PendingDatagramSize() const;
   TBool WaitForBytesWritten(TInt aMilliSeconds);

private:
   enum TWaitStatus
       {
       ENone,
       EWaitForBytesWritten
       };

private:
   TBool WaitForOperationReady(TWaitStatus aWaitStatus,TInt aMilliSeconds);
   void StopWaitNow(TWaitStatus aWaitStatus);

private:  // from  MLlcpReadWriteCb
     void ReceiveComplete(TInt aError);
     void WriteComplete(TInt aError, TInt aSize);

private: // From MLlcpConnLessListener
    void FrameReceived(MLlcpConnLessTransporter* aConnection);

private:
    // Constructor
    CLlcpSocketType1(QLlcpSocketPrivate&);

    // Second phase constructor
    void ConstructL();
    void Cleanup();

    TInt CreateConnection(TUint8 portNum);
    TInt StartTransportAndReceive(MLlcpConnLessTransporter* aConnection);

private:
   /*
    * Handle to NFC-server.
    * Own.
    */
   RNfcServer iNfcServer;

   /*
    * Pointer to CLlcpProvider object.
    * Own.
    */
   CLlcpProvider* iLlcp;   // Own

   /*
    * Pointer to MLlcpConnLessTransporter object.
    * Own.
    *
    * This is used to send data to local device.
    */
   COwnLlcpConnectionWrapper* iConnectionWrapper;  // Own

   CActiveSchedulerWait * iWait;  //Own
   CLlcpTimer * iTimer;  // Own
   TWaitStatus iWaitStatus;

   bool iPortBinded;
   TUint8 iLocalPort;
   TUint8 iRemotePort;

   QLlcpSocketPrivate& iCallback;
   };

/*
 *  CLASS DECLARATION for COwnLlcpConnectionWrapper.
 *
 */
class COwnLlcpConnectionWrapper : public CBase
    {
public:

   /*
    * Creates a new COwnLlcpConnection object.
    */
   static COwnLlcpConnectionWrapper* NewL(MLlcpConnLessTransporter* aTransporter
                                          , MLlcpReadWriteCb& aCallBack);

   /*
    * Creates a new COwnLlcpConnection object.
    */
   static COwnLlcpConnectionWrapper* NewLC(MLlcpConnLessTransporter* aTransporter
                                           , MLlcpReadWriteCb& aCallBack);

   /*
    * Destructor.
    */
   ~COwnLlcpConnectionWrapper();

public:
   /*
    * Transfer given data to remote device.
    */
   TInt TransferL(const TDesC8& aData);
   bool TransferQueued();
   void TransferCancel();
   TInt Receive();

   /*
    * Cancels COwnLlcpConnection::Receive() request.
    */
   void ReceiveCancel();

   TInt ReceiveDataFromBuf(TDes8& aData);
   bool HasPendingDatagrams() const;
   TInt64 PendingDatagramSize() const;
   bool HasQueuedWrittenDatagram() const;

private:

    // Constructor
    COwnLlcpConnectionWrapper(MLlcpConnLessTransporter* aConnection);
    // Second phase constructor
    void ConstructL(MLlcpReadWriteCb& aCallBack);

private:
    MLlcpConnLessTransporter* iConnection;
    CLlcpSenderType1*      iSenderAO;
    CLlcpReceiverType1*    iReceiverAO;
    RPointerArray<HBufC8> iSendBufArray;
    };


class CLlcpSenderType1 : public CActive
    {
public:
     static CLlcpSenderType1* NewL(MLlcpConnLessTransporter& aConnection, MLlcpReadWriteCb& aCallBack);
    ~CLlcpSenderType1();

public:
    /*
     * Transfer given data to remote device.
     */
    TInt Transfer(const TDesC8& aData);

    /*
     * Cancels COwnLlcpConnection::Transfer() request.
     */
    void TransferCancel();

public: // From CActive
    void RunL();
    void DoCancel();

private:
    CLlcpSenderType1(MLlcpConnLessTransporter& aConnection, MLlcpReadWriteCb& aCallBack);
private:
    /*
         Buffered data for transmitting data.
     */
    MLlcpConnLessTransporter& iConnection;
    MLlcpReadWriteCb& iSendObserver;
    RBuf8 iTransmitBuf;
    // Symbian have limitaion for sending buffer in one send,
    // The variable used to record how many buffer have been sent so far
    TInt   iCurrentSendBufPos;
    TPtrC8 iCurrentSendBufPtr;
    RBuf8  iTempSendBuf; // Temp workround to avoid NFC server's bug, if use ptr, it will crash
    };

class CLlcpReceiverType1 : public CActive
    {
public:
    static CLlcpReceiverType1* NewL(MLlcpConnLessTransporter& aConnection, MLlcpReadWriteCb& aCallBack);
    ~CLlcpReceiverType1();

public:
    /*
     * Starts receive data from ConnLess.
     */
    TInt Receive();

    /*
     * Cancels COwnLlcpConnection::Receive() request.
     */
    void ReceiveCancel();
    TInt ReceiveDataFromBuf(TDes8& aData);

    bool HasPendingDatagrams() const;
    TInt64 PendingDatagramSize() const;

public: // From CActive
    void RunL();
    void DoCancel();

private:
     CLlcpReceiverType1(MLlcpConnLessTransporter& aConnection, MLlcpReadWriteCb& aCallBack);

private:
    RBuf8 iReceiveBuf;
    MLlcpConnLessTransporter& iConnection;
    MLlcpReadWriteCb&         iReceiveObserver;
    };
#endif /* LLCPSOCKETTYPE1_SYMBIAN_H_ */