summaryrefslogtreecommitdiffstats
path: root/src/connectivity/nfc/symbian/nearfieldutility_symbian.cpp
blob: f643d63f54c8e07ca7ed27a39499b7a637dc2c8f (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
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights.  These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <ndefmessage.h>
#include <QtCore/QList>
#include <e32base.h>
#include "../qndefmessage.h"
#include "nearfieldutility_symbian.h"
#include "debug.h"

QTM_BEGIN_NAMESPACE


CNdefMessage* QNFCNdefUtility::QNdefMsg2CNdefMsgL( const QNdefMessage& msg )
    {
        QByteArray payload = msg.toByteArray();
        CNdefMessage* cmsg = CNdefMessage::NewL();
        TPtrC8 rawData(reinterpret_cast<const TUint8*>(payload.constData()), payload.size());
        cmsg->ImportRawDataL(rawData, 0);
        return cmsg;
    }


QNdefMessage QNFCNdefUtility::CNdefMsg2QNdefMsgL( const CNdefMessage& msg )
    {
        BEGIN
        QNdefMessage result;
        LOG("CNdefMessage size is "<<msg.SizeL());
        HBufC8* newBuf = HBufC8::NewL(msg.SizeL());
        RBuf8 buf;
        buf.Assign(newBuf);
        buf.CleanupClosePushL();
        LOG("export msg to raw data");
        msg.ExportRawDataL(buf,0);
        LOG("import raw data to msg");
        QByteArray qtArray;
        qtArray.append(reinterpret_cast<const char*>(newBuf->Ptr()),newBuf->Size());
        result = QNdefMessage::fromByteArray(qtArray);
        CleanupStack::PopAndDestroy(&buf);
        END
        return result;
    }

TPtrC8 QNFCNdefUtility::QByteArray2TPtrC8(const QByteArray& qbytearray)
    {
    TPtrC8 ptr(reinterpret_cast<const TUint8*>(qbytearray.constData()), qbytearray.size());
    return ptr;
    }

QByteArray QNFCNdefUtility::TDesC2QByteArray( const TDesC8& des)
    {
        QByteArray result;
        for(int i = 0; i < des.Length(); ++i)
        {
            result.append(des[i]);
        }
        return result;
    }


HBufC8* QNFCNdefUtility::QString2HBufC8L(const QString& qstring)
    {
    TPtrC wide(static_cast<const TUint16*>(qstring.utf16()),qstring.length());
    HBufC8* newBuf = HBufC8::NewL(wide.Length());
    TPtr8 des = newBuf->Des();
    des.Copy(wide);
    return newBuf;
    }

QString QNFCNdefUtility::TDesC82QStringL(const TDesC8& aDescriptor)
    {
    HBufC* newBuf = NULL;
    QT_TRAP_THROWING(newBuf = HBufC::NewL(aDescriptor.Length()));
    TPtr des = newBuf->Des();
    des.Copy(aDescriptor);
    QString ret = QString::fromUtf16(newBuf->Ptr(),newBuf->Length());
    delete newBuf;
    return ret;
    }

QTM_END_NAMESPACE

// timer implementation
CLlcpTimer* CLlcpTimer::NewL(CActiveSchedulerWait & aWait)
    {
    BEGIN
    CLlcpTimer* self = new (ELeave) CLlcpTimer(aWait);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    END
    return self;
    }

/**
Destructor.
*/
CLlcpTimer::~CLlcpTimer()
    {
    BEGIN
    Cancel();
    END
    }

/**
Starts the shutdown timer.
*/
void CLlcpTimer::Start(TInt aMSecs)
    {
    BEGIN
    const TUint KDelay = (1000 * aMSecs);
    After(KDelay);
    END
    }

void CLlcpTimer::RunL()
    {
    BEGIN
    if (iWait.IsStarted())
        {
        iWait.AsyncStop();
        }
    END
    }

/**
Constructor
*/
CLlcpTimer::CLlcpTimer(CActiveSchedulerWait & aWait) :
    CTimer(EPriorityNormal),
    iWait(aWait)
    {
    }

/**
Second phase constructor.
*/
void CLlcpTimer::ConstructL()
    {
    BEGIN
    CTimer::ConstructL();
    CActiveScheduler::Add(this);
    END
    }