~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/serviceframework/ipc/qremoteserviceregister_s60_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
 
5
** Contact: Nokia Corporation (qt-info@nokia.com)
 
6
**
 
7
** This file is part of the Qt Mobility Components.
 
8
**
 
9
** $QT_BEGIN_LICENSE:LGPL$
 
10
** Commercial Usage
 
11
** Licensees holding valid Qt Commercial licenses may use this file in 
 
12
** accordance with the Qt Commercial License Agreement provided with
 
13
** the Software or, alternatively, in accordance with the terms
 
14
** contained in a written agreement between you and Nokia.
 
15
**
 
16
** GNU Lesser General Public License Usage
 
17
** Alternatively, this file may be used under the terms of the GNU Lesser
 
18
** General Public License version 2.1 as published by the Free Software
 
19
** Foundation and appearing in the file LICENSE.LGPL included in the
 
20
** packaging of this file.  Please review the following information to
 
21
** ensure the GNU Lesser General Public License version 2.1 requirements
 
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
23
**
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** GNU General Public License Usage
 
29
** Alternatively, this file may be used under the terms of the GNU
 
30
** General Public License version 3.0 as published by the Free Software
 
31
** Foundation and appearing in the file LICENSE.GPL included in the
 
32
** packaging of this file.  Please review the following information to
 
33
** ensure the GNU General Public License version 3.0 requirements will be
 
34
** met: http://www.gnu.org/copyleft/gpl.html.
 
35
**
 
36
** If you are unsure which license is appropriate for your use, please
 
37
** contact the sales department at qt-sales@nokia.com.
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QREMOTESERVICEREGISTER_S60_P_H
 
43
#define QREMOTESERVICEREGISTER_S60_P_H
 
44
 
 
45
//#define QT_SFW_SYMBIAN_IPC_DEBUG
 
46
 
 
47
#include "qremoteserviceregister.h"
 
48
#include "qremoteserviceregister_p.h"
 
49
//#include "qremoteserviceclassregister.h"
 
50
#include "qservicepackage_p.h"
 
51
#include "qservice.h"
 
52
#include <e32base.h>
 
53
 
 
54
#ifdef QT_SFW_SYMBIAN_IPC_DEBUG
 
55
#include <QDebug>
 
56
#endif
 
57
 
 
58
#include <QQueue>
 
59
 
 
60
QTM_BEGIN_NAMESPACE
 
61
 
 
62
class ServiceMessageListener;
 
63
 
 
64
const TUint KServerMajorVersionNumber = 1;
 
65
const TUint KServerMinorVersionNumber = 0;
 
66
const TUint KServerBuildVersionNumber = 0;
 
67
 
 
68
enum TServiceProviderRequest
 
69
{
 
70
    EServicePackage = 1,
 
71
    EPackageRequest = 2,
 
72
    EPackageRequestCancel = 3,
 
73
    EPackageRequestComplete = 4
 
74
};
 
75
 
 
76
 
 
77
// Forward declarations
 
78
class ObjectEndPoint;
 
79
class CServiceProviderServerSession;
 
80
class CServiceProviderServer;
 
81
class SymbianServerEndPoint;
 
82
class SymbianClientEndPoint;
 
83
class QRemoteServiceRegisterSymbianPrivate;
 
84
 
 
85
// Type definitions
 
86
typedef TPckgBuf<TInt> TError; 
 
87
 
 
88
#ifdef QT_SFW_SYMBIAN_IPC_DEBUG
 
89
void printServicePackage(const QServicePackage& package);
 
90
#endif
 
91
 
 
92
 
 
93
// Internal class handling the actual communication with the service provider.
 
94
// Communication is based on standard Symbian client-server architecture.
 
95
class RServiceSession : public QObject, public RSessionBase
 
96
{
 
97
    Q_OBJECT
 
98
public: 
 
99
    RServiceSession(QString address);
 
100
    virtual ~RServiceSession();
 
101
    TInt Connect(); 
 
102
    void Close();
 
103
    TVersion Version() const;
 
104
    void SendServicePackage(const QServicePackage& aPackage);
 
105
    
 
106
 public:
 
107
    // 255 bytes seems to cover a lot of test cases in house
 
108
    // this size might need to be increased to avoid a lot
 
109
    // of context switches
 
110
    TBuf8<255> iMessageFromServer; 
 
111
    TPckgBuf<TInt> iSize; // TPckgBuf type can be used directly as IPC parameter
 
112
 
 
113
    void setListener(ServiceMessageListener* listener);
 
114
 
 
115
public slots:
 
116
     void ipcFailure(QService::UnrecoverableIPCError);
 
117
    
 
118
signals:
 
119
    void Disconnected();
 
120
    void errorUnrecoverableIPCFault(QService::UnrecoverableIPCError);
 
121
 
 
122
protected:
 
123
    void ListenForPackages(TRequestStatus& aStatus);
 
124
    void CancelListenForPackages();
 
125
    
 
126
private:
 
127
    TInt StartServer();
 
128
 
 
129
private: 
 
130
    TIpcArgs iArgs; // These two are used in actively listening to server
 
131
    TError iError;
 
132
    QString iServerAddress;
 
133
    ServiceMessageListener* iListener;
 
134
    
 
135
    friend class ServiceMessageListener;
 
136
};
 
