javamanager/javaqtrequest/src.s60/requestapp.cpp
branchRCL_3
changeset 25 ae942d28ec0e
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  QT Service application the implements support for
       
    15 *               starting Java applications using "javaapp:" QUrl
       
    16 *
       
    17 */
       
    18 
       
    19 #include <QList>
       
    20 #include <QUrl>
       
    21 #include <xqappmgr.h>
       
    22 #include <xqaiwrequest.h>
       
    23 
       
    24 #include "logger.h"
       
    25 #include "requestapp.h"
       
    26 
       
    27 
       
    28 RequestApp::RequestApp(int &argc, char **argv) : QApplication(argc, argv)
       
    29 {
       
    30     LOG(EJavaQtServiceApp, EInfo, "RequestApp (QApplication) constructor called");
       
    31 }
       
    32 
       
    33 void RequestApp::sendRequest()
       
    34 {
       
    35     QString uriString = arguments().at(1);
       
    36     std::wstring stdWStrUri = uriString.toStdWString();
       
    37     LOG1(EJavaQtServiceApp, EInfo,
       
    38         "SLOT RequestApp::sendRequest called with Uri %S", stdWStrUri.c_str());
       
    39 
       
    40     QUrl uri(uriString);
       
    41     XQApplicationManager appMgr;
       
    42     // Make the request in non-embedded mode
       
    43     XQAiwRequest *request = appMgr.create(uri, false); 
       
    44     if (!request)
       
    45     {
       
    46         // No handlers for the URI
       
    47         ELOG1(EJavaQtServiceApp,
       
    48             "RequestApp::sendRequest No QtHighway service found for URI: %S",
       
    49             stdWStrUri.c_str());
       
    50         exit(KErrNotFound);
       
    51         return;
       
    52     }
       
    53 
       
    54     // Set function parameters
       
    55     QList<QVariant> args;
       
    56     args << uri.toString();
       
    57     request->setArguments(args);
       
    58 
       
    59     // Send the request
       
    60     if  (!request->send())
       
    61     {
       
    62         // Request failed.
       
    63         int error = request->lastError();
       
    64         ELOG2(EJavaQtServiceApp,
       
    65             "RequestApp::sendRequest QtHighway request failed "
       
    66             "with err %d, URI was %S",
       
    67             error, stdWStrUri.c_str());
       
    68         delete request;
       
    69         exit(KErrCompletion);
       
    70         return;
       
    71     }
       
    72 
       
    73     delete request;
       
    74 
       
    75     exit(KErrNone); // Exit with OK status
       
    76 }
       
    77 
       
    78 
       
    79