qthighway/xqserviceutil/src/xqrequestinfo.cpp
branchRCL_3
changeset 22 5d007b20cfd0
equal deleted inserted replaced
21:885c2596c964 22:5d007b20cfd0
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:                                                         
       
    19 *
       
    20 */
       
    21 
       
    22 #include "xqservicelog.h"
       
    23 #include "xqrequestinfo.h"
       
    24 #include "xqrequestutil.h"
       
    25 
       
    26 /*!
       
    27     \class XQRequestInfo
       
    28     \inpublicgroup QtBaseModule
       
    29 
       
    30     \ingroup ipc
       
    31     \brief The XQRequestInfo class encapsulates additional information of a service request
       
    32     
       
    33     The XQRequestInfo class encapsulates additional information of a service request:
       
    34     - For service provider it contains additional information of the service request, some set by the client, some set by the QtHighway framework.
       
    35     - For client it gives possibility to add UI oriented options of the request
       
    36     The XQRequestInfo is exported by the xqserviceutil library
       
    37 */
       
    38 
       
    39 /*!
       
    40     Constructor.
       
    41 */
       
    42 XQRequestInfo::XQRequestInfo()
       
    43 {
       
    44     XQSERVICE_DEBUG_PRINT("XQRequestInfo::XQRequestInfo");
       
    45 }
       
    46 
       
    47 /*!
       
    48     Destructor.
       
    49 */
       
    50 XQRequestInfo::~XQRequestInfo()
       
    51 {
       
    52     XQSERVICE_DEBUG_PRINT("XQRequestInfo::~XQRequestInfo");
       
    53 }
       
    54 
       
    55 /*!
       
    56     Requests service application to be launched as embedded mode.
       
    57     \param on Set to true to turn embedded mode on.
       
    58 */
       
    59 void XQRequestInfo::setEmbedded(bool on)
       
    60 {
       
    61     XQSERVICE_DEBUG_PRINT("XQRequestInfo::setEmbedded %d", on);
       
    62     setInfo(XQServiceUtils::OptEmbedded, on);
       
    63 }
       
    64 
       
    65 /*!
       
    66     Get embedded option value.
       
    67     \return True if embedded mode is turned on, false otherwise.
       
    68 */
       
    69 bool XQRequestInfo::isEmbedded() const
       
    70 {
       
    71     XQSERVICE_DEBUG_PRINT("XQRequestInfo::isEmbedded");
       
    72     return info(XQServiceUtils::OptEmbedded).toBool();
       
    73 }
       
    74 
       
    75 /*!
       
    76     Requests service application to be set to background before a slot call to service provider. 
       
    77     If this option is set to false or not set, the QtHighway does not alter the Z-order.
       
    78     \param on Set to true if service application should be launched to background.
       
    79 */
       
    80 void XQRequestInfo::setBackground(bool on)
       
    81 {
       
    82     XQSERVICE_DEBUG_PRINT("XQRequestInfo::setBackground %d", on);
       
    83     setInfo(XQServiceUtils::OptBackground, on);
       
    84 }
       
    85 
       
    86 /*!
       
    87     Get the value of the background option.
       
    88     \return True if option has been set on, false otherwise.
       
    89 */
       
    90 bool XQRequestInfo::isBackground() const
       
    91 {
       
    92     XQSERVICE_DEBUG_PRINT("XQRequestInfo::isBackground");
       
    93     return info(XQServiceUtils::OptBackground).toBool();
       
    94 }
       
    95 
       
    96 /*!
       
    97     Requests service application to be brought to foreground before a slot call to service provider.
       
    98     If this option is false or not set, the QtHighway does not alter the Z-order.
       
    99     \param on Set to true if service application should be launched to foreground.
       
   100 */
       
   101 void XQRequestInfo::setForeground(bool on)
       
   102 {
       
   103     XQSERVICE_DEBUG_PRINT("XQRequestInfo::setForeground %d", on);
       
   104     setInfo(XQServiceUtils::OptForeground, on);
       
   105 }
       
   106 
       
   107 /*!
       
   108     Get the value of the foreground option.
       
   109     \return True if option has been set on, false otherwise.
       
   110 */
       
   111 bool XQRequestInfo::isForeground() const
       
   112 {
       
   113     XQSERVICE_DEBUG_PRINT("XQRequestInfo::isForeground");
       
   114     return info(XQServiceUtils::OptForeground).toBool();
       
   115 }
       
   116 
       
   117 /*!
       
   118     Gets the vaule of the synchronous option.
       
   119     \return True if request is synchronous , false if asynchronous.
       
   120 */
       
   121 bool XQRequestInfo::isSynchronous() const
       
   122 {
       
   123     XQSERVICE_DEBUG_PRINT("XQRequestInfo::isSynchronous");
       
   124     return info(XQServiceUtils::OptSynchronous).toBool();
       
   125 }
       
   126 
       
   127 /*!
       
   128     Gets the client's secure id option. Valid only for service provider.
       
   129     \return Calling client's secure ID as defined by the Symbian OS platform security model.
       
   130 */
       
   131 quint32 XQRequestInfo::clientSecureId() const
       
   132 {
       
   133     XQSERVICE_DEBUG_PRINT("XQRequestInfo::clientSecureId");
       
   134     bool b=false;
       
   135     quint32 id = info(XQServiceUtils::InfoSID).toUInt(&b);
       
   136     XQSERVICE_DEBUG_PRINT("\tSID status=%d", b);
       
   137     return id;
       
   138 }
       
   139 
       
   140 /*!
       
   141     Gets the clients's vendor id option. Valid only for service provider.
       
   142     \return Calling client's vendor ID as defined by the Symbian OS platform security model.
       
   143 */
       
   144 quint32 XQRequestInfo::clientVendorId() const
       
   145 {
       
   146     XQSERVICE_DEBUG_PRINT("XQRequestInfo::clientVendorId");
       
   147     bool b=false;
       
   148     quint32 id = info(XQServiceUtils::InfoVID).toUInt(&b);
       
   149     XQSERVICE_DEBUG_PRINT("\tVID status=%d", b);
       
   150     return id;
       
   151 }
       
   152 
       
   153 /*!
       
   154     Gets the client's capabilities. Valid only for service provider.
       
   155     \return Calling client's capabilities as defined by the Symbian OS platform security model. 
       
   156             The values in the QSet are compatible with the TCapability values in e32capability.h.
       
   157 */
       
   158 QSet<int> XQRequestInfo::clientCapabilities() const
       
   159 {
       
   160     XQSERVICE_DEBUG_PRINT("XQRequestInfo::clientCapabilities");
       
   161     bool b=false;
       
   162     quint32 caps = info(XQServiceUtils::InfoCap).toUInt(&b);
       
   163     XQSERVICE_DEBUG_PRINT("\tCaps status", b);
       
   164     QSet<int> ret;
       
   165     if (!b)
       
   166         return ret;  // Empty set
       
   167     
       
   168     for(int i = 0; i < 32; i++)
       
   169     {
       
   170         quint32 ix = 0;
       
   171         ix |= 1 << i;
       
   172         if (caps & ix)
       
   173         {
       
   174             ret.insert(i);
       
   175         }
       
   176     }
       
   177     
       
   178     return ret;
       
   179 }
       
   180 
       
   181 /*!
       
   182     Sets a \a value of the named info \a key. Key names starting with "XQ" are reserved for
       
   183     the QtHighway internal usage. If the service operation (message) does not accept
       
   184     these parameters already, the recommened way is to pass these in the XQRequestInfo
       
   185     and use the following pre-defined keys:
       
   186     - XQINFO_KEY_WINDOW_TITLE for passing the title string be shown in the service application
       
   187       window (QtHighway does not pick the Orbit window title automatically).
       
   188     - ViewName (QString) for passing the view to be activated in the service application.
       
   189     \param key Info key for which \a value will be set.
       
   190     \param value Value to be set to a \a key
       
   191 */
       
   192 void XQRequestInfo::setInfo(const QString &key, const QVariant &value)
       
   193 {
       
   194     XQSERVICE_DEBUG_PRINT("XQRequestInfo::setInfo %s:%s,%s",
       
   195         qPrintable(key), qPrintable(value.toString()), value.typeName());
       
   196     mInfo.insert(key, value);
       
   197 }
       
   198 
       
   199 /*!
       
   200     Gets the set value of the \a key. The returned value may be invalid if not set.
       
   201     \param key Key name for which value is retrieved.
       
   202     \return Value set to the key, or invalid QVariant if not set.
       
   203 */
       
   204 QVariant XQRequestInfo::info(const QString &key) const
       
   205 {
       
   206     XQSERVICE_DEBUG_PRINT("XQRequestInfo::info %s", qPrintable(key));
       
   207     QVariant v =  mInfo.value(key);
       
   208     XQSERVICE_DEBUG_PRINT("XQRequestInfo::info type=%s,valid=%d,str=%s", v.typeName(), v.isValid(), qPrintable(v.toString()));
       
   209     return v;
       
   210 }
       
   211 
       
   212 /*!
       
   213     Gets the list of key names set for the object.
       
   214     \return List of key names set for the object.
       
   215 */
       
   216 QStringList XQRequestInfo::infoKeys() const
       
   217 {
       
   218     XQSERVICE_DEBUG_PRINT("XQRequestInfo::infoKeys");
       
   219     return mInfo.keys();
       
   220 }
       
   221 
       
   222 /*!
       
   223     Gets the internal id of the current request. As there can be several
       
   224     requests ongoing to the same interface, this separates multiple requests.
       
   225     Once the request has been completed the ID becomes invalid.
       
   226     This is the same value as returned by the XQServiceProvider::setCurrentRequestAsync()
       
   227     to set response asynchronous.
       
   228     \return Id of the current request as integer value.
       
   229 */
       
   230 int XQRequestInfo::id() const
       
   231 {
       
   232     XQSERVICE_DEBUG_PRINT("XQRequestInfo::id");
       
   233     bool b=false;
       
   234     int id = info(XQServiceUtils::InfoId).toInt(&b);
       
   235     XQSERVICE_DEBUG_PRINT("\tId status=%d", b);
       
   236     if (!b)
       
   237     {
       
   238         return -1;
       
   239     }
       
   240     return id;
       
   241 }
       
   242 
       
   243 /*!
       
   244     Checks if object is valid.
       
   245     \return True if object is valid, false otherwise.
       
   246 */
       
   247 bool XQRequestInfo::isValid() const
       
   248 {
       
   249     return !mInfo.isEmpty();
       
   250 }
       
   251 
       
   252 /*!
       
   253     Serializes this XQRequestInfo data into the given stream.
       
   254     \param s Stream the data is serialized into.
       
   255 */
       
   256 template <typename Stream> void XQRequestInfo::serialize(Stream &s) const
       
   257 {
       
   258     XQSERVICE_DEBUG_PRINT("XQRequestInfo::serialize");
       
   259     s << mInfo;
       
   260 }
       
   261 
       
   262 /*!
       
   263     Deserializes XQRequestInfo data from the given stream.
       
   264     \param s Stream the data is deserialized from.
       
   265 */
       
   266 template <typename Stream> void XQRequestInfo::deserialize(Stream &s)
       
   267 {
       
   268     XQSERVICE_DEBUG_PRINT("XQRequestInfo::de-serialize");
       
   269     s >> mInfo;
       
   270 }
       
   271 
       
   272 Q_IMPLEMENT_USER_METATYPE(XQRequestInfo)