137
 
 
138
// needed for creating server thread.
 
139
const TUint KDefaultHeapSize = 0x10000;
 
140
 
 
141
class CServiceProviderServer : public CPolicyServer
 
142
    {
 
143
    public:
 
144
        CServiceProviderServer(QRemoteServiceRegisterSymbianPrivate* aOwner);
 
145
        CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
 
146
 
 
147
    public:
 
148
 
 
149
        void IncreaseSessions();
 
150
        void DecreaseSessions();
 
151
 
 
152
        void setSecurityFilter(QRemoteServiceRegister::SecurityFilter filter);
 
153
 
 
154
    protected:
 
155
        virtual TCustomResult CustomSecurityCheckL(const RMessage2 &,TInt &,TSecurityInfo &);
 
156
 
 
157
    private:
 
158
 
 
159
        int iSessionCount;
 
160
        QRemoteServiceRegisterSymbianPrivate* iOwner;
 
161
        QRemoteServiceRegister::SecurityFilter iFilter;
 
162
    };
 
163
 
 
164
class CServiceProviderServerSession : public CSession2
 
165
    {
 
166
    public:
 
167
        static CServiceProviderServerSession* NewL(CServiceProviderServer& aServer);
 
168
        static CServiceProviderServerSession* NewLC(CServiceProviderServer& aServer);
 
169
        virtual ~CServiceProviderServerSession();
 
170
        void ServiceL(const RMessage2& aMessage);
 
171
        void SetParent(SymbianServerEndPoint* aOwner);
 
172
        void SendServicePackageL(const QServicePackage& aPackage);
 
173
 
 
174
        TInt HandleServicePackageL(const RMessage2& aMessage);
 
175
        void HandlePackageRequestL(const RMessage2& aMessage);
 
176
        void HandlePackageRequestCancelL(const RMessage2& aMessage);
 
177
 
 
178
    private:
 
179
        CServiceProviderServerSession(CServiceProviderServer& aServer);
 
180
        void ConstructL(); 
 
181
 
 
182
    private:
 
183
        CServiceProviderServer& iServer;
 
184
        SymbianServerEndPoint* iOwner;
 
185
        QByteArray* iByteArray;
 
186
        RMessage2 iMsg; // For replying pending service package requests
 
187
        QQueue<QServicePackage> iPendingPackageQueue;
 
188
        TBool iPendingPackageRequest;
 
189
        QByteArray iBlockData;
 
190
        int iTotalSize;
 
191
    };
 
192
 
 
193
 
 
194
class QRemoteServiceRegisterSymbianPrivate: public QRemoteServiceRegisterPrivate
 
195
{
 
196
    Q_OBJECT
 
197
 
 
198
public:
 
199
    QRemoteServiceRegisterSymbianPrivate(QObject* parent);
 
200
    void publishServices(const QString& ident );
 
201
    static QObject* proxyForService(const QRemoteServiceRegister::Entry& entry, const QString& location);
 
202
    void processIncoming(CServiceProviderServerSession* session);
 
203
 
 
204
    virtual QRemoteServiceRegister::SecurityFilter setSecurityFilter(QRemoteServiceRegister::SecurityFilter filter);
 
205
 
 
206
private:
 
207
    CServiceProviderServer *m_server;
 
208
};
 
209
 
 
210
// A helper class that actively listens for serviceprovider messages.
 
211
// Needed because Symbian server cannot send messages without active request
 
212
// from the client.
 
213
class ServiceMessageListener : public CActive
 
214
{
 
215
public:
 
216
    ServiceMessageListener(RServiceSession* aSession, SymbianClientEndPoint* aOwner);
 
217
    ~ServiceMessageListener();
 
218
 
 
219
protected:
 
220
    void StartListening();
 
221
    // from CActive baseclass
 
222
    void DoCancel();
 
223
    void RunL();
 
224
    
 
225
private:
 
226
    RServiceSession* iClientSession;
 
227
    SymbianClientEndPoint* iOwnerEndPoint;
 
228
    QByteArray iByteArray;
 
229
};
 
230
 
 
231
QTM_END_NAMESPACE
 
232
 
 
233
#endif // QREMOTESERVICEREGISTER_S60_P_H