qthighway/xqserviceipc/xqserviceipcserver/xqserviceipcrequest.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /*
       
     2 * Copyright (c) 2008 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:  IPC request class
       
    19 *
       
    20 */
       
    21 
       
    22 #include "xqservicelog.h"
       
    23 
       
    24 #include <xqserviceclientinfo.h>
       
    25 #include "xqserviceipcrequest.h"
       
    26 #include "xqserviceipcserversession.h"
       
    27 #include "xqrequestutil.h"
       
    28 
       
    29 namespace QtService
       
    30 {
       
    31 /*!
       
    32  \class ServiceIPCRequest
       
    33  Class to encapsulate a service request
       
    34  */
       
    35 
       
    36 /*!
       
    37  Constructor
       
    38  @param aSession session associated with this request
       
    39  @param aDataLength amount of data to be received in this request
       
    40  @param aRequestOp operaion name
       
    41  */
       
    42 ServiceIPCRequest::ServiceIPCRequest(ServiceIPCSession* aSession,
       
    43                                      qint64 aDataLength,
       
    44                                      const QString& aRequestOp) :
       
    45     iSession(aSession), 
       
    46     iRequestOp(aRequestOp), 
       
    47     iDatalength(aDataLength),
       
    48     iClientInfo(NULL),
       
    49     QObject(NULL),
       
    50     iId(-1),
       
    51     iAsync(false)
       
    52 {
       
    53     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::ServiceIPCRequest(1)");
       
    54     XQSERVICE_DEBUG_PRINT("aDataLength: %d", aDataLength);
       
    55     XQSERVICE_DEBUG_PRINT("aRequestOp: %s", qPrintable(aRequestOp));
       
    56 }
       
    57 
       
    58 /*!
       
    59  Copy Constructor
       
    60  @param aRequest request to be copied
       
    61  */
       
    62 ServiceIPCRequest::ServiceIPCRequest(ServiceIPCRequest& aRequest)
       
    63 {
       
    64     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::ServiceIPCRequest(2)");
       
    65     //session
       
    66     iSession = aRequest.getSession();
       
    67     
       
    68     //client info
       
    69     iClientInfo = new ClientInfo();
       
    70     iClientInfo->setName((aRequest.clientInfo())->name());
       
    71     iClientInfo->setProcessId(aRequest.clientInfo()->processId());
       
    72     iClientInfo->setVendorId(aRequest.clientInfo()->vendorId());
       
    73     
       
    74     // request operation
       
    75     iRequestOp = aRequest.getOperation();
       
    76     
       
    77     //data part
       
    78     iRequestData = aRequest.getData();
       
    79     iDatalength = iRequestData.length();
       
    80 
       
    81     // Request options
       
    82     iRequestInfo = aRequest.requestInfo();
       
    83 
       
    84 }
       
    85 
       
    86 /*!
       
    87  Destructor
       
    88  */
       
    89 ServiceIPCRequest::~ServiceIPCRequest()
       
    90 {
       
    91     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::~ServiceIPCRequest");
       
    92     delete iClientInfo;
       
    93 }
       
    94 
       
    95 /*!
       
    96  Assignment operator
       
    97  @param aRequest request to be assigned
       
    98  @return ServiceIPCRequest assigned request
       
    99  */
       
   100 ServiceIPCRequest& ServiceIPCRequest::operator=(ServiceIPCRequest& aRequest)
       
   101 {
       
   102     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::operator=");
       
   103     if (this != &aRequest) {
       
   104         //session
       
   105         iSession = aRequest.getSession();
       
   106         
       
   107         //client info
       
   108         ClientInfo* info = new ClientInfo();
       
   109         info->setName((aRequest.clientInfo())->name());
       
   110         info->setProcessId(aRequest.clientInfo()->processId());
       
   111         info->setVendorId(aRequest.clientInfo()->vendorId());
       
   112         delete iClientInfo;
       
   113         iClientInfo = info;    
       
   114         
       
   115         // request operation
       
   116         iRequestOp = aRequest.getOperation();
       
   117             
       
   118         //data part
       
   119         iRequestData = aRequest.getData();
       
   120         iDatalength = iRequestData.length();
       
   121 
       
   122         // Request options
       
   123         iRequestInfo = aRequest.requestInfo();
       
   124         
       
   125     }
       
   126     return *this;
       
   127 }
       
   128 
       
   129 /*!
       
   130  Get the requested operation
       
   131  @return QString operation ID
       
   132  */
       
   133 const QString& ServiceIPCRequest::getOperation()
       
   134 {
       
   135     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getOperation");
       
   136     XQSERVICE_DEBUG_PRINT("iRequestOp: %s", qPrintable(iRequestOp));
       
   137     return iRequestOp;
       
   138 }
       
   139 
       
   140 /*!
       
   141  Get the requested data
       
   142  @return QByteArray data for this operation
       
   143  */
       
   144 const QByteArray& ServiceIPCRequest::getData()
       
   145 {
       
   146     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getData");
       
   147     XQSERVICE_DEBUG_PRINT("iRequestData: %s", iRequestData.constData());
       
   148     return iRequestData;
       
   149 }
       
   150 
       
   151 /*!
       
   152  Write some data to the request
       
   153  @param aData data to write to the socket
       
   154  */
       
   155 bool ServiceIPCRequest::write(const QByteArray& aData)
       
   156 {
       
   157     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::write");
       
   158     XQSERVICE_DEBUG_PRINT("aData: %s", aData.constData());
       
   159     // Do we want to buffer the writes?
       
   160     return iSession->write(aData);
       
   161 }
       
   162 
       
   163 /*!
       
   164  Complete the request
       
   165  @return true if request completed successfully
       
   166  */
       
   167 bool ServiceIPCRequest::completeRequest()
       
   168 {
       
   169     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::completeRequest");
       
   170     return iSession->completeRequest();
       
   171 }
       
   172 
       
   173 /*!
       
   174  Append more data when creating the request
       
   175  @arg aMoreData data to be appended to the request
       
   176  @return true if iDataLength now equals the full length
       
   177  */
       
   178 bool ServiceIPCRequest::addRequestdata(const QByteArray& aMoreData)
       
   179 {
       
   180     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::addRequestdata");
       
   181     XQSERVICE_DEBUG_PRINT("aMoreData: %s", aMoreData.constData());
       
   182     iRequestData.append(aMoreData);
       
   183     return (iRequestData.length() == iDatalength);
       
   184 }
       
   185 
       
   186 /*!
       
   187  Sets the client info.  Onwership of the object is passed in.
       
   188  @arg aClientInfo Client information
       
   189  */
       
   190 void ServiceIPCRequest::setClientInfo(ClientInfo *aClientInfo)
       
   191 {
       
   192     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setClientInfo");
       
   193     delete iClientInfo;
       
   194     iClientInfo = aClientInfo;
       
   195 }
       
   196 
       
   197 /*!
       
   198  Gets the client info.
       
   199  @return Client Information object.  NULL if none is available
       
   200  */
       
   201 ClientInfo* ServiceIPCRequest::clientInfo()
       
   202 {
       
   203     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::clientInfo");
       
   204     return iClientInfo;
       
   205 }
       
   206 
       
   207 /*!
       
   208  Gets the session.
       
   209  @return ServiceIPCSession.  NULL if none is available
       
   210  */
       
   211 ServiceIPCSession* ServiceIPCRequest::getSession()
       
   212 {
       
   213     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getSession");
       
   214     return iSession;
       
   215 }
       
   216 
       
   217 /*!
       
   218  Sets id of the request.
       
   219  @arg id Identifier of the request.
       
   220  */
       
   221 void ServiceIPCRequest::setId(int aId)
       
   222 {
       
   223     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setId");
       
   224     XQSERVICE_DEBUG_PRINT("\t aId = %d", aId);
       
   225     iId = aId;
       
   226 }
       
   227 
       
   228 /*!
       
   229  Returns id of the request.
       
   230  @return Id of the request.
       
   231  */
       
   232 int ServiceIPCRequest::id() const
       
   233 {
       
   234     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::id");
       
   235     XQSERVICE_DEBUG_PRINT("\t iId = %d", iId);
       
   236     return iId;
       
   237 }
       
   238 
       
   239 /*!
       
   240  Sets asynchcronous flag to true or false.
       
   241  @arg A value of the async flag.
       
   242  */
       
   243 void ServiceIPCRequest::setAsync(bool aAsync)
       
   244 {
       
   245     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setAsync");
       
   246     XQSERVICE_DEBUG_PRINT("\t iAsync = %d", aAsync);
       
   247     iAsync = aAsync;
       
   248 }
       
   249 
       
   250 /*!
       
   251  Returns asynch flag.
       
   252  @return True if the request is asynchronous. False, if synchronous
       
   253  */
       
   254 bool ServiceIPCRequest::isAsync() const
       
   255 {
       
   256     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getAsync");
       
   257     XQSERVICE_DEBUG_PRINT("\t iAsync = %d", iAsync);
       
   258     return iAsync;
       
   259 }
       
   260 
       
   261 
       
   262 void ServiceIPCRequest::setRequestInfo(XQRequestInfo *info)
       
   263 {
       
   264     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setRequestInfo");
       
   265     if (info)
       
   266     {
       
   267         iRequestInfo = *info;
       
   268         if (iClientInfo)
       
   269         {
       
   270             // Fill in client security info from the client info
       
   271             XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSecurityInfo");
       
   272             iRequestInfo.setInfo(XQServiceUtils::InfoSID, iClientInfo->processId());
       
   273             iRequestInfo.setInfo(XQServiceUtils::InfoVID, iClientInfo->vendorId());
       
   274             iRequestInfo.setInfo(XQServiceUtils::InfoCap, iClientInfo->capabilities());
       
   275         }
       
   276     }
       
   277 }
       
   278 
       
   279 XQRequestInfo ServiceIPCRequest::requestInfo() const
       
   280 {
       
   281     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::requestInfo");
       
   282     return iRequestInfo;
       
   283 }
       
   284 
       
   285 void ServiceIPCRequest::addSharableFile(XQSharableFile *file, int index)
       
   286 {
       
   287     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile");
       
   288     if (file != NULL)
       
   289         iSharableFiles.append(*file);
       
   290 }
       
   291 
       
   292 XQSharableFile ServiceIPCRequest::sharableFile(int index) const
       
   293 {
       
   294     XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile");
       
   295     if (index >= 0 && index < iSharableFiles.size())
       
   296     {
       
   297         XQSharableFile file = iSharableFiles.at(index);
       
   298         XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile valid=%d", file.isValid());
       
   299         return file;
       
   300     }
       
   301     return XQSharableFile();
       
   302 }
       
   303 
       
   304 
       
   305 }
       
   306 // END OF FILE