javamanager/javainstaller/javasifplugin/src/resultsserver.cpp
changeset 49 35baca0e7a2e
parent 35 85266cc22c7f
child 78 71ad690e91f5
equal deleted inserted replaced
35:85266cc22c7f 49:35baca0e7a2e
     1 /*
     1 /*
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 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,
    14 * Description:  Comms server, part of Java Sif plugin.
    15 *    part of Java platform 2.0 javarestoreconverter process
    15 *               When started  in 'commsresult' mode from Java Sif plugin
       
    16 *               Java Installer sends the results of the operation
       
    17 *               it executes (install, uninstall or component info)
       
    18 *               to this server.
    16 *
    19 *
    17 */
    20 */
    18 
    21 
    19 
    22 
    20 #include <iostream>
    23 #include <iostream>
    21 #include <unistd.h>
    24 #include <unistd.h>
    22 #include <usiferror.h>
    25 #include <usif/usiferror.h>
    23 
    26 
    24 #include "comms.h"
    27 #include "comms.h"
    25 #include "javasymbianoslayer.h"
    28 #include "javasymbianoslayer.h"
    26 #include "logger.h"
    29 #include "logger.h"
    27 #include "resultsserver.h"
    30 #include "resultsserver.h"
    28 
    31 
    29 using namespace java::comms;
    32 using namespace java::comms;
    30 using namespace std;
    33 using namespace std;
    31 
    34 
    32 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) :
    35 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) :
    33         iResults(aResults), iInfo(aInfo)
    36         mResults(aResults), mInfo(aInfo)
    34 {
    37 {
    35 }
    38 }
    36 
    39 
    37 ResultsServer::~ResultsServer()
    40 ResultsServer::~ResultsServer()
    38 {
    41 {
    43     iStringPairs.clear();
    46     iStringPairs.clear();
    44 }
    47 }
    45 
    48 
    46 int ResultsServer::start()
    49 int ResultsServer::start()
    47 {
    50 {
    48     // Write reasonable error codes to iResults that can be used if
    51     // Write reasonable error codes to mResults that can be used if
    49     // Java Installer never returns InstallerResultMessage.
    52     // Java Installer never returns InstallerResultMessage.
    50     // If InstallerResultMessage is received the values will be overwritten.
    53     // If InstallerResultMessage is received the values will be overwritten.
    51     TRAPD(err, iResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
    54     TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
    52     if (KErrNone != err)
    55     if (KErrNone != err)
    53     {
    56     {
    54         ELOG1(EJavaInstaller,
    57         ELOG1(EJavaInstaller,
    55             "ResultsServer::start iResults.AddIntL ErrCategory err %d", err);
    58             "ResultsServer::start mResults.AddIntL ErrCategory err %d", err);
    56     }
    59     }
    57 
    60 
    58     TRAP(err, iResults.AddIntL(KSifOutParam_ErrCode, KErrUnknown));
    61     TRAP(err, mResults.AddIntL(KSifOutParam_ErrCode, KErrUnknown));
    59     if (KErrNone != err)
    62     if (KErrNone != err)
    60     {
    63     {
    61         ELOG1(EJavaInstaller,
    64         ELOG1(EJavaInstaller,
    62             "ResultsServer::start iResults.AddIntL ErrCode err %d", err);
    65             "ResultsServer::start mResults.AddIntL ErrCode err %d", err);
    63     }
    66     }
    64 
    67 
    65     TRAP(err, iResults.AddIntL(KSifOutParam_ExtendedErrCode, 0));
    68     TRAP(err, mResults.AddIntL(KSifOutParam_ExtendedErrCode, 0));
    66     if (KErrNone != err)
    69     if (KErrNone != err)
    67     {
    70     {
    68         ELOG1(EJavaInstaller,
    71         ELOG1(EJavaInstaller,
    69             "ResultsServer::start iResults.AddIntL ExtendedErrCode err %d", err);
    72             "ResultsServer::start mResults.AddIntL ExtendedErrCode err %d", err);
    70     }
    73     }
    71 
    74 
    72     // TODO: return also localized error message from usif
    75     // TODO: return also localized error message (KSifOutParam_ErrMessage and
       
    76     // perhaps also KSifOutParam_ErrMessageDetails) from usif
    73     // common localization file after the localized strings are available
    77     // common localization file after the localized strings are available
    74 
    78 
    75     iRunning = 1;
    79 
    76     iComms.registerDefaultListener(this);
    80     mComms.registerDefaultListener(this);
    77     return iComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
    81     return mComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
    78 }
    82 }
    79 
    83 
    80 int ResultsServer::stop()
    84 int ResultsServer::stop()
    81 {
    85 {
    82     if (iRunning > 0)
    86     mComms.unregisterDefaultListener(this);
    83     {
    87     return mComms.stop();
    84         iRunning = 0;
       
    85         iComms.unregisterDefaultListener(this);
       
    86         return iComms.stop();
       
    87     }
       
    88     else
       
    89     {
       
    90         return 0;
       
    91     }
       
    92 }
    88 }
    93 
    89 
    94 /**
    90 /**
    95  * Communicates with Java Installer. The following messages are used.
    91  * Communicates with Java Installer. The following messages are used.
    96  *
    92  *
   143             // result is KErrNone if the operation succeeded
   139             // result is KErrNone if the operation succeeded
   144             int result = iIntPairs[L"result"];
   140             int result = iIntPairs[L"result"];
   145 
   141 
   146             if (KErrNone != result)
   142             if (KErrNone != result)
   147             {
   143             {
   148                 // return common error information
   144                 // return common error information;
   149                 TRAP(err, iResults.AddIntL(KSifOutParam_ErrCode, result));
   145                 setCommonErrorInfo();
   150                 if (KErrNone != err)
       
   151                 {
       
   152                     ELOG1(EJavaInstaller,
       
   153                         "ResultsServer::processMessage iResults.AddIntL ErrCode err %d", err);
       
   154                 }
       
   155 
       
   156                 TRAP(err, iResults.AddIntL(
       
   157                     KSifOutParam_ErrCategory, iIntPairs[L"error-category"]));
       
   158                 if (KErrNone != err)
       
   159                 {
       
   160                     ELOG1(EJavaInstaller,
       
   161                         "ResultsServer::processMessage iResults.AddIntL ErrCategory err %d",
       
   162                         err);
       
   163                 }
       
   164 
       
   165                 HBufC *message = wstringToBuf(iStringPairs[L"error-message"]);
       
   166                 if (message == NULL)
       
   167                 {
       
   168                     ELOG(EJavaInstaller,
       
   169                           "ResultsServer::processMessage iResults.wstringToBuf returned NULL ");
       
   170                 }
       
   171                 else
       
   172                 {
       
   173                     TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessage, *message));
       
   174                     if (KErrNone != err)
       
   175                     {
       
   176                         ELOG1(EJavaInstaller,
       
   177                             "ResultsServer::processMessage iResults.AddStringL ErrMessage err %d",
       
   178                             err);
       
   179                     }
       
   180                     delete message;
       
   181                 }
       
   182 
       
   183                 message = wstringToBuf(iStringPairs[L"error-details"]);
       
   184                 if (message == NULL)
       
   185                 {
       
   186                     ELOG(EJavaInstaller,
       
   187                           "ResultsServer::processMessage iResults.wstringToBuf 2 returned NULL ");
       
   188                 }
       
   189                 else
       
   190                 {
       
   191                     TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessageDetails, *message));
       
   192                     if (KErrNone != err)
       
   193                     {
       
   194                         ELOG1(EJavaInstaller,
       
   195                             "ResultsServer::processMessage iResults.AddStringL ErrMessageDetails "
       
   196                             "err %d", err);
       
   197                     }
       
   198                     delete message;
       
   199                 }
       
   200 
   146 
   201                 if (INSTALL_OPERATION == operation)
   147                 if (INSTALL_OPERATION == operation)
   202                 {
   148                 {
   203                     ELOG1(EJavaInstaller,
   149                     ELOG1(EJavaInstaller,
   204                         "ResultsServer::processMessage, Install failed with error %d", result);
   150                         "ResultsServer::processMessage, Install failed with error %d", result);
   219             {
   165             {
   220                 // Operation succeeded
   166                 // Operation succeeded
   221 
   167 
   222                 // Overwrite (reset) the default error values set for the case where no
   168                 // Overwrite (reset) the default error values set for the case where no
   223                 // InstallerResultMessage is never received
   169                 // InstallerResultMessage is never received
   224                 TRAPD(err, iResults.AddIntL(KSifOutParam_ErrCategory, 0));
   170                 resetDefaultErrorValues();
   225                 if (KErrNone != err)
       
   226                 {
       
   227                     ELOG1(EJavaInstaller,
       
   228                         "ResultsServer::processMessage iResults.AddIntL ErrCategory err %d", err);
       
   229                 }
       
   230 
       
   231                 TRAP(err, iResults.AddIntL(KSifOutParam_ErrCode, 0));
       
   232                 if (KErrNone != err)
       
   233                 {
       
   234                     ELOG1(EJavaInstaller,
       
   235                         "ResultsServer::processMessage iResults.AddIntL ErrCode err %d", err);
       
   236                 }
       
   237 
       
   238 
   171 
   239                 if (INSTALL_OPERATION == operation)
   172                 if (INSTALL_OPERATION == operation)
   240                 {
   173                 {
   241                     // Return the component ids of the installed Java application.
   174                     // Return the component ids of the installed Java application.
   242                     TComponentId resultComponentId = iIntPairs[L"suite-cid"];
   175                     TComponentId resultComponentId = iIntPairs[L"suite-cid"];
   243                     TRAP(err, iResults.AddIntL(KSifOutParam_ComponentId, resultComponentId));
   176                     TRAP(err, mResults.AddIntL(KSifOutParam_ComponentId, resultComponentId));
   244                     if (KErrNone != err)
   177                     if (KErrNone != err)
   245                     {
   178                     {
   246                         ELOG1(EJavaInstaller,
   179                         ELOG1(EJavaInstaller,
   247                               "ResultsServer::processMessage iResults.AddIntL cid error %d", err);
   180                               "ResultsServer::processMessage mResults.AddIntL cid error %d", err);
   248                     }
   181                     }
   249                 }
   182                 }
   250                 else if (UNINSTALL_OPERATION == operation)
   183                 else if (UNINSTALL_OPERATION == operation)
   251                 {
   184                 {
   252                     // Return nothing if uninstall succeeds
   185                     // Return nothing if uninstall succeeds
   274             CommsMessage reply;
   207             CommsMessage reply;
   275             reply.replyTo(aMessage);
   208             reply.replyTo(aMessage);
   276             reply.setMessageId(INSTALLER_RESULT_RESPONSE_MESSAGE_ID);
   209             reply.setMessageId(INSTALLER_RESULT_RESPONSE_MESSAGE_ID);
   277             reply << 0;
   210             reply << 0;
   278 
   211 
   279             int err = iComms.send(reply);
   212             int err = mComms.send(reply);
   280             if (err != 0)
   213             if (err != 0)
   281             {
   214             {
   282                 ELOG1(EJavaInstaller,
   215                 ELOG1(EJavaInstaller,
   283                     "ResultsServer: Sending reply to Java Installer failed, err %d", err);
   216                     "ResultsServer: Sending reply to Java Installer failed, err %d", err);
   284             }
   217             }
   297 
   230 
   298     clearData();
   231     clearData();
   299 }
   232 }
   300 
   233 
   301 
   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 }
       
   322 
       
   323 
   302 void ResultsServer::clearData()
   324 void ResultsServer::clearData()
   303 {
   325 {
   304     iIntPairs.clear();
   326     iIntPairs.clear();
   305     iStringPairs.clear();
   327     iStringPairs.clear();
   306 }
   328 }
   335         ss << midletUidN;
   357         ss << midletUidN;
   336         ss << n;
   358         ss << n;
   337         ss >> midletUidN;
   359         ss >> midletUidN;
   338 
   360 
   339         //LOG1WSTR(EJavaInstaller, EInfo,
   361         //LOG1WSTR(EJavaInstaller, EInfo,
   340         //         "ResultsServer::processMessage: checking %s", midletUidN.c_str());
   362         //  "ResultsServer::processMessage: checking %S", midletUidN.c_str());
   341 
   363 
   342         int uid = iIntPairs[midletUidN];
   364         int uid = iIntPairs[midletUidN];
   343         if (uid == 0)
   365         if (uid == 0)
   344         {
   366         {
   345             // no more midlets in the suite
   367             // no more midlets in the suite
   361                 TUid::Uid(uid), midletName, KNullDesC(), KNullDesC());
   383                 TUid::Uid(uid), midletName, KNullDesC(), KNullDesC());
   362         applications.AppendL(applicationInfo);
   384         applications.AppendL(applicationInfo);
   363         CleanupStack::Pop(applicationInfo);
   385         CleanupStack::Pop(applicationInfo);
   364 
   386 
   365         n++;
   387         n++;
   366     }
   388     } // sanity check: no suite can have 10000 midlets
   367     while (n < 10000);  // sanity check: no suite can have 10000 midlets
   389     while (n < 10000);   // codescanner::magicnumbers
   368 
   390 
   369     CComponentInfo::CNode *rootNode = NULL;
   391     CComponentInfo::CNode *rootNode = NULL;
   370     rootNode = CComponentInfo::CNode::NewLC(
   392     rootNode = CComponentInfo::CNode::NewLC(
   371                    KSoftwareTypeJava,
   393                    KSoftwareTypeJava,
   372                    suiteName,
   394                    suiteName,
   383                    EFalse, // drive selection is not required
   405                    EFalse, // drive selection is not required
   384                    &applications
   406                    &applications
   385                );
   407                );
   386 
   408 
   387     // Store whole component info tree
   409     // Store whole component info tree
   388     iInfo.SetRootNodeL(rootNode);
   410     mInfo.SetRootNodeL(rootNode);
   389     CleanupStack::Pop(rootNode);
   411     CleanupStack::Pop(rootNode);
   390     CleanupStack::PopAndDestroy(&applications);
   412     CleanupStack::PopAndDestroy(&applications);
   391 }
   413 }