javamanager/javainstaller/javasifplugin/src/resultsserver.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Comms server, part of Java Sif plugin.
    14 * Description:  Comms server,
    15 *               When started  in 'commsresult' mode from Java Sif plugin
    15 *    part of Java platform 2.0 javarestoreconverter process
    16 *               Java Installer sends the results of the operation
       
    17 *               it executes (install, uninstall or component info)
       
    18 *               to this server.
       
    19 *
    16 *
    20 */
    17 */
    21 
    18 
    22 
    19 
    23 #include <iostream>
    20 #include <iostream>
    24 #include <unistd.h>
    21 #include <unistd.h>
    25 #include <usif/usiferror.h>
       
    26 
    22 
    27 #include "comms.h"
    23 #include "comms.h"
    28 #include "javasymbianoslayer.h"
    24 #include "javasymbianoslayer.h"
    29 #include "logger.h"
    25 #include "logger.h"
    30 #include "resultsserver.h"
    26 #include "resultsserver.h"
    31 
    27 
    32 using namespace java::comms;
    28 using namespace java::comms;
    33 using namespace std;
    29 using namespace std;
    34 
    30 
    35 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) :
    31 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) :
    36         mResults(aResults), mInfo(aInfo)
    32         iResults(aResults), iInfo(aInfo)
    37 {
    33 {
    38 }
    34 }
    39 
    35 
    40 ResultsServer::~ResultsServer()
    36 ResultsServer::~ResultsServer()
    41 {
    37 {
    46     iStringPairs.clear();
    42     iStringPairs.clear();
    47 }
    43 }
    48 
    44 
    49 int ResultsServer::start()
    45 int ResultsServer::start()
    50 {
    46 {
    51     // Write reasonable error codes to mResults that can be used if
    47     iRunning = 1;
    52     // Java Installer never returns InstallerResultMessage.
    48     iComms.registerDefaultListener(this);
    53     // If InstallerResultMessage is received the values will be overwritten.
    49     return iComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
    54     TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
    50 }
    55     if (KErrNone != err)
    51 
       
    52 int ResultsServer::stop()
       
    53 {
       
    54     if (iRunning > 0)
    56     {
    55     {
    57         ELOG1(EJavaInstaller,
    56         iRunning = 0;
    58             "ResultsServer::start mResults.AddIntL ErrCategory err %d", err);
    57         iComms.unregisterDefaultListener(this);
       
    58         return iComms.stop();
    59     }
    59     }
    60 
    60     else
    61     TRAP(err, mResults.AddIntL(KSifOutParam_ErrCode, KErrUnknown));
       
    62     if (KErrNone != err)
       
    63     {
    61     {
    64         ELOG1(EJavaInstaller,
    62         return 0;
    65             "ResultsServer::start mResults.AddIntL ErrCode err %d", err);
       
    66     }
    63     }
    67 
       
    68     TRAP(err, mResults.AddIntL(KSifOutParam_ExtendedErrCode, 0));
       
    69     if (KErrNone != err)
       
    70     {
       
    71         ELOG1(EJavaInstaller,
       
    72             "ResultsServer::start mResults.AddIntL ExtendedErrCode err %d", err);
       
    73     }
       
    74 
       
    75     // TODO: return also localized error message (KSifOutParam_ErrMessage and
       
    76     // perhaps also KSifOutParam_ErrMessageDetails) from usif
       
    77     // common localization file after the localized strings are available
       
    78 
       
    79 
       
    80     mComms.registerDefaultListener(this);
       
    81     return mComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
       
    82 }
       
    83 
       
    84 int ResultsServer::stop()
       
    85 {
       
    86     mComms.unregisterDefaultListener(this);
       
    87     return mComms.stop();
       
    88 }
    64 }
    89 
    65 
    90 /**
    66 /**
    91  * Communicates with Java Installer. The following messages are used.
    67  * Communicates with Java Installer. The following messages are used.
    92  *
    68  *
   139             // result is KErrNone if the operation succeeded
   115             // result is KErrNone if the operation succeeded
   140             int result = iIntPairs[L"result"];
   116             int result = iIntPairs[L"result"];
   141 
   117 
   142             if (KErrNone != result)
   118             if (KErrNone != result)
   143             {
   119             {
   144                 // return common error information;
   120                 // return common error information
   145                 setCommonErrorInfo();
   121                 TRAP(err, iResults.AddIntL(KSifOutParam_ExtendedErrCode, result));
   146 
   122                 if (KErrNone != err)
   147                 if (INSTALL_OPERATION == operation)
   123                 {
   148                 {
   124                     ELOG1(EJavaInstaller,
   149                     ELOG1(EJavaInstaller,
   125                         "ResultsServer::processMessage iResults.AddIntL ExtendedErrCode err %d",
   150                         "ResultsServer::processMessage, Install failed with error %d", result);
   126                         err);
   151                 }
   127                 }
   152                 else if (UNINSTALL_OPERATION == operation)
   128 
   153                 {
   129                 TRAP(err, iResults.AddIntL(KSifOutParam_ErrCode, result));
   154                     ELOG1(EJavaInstaller,
   130                 if (KErrNone != err)
   155                         "ResultsServer::processMessage, Uninstall failed with error %d", result);
   131                 {
   156                 }
   132                     ELOG1(EJavaInstaller,
   157                 else if (COMPONENT_INFO_OPERATION == operation)
   133                         "ResultsServer::processMessage iResults.AddIntL ErrCode err %d", err);
   158                 {
   134                 }
   159                     ELOG1(EJavaInstaller,
   135 
   160                         "ResultsServer::processMessage, Component info failed with error %d",
   136                 TRAP(err, iResults.AddIntL(
   161                         result);
   137                     KSifOutParam_ErrCategory, iIntPairs[L"error-category"]));
   162                 }
   138                 if (KErrNone != err)
   163             }
   139                 {
   164             else
   140                     ELOG1(EJavaInstaller,
   165             {
   141                         "ResultsServer::processMessage iResults.AddIntL ErrCategory err %d",
   166                 // Operation succeeded
   142                         err);
   167 
   143                 }
   168                 // Overwrite (reset) the default error values set for the case where no
   144 
   169                 // InstallerResultMessage is never received
   145                 HBufC *message = wstringToBuf(iStringPairs[L"error-message"]);
   170                 resetDefaultErrorValues();
   146                 if (message == NULL)
   171 
   147                 {
   172                 if (INSTALL_OPERATION == operation)
   148                     ELOG(EJavaInstaller,
   173                 {
   149                           "ResultsServer::processMessage iResults.wstringToBuf returned NULL ");
   174                     // Return the component ids of the installed Java application.
   150                 }
   175                     TComponentId resultComponentId = iIntPairs[L"suite-cid"];
   151                 else
   176                     TRAP(err, mResults.AddIntL(KSifOutParam_ComponentId, resultComponentId));
   152                 {
       
   153                     TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessage, *message));
   177                     if (KErrNone != err)
   154                     if (KErrNone != err)
   178                     {
   155                     {
   179                         ELOG1(EJavaInstaller,
   156                         ELOG1(EJavaInstaller,
   180                               "ResultsServer::processMessage mResults.AddIntL cid error %d", err);
   157                             "ResultsServer::processMessage iResults.AddStringL ErrMessage err %d",
       
   158                             err);
       
   159                     }
       
   160                     delete message;
       
   161                 }
       
   162 
       
   163                 message = wstringToBuf(iStringPairs[L"error-details"]);
       
   164                 if (message == NULL)
       
   165                 {
       
   166                     ELOG(EJavaInstaller,
       
   167                           "ResultsServer::processMessage iResults.wstringToBuf 2 returned NULL ");
       
   168                 }
       
   169                 else
       
   170                 {
       
   171                     TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessageDetails, *message));
       
   172                     if (KErrNone != err)
       
   173                     {
       
   174                         ELOG1(EJavaInstaller,
       
   175                             "ResultsServer::processMessage iResults.AddStringL ErrMessageDetails "
       
   176                             "err %d", err);
       
   177                     }
       
   178                     delete message;
       
   179                 }
       
   180 
       
   181                 if (INSTALL_OPERATION == operation)
       
   182                 {
       
   183                     ELOG1(EJavaInstaller,
       
   184                         "ResultsServer::processMessage, Install failed with error %d", result);
       
   185                 }
       
   186                 else if (UNINSTALL_OPERATION == operation)
       
   187                 {
       
   188                     ELOG1(EJavaInstaller,
       
   189                         "ResultsServer::processMessage, Uninstall failed with error %d", result);
       
   190                 }
       
   191                 else if (COMPONENT_INFO_OPERATION == operation)
       
   192                 {
       
   193                     ELOG1(EJavaInstaller,
       
   194                         "ResultsServer::processMessage, Component info failed with error %d",
       
   195                         result);
       
   196                 }
       
   197             }
       
   198             else
       
   199             {
       
   200                 // operation succeeded
       
   201 
       
   202                 if (INSTALL_OPERATION == operation)
       
   203                 {
       
   204                     // Return the component ids of the installed Java application.
       
   205                     TComponentId resultComponentId = iIntPairs[L"suite-cid"];
       
   206                     TRAP(err, iResults.AddIntL(KSifOutParam_ComponentId, resultComponentId));
       
   207                     if (KErrNone != err)
       
   208                     {
       
   209                         ELOG1(EJavaInstaller,
       
   210                               "ResultsServer::processMessage iResults.AddIntL cid error %d", err);
   181                     }
   211                     }
   182                 }
   212                 }
   183                 else if (UNINSTALL_OPERATION == operation)
   213                 else if (UNINSTALL_OPERATION == operation)
   184                 {
   214                 {
   185                     // Return nothing if uninstall succeeds
   215                     // Return nothing if uninstall succeeds
   207             CommsMessage reply;
   237             CommsMessage reply;
   208             reply.replyTo(aMessage);
   238             reply.replyTo(aMessage);
   209             reply.setMessageId(INSTALLER_RESULT_RESPONSE_MESSAGE_ID);
   239             reply.setMessageId(INSTALLER_RESULT_RESPONSE_MESSAGE_ID);
   210             reply << 0;
   240             reply << 0;
   211 
   241 
   212             int err = mComms.send(reply);
   242             int err = iComms.send(reply);
   213             if (err != 0)
   243             if (err != 0)
   214             {
   244             {
   215                 ELOG1(EJavaInstaller,
   245                 ELOG1(EJavaInstaller,
   216                     "ResultsServer: Sending reply to Java Installer failed, err %d", err);
   246                     "ResultsServer: Sending reply to Java Installer failed, err %d", err);
   217             }
   247             }
   227         }
   257         }
   228         break;
   258         break;
   229     }
   259     }
   230 
   260 
   231     clearData();
   261     clearData();
   232 }
       
   233 
       
   234 
       
   235 /**
       
   236  * Set common error information.
       
   237  * Note that the information is in member variables
       
   238  * iIntPairs and iStringPairs
       
   239  */
       
   240 void ResultsServer::setCommonErrorInfo()
       
   241 {
       
   242     // return common error information
       
   243     TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCode, iIntPairs[L"error-code"]));
       
   244     if (KErrNone != err)
       
   245     {
       
   246         ELOG1(EJavaInstaller,
       
   247             "ResultsServer::setCommonErrorInfo mResults.AddIntL ErrCode err %d", err);
       
   248     }
       
   249 
       
   250     TRAP(err, mResults.AddIntL(
       
   251         KSifOutParam_ErrCategory, iIntPairs[L"error-category"]));
       
   252     if (KErrNone != err)
       
   253     {
       
   254         ELOG1(EJavaInstaller,
       
   255             "ResultsServer::setCommonErrorInfo mResults.AddIntL ErrCategory err %d",
       
   256             err);
       
   257     }
       
   258 
       
   259     HBufC *message = wstringToBuf(iStringPairs[L"error-message"]);
       
   260     if (!message)
       
   261     {
       
   262         ELOG(EJavaInstaller,
       
   263               "ResultsServer::setCommonErrorInfo mResults.wstringToBuf returned NULL ");
       
   264     }
       
   265     else
       
   266     {
       
   267         TRAP(err, mResults.AddStringL(KSifOutParam_ErrMessage, *message));
       
   268         if (KErrNone != err)
       
   269         {
       
   270             ELOG1(EJavaInstaller,
       
   271                 "ResultsServer::setCommonErrorInfo mResults.AddStringL ErrMessage err %d",
       
   272                 err);
       
   273         }
       
   274         delete message;
       
   275     }
       
   276 
       
   277     message = wstringToBuf(iStringPairs[L"error-details"]);
       
   278     if (!message)
       
   279     {
       
   280         ELOG(EJavaInstaller,
       
   281               "ResultsServer::setCommonErrorInfo mResults.wstringToBuf 2 returned NULL ");
       
   282     }
       
   283     else
       
   284     {
       
   285         TRAP(err, mResults.AddStringL(KSifOutParam_ErrMessageDetails, *message));
       
   286         if (KErrNone != err)
       
   287         {
       
   288             ELOG1(EJavaInstaller,
       
   289                 "ResultsServer::setCommonErrorInfo mResults.AddStringL ErrMessageDetails "
       
   290                 "err %d", err);
       
   291         }
       
   292         delete message;
       
   293     }
       
   294 }
       
   295 
       
   296 
       
   297 /**
       
   298  * Overwrite (reset) the default error values to 'no error'.
       
   299  * The default error values were originally set for the case
       
   300  * where no InstallerResultMessage is never received and we must
       
   301  * return sensible error information.
       
   302  */
       
   303 void ResultsServer::resetDefaultErrorValues()
       
   304 {
       
   305     TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCategory, 0));
       
   306     if (KErrNone != err)
       
   307     {
       
   308         ELOG1(EJavaInstaller,
       
   309             "ResultsServer::resetDefaultErrorValues mResults.AddIntL ErrCategory err %d", err);
       
   310     }
       
   311 
       
   312     TRAP(err, mResults.AddIntL(KSifOutParam_ErrCode, 0));
       
   313     if (KErrNone != err)
       
   314     {
       
   315         ELOG1(EJavaInstaller,
       
   316             "ResultsServer::resetDefaultErrorValues mResults.AddIntL ErrCode err %d", err);
       
   317     }
       
   318 
       
   319     // TODO: reset also localized error message KSifOutParam_ErrMessage and
       
   320     // perhaps also KSifOutParam_ErrMessageDetails if they have been set in start()
       
   321 }
   262 }
   322 
   263 
   323 
   264 
   324 void ResultsServer::clearData()
   265 void ResultsServer::clearData()
   325 {
   266 {
   357         ss << midletUidN;
   298         ss << midletUidN;
   358         ss << n;
   299         ss << n;
   359         ss >> midletUidN;
   300         ss >> midletUidN;
   360 
   301 
   361         //LOG1WSTR(EJavaInstaller, EInfo,
   302         //LOG1WSTR(EJavaInstaller, EInfo,
   362         //  "ResultsServer::processMessage: checking %S", midletUidN.c_str());
   303         //         "ResultsServer::processMessage: checking %s", midletUidN.c_str());
   363 
   304 
   364         int uid = iIntPairs[midletUidN];
   305         int uid = iIntPairs[midletUidN];
   365         if (uid == 0)
   306         if (uid == 0)
   366         {
   307         {
   367             // no more midlets in the suite
   308             // no more midlets in the suite
   383                 TUid::Uid(uid), midletName, KNullDesC(), KNullDesC());
   324                 TUid::Uid(uid), midletName, KNullDesC(), KNullDesC());
   384         applications.AppendL(applicationInfo);
   325         applications.AppendL(applicationInfo);
   385         CleanupStack::Pop(applicationInfo);
   326         CleanupStack::Pop(applicationInfo);
   386 
   327 
   387         n++;
   328         n++;
   388     } // sanity check: no suite can have 10000 midlets
   329     }
   389     while (n < 10000);   // codescanner::magicnumbers
   330     while (n < 10000);  // sanity check: no suite can have 10000 midlets
   390 
   331 
   391     CComponentInfo::CNode *rootNode = NULL;
   332     CComponentInfo::CNode *rootNode = NULL;
   392     rootNode = CComponentInfo::CNode::NewLC(
   333     rootNode = CComponentInfo::CNode::NewLC(
   393                    KSoftwareTypeJava,
   334                    KSoftwareTypeJava,
   394                    suiteName,
   335                    suiteName,
   405                    EFalse, // drive selection is not required
   346                    EFalse, // drive selection is not required
   406                    &applications
   347                    &applications
   407                );
   348                );
   408 
   349 
   409     // Store whole component info tree
   350     // Store whole component info tree
   410     mInfo.SetRootNodeL(rootNode);
   351     iInfo.SetRootNodeL(rootNode);
   411     CleanupStack::Pop(rootNode);
   352     CleanupStack::Pop(rootNode);
   412     CleanupStack::PopAndDestroy(&applications);
   353     CleanupStack::PopAndDestroy(&applications);
   413 }
   354 }