javamanager/javaappscheme/src.s60/serviceapp.cpp
changeset 61 bf7ee68962da
child 67 63b81d807542
equal deleted inserted replaced
48:e0d6e9bd3ca7 61:bf7ee68962da
       
     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 <QUrl>
       
    20 
       
    21 #include "logger.h"
       
    22 
       
    23 #include "serviceapp.h"
       
    24 #include <xqserviceutil.h>
       
    25 
       
    26 
       
    27 ServiceApp::ServiceApp(int &argc, char **argv)
       
    28     : QApplication(argc, argv), mUriService(NULL)
       
    29 {
       
    30     LOG(EJavaQtServiceApp, EInfo, "ServiceApp (QApplication) constructor called");
       
    31     bool isService = XQServiceUtil::isService();
       
    32     if (isService)
       
    33     {
       
    34         mUriService = new UriService(this);
       
    35     }
       
    36 
       
    37     QString interface = XQServiceUtil::interfaceName();
       
    38     QString operation = XQServiceUtil::operationName();
       
    39 
       
    40     QString t = "SERVICEAPP:\n";
       
    41     t = t + (isService ?  "    Service launch\n" : "    Normal launch\n");
       
    42     t = t + (XQServiceUtil::isEmbedded() ? "    Embedded\n" : "    Not embedded\n");
       
    43     t = t + ("    Interface=" + interface + "\n");
       
    44     t = t + ("    Operation=" + operation + "\n");
       
    45 
       
    46     std::string callType = t.toStdString();
       
    47     LOG1(EJavaQtServiceApp, EInfo, "ServiceApp called as %s", callType.c_str());
       
    48 }
       
    49 
       
    50 ServiceApp::~ServiceApp()
       
    51 {
       
    52     LOG(EJavaQtServiceApp, EInfo, "ServiceApp destructor called");
       
    53     delete mUriService;
       
    54 }
       
    55 
       
    56 void ServiceApp::quit()
       
    57 {
       
    58     LOG(EJavaQtServiceApp, EInfo, "ServiceApp quit() called");
       
    59 }
       
    60 
       
    61 
       
    62 // ----------UriService---------------
       
    63 
       
    64 // The service string param given to XQServiceProvider must contain first
       
    65 // the name of the name of the service and then the name of the interface
       
    66 // (from service_conf.xml)
       
    67 UriService::UriService(ServiceApp* parent)
       
    68 : XQServiceProvider(QLatin1String("javaappscheme.com.nokia.symbian.IUriView"),parent),
       
    69     mServiceApp(parent)
       
    70 {
       
    71     LOG(EJavaQtServiceApp, EInfo, "UriService::UriService called");
       
    72     publishAll();
       
    73 }
       
    74 
       
    75 UriService::~UriService()
       
    76 {
       
    77     LOG(EJavaQtServiceApp, EInfo, "UriService::~UriService called");
       
    78 }
       
    79 
       
    80 bool UriService::view(const QString& uri)
       
    81 {
       
    82     LOG(EJavaQtServiceApp, EInfo, "UriService::view(uri) called");
       
    83     return view(uri, true);
       
    84 }
       
    85 
       
    86 bool UriService::view(const QString& uri, bool retValue)
       
    87 {
       
    88     LOG(EJavaQtServiceApp, EInfo, "UriService::view(uri, retValue) called");
       
    89     std::wstring stdWStrUri = uri.toStdWString();
       
    90     LOG1(EJavaQtServiceApp, EInfo, "url is %S", stdWStrUri.c_str());
       
    91     if (retValue)
       
    92     {
       
    93         LOG(EJavaQtServiceApp, EInfo, "UriService::view retValue parameter is true");
       
    94     }
       
    95 
       
    96     XQRequestInfo info = requestInfo();
       
    97     bool asyncAnswer = !info.isSynchronous();
       
    98 
       
    99     // Start javalauncher.exe and pass the Url to it
       
   100     _LIT(KJavaLauncherExe, "javalauncher.exe");
       
   101     RProcess rProcess;
       
   102     retValue = true;
       
   103 
       
   104     // start
       
   105     HBufC* bufUri = HBufC::New(stdWStrUri.size());
       
   106     if (0 == bufUri)
       
   107     {
       
   108         return false;
       
   109     }
       
   110     TPtr16 ptrUri(bufUri->Des());
       
   111     ptrUri.Append((const TUint16*)stdWStrUri.c_str(), stdWStrUri.size());
       
   112 
       
   113     TInt err = rProcess.Create(KJavaLauncherExe, ptrUri);
       
   114     if (KErrNone == err)
       
   115     {
       
   116         // This call will wait until javalauncher exits (or panics)
       
   117         TRequestStatus status;
       
   118         rProcess.Logon(status);
       
   119         rProcess.Resume();
       
   120 
       
   121         // now wait until javalauncher exits
       
   122         User::WaitForRequest(status);
       
   123         err = status.Int();
       
   124         if (err != KErrNone)
       
   125         {
       
   126             ELOG1(EJavaQtServiceApp,
       
   127                 "UriService::view javalauncher exited with error %d", err);
       
   128             retValue = false;
       
   129         }
       
   130     }
       
   131     else
       
   132     {
       
   133         ELOG1(EJavaQtServiceApp,
       
   134             "UriService::view Cannot create javalauncher process, error %d", err);
       
   135         retValue = false;
       
   136     }
       
   137 
       
   138     // free resources before returning
       
   139     rProcess.Close();
       
   140     delete bufUri;
       
   141 
       
   142     if (KErrNone != err)
       
   143     {
       
   144 #ifndef _DEBUG
       
   145         // Make sure Url is logged always if an error has happened
       
   146         ELOG1(EJavaQtServiceApp, "UriService::view url was %S", stdWStrUri.c_str());
       
   147 #endif
       
   148         retValue = false;
       
   149     }
       
   150 
       
   151     return retValue;
       
   152 }