hti/PC_Tools/HTIGateway/ServicePlugins/HtiApplication/HtiApplication.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 */
       
    16 #include "HtiApplicationH.h"
       
    17 #include "HtiPlugin.h"
       
    18 #include "HtiSoapHandlerInterface.h"
       
    19 #include "hticommon.h"
       
    20 
       
    21 // Application control commands
       
    22 // NOTE: Only unicode versions of commands are used.
       
    23 //const int CMD_HTI_START_PROCESS         = 0x02;
       
    24 const int CMD_HTI_START_PROCESS_U         = 0x03;
       
    25 //const int CMD_HTI_STATUS_PROCESS        = 0x04;
       
    26 const int CMD_HTI_STATUS_PROCESS_U        = 0x05;
       
    27 const int CMD_HTI_STATUS_PROCESSID        = 0x06;
       
    28 const int CMD_HTI_START_PROCESS_RET_VAL_U = 0x07;
       
    29 //const int CMD_HTI_STOP_PROCESS          = 0x08;
       
    30 const int CMD_HTI_STOP_PROCESS_U          = 0x09;
       
    31 const int CMD_HTI_STOP_PROCESSID          = 0x0A;
       
    32 const int CMD_HTI_GET_PROCESS_EXIT_CODE   = 0x0B;
       
    33 //const int CMD_HTI_LIST_PROCESSES        = 0x0C;
       
    34 const int CMD_HTI_LIST_PROCESSES_U        = 0x0D;
       
    35 //const int CMD_HTI_START_PROCESS_RET_VAL = 0x0E;
       
    36 //const int CMD_HTI_START_APP             = 0x10;
       
    37 const int CMD_HTI_START_APP_U             = 0x11;
       
    38 //const int CMD_HTI_START_APP_UID         = 0x12;
       
    39 const int CMD_HTI_START_APP_UID_U         = 0x13;
       
    40 //const int CMD_HTI_START_DOC             = 0x14;
       
    41 const int CMD_HTI_START_DOC_U             = 0x15;
       
    42 //const int CMD_HTI_STATUS_APP            = 0x16;
       
    43 const int CMD_HTI_STATUS_APP_U            = 0x17;
       
    44 //const int CMD_HTI_STATUS_DOC            = 0x18;
       
    45 const int CMD_HTI_STATUS_DOC_U            = 0x19;
       
    46 const int CMD_HTI_STATUS_APP_UID          = 0x1A;
       
    47 //const int CMD_HTI_STOP_APP              = 0x1C;
       
    48 const int CMD_HTI_STOP_APP_U              = 0x1D;
       
    49 //const int CMD_HTI_STOP_DOC              = 0x1E;
       
    50 const int CMD_HTI_STOP_DOC_U              = 0x1F;
       
    51 const int CMD_HTI_STOP_APP_UID            = 0x20;
       
    52 //const int CMD_HTI_LIST_APPS               = 0x24;
       
    53 const int CMD_HTI_LIST_APPS_U             = 0x25;
       
    54 
       
    55 // Application install commands
       
    56 //const int CMD_HTI_INSTALL_SOFTWARE        = 0x30;
       
    57 const int CMD_HTI_INSTALL_SOFTWARE_U        = 0x31;
       
    58 const int CMD_HTI_UNINSTALL_SOFTWARE        = 0x32;
       
    59 const int CMD_HTI_UNINSTALL_SOFTWARE_NAME_U = 0x33;
       
    60 //const int CMD_HTI_UNINSTALL_SOFTWARE_NAME   = 0x34;
       
    61 
       
    62 // Application control response codes
       
    63 const int CMD_RESP_OK               = 0xF0;
       
    64 const int CMD_RESP_NOT_FOUND        = 0xF1;
       
    65 const int CMD_RESP_ALREADY_RUNNING  = 0xF2;
       
    66 const int CMD_RESP_ALREADY_STOPPED  = 0xF3;
       
    67 const int CMD_RESP_RUNNING          = 0xF4;
       
    68 const int CMD_RESP_KILLED           = 0xF5;
       
    69 const int CMD_RESP_PANIC            = 0xF6;
       
    70 
       
    71 //**********************************************************************************
       
    72 // HELPER FUNCTIONS
       
    73 //
       
    74 //**********************************************************************************
       
    75 
       
    76 //**********************************************************************************
       
    77 // ResponseCode2String
       
    78 //**********************************************************************************
       
    79 char* ResponseCode2String(struct soap* soap, BYTE code)
       
    80 {
       
    81     char tmp[50]; // 50 should be more than enough
       
    82 
       
    83     switch(code)
       
    84     {
       
    85     case CMD_RESP_OK:               sprintf(tmp, "ok"); break;
       
    86     case CMD_RESP_NOT_FOUND:        sprintf(tmp, "not found"); break;
       
    87     case CMD_RESP_ALREADY_RUNNING:  sprintf(tmp, "already running"); break;
       
    88     case CMD_RESP_ALREADY_STOPPED:  sprintf(tmp, "already stopped"); break;
       
    89     case CMD_RESP_RUNNING:          sprintf(tmp, "running"); break;
       
    90     case CMD_RESP_KILLED:           sprintf(tmp, "killed"); break;
       
    91     case CMD_RESP_PANIC:            sprintf(tmp, "panic"); break;
       
    92     default:                        sprintf(tmp, "unknown response code 0x%02x", code);
       
    93     }
       
    94 
       
    95     char* text = (char*) soap_malloc(soap, strlen(tmp)+1); // +1 is for null character
       
    96     memcpy(text, tmp, strlen(tmp)+1);
       
    97     return text;
       
    98 }
       
    99 
       
   100 //**********************************************************************************
       
   101 // ExitTypeCode2String
       
   102 //**********************************************************************************
       
   103 char* ExitTypeCode2String(struct soap* soap, BYTE code)
       
   104 {
       
   105     char tmp[50]; // 50 should be more than enough
       
   106 
       
   107     switch(code)
       
   108     {
       
   109     case 0:  sprintf(tmp, "killed"); break;
       
   110     case 1:  sprintf(tmp, "terminated"); break;
       
   111     case 2:  sprintf(tmp, "panic"); break;
       
   112     case 3:  sprintf(tmp, "running"); break;
       
   113     default: sprintf(tmp, "unknown exit type code 0x%02x", code);
       
   114     }
       
   115 
       
   116     char* text = (char*) soap_malloc(soap, strlen(tmp)+1); // +1 is for null character
       
   117     memcpy(text, tmp, strlen(tmp)+1);
       
   118     return text;
       
   119 }
       
   120 
       
   121 //**********************************************************************************
       
   122 // SOAP FUNCTIONS
       
   123 //
       
   124 //**********************************************************************************
       
   125 //**********************************************************************************
       
   126 // ns1__startProcess()
       
   127 //**********************************************************************************
       
   128 int ns1__startProcess(struct soap* soap,
       
   129                       wchar_t *fileName,
       
   130                       wchar_t *args,
       
   131                       struct startProcessResponse &r)
       
   132 {
       
   133     // Check parameters
       
   134     if ( check_mandatory_wcstring_parameter( soap, fileName, "fileName" ) )
       
   135         return SOAP_FAULT;
       
   136 
       
   137     // Construct & send HTI message
       
   138     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_START_PROCESS_U );
       
   139     msg.AddWCStringWithLengthByte( fileName );
       
   140     msg.AddWCStringWithLengthByte( args );
       
   141     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_30_SECONDS ) )
       
   142         return SOAP_FAULT;
       
   143 
       
   144     // Check response
       
   145     if ( msg.CheckMsgMinLen( 1 ) )
       
   146         return SOAP_FAULT;
       
   147 
       
   148     r._returnstartProcessResult.status = ResponseCode2String( soap, msg.GetByte(0) );
       
   149 
       
   150     if( msg.GetByte( 0 ) == CMD_RESP_OK )
       
   151     {
       
   152         // pid only returned if found
       
   153         if ( msg.CheckMsgExactLen( 5 ) )
       
   154             return SOAP_FAULT;
       
   155         r._returnstartProcessResult.pid = msg.GetInt(1);
       
   156     }
       
   157 
       
   158     return SOAP_OK;
       
   159 }
       
   160 
       
   161 //**********************************************************************************
       
   162 // ns1__stopProcess()
       
   163 //**********************************************************************************
       
   164 int ns1__stopProcess(struct soap* soap,
       
   165                      wchar_t *matchPattern,
       
   166                      char *&result)
       
   167 {
       
   168     // Check parameters
       
   169     if ( check_mandatory_wcstring_parameter( soap, matchPattern, "matchPattern" ) )
       
   170         return SOAP_FAULT;
       
   171 
       
   172     // Construct & send HTI message
       
   173     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STOP_PROCESS_U );
       
   174     msg.AddWCStringWithLengthByte( matchPattern );
       
   175     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   176         return SOAP_FAULT;
       
   177 
       
   178     // Check response
       
   179     if ( msg.CheckMsgExactLen( 1 ) )
       
   180         return SOAP_FAULT;
       
   181 
       
   182     result = ResponseCode2String( soap, msg.GetByte(0) );
       
   183 
       
   184     return SOAP_OK;
       
   185 }
       
   186 
       
   187 //**********************************************************************************
       
   188 // ns1__stopProcessById()
       
   189 //**********************************************************************************
       
   190 int ns1__stopProcessById(struct soap* soap,
       
   191                          int pid,
       
   192                          char *&result)
       
   193 {
       
   194     // Construct & send HTI message
       
   195     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STOP_PROCESSID );
       
   196     msg.AddInt( pid );
       
   197     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   198         return SOAP_FAULT;
       
   199 
       
   200     // Check response
       
   201     if ( msg.CheckMsgExactLen( 1 ) )
       
   202         return SOAP_FAULT;
       
   203 
       
   204     result = ResponseCode2String( soap, msg.GetByte(0) );
       
   205 
       
   206     return SOAP_OK;
       
   207 }
       
   208 
       
   209 //**********************************************************************************
       
   210 // ns1__getProcessStatus()
       
   211 //**********************************************************************************
       
   212 int ns1__getProcessStatus(struct soap* soap,
       
   213                           wchar_t *matchPattern,
       
   214                           char* &status)
       
   215 {
       
   216     // Check parameters
       
   217     if ( check_mandatory_wcstring_parameter( soap, matchPattern, "matchPattern" ) )
       
   218         return SOAP_FAULT;
       
   219 
       
   220     // Construct & send HTI message
       
   221     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STATUS_PROCESS_U );
       
   222     msg.AddWCStringWithLengthByte( matchPattern );
       
   223     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   224         return SOAP_FAULT;
       
   225 
       
   226     // Check response
       
   227     if ( msg.CheckMsgExactLen( 1 ) )
       
   228         return SOAP_FAULT;
       
   229 
       
   230     status = ResponseCode2String( soap, msg.GetByte(0) );
       
   231 
       
   232     return SOAP_OK;
       
   233 }
       
   234 
       
   235 //**********************************************************************************
       
   236 // ns1__getProcessStatusById()
       
   237 //**********************************************************************************
       
   238 int ns1__getProcessStatusById(struct soap* soap,
       
   239                               int pid,
       
   240                               char* &status)
       
   241 {
       
   242     // Construct & send HTI message
       
   243     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STATUS_PROCESSID );
       
   244     msg.AddInt( pid );
       
   245     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   246         return SOAP_FAULT;
       
   247 
       
   248     // Check response
       
   249     if ( msg.CheckMsgExactLen( 1 ) )
       
   250         return SOAP_FAULT;
       
   251 
       
   252     status = ResponseCode2String( soap, msg.GetByte(0) );
       
   253 
       
   254     return SOAP_OK;
       
   255 }
       
   256 
       
   257 //**********************************************************************************
       
   258 // ns1__startApp()
       
   259 //**********************************************************************************
       
   260 int ns1__startApp(struct soap* soap,
       
   261                   wchar_t *appName,
       
   262                   wchar_t *docName,
       
   263                   struct startAppResponse &r)
       
   264 {
       
   265     // Check parameters
       
   266     if ( check_mandatory_wcstring_parameter( soap, appName, "appName" ) )
       
   267         return SOAP_FAULT;
       
   268 
       
   269     // Construct & send HTI message
       
   270     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_START_APP_U );
       
   271     msg.AddWCStringWithLengthByte( appName );
       
   272     msg.AddWCStringWithLengthByte( docName );
       
   273     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   274         return SOAP_FAULT;
       
   275 
       
   276     // Check response
       
   277     if ( msg.CheckMsgMinLen( 1 ) )
       
   278         return SOAP_FAULT;
       
   279 
       
   280     r._returnstartAppResult.status = ResponseCode2String( soap, msg.GetByte(0) );
       
   281 
       
   282     if( msg.GetByte( 0 ) == CMD_RESP_OK )
       
   283     {
       
   284         // threadId only returned if found
       
   285         if ( msg.CheckMsgExactLen( 5 ) )
       
   286             return SOAP_FAULT;
       
   287         r._returnstartAppResult.threadId = msg.GetInt(1);
       
   288     }
       
   289 
       
   290     return SOAP_OK;
       
   291 }
       
   292 
       
   293 //**********************************************************************************
       
   294 // ns1__startAppByUid()
       
   295 //**********************************************************************************
       
   296 int ns1__startAppByUid(struct soap* soap,
       
   297                        int uid,
       
   298                        wchar_t *docName,
       
   299                        struct startAppByUidResponse &r)
       
   300 {
       
   301     // Construct & send HTI message
       
   302     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_START_APP_UID_U );
       
   303     msg.AddInt( uid );
       
   304     msg.AddWCStringWithLengthByte( docName );
       
   305     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   306         return SOAP_FAULT;
       
   307 
       
   308     // Check response
       
   309     if ( msg.CheckMsgMinLen( 1 ) )
       
   310         return SOAP_FAULT;
       
   311 
       
   312     r._returnstartAppByUidResult.status = ResponseCode2String( soap, msg.GetByte(0) );
       
   313 
       
   314     if( msg.GetByte( 0 ) == CMD_RESP_OK )
       
   315     {
       
   316         // threadId only returned if found
       
   317         if ( msg.CheckMsgExactLen( 5 ) )
       
   318             return SOAP_FAULT;
       
   319         r._returnstartAppByUidResult.threadId = msg.GetInt(1);
       
   320     }
       
   321 
       
   322     return SOAP_OK;
       
   323 }
       
   324 
       
   325 //**********************************************************************************
       
   326 // ns1__startDoc()
       
   327 //**********************************************************************************
       
   328 int ns1__startDoc(struct soap* soap,
       
   329                   wchar_t *docName,
       
   330                   struct startDocResponse &r)
       
   331 {
       
   332     // Check parameters
       
   333     if ( check_mandatory_wcstring_parameter( soap, docName, "docName" ) )
       
   334         return SOAP_FAULT;
       
   335 
       
   336     // Construct & send HTI message
       
   337     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_START_DOC_U );
       
   338     msg.AddWCStringWithLengthByte( docName );
       
   339     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   340         return SOAP_FAULT;
       
   341 
       
   342     // Check response
       
   343     if ( msg.CheckMsgMinLen( 1 ) )
       
   344         return SOAP_FAULT;
       
   345 
       
   346     r._returnstartDocResult.status = ResponseCode2String( soap, msg.GetByte(0) );
       
   347 
       
   348     if( msg.GetByte( 0 ) == CMD_RESP_OK )
       
   349     {
       
   350         // threadId only returned if found
       
   351         if ( msg.CheckMsgExactLen( 5 ) )
       
   352             return SOAP_FAULT;
       
   353         r._returnstartDocResult.threadId = msg.GetInt(1);
       
   354     }
       
   355 
       
   356     return SOAP_OK;
       
   357 }
       
   358 
       
   359 //**********************************************************************************
       
   360 // ns1__getAppStatus()
       
   361 //**********************************************************************************
       
   362 int ns1__getAppStatus(struct soap* soap,
       
   363                       wchar_t *appName,
       
   364                       char* &status)
       
   365 {
       
   366     // Check parameters
       
   367     if ( check_mandatory_wcstring_parameter( soap, appName, "appName" ) )
       
   368         return SOAP_FAULT;
       
   369 
       
   370     // Construct & send HTI message
       
   371     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STATUS_APP_U );
       
   372     msg.AddWCStringWithLengthByte( appName );
       
   373     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   374         return SOAP_FAULT;
       
   375 
       
   376     // Check response
       
   377     if ( msg.CheckMsgExactLen( 1 ) )
       
   378         return SOAP_FAULT;
       
   379 
       
   380     status = ResponseCode2String( soap, msg.GetByte(0) );
       
   381 
       
   382     return SOAP_OK;
       
   383 }
       
   384 
       
   385 //**********************************************************************************
       
   386 // ns1__getAppStatusByUid()
       
   387 //**********************************************************************************
       
   388 int ns1__getAppStatusByUid(struct soap* soap,
       
   389                            int uid,
       
   390                            char* &status)
       
   391 {
       
   392     // Construct & send HTI message
       
   393     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STATUS_APP_UID );
       
   394     msg.AddInt( uid );
       
   395     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   396         return SOAP_FAULT;
       
   397 
       
   398     // Check response
       
   399     if ( msg.CheckMsgExactLen( 1 ) )
       
   400         return SOAP_FAULT;
       
   401 
       
   402     status = ResponseCode2String( soap, msg.GetByte(0) );
       
   403 
       
   404     return SOAP_OK;
       
   405 }
       
   406 
       
   407 //**********************************************************************************
       
   408 // ns1__getAppStatusByDoc()
       
   409 //**********************************************************************************
       
   410 int ns1__getAppStatusByDoc(struct soap* soap,
       
   411                            wchar_t *docName,
       
   412                            char* &status)
       
   413 {
       
   414     // Check parameters
       
   415     if ( check_mandatory_wcstring_parameter( soap, docName, "docName" ) )
       
   416         return SOAP_FAULT;
       
   417 
       
   418     // Construct & send HTI message
       
   419     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STATUS_DOC_U );
       
   420     msg.AddWCStringWithLengthByte( docName );
       
   421     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   422         return SOAP_FAULT;
       
   423 
       
   424     // Check response
       
   425     if ( msg.CheckMsgExactLen( 1 ) )
       
   426         return SOAP_FAULT;
       
   427 
       
   428     status = ResponseCode2String( soap, msg.GetByte(0) );
       
   429 
       
   430     return SOAP_OK;
       
   431 }
       
   432 
       
   433 //**********************************************************************************
       
   434 // ns1__stopApp()
       
   435 //**********************************************************************************
       
   436 int ns1__stopApp(struct soap* soap,
       
   437                  wchar_t *appName,
       
   438                  char *&result)
       
   439 {
       
   440     // Check parameters
       
   441     if ( check_mandatory_wcstring_parameter( soap, appName, "appName" ) )
       
   442         return SOAP_FAULT;
       
   443 
       
   444     // Construct & send HTI message
       
   445     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STOP_APP_U );
       
   446     msg.AddWCStringWithLengthByte( appName );
       
   447     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   448         return SOAP_FAULT;
       
   449 
       
   450     // Check response
       
   451     if ( msg.CheckMsgExactLen( 1 ) )
       
   452         return SOAP_FAULT;
       
   453 
       
   454     result = ResponseCode2String( soap, msg.GetByte(0) );
       
   455 
       
   456     return SOAP_OK;
       
   457 }
       
   458 
       
   459 //**********************************************************************************
       
   460 // ns1__stopAppByUid()
       
   461 //**********************************************************************************
       
   462 int ns1__stopAppByUid(struct soap* soap,
       
   463                       int uid,
       
   464                       char *&result)
       
   465 {
       
   466     // Construct & send HTI message
       
   467     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STOP_APP_UID );
       
   468     msg.AddInt( uid );
       
   469     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   470         return SOAP_FAULT;
       
   471 
       
   472     // Check response
       
   473     if ( msg.CheckMsgExactLen( 1 ) )
       
   474         return SOAP_FAULT;
       
   475 
       
   476     result = ResponseCode2String( soap, msg.GetByte(0) );
       
   477 
       
   478     return SOAP_OK;
       
   479 }
       
   480 
       
   481 //**********************************************************************************
       
   482 // ns1__stopAppByDoc()
       
   483 //**********************************************************************************
       
   484 int ns1__stopAppByDoc(struct soap* soap,
       
   485                       wchar_t *docName,
       
   486                       char *&result)
       
   487 {
       
   488     // Check parameters
       
   489     if ( check_mandatory_wcstring_parameter( soap, docName, "docName" ) )
       
   490         return SOAP_FAULT;
       
   491 
       
   492     // Construct & send HTI message
       
   493     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_STOP_DOC_U );
       
   494     msg.AddWCStringWithLengthByte( docName );
       
   495     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   496         return SOAP_FAULT;
       
   497 
       
   498     // Check response
       
   499     if ( msg.CheckMsgExactLen( 1 ) )
       
   500         return SOAP_FAULT;
       
   501 
       
   502     result = ResponseCode2String( soap, msg.GetByte(0) );
       
   503 
       
   504     return SOAP_OK;
       
   505 }
       
   506 
       
   507 //**********************************************************************************
       
   508 // ns1__listProcesses()
       
   509 //**********************************************************************************
       
   510 int ns1__listProcesses(struct soap* soap,
       
   511                        wchar_t *matchPattern,
       
   512                        ArrayOfHtiProcess *HtiProcesses)
       
   513 {
       
   514     // Construct & send HTI message
       
   515     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_LIST_PROCESSES_U );
       
   516     msg.AddWCStringWithLengthByte( matchPattern );
       
   517     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   518         return SOAP_FAULT;
       
   519 
       
   520     // Check response
       
   521     if ( msg.CheckMsgMinLen( 1 ) )
       
   522         return SOAP_FAULT;
       
   523 
       
   524     if(msg.GetByte(0) != CMD_RESP_OK)
       
   525     {
       
   526         // This sould happen only if message is corrupted somehow...
       
   527         soap->error = soap_receiver_fault_format(soap, "HtiError",
       
   528             "response code error (0x%x)", msg.GetByte(0));
       
   529         return SOAP_FAULT;
       
   530     }
       
   531 
       
   532     // Fill & alloc soap stuff
       
   533     HtiProcesses->__size = (int) msg.GetWord(1);
       
   534     HtiProcesses->__ptr = soap_new_ns1__HtiProcess(soap, HtiProcesses->__size);
       
   535 
       
   536     // Go through processes
       
   537     int offset = 3;
       
   538     ns1__HtiProcess *process = HtiProcesses->__ptr;
       
   539     for(int i = 0; i < HtiProcesses->__size; i++)
       
   540     {
       
   541         process->processId = msg.GetInt(offset);//pid;
       
   542         process->processStatus = ResponseCode2String(soap, msg.GetByte(offset+4));
       
   543 
       
   544         // Get processname
       
   545         char* tmp = (char*) msg.GetMsgBody();
       
   546         tmp += offset+6;
       
   547         int processNameLen = msg.GetByte(offset+5);
       
   548         process->processName = (char*) soap_malloc(soap, processNameLen+1);
       
   549         memcpy(process->processName, tmp, processNameLen);
       
   550         process->processName[processNameLen] = 0x0; //  add null
       
   551 
       
   552         // for the next iteration
       
   553         offset += 4+1+1+processNameLen;
       
   554         process++;
       
   555     }
       
   556 
       
   557     return SOAP_OK;
       
   558 }
       
   559 
       
   560 //**********************************************************************************
       
   561 // ns1__startProcessRetVal()
       
   562 //**********************************************************************************
       
   563 int ns1__startProcessRetVal(struct soap* soap,
       
   564                             wchar_t *fileName,
       
   565                             wchar_t *args,
       
   566                             struct startProcessResponse &r)
       
   567 {
       
   568     // Check parameters
       
   569     if ( check_mandatory_wcstring_parameter( soap, fileName, "fileName" ) )
       
   570         return SOAP_FAULT;
       
   571 
       
   572     // Construct & send HTI message
       
   573     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_START_PROCESS_RET_VAL_U );
       
   574     msg.AddWCStringWithLengthByte( fileName );
       
   575     msg.AddWCStringWithLengthByte( args );
       
   576     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_30_SECONDS ) )
       
   577         return SOAP_FAULT;
       
   578 
       
   579     // Check response
       
   580     if ( msg.CheckMsgMinLen( 1 ) )
       
   581         return SOAP_FAULT;
       
   582 
       
   583     r._returnstartProcessResult.status = ResponseCode2String( soap, msg.GetByte(0) );
       
   584 
       
   585     if( msg.GetByte( 0 ) == CMD_RESP_OK )
       
   586     {
       
   587         // pid only returned if found
       
   588         if ( msg.CheckMsgExactLen( 5 ) )
       
   589             return SOAP_FAULT;
       
   590         r._returnstartProcessResult.pid = msg.GetInt(1);
       
   591     }
       
   592 
       
   593     return SOAP_OK;
       
   594 }
       
   595 
       
   596 //**********************************************************************************
       
   597 // ns1__getProcessExitCode()
       
   598 //**********************************************************************************
       
   599 int ns1__getProcessExitCode(struct soap* soap,
       
   600                             int pid,
       
   601                             struct getProcessExitCodeResponse &r)
       
   602 {
       
   603     // Construct & send HTI message
       
   604     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_GET_PROCESS_EXIT_CODE );
       
   605     msg.AddInt( pid );
       
   606     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   607         return SOAP_FAULT;
       
   608 
       
   609     // Check response
       
   610     if ( msg.CheckMsgMinLen( 7 ) )
       
   611         return SOAP_FAULT;
       
   612     if ( msg.GetByte( 0 ) != CMD_RESP_OK )
       
   613         return SOAP_FAULT;
       
   614 
       
   615     r._returngetProcessExitCodeResult.exitType = ExitTypeCode2String( soap, msg.GetByte( 1 ) );
       
   616     r._returngetProcessExitCodeResult.exitReason = msg.GetInt( 2 );
       
   617     r._returngetProcessExitCodeResult.exitCategory = msg.GetSoapString( 7, (int) msg.GetByte( 6 ) );
       
   618 
       
   619     return SOAP_OK;
       
   620 }
       
   621 
       
   622 //**********************************************************************************
       
   623 // ns1__installSoftware()
       
   624 //**********************************************************************************
       
   625 int ns1__installSoftware(struct soap* soap,
       
   626                          wchar_t *installPackagePath,
       
   627                          bool upgrade,
       
   628                          bool optionalItems,
       
   629                          bool ocsp,
       
   630                          bool ignoreOCSPWarnings,
       
   631                          bool installUntrusted,
       
   632                          bool allowPackageInfo,
       
   633                          bool grantUserCapabilities,
       
   634                          bool killApp,
       
   635                          bool overwrite,
       
   636                          bool download,
       
   637                          wchar_t *username,
       
   638                          wchar_t *password,
       
   639                          char *drive,
       
   640                          unsigned char language,
       
   641                          bool usePhoneLanguage,
       
   642                          bool upgradeData,
       
   643                          struct ns1__installSoftwareResponse *out)
       
   644 {
       
   645     // Check parameters
       
   646     if ( check_mandatory_wcstring_parameter(
       
   647              soap, installPackagePath, "installPackagePath" ) )
       
   648         return SOAP_FAULT;
       
   649     if ( check_mandatory_string_parameter( soap, drive, "drive" ) )
       
   650         return SOAP_FAULT;
       
   651 
       
   652     // Construct HTI message
       
   653     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_INSTALL_SOFTWARE_U );
       
   654     msg.AddWCStringWithLengthByte( installPackagePath );
       
   655     msg.AddByte( upgrade );
       
   656     msg.AddByte( optionalItems );
       
   657     msg.AddByte( ocsp );
       
   658     msg.AddByte( ignoreOCSPWarnings );
       
   659     msg.AddByte( installUntrusted );
       
   660     msg.AddByte( allowPackageInfo );
       
   661     msg.AddByte( grantUserCapabilities );
       
   662     msg.AddByte( killApp );
       
   663     msg.AddByte( overwrite );
       
   664     msg.AddByte( download );
       
   665     msg.AddWCStringWithLengthByteZero( username );
       
   666     msg.AddWCStringWithLengthByteZero( password );
       
   667     msg.AddString( drive );
       
   668     msg.AddByte( language );
       
   669     msg.AddByte( usePhoneLanguage );
       
   670     msg.AddByte( upgradeData );
       
   671 
       
   672     // Send message
       
   673     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_60_SECONDS ) )
       
   674         return SOAP_FAULT;
       
   675 
       
   676     // Check response
       
   677     if ( msg.CheckMsgExactLen( 1 ) != SOAP_OK )
       
   678         return SOAP_FAULT;
       
   679     if ( msg.GetByte( 0 ) != CMD_RESP_OK )
       
   680         return SOAP_FAULT;
       
   681 
       
   682     return SOAP_OK;
       
   683 }
       
   684 
       
   685 //**********************************************************************************
       
   686 // ns1__uninstallSoftware()
       
   687 //**********************************************************************************
       
   688 int ns1__uninstallSoftware(struct soap* soap,
       
   689                            int uid,
       
   690                            bool killApp,
       
   691                            bool breakDependency,
       
   692                            enum ns1__mimeType  mimeType,
       
   693                            struct ns1__uninstallSoftwareResponse *out)
       
   694 {
       
   695     // Construct HTI message
       
   696     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_UNINSTALL_SOFTWARE );
       
   697     msg.AddInt( uid );
       
   698     msg.AddByte( killApp );
       
   699     msg.AddByte( breakDependency );
       
   700     msg.AddByte( mimeType );
       
   701 
       
   702     // Send message
       
   703     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_60_SECONDS ) )
       
   704         return SOAP_FAULT;
       
   705 
       
   706     // Check response
       
   707     if ( msg.CheckMsgExactLen( 1 ) != SOAP_OK )
       
   708         return SOAP_FAULT;
       
   709     if ( msg.GetByte( 0 ) != CMD_RESP_OK )
       
   710         return SOAP_FAULT;
       
   711 
       
   712     return SOAP_OK;
       
   713 }
       
   714 
       
   715 //**********************************************************************************
       
   716 // ns1__uninstallSoftwareByName()
       
   717 //**********************************************************************************
       
   718 int ns1__uninstallSoftwareByName(struct soap* soap,
       
   719                                  wchar_t *packageName,
       
   720                                  bool killApp,
       
   721                                  bool breakDependency,
       
   722                                  enum ns1__mimeType  mimeType,
       
   723                                  struct ns1__uninstallSoftwareByNameResponse *out)
       
   724 {
       
   725     if ( check_mandatory_wcstring_parameter(
       
   726              soap, packageName, "packageName" ) )
       
   727         return SOAP_FAULT;
       
   728 
       
   729     // Construct HTI message
       
   730     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_UNINSTALL_SOFTWARE_NAME_U );
       
   731     msg.AddWCStringWithLengthByte( packageName );
       
   732     msg.AddByte( killApp );
       
   733     msg.AddByte( breakDependency );
       
   734     msg.AddByte( mimeType );
       
   735 
       
   736     // Send message
       
   737     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_60_SECONDS ) )
       
   738         return SOAP_FAULT;
       
   739 
       
   740     // Check response
       
   741     if ( msg.CheckMsgExactLen( 1 ) != SOAP_OK )
       
   742         return SOAP_FAULT;
       
   743     if ( msg.GetByte( 0 ) != CMD_RESP_OK )
       
   744         return SOAP_FAULT;
       
   745 
       
   746     return SOAP_OK;
       
   747 }
       
   748 
       
   749 //**********************************************************************************
       
   750 // ns1__listRunningApps()
       
   751 //**********************************************************************************
       
   752 int ns1__listRunningApps(struct soap* soap,
       
   753                          bool includeHidden,
       
   754                          bool includeSystem,
       
   755                          ArrayOfHtiRunningApp *htiApps)
       
   756 {
       
   757     // Construct & send HTI message
       
   758     HtiMsgHelper msg( soap, HTI_APPLICATION_UID, CMD_HTI_LIST_APPS_U );
       
   759     msg.AddByte( includeHidden );
       
   760     msg.AddByte( includeSystem );
       
   761     if ( msg.SendReceiveMsg( HTIMSG_TIMEOUT_10_SECONDS ) )
       
   762         return SOAP_FAULT;
       
   763 
       
   764     // Check response
       
   765     if ( msg.CheckMsgMinLen( 3 ) )
       
   766         return SOAP_FAULT;
       
   767 
       
   768     if ( msg.GetByte(0) != CMD_RESP_OK )
       
   769     {
       
   770         // This sould happen only if message is corrupted somehow...
       
   771         soap->error = soap_receiver_fault_format(soap, "HtiError",
       
   772             "response code error (0x%x)", msg.GetByte(0));
       
   773         return SOAP_FAULT;
       
   774     }
       
   775 
       
   776     // Fill & alloc soap stuff
       
   777     htiApps->__size = (int) msg.GetWord( 1 );
       
   778     htiApps->__ptr = soap_new_ns1__HtiRunningApp( soap, htiApps->__size );
       
   779 
       
   780     // Go through apps
       
   781     int offset = 3;
       
   782     ns1__HtiRunningApp *app = htiApps->__ptr;
       
   783     for ( int i = 0; i < htiApps->__size; i++ )
       
   784     {
       
   785         // App UID
       
   786         app->uid = msg.GetInt( offset );
       
   787         offset += 4;
       
   788 
       
   789         // Caption
       
   790         int captionLen = msg.GetByte( offset );
       
   791         offset++;
       
   792         app->caption = msg.GetSoapWCString( offset, captionLen );
       
   793         offset += captionLen * 2;
       
   794 
       
   795         // Document name
       
   796         int docLen = msg.GetByte( offset );
       
   797         offset++;
       
   798         app->document = msg.GetSoapWCString( offset, docLen );
       
   799         offset += docLen * 2;
       
   800 
       
   801         // Flags
       
   802         app->hidden = msg.GetByte( offset );
       
   803         offset++;
       
   804         app->system = msg.GetByte( offset );
       
   805         offset++;
       
   806         app->ready = msg.GetByte( offset );
       
   807         offset++;
       
   808         app->busy = msg.GetByte( offset );
       
   809         offset++;
       
   810         app->closable = msg.GetByte( offset );
       
   811         offset++;   
       
   812 
       
   813         // Advance the array pointer for the next iteration
       
   814         app++;
       
   815     }
       
   816 
       
   817     return SOAP_OK;
       
   818 }