src/publishsubscribe/pathmapper_proxy_symbian.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "pathmapper_proxy_symbian_p.h"
       
    42 #include "clientservercommon.h"
       
    43 
       
    44 #include <QDir>
       
    45 #include <QDebug>
       
    46 
       
    47 QTM_BEGIN_NAMESPACE
       
    48 
       
    49 PathMapper::PathMapper()
       
    50 {
       
    51     m_pathMapperServerSession.Connect();
       
    52 }
       
    53 
       
    54 PathMapper::~PathMapper()
       
    55 {
       
    56     m_pathMapperServerSession.Close();
       
    57 }
       
    58 
       
    59 bool PathMapper::getChildren(const QString &path, QSet<QString> &children) const
       
    60 {
       
    61     return m_pathMapperServerSession.getChildren(path, children);
       
    62 }
       
    63 
       
    64 QStringList PathMapper::childPaths(const QString &path) const
       
    65 {
       
    66     return m_pathMapperServerSession.childPaths(path);
       
    67 }
       
    68 
       
    69 bool PathMapper::resolvePath(const QString &path, Target &target, quint32 &category, quint32 &key) const
       
    70 {
       
    71     return m_pathMapperServerSession.resolvePath(path, target, category, key);
       
    72 }
       
    73 
       
    74 PathMapper::RPathMapperServerSession::RPathMapperServerSession()
       
    75 {
       
    76 }
       
    77 
       
    78 TInt PathMapper::RPathMapperServerSession::Connect()
       
    79 {
       
    80     TInt err = StartServer();
       
    81     if (err == KErrNone)    {
       
    82         err = CreateSession(KPSPathMapperServerName, Version(), 8, EIpcSession_Sharable);
       
    83     }
       
    84     return err;
       
    85 }
       
    86 
       
    87 
       
    88 TVersion PathMapper::RPathMapperServerSession::Version() const
       
    89 {
       
    90     return TVersion(KServerMajorVersionNumber, KServerMinorVersionNumber, KServerBuildVersionNumber);
       
    91 }
       
    92 
       
    93 bool PathMapper::RPathMapperServerSession::getChildren(const QString &path, QSet<QString> &children) const
       
    94 {
       
    95     QByteArray pathByteArray;
       
    96     QDataStream out(&pathByteArray, QIODevice::WriteOnly);
       
    97     out.setVersion(QDataStream::Qt_4_6);
       
    98     out << path;
       
    99     TPtrC8 pathPtr((TUint8*)(pathByteArray.constData()), pathByteArray.size());
       
   100     TPckgBuf<TInt> lengthPckg(0);
       
   101     SendReceive(EGetChildrenLengthRequest, TIpcArgs(&pathPtr, &lengthPckg));
       
   102     int length = lengthPckg();
       
   103     if (length == 0)
       
   104         return false;
       
   105 
       
   106     HBufC8 *childrenBuf = HBufC8::New(length);
       
   107     if (!childrenBuf)
       
   108         return false;
       
   109 
       
   110     TPtr8 childrenPtr(childrenBuf->Des());
       
   111     SendReceive(EGetChildrenRequest, TIpcArgs(&childrenPtr));
       
   112 
       
   113     QByteArray childrenByteArray((const char*)childrenPtr.Ptr(), childrenPtr.Length());
       
   114     QDataStream in(childrenByteArray);
       
   115     in >> children;
       
   116 
       
   117     delete childrenBuf;
       
   118 
       
   119     return true;
       
   120 }
       
   121 
       
   122 QStringList PathMapper::RPathMapperServerSession::childPaths(const QString &path) const
       
   123 {
       
   124     QByteArray pathByteArray;
       
   125     QDataStream out(&pathByteArray, QIODevice::WriteOnly);
       
   126     out.setVersion(QDataStream::Qt_4_6);
       
   127     out << path;
       
   128     TPtrC8 pathPtr((TUint8*)(pathByteArray.constData()), pathByteArray.size());
       
   129     TPckgBuf<TInt> lengthPckg(0);
       
   130     SendReceive(EChildPathsLengthRequest, TIpcArgs(&pathPtr, &lengthPckg));
       
   131     int length = lengthPckg();
       
   132     if (length == 0)
       
   133         return QStringList();
       
   134 
       
   135     HBufC8 *childPathsBuf = HBufC8::New(length);
       
   136     if (!childPathsBuf)
       
   137         return QStringList();
       
   138 
       
   139     TPtr8 childPathsPtr(childPathsBuf->Des());
       
   140     SendReceive(EChildPathsRequest, TIpcArgs(&childPathsPtr));
       
   141 
       
   142     QByteArray childPathsByteArray((const char*)childPathsPtr.Ptr(), childPathsPtr.Length());
       
   143     QDataStream in(childPathsByteArray);
       
   144     QStringList childPaths;
       
   145     in >> childPaths;
       
   146 
       
   147     delete childPathsBuf;
       
   148     return childPaths;
       
   149 }
       
   150 
       
   151 bool PathMapper::RPathMapperServerSession::resolvePath(const QString &path, Target &target, quint32 &category, quint32 &key) const
       
   152 {
       
   153     QByteArray pathByteArray;
       
   154     QDataStream out(&pathByteArray, QIODevice::WriteOnly);
       
   155     out.setVersion(QDataStream::Qt_4_6);
       
   156     out << path;
       
   157     TPtrC8 pathPtr((TUint8*)(pathByteArray.constData()), pathByteArray.size());
       
   158     TPckgBuf<TInt> lengthPckg(0);
       
   159     SendReceive(EResolvePathLengthRequest, TIpcArgs(&pathPtr, &lengthPckg));
       
   160     int length = lengthPckg();
       
   161     if (length == 0)
       
   162         return false;
       
   163 
       
   164     HBufC8 *keyDetailsBuf = HBufC8::New(length);
       
   165     if (!keyDetailsBuf)
       
   166         return false;
       
   167 
       
   168     TPtr8 keyDetailsPtr(keyDetailsBuf->Des());
       
   169     SendReceive(EResolvePathRequest, TIpcArgs(&keyDetailsPtr));
       
   170 
       
   171     QByteArray keyDetailsByteArray((const char*)keyDetailsPtr.Ptr(), keyDetailsPtr.Length());
       
   172     QDataStream in(keyDetailsByteArray);
       
   173 
       
   174     int t;
       
   175     quint32 c;
       
   176     quint32 k;
       
   177 
       
   178     in >> t;
       
   179     in >> c;
       
   180     in >> k;
       
   181     target = (Target)t;
       
   182     category = c;
       
   183     key = k;
       
   184     delete keyDetailsBuf;
       
   185     return true;
       
   186 }
       
   187 
       
   188 TInt PathMapper::RPathMapperServerSession::StartServer()
       
   189 {
       
   190     TInt ret = KErrNone;
       
   191     TFindServer findServer(KPSPathMapperServerName);
       
   192     TFullName name;
       
   193     if (findServer.Next(name) != KErrNone) {
       
   194         TRequestStatus status;
       
   195         RProcess server;
       
   196         ret = server.Create(KPSPathMapperServerProcess, KNullDesC);
       
   197         if(ret != KErrNone) {
       
   198             return ret;
       
   199         }
       
   200         server.Rendezvous(status);
       
   201         if(status != KRequestPending) {
       
   202             server.Kill(KErrNone);
       
   203             server.Close();
       
   204             return KErrGeneral;
       
   205         } else {
       
   206             server.Resume();
       
   207         }
       
   208 
       
   209         User::WaitForRequest(status);
       
   210         if(status != KErrNone) {
       
   211             server.Close();
       
   212             return status.Int();
       
   213         }
       
   214         server.Close();
       
   215     }
       
   216     return ret;
       
   217 }
       
   218 
       
   219 #include "moc_pathmapper_proxy_symbian_p.cpp"
       
   220 
       
   221 QTM_END_NAMESPACE