mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsoperation.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2006, 2007 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:  These classes implement dps operations replies. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32debug.h>
       
    20 #include "dpsoperation.h"
       
    21 #include "dpsconst.h"
       
    22 #include "dpstransaction.h"
       
    23 #include "pictbridge.h"
       
    24 #include "dpsxmlparser.h"
       
    25 #include "dpsxmlgenerator.h"
       
    26 #include "dpsstatemachine.h"
       
    27 
       
    28 #ifdef _DEBUG
       
    29 #	define IF_DEBUG(t) {RDebug::t;}
       
    30 #else
       
    31 #	define IF_DEBUG(t)
       
    32 #endif
       
    33 
       
    34 const TInt KConfigPrintService = 5;
       
    35 const TInt KCopyFileWidth = 3;
       
    36 // ---------------------------------------------------------------------------
       
    37 // 
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C void TMDpsOperation::CreateReqScriptL(
       
    41                                       const TDpsArgArray& aArguments, 
       
    42                                       const TDpsEleArray& /*aElements*/,
       
    43                                       TDpsAttribute /*aAttribute*/, 
       
    44                                       RWriteStream& aScript, 
       
    45                                       CDpsTransaction* aTrader)
       
    46     {
       
    47     IF_DEBUG(Print(_L(">>>TMDpsOperation::CreateReqScript")));        
       
    48     CDpsXmlGenerator* g = aTrader->Generator();
       
    49     g->StartDocumentL(aScript);
       
    50     g->StartInputL(aScript);
       
    51     TInt count = aArguments.Count();
       
    52     if (!count)
       
    53 	    {
       
    54 		g->StartOperationL((TDpsOperation)iOperation, aScript, ETrue);
       
    55 		}
       
    56 	else
       
    57 		{
       
    58 		g->StartOperationL((TDpsOperation)iOperation, aScript);
       
    59 		for (TInt i = 0; i < count; i++)
       
    60 			{
       
    61 			g->CreateArgL(aScript, aArguments[i]);
       
    62 			}
       
    63 		g->EndOperationL((TDpsOperation)iOperation, aScript);	
       
    64 		}
       
    65 			
       
    66     g->EndInputL(aScript);
       
    67 	g->EndDocumentL(aScript);	
       
    68 	IF_DEBUG(Print(_L("<<<TMDpsOperation::CreateReqScript")));        	
       
    69     }
       
    70     
       
    71 // ---------------------------------------------------------------------------
       
    72 // Some request parameters should be checked
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C TInt TDpsStartJob::FillReqArgs(TDpsArgArray& aArgs, 
       
    76                                         TDpsEleArray& aElements,
       
    77                                         TDpsAttribute& /*aAttrib*/, 
       
    78                                         CDpsTransaction* aTrader)
       
    79     {
       
    80     IF_DEBUG(Print(_L(">>>TDpsStartJob::FillReqArgs")));                    
       
    81     TInt imageCount = iReqParam.iPrintInfo.Count();
       
    82     if (!imageCount) 
       
    83         {
       
    84         return KErrUnknown;
       
    85         }
       
    86     TUint32* objectHandles = new TUint32[imageCount];
       
    87     if (!objectHandles)
       
    88         {
       
    89         return KErrNoMemory;
       
    90         }
       
    91     for (TInt i = 0; i < imageCount; i++)
       
    92         {
       
    93         TInt err = aTrader->Engine()->Ptp().
       
    94              GetObjectHandleByName(
       
    95                  iReqParam.iPrintInfo[i].iFile, objectHandles[i], ETrue); 
       
    96         if (err != KErrNone)
       
    97             {
       
    98             IF_DEBUG(Print(_L("---error %d"), err));
       
    99             
       
   100             delete[] objectHandles;
       
   101             return err;
       
   102             }
       
   103         }
       
   104     TDpsArg* argsP = new TDpsArg[iReqParam.GetParamNum()];
       
   105     if (!argsP)
       
   106         {
       
   107 		delete[] objectHandles;
       
   108         return KErrNoMemory;
       
   109         }
       
   110     TDpsEle* elemsP = new TDpsEle[1 + imageCount];
       
   111     if (!elemsP)
       
   112         {
       
   113 		delete[] argsP;
       
   114 		delete[] objectHandles;
       
   115         return KErrNoMemory;
       
   116         }
       
   117     // jobConfig    
       
   118     TInt count = iReqParam.iJobConfig.Count();
       
   119               
       
   120     elemsP[0].iElement = EDpsJobConfig;
       
   121     elemsP[0].iNum = count;
       
   122     aElements.Append(elemsP[0]);
       
   123     for (TInt i = 0; i < count; i++)
       
   124         {
       
   125         argsP[i].iElement = iReqParam.iJobConfig[i].iElement;
       
   126     	// the parameter only has high bytes (0x1234)
       
   127     	argsP[i].iContent.AppendNumUC(iReqParam.iJobConfig[i].iContent, EHex);
       
   128     	// we have to append the low bytes (0000)
       
   129     	argsP[i].iContent.Append(KDpsLowZero);
       
   130     	aArgs.Append(argsP[i]);
       
   131     	IF_DEBUG(Print(_L("the element is %d"), argsP[i].iElement));
       
   132     	IF_DEBUG(Print(_L("the content is %S"), &(argsP[i].iContent)));
       
   133     	}    
       
   134     	
       
   135     // printInfo
       
   136     for (TInt j = 0; j < imageCount; j++)
       
   137         {
       
   138     	// there is at least one argument for fileID
       
   139     	TInt k = 1;
       
   140     	elemsP[j + 1].iElement = EDpsPrintInfo;
       
   141     	argsP[count].iElement = EDpsArgFileID;
       
   142     	argsP[count].iContent.AppendNumFixedWidth(objectHandles[j], EHex, 
       
   143     	                                          KFullWordWidth);
       
   144     	aArgs.Append(argsP[count]);
       
   145     
       
   146     	IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   147     	IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   148     	count++;
       
   149     	
       
   150     	// not empty
       
   151     	if (iReqParam.iPrintInfo[j].iFileName)
       
   152     	    {
       
   153     	    argsP[count].iElement = EDpsArgFileName;
       
   154     	    argsP[count].iContent.Copy(iReqParam.iPrintInfo[j].iFile);
       
   155     	    aArgs.Append(argsP[count]);
       
   156     	    
       
   157     	    IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   158     	    IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   159     	    
       
   160     	    k++; count++;
       
   161     	    }
       
   162     	// not empty    
       
   163     	if (iReqParam.iPrintInfo[j].iDate.Size())
       
   164     	    {
       
   165             argsP[count].iElement = EDpsArgDate;
       
   166             argsP[count].iContent.Copy(iReqParam.iPrintInfo[j].iDate);
       
   167             aArgs.Append(argsP[count]);
       
   168             IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   169     	    IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   170             k++; count++;
       
   171     	    }
       
   172     	if (iReqParam.iPrintInfo[j].iCopies != 0)
       
   173     	    {
       
   174             argsP[count].iElement = EDpsArgCopies;
       
   175             argsP[count].iContent.AppendNumFixedWidthUC(
       
   176                 iReqParam.iPrintInfo[j].iCopies, EDecimal, KCopyFileWidth);
       
   177             aArgs.Append(argsP[count]);
       
   178             IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   179     	    IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   180     	    k++; count++;
       
   181     	    }    
       
   182     	if (iReqParam.iPrintInfo[j].iPrtPID != 0)
       
   183     	    {
       
   184             argsP[count].iElement = EDpsArgPrtPID;
       
   185             argsP[count].iContent.AppendNumUC(iReqParam.iPrintInfo[j].iPrtPID);
       
   186             aArgs.Append(argsP[count]);
       
   187             IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   188     	    IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   189     	    k++; count++;
       
   190     	    }
       
   191     	if (iReqParam.iPrintInfo[j].iCopyID != 0)
       
   192     	    {
       
   193             argsP[count].iElement = EDpsArgCopyID;
       
   194             argsP[count].iContent.AppendNumUC(iReqParam.iPrintInfo[j].iCopyID);
       
   195             aArgs.Append(argsP[count]);
       
   196             IF_DEBUG(Print(_L("the element is %d"), argsP[count].iElement));
       
   197     	    IF_DEBUG(Print(_L("the content is %S"), &(argsP[count].iContent)));
       
   198     	    k++; count++;
       
   199     	    }
       
   200         
       
   201     	elemsP[j + 1].iNum = k;
       
   202     	aElements.Append(elemsP[j + 1]);    
       
   203     	}
       
   204     	        
       
   205     delete[] objectHandles;	
       
   206     delete[] argsP;
       
   207     delete[] elemsP;
       
   208     IF_DEBUG(Print(_L("<<<TDpsStartJob::FillReqArgs")));                        
       
   209     return KErrNone;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // 
       
   214 // ---------------------------------------------------------------------------
       
   215 // 
       
   216 EXPORT_C void TDpsStartJob::CreateReqScriptL(const TDpsArgArray& aArguments, 
       
   217                                             const TDpsEleArray& aElements,
       
   218                                             TDpsAttribute /*aAttribute*/,  
       
   219                                             RWriteStream& aScript, 
       
   220                                             CDpsTransaction* aTrader)
       
   221     {
       
   222     IF_DEBUG(Print(_L(">>>TDpsStartJob::CreateReqScript")));                        
       
   223     CDpsXmlGenerator* g = aTrader->Generator();
       
   224     g->StartDocumentL(aScript);
       
   225     g->StartInputL(aScript);
       
   226     g->StartOperationL((TDpsOperation)iOperation, aScript);
       
   227     TInt count = aElements.Count();
       
   228     TInt limit = 0;
       
   229     for (TInt i = 0; i < count; i++)
       
   230 	    {
       
   231 		g->StartElementL(aElements[i].iElement, aScript);
       
   232 		TInt init = limit;
       
   233 		limit = (i == 0 ? aElements[0].iNum : limit + aElements[i].iNum);
       
   234 		for (TInt j = init; j < limit; j++)
       
   235 			{
       
   236 			g->CreateArgL(aScript,aArguments[j]);
       
   237 			}
       
   238 		g->EndElementL(aElements[i].iElement, aScript);	
       
   239 		}
       
   240 	g->EndOperationL((TDpsOperation)iOperation, aScript);
       
   241 	g->EndInputL(aScript);
       
   242 	g->EndDocumentL(aScript);	
       
   243 	IF_DEBUG(Print(_L("<<<TDpsStartJob::CreateReqScript")));                        	
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // 
       
   248 // ---------------------------------------------------------------------------
       
   249 //    
       
   250 EXPORT_C TInt TDpsAbortJob::FillReqArgs(TDpsArgArray& aArgs, 
       
   251                                         TDpsEleArray& /*aElems*/,
       
   252                                         TDpsAttribute& /*aAttrib*/, 
       
   253                                         CDpsTransaction* /*aParam*/)
       
   254     {
       
   255     IF_DEBUG(Print(_L(">>>TDpsAbortJob::FillReqArgs")));                            
       
   256     TDpsArg arg;
       
   257     arg.iElement = EDpsArgAbortStyle;
       
   258     arg.iContent.AppendNumUC(iReqParam.iAbortStyle, EHex);
       
   259     arg.iContent.Append(KDpsLowZero);
       
   260     aArgs.Append(arg);
       
   261     IF_DEBUG(Print(_L("<<<TDpsAbortJob::FillReqArgs")));                            
       
   262     return KErrNone;
       
   263     }
       
   264     
       
   265 // ---------------------------------------------------------------------------
       
   266 // Some request parameters should be checked
       
   267 // ---------------------------------------------------------------------------
       
   268 //    
       
   269 EXPORT_C TInt TDpsGetCapability::FillReqArgs(TDpsArgArray& aArgs, 
       
   270                                              TDpsEleArray& aElements,
       
   271                                              TDpsAttribute& aAttrib, 
       
   272                                              CDpsTransaction* /*aParam*/)
       
   273     {
       
   274     IF_DEBUG(Print(_L(">>>TDpsGetCapability::FillReqArgs")));                                
       
   275     // only one element
       
   276     TDpsEle elems;
       
   277     elems.iElement = EDpsCapability;
       
   278     elems.iNum = 1;
       
   279     aElements.Append(elems);
       
   280     
       
   281     // only one parameter
       
   282     TDpsArg argsP;
       
   283     argsP.iElement = iReqParam.iCap;
       
   284     aArgs.Append(argsP);
       
   285     if (EDpsArgPaperTypes == iReqParam.iCap || EDpsArgLayouts == iReqParam.iCap)
       
   286         {
       
   287         if (iReqParam.iAttribute != 0)
       
   288             {
       
   289             aAttrib = iReqParam.iAttribute;
       
   290             }
       
   291         }
       
   292     IF_DEBUG(Print(_L("<<<TDpsGetCapability::FillReqArgs")));                                    
       
   293     return KErrNone;    
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // 
       
   298 // ---------------------------------------------------------------------------
       
   299 //    
       
   300 EXPORT_C void TDpsGetCapability::CreateReqScriptL(
       
   301                                              const TDpsArgArray& aArguments, 
       
   302                                              const TDpsEleArray& aElements,
       
   303                                              TDpsAttribute aAttribute, 
       
   304                                              RWriteStream& aScript, 
       
   305                                              CDpsTransaction* aTrader)
       
   306     {
       
   307     IF_DEBUG(Print(_L(">>>TDpsGetCapability::CreateReqScript")));    
       
   308     CDpsXmlGenerator* g = aTrader->Generator();
       
   309     g->StartDocumentL(aScript);
       
   310     g->StartInputL(aScript);
       
   311     g->StartOperationL((TDpsOperation)iOperation, aScript);
       
   312 	g->StartElementL(aElements[0].iElement, aScript);
       
   313 	const TInt count = aArguments.Count();
       
   314 	for (TInt i = 0; i < count; i++)
       
   315 		{
       
   316 		g->CreateArgL(aScript, aArguments[i], aAttribute);
       
   317 		}
       
   318 	g->EndElementL(aElements[0].iElement, aScript);
       
   319 	g->EndOperationL((TDpsOperation)iOperation, aScript);	
       
   320 	g->EndInputL(aScript);
       
   321 	g->EndDocumentL(aScript);
       
   322 	IF_DEBUG(Print(_L("<<<TDpsGetCapability::CreateReqScript")));    		
       
   323     }
       
   324         
       
   325 // ---------------------------------------------------------------------------
       
   326 // Some request parameters should be checked
       
   327 // ---------------------------------------------------------------------------
       
   328 //    
       
   329 EXPORT_C TInt TDpsConfigPrintService::FillReqArgs(TDpsArgArray& aArgs, 
       
   330                                                   TDpsEleArray& /*aElems*/,
       
   331                                                   TDpsAttribute& /*aAttrib*/, 
       
   332                                                   CDpsTransaction* /*aParam*/)
       
   333     {
       
   334     IF_DEBUG(Print(_L(">>>TDpsConfigPrintService::FillReqArgs")));
       
   335     TDpsArg* argsP = new TDpsArg[KConfigPrintService]; 
       
   336     if (!argsP)
       
   337         {
       
   338         return KErrNoMemory;
       
   339         }
       
   340     TInt count;     
       
   341     for (TInt i = 0; i < KConfigPrintService; i++)
       
   342         {
       
   343         switch (i)
       
   344             {
       
   345         // there might be several versions
       
   346         case EDpsArgDpsVersions:
       
   347             argsP[i].iElement = EDpsArgDpsVersions;
       
   348             count = iReqParam.iDpsVersions.Count();
       
   349             for (TInt j = 0; j < count; j++)
       
   350                 {
       
   351                 argsP[i].iContent.AppendNumUC
       
   352                     (iReqParam.iDpsVersions[j].iMajor);
       
   353                 argsP[i].iContent.Append(_L("."));    
       
   354                 argsP[i].iContent.AppendNumUC
       
   355                     (iReqParam.iDpsVersions[j].iMinor);    
       
   356                 }
       
   357             aArgs.Append(argsP[i]);
       
   358         break;    
       
   359         
       
   360         case EDpsArgVendorName: // vender name
       
   361             
       
   362             argsP[i].iElement = EDpsArgVendorName;
       
   363             argsP[i].iContent.Append(iReqParam.iVendorName);
       
   364             aArgs.Append(argsP[i]);
       
   365                         
       
   366         break;  
       
   367         
       
   368         case EDpsArgVendorSpecificVersion: // vender version (optional)
       
   369             if (iReqParam.iVendorVersion.iMajor && 
       
   370                 iReqParam.iVendorVersion.iMinor)
       
   371                 {
       
   372                 argsP[i].iElement = EDpsArgVendorSpecificVersion;
       
   373                 argsP[i].iContent.AppendNumUC(iReqParam.iVendorVersion.iMajor);
       
   374                 argsP[i].iContent.Append(_L("."));    
       
   375                 argsP[i].iContent.AppendNumUC(iReqParam.iVendorVersion.iMinor);
       
   376                 aArgs.Append(argsP[i]);        
       
   377                 }
       
   378             
       
   379         break;
       
   380         
       
   381         case EDpsArgProductName: // produce name
       
   382             argsP[i].iElement = EDpsArgProductName;
       
   383             argsP[i].iContent.Append(iReqParam.iProductName);
       
   384             aArgs.Append(argsP[i]);
       
   385         break;
       
   386         
       
   387         case EDpsArgSerialNo: // serialNo (optional)
       
   388             if (iReqParam.iSerialNo.Length())
       
   389                 {
       
   390                 argsP[i].iElement = EDpsArgSerialNo;
       
   391                 argsP[i].iContent.Append(iReqParam.iSerialNo);    
       
   392                 aArgs.Append(argsP[i]);
       
   393                 }
       
   394             
       
   395         break;
       
   396         
       
   397         default:
       
   398             IF_DEBUG(Print(_L("***Wrong parameter")));
       
   399             delete[] argsP;
       
   400             return KErrArgument;
       
   401             }
       
   402         
       
   403         }
       
   404     delete[] argsP;
       
   405     IF_DEBUG(Print(_L("<<<TDpsConfigPrintService::FillReqArgs")));    
       
   406     return KErrNone;    
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 //  Not all parameters are checked. If the invalid parameter can pass the 
       
   411 //  the complaint test, it should not be checked. Instead, the client will see
       
   412 //  it as unknown error. Otherwise, there might be unnecessary code and the
       
   413 //  client cannot be informed. 
       
   414 // ---------------------------------------------------------------------------
       
   415 //    
       
   416 EXPORT_C TInt TDpsGetCapability::FillRepArgs(const TDpsArgArray& aArgs, 
       
   417                                              CDpsTransaction* aTrader)
       
   418     {
       
   419     IF_DEBUG(Print(_L(">>>TDpsGetCapability::FillRepArgs")));    
       
   420     CDpsXmlParser* XmlPar = aTrader->Parser();
       
   421     
       
   422     if (aArgs.Count())
       
   423         {
       
   424         if (EDpsArgPaperTypes == aArgs[0].iElement || 
       
   425             EDpsArgLayouts == aArgs[0].iElement)
       
   426             {
       
   427             if (XmlPar->HasAttribute())
       
   428                 {
       
   429                 TDpsAttribute attrib;
       
   430 		        XmlPar->GetAttribute(attrib);
       
   431 		        iRepParam.iContent.Append(attrib);            
       
   432                 }
       
   433             else
       
   434                 {
       
   435                 iRepParam.iContent.Append(0);
       
   436                 }    
       
   437             }
       
   438         TUint32 value;
       
   439         TLex8 converter;
       
   440         TLex8 parser(aArgs[0].iContent);
       
   441         parser.SkipSpace();
       
   442         while (!parser.Eos())
       
   443             {
       
   444             parser.Mark();
       
   445             parser.SkipCharacters();
       
   446             if (KFullWordWidth == parser.TokenLength())
       
   447                 {
       
   448                 TPtrC8 token = parser.MarkedToken();
       
   449                 converter.Assign(token);
       
   450                 parser.SkipSpace();  
       
   451                 }
       
   452             else
       
   453                 {
       
   454                 IF_DEBUG(Print(_L("***Wrong argument")));
       
   455                 return KErrArgument;
       
   456                 }
       
   457             TInt error = converter.Val(value, EHex);
       
   458             if (error != KErrNone)
       
   459                 {
       
   460                 IF_DEBUG(Print(_L("convert error %d"), error));
       
   461                 return error;
       
   462                 }
       
   463             if (EDpsArgPaperTypes == aArgs[0].iElement)
       
   464                 {
       
   465                 TDpsPaperType paperType;
       
   466                 TInt major = value >> KShiftLength;
       
   467                 paperType.iMajor = (TDpsPaperTypeMajor)major;
       
   468                 paperType.iMinor = (TDpsPaperTypeMinor)(value & KDpsMinorMask);
       
   469                 iRepParam.iPaperType.Append(paperType);
       
   470                 }
       
   471             else
       
   472                 {
       
   473                 // remove the extra zeros
       
   474                 value = value >> KShiftLength; 
       
   475                 iRepParam.iContent.Append(value);
       
   476                 IF_DEBUG(Print(_L("the value is %x"), value));
       
   477                 }
       
   478             
       
   479             }
       
   480         iRepParam.iCap = aArgs[0].iElement;
       
   481            
       
   482         }
       
   483     
       
   484     IF_DEBUG(Print(_L("<<<TDpsGetCapability::FillRepArgs")));
       
   485     return KErrNone;    
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------------------------
       
   489 //  Not all parameters are checked. If the invalid parameter can pass the 
       
   490 //  the complaint test, it should not be checked. Instead, the client will see
       
   491 //  it as unknown error. Otherwise, there might be unnecessary code and the
       
   492 //  client cannot be informed. 
       
   493 // ---------------------------------------------------------------------------
       
   494 //    
       
   495 EXPORT_C TInt TDpsConfigPrintService::FillRepArgs(const TDpsArgArray& aArgs, 
       
   496                                                   CDpsTransaction* aTrader)
       
   497     {
       
   498     IF_DEBUG(Print(_L(">>>TDpsConfigPrintService::FillRepArgs")));    
       
   499     TInt error = KErrNone;
       
   500     TLex8 converter, parser;
       
   501     const TInt count = aArgs.Count();
       
   502     
       
   503     for (TInt i = 0; i < count; i++)
       
   504         {
       
   505         switch (aArgs[i].iElement)
       
   506             {
       
   507             case EDpsArgPrintServiceAvailable: 
       
   508                 converter.Assign(aArgs[i].iContent);
       
   509                 TInt64 result;
       
   510                 error = converter.Val(result, EHex);
       
   511                 if (error != KErrNone)
       
   512                     {
       
   513                     IF_DEBUG(Print(_L("*** convert error")));
       
   514                     return error;
       
   515                     }
       
   516                 // removes the low four bytes zeros. 
       
   517                 IF_DEBUG(Print(_L("--Printer available is %x"), result));   
       
   518                 result = result >> KShiftLength;    
       
   519                 iRepParam.iPrintAvailable = result;
       
   520             break;
       
   521         
       
   522             case EDpsArgDpsVersions:
       
   523                 TDpsVersion version;
       
   524             
       
   525                 parser.Assign(aArgs[i].iContent);
       
   526                 while (!parser.Eos())
       
   527                     {
       
   528                     parser.Mark();
       
   529                     parser.SkipCharacters();
       
   530                     if (parser.TokenLength())
       
   531                         {
       
   532                         TPtrC8 token = parser.MarkedToken();
       
   533                         converter.Assign(token);
       
   534                         parser.SkipSpace();
       
   535                         }
       
   536                     else
       
   537                         {
       
   538                         IF_DEBUG(Print(_L("***wrong !!!")));
       
   539                         return KErrArgument;
       
   540                         }
       
   541                     error = aTrader->ConvertVersion(converter, version);
       
   542                     if (error != KErrNone)
       
   543                         {
       
   544                         return error;
       
   545                         }
       
   546                     iRepParam.iDpsVersions.Append(version);            
       
   547                     }
       
   548             break;
       
   549         
       
   550             case EDpsArgVendorName:
       
   551                 iRepParam.iVendorName.Copy(aArgs[i].iContent);
       
   552                 IF_DEBUG(Print(_L
       
   553                                 ("vendor name is %S"), &iRepParam.iVendorName));
       
   554             break;
       
   555         
       
   556             case EDpsArgVendorSpecificVersion:
       
   557                 parser.Assign(aArgs[i].iContent);
       
   558                 aTrader->ConvertVersion(parser, version);
       
   559                 iRepParam.iVendorVersion = version;
       
   560                 IF_DEBUG(Print(_L
       
   561                         ("vendor version is %x"), iRepParam.iVendorVersion));
       
   562             break;
       
   563        
       
   564             case EDpsArgProductName:
       
   565                 iRepParam.iProductName.Copy(aArgs[i].iContent);
       
   566                 IF_DEBUG(Print(_L
       
   567                         ("product name is %S"), &iRepParam.iProductName));
       
   568             break;
       
   569         
       
   570             case EDpsArgSerialNo:
       
   571                 iRepParam.iSerialNo.Copy(aArgs[i].iContent);
       
   572                 IF_DEBUG(Print(_L("SerialNo is %S"), &iRepParam.iSerialNo));
       
   573             break;
       
   574         
       
   575             default:
       
   576                 IF_DEBUG(Print(_L("--Unknown param!!")));
       
   577                 return KErrArgument;
       
   578             }
       
   579         }
       
   580         
       
   581     IF_DEBUG(Print(_L("<<<TDpsConfigPrintService::FillRepArgs")));
       
   582     return KErrNone;
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 //  Not all parameters are checked. If the invalid parameter can pass the 
       
   587 //  the complaint test, it should not be checked. Instead, the client will see
       
   588 //  it as unknown error. Otherwise, there might be unnecessary code and the
       
   589 //  client cannot be informed. 
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 EXPORT_C TInt TDpsGetJobStatus::FillRepArgs(const TDpsArgArray& aArgs, 
       
   593                                             CDpsTransaction* aTrader)
       
   594     {
       
   595     IF_DEBUG(Print(_L(">>>TDpsGetJobStatus::FillRepArgs")));
       
   596     TInt value, error, per;
       
   597     TBuf<KMaxArgLen> fileName;
       
   598     TLex8 converter;    
       
   599     TInt count = aArgs.Count();
       
   600     TBool reply = aTrader->IsReply();
       
   601     if (!reply)
       
   602         {
       
   603         aTrader->Engine()->Event()->iEvent = EDpsEvtNotifyJobStatus;
       
   604         }
       
   605     else
       
   606         {
       
   607         aTrader->Engine()->Event()->iEvent = EDpsEvtEmpty;
       
   608         }
       
   609     for (TInt i = 0; i < count; i++)
       
   610         {
       
   611         switch (aArgs[i].iElement)
       
   612             {
       
   613             case EDpsArgPrtPID:
       
   614                 converter.Assign(aArgs[i].iContent);
       
   615                 error = converter.Val(value);
       
   616                 if (error != KErrNone)
       
   617                     {
       
   618                     return error;
       
   619                     }
       
   620                 if (reply)
       
   621                     {
       
   622                     iRepParam.iPrtPID = value;
       
   623                     }
       
   624                 else
       
   625                     {
       
   626                     aTrader->Engine()->Event()->iJobEvent.iRepParam.iPrtPID = 
       
   627                         value;
       
   628                     }
       
   629             break;
       
   630                 
       
   631             case EDpsArgFilePath:
       
   632                 if (reply)
       
   633                     {
       
   634                     iRepParam.iFilePath.Copy(aArgs[i].iContent);
       
   635                     }
       
   636                 else
       
   637                     {
       
   638                     aTrader->Engine()->Event()->iJobEvent.iRepParam.iFilePath. 
       
   639                     Copy(aArgs[i].iContent);
       
   640                     }
       
   641             break;
       
   642                 
       
   643             case EDpsArgCopyID:
       
   644                 converter.Assign(aArgs[i].iContent);
       
   645                 error = converter.Val(value);
       
   646                 if (error != KErrNone)
       
   647                     {
       
   648                      return error;
       
   649                     }
       
   650                 if (reply)
       
   651                     {
       
   652                     iRepParam.iCopyID = value;
       
   653                     }
       
   654                 else
       
   655                     {
       
   656                     aTrader->Engine()->Event()->iJobEvent.iRepParam.iCopyID = 
       
   657                         value;
       
   658                     }    
       
   659             break;
       
   660                 
       
   661             case EDpsArgProgress:
       
   662                 per = aTrader->ParsePercentage(aArgs[i].iContent);
       
   663                 if (per < KErrNone)
       
   664                     {
       
   665                     return per;
       
   666                     }
       
   667                 
       
   668                 if (reply)
       
   669                     {
       
   670                     iRepParam.iProgress = per;
       
   671                     }
       
   672                 else
       
   673                     {
       
   674                     aTrader->Engine()->Event()->iJobEvent.iRepParam.iProgress = 
       
   675                         per;
       
   676                     }
       
   677             break;
       
   678                
       
   679             case EDpsArgImagesPrinted:
       
   680                 converter.Assign(aArgs[i].iContent);
       
   681                 error = converter.Val(value);
       
   682                 if (error != KErrNone)
       
   683                     {
       
   684                      return error;
       
   685                     }
       
   686                 if (reply)
       
   687                     {
       
   688                     iRepParam.iImagesPrinted = value;
       
   689                     }
       
   690                 else
       
   691                     {
       
   692                     aTrader->Engine()->Event()->iJobEvent.iRepParam.
       
   693                         iImagesPrinted = value;
       
   694                     }                                                                  
       
   695             break;
       
   696             
       
   697             default:
       
   698                 IF_DEBUG(Print(_L("***wrong param!!!")));
       
   699                 return KErrArgument;                
       
   700             }
       
   701         }
       
   702     IF_DEBUG(Print(_L("<<<TDpsGetJobStatus::FillRepArgs")));    
       
   703     return KErrNone;    
       
   704     }
       
   705 
       
   706 // ---------------------------------------------------------------------------
       
   707 //  Not all parameters are checked. If the invalid parameter can pass the 
       
   708 //  the complaint test, it should not be checked. Instead, the client will see
       
   709 //  it as unknown error. Otherwise, there might be unnecessary code and the
       
   710 //  client cannot be informed. 
       
   711 // ---------------------------------------------------------------------------
       
   712 //    
       
   713 EXPORT_C TInt TDpsGetPrinterStatus::FillRepArgs(const TDpsArgArray& aArgs, 
       
   714                                                 CDpsTransaction* aTrader)
       
   715     {
       
   716     IF_DEBUG(Print(_L(">>>TDpsGetPrinterStatus::FillRepArgs")));
       
   717     // if UI has not pass the event pointer, we do need to fill in it
       
   718     if (!aTrader->Engine()->Event())
       
   719         {
       
   720         return KErrNone;
       
   721         }
       
   722     TLex8 converter;
       
   723     TDpsPrinterStatusRep param;
       
   724     const TInt count = aArgs.Count();
       
   725     TUint32 value, temp;
       
   726     TBool reply = aTrader->IsReply();
       
   727     if (!reply)
       
   728         {
       
   729         aTrader->Engine()->Event()->iEvent = EDpsEvtNotifyDeviceStatus;
       
   730         }
       
   731     else
       
   732         {
       
   733         aTrader->Engine()->Event()->iEvent = EDpsEvtEmpty;
       
   734         }
       
   735     for (TInt i = 0; i < count; i++)
       
   736         {
       
   737         converter.Assign(aArgs[i].iContent);
       
   738         TInt error = converter.Val(value, EHex);
       
   739         if (error != KErrNone)
       
   740             {
       
   741             return error;
       
   742             }
       
   743         IF_DEBUG(Print(_L("--the value is %x"), value));
       
   744         
       
   745         switch (aArgs[i].iElement)
       
   746             {
       
   747             case EDpsArgDpsPrintServiceStatus:
       
   748                 value = value >> KShiftLength;
       
   749                 if (EDpsPrintServiceStatusPrinting == value ||
       
   750                     EDpsPrintServiceStatusIdle == value ||
       
   751                     EDpsPrintServiceStatusPaused == value)
       
   752                     {
       
   753                     if (reply)
       
   754                         {
       
   755                         iRepParam.iPrintStatus = 
       
   756                             (TDpsPrintServiceStatus)(value);
       
   757                         }
       
   758                     else
       
   759                         {
       
   760                         aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   761                             iPrintStatus = (TDpsPrintServiceStatus)(value);
       
   762                         }
       
   763                     }
       
   764                 else
       
   765                     {
       
   766                     return KErrArgument;
       
   767                     }
       
   768                     
       
   769             break;
       
   770             
       
   771             case EDpsArgJobEndReason:
       
   772                 value = value >> KShiftLength;
       
   773                 if (EDpsJobStatusNotEnded == value ||
       
   774                     EDpsJobStatusEndedOk == value ||
       
   775                     EDpsJobStatusEndedAbortImmediately == value ||
       
   776                     EDpsJobStatusEndedAbortCompleteCurrent == value ||
       
   777                     EDpsJobStatusEndedOther == value)
       
   778                     {
       
   779                     if (reply)
       
   780                         {
       
   781                         iRepParam.iJobStatus = (TDpsJobStatus)(value);    
       
   782                         }
       
   783                     else
       
   784                         {
       
   785                         aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   786                             iJobStatus = (TDpsJobStatus)(value);    
       
   787                         }    
       
   788                     }
       
   789                 else
       
   790                     {
       
   791                     return KErrArgument;
       
   792                     }
       
   793                 
       
   794             break;
       
   795             
       
   796             case EDpsArgErrorStatus:
       
   797                 value = value >> KShiftLength;
       
   798                 if (EDpsErrorStatusOk == value ||
       
   799                     EDpsErrorStatusWarning == value ||
       
   800                     EDpsErrorStatusFatal == value)
       
   801                     {
       
   802                     if (reply)
       
   803                         {
       
   804                         iRepParam.iErrorStatus = (TDpsErrorStatus)(value);    
       
   805                         }
       
   806                     else
       
   807                         {
       
   808                         aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   809                             iErrorStatus = (TDpsErrorStatus)(value);
       
   810                         }    
       
   811                     }
       
   812                 else
       
   813                     {
       
   814                     return KErrArgument;
       
   815                     }
       
   816                 
       
   817             break;
       
   818             
       
   819             case EDpsArgErrorReason:
       
   820                 temp = value >> KShiftLength;
       
   821                 if (EDpsJobErrorNone == temp ||
       
   822                     EDpsJobErrorPaper == temp ||
       
   823                     EDpsJobErrorInk == temp ||
       
   824                     EDpsJobErrorHardware == temp ||
       
   825                     EDpsJobErrorFile == temp)
       
   826                     {
       
   827                     param.iJobEndReason.iMajor = 
       
   828                         (TDpsJobEndReasonMajor)(temp);
       
   829                     IF_DEBUG(Print(_L("the end reason is %x"), temp));
       
   830                     value = value & KDpsMinorMask;
       
   831                     switch (param.iJobEndReason.iMajor)
       
   832                         {
       
   833                         case EDpsJobErrorPaper:
       
   834                             param.iJobEndReason.iPaperMinor = 
       
   835                                 (TDpsJobEndReasonPaper)(value);
       
   836                         break;
       
   837         
       
   838                         case EDpsJobErrorInk:
       
   839                             param.iJobEndReason.iInkMinor = 
       
   840                                 (TDpsJobEndReasonInk)(value);
       
   841                         break;
       
   842         
       
   843                         case EDpsJobErrorHardware:
       
   844                             param.iJobEndReason.iHardMinor = 
       
   845                                 (TDpsJobEndReasonHard)(value);
       
   846                         break;
       
   847         
       
   848                         case EDpsJobErrorFile:
       
   849                             param.iJobEndReason.iFileMinor = 
       
   850                                 (TDpsJobEndReasonFile)(value);
       
   851                         break;
       
   852         
       
   853                         default:
       
   854                             IF_DEBUG(Print(_L("no minor error")));
       
   855                         break; 
       
   856                         }
       
   857                     if (reply)
       
   858                         {
       
   859                         iRepParam.iJobEndReason = param.iJobEndReason;
       
   860                         }
       
   861                     else
       
   862                         {
       
   863                         aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   864                             iJobEndReason = param.iJobEndReason;
       
   865                         }
       
   866                     }
       
   867                 else
       
   868                     {
       
   869                     return KErrArgument;
       
   870                     }
       
   871                 
       
   872             break;
       
   873             
       
   874             case EDpsArgDisconnectEnable:
       
   875                 value = value >> KShiftLength;
       
   876                 if (EDpsDisconnectEnableFalse == value)
       
   877                     {
       
   878                     param.iDisconnectEnable = EFalse;    
       
   879                     }
       
   880                 else if (EDpsDisconnectEnableTrue == value)
       
   881                     {
       
   882                     param.iDisconnectEnable = ETrue;
       
   883                     }
       
   884                 else
       
   885                     {
       
   886                     return KErrArgument;
       
   887                     }
       
   888                 if (reply)
       
   889                     {
       
   890                     iRepParam.iDisconnectEnable = param.iDisconnectEnable; 
       
   891                     }
       
   892                 else
       
   893                     {
       
   894                     aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   895                         iDisconnectEnable = param.iDisconnectEnable; 
       
   896                     }    
       
   897             break;
       
   898             
       
   899             case EDpsArgCapabilityChanged:
       
   900                 value = value >> KShiftLength;
       
   901                 if (EDpsCapabilityChangedFalse == value)
       
   902                     {
       
   903                     param.iCapabilityChange = EFalse;    
       
   904                     }
       
   905                 else if (EDpsCapabilityChangedTrue == value)
       
   906                     {
       
   907                     param.iCapabilityChange = ETrue;
       
   908                     }
       
   909                 else
       
   910                     {
       
   911                     return KErrArgument;
       
   912                     }
       
   913                 if (reply)
       
   914                     {
       
   915                     iRepParam.iCapabilityChange = param.iCapabilityChange;
       
   916                     }
       
   917                 else
       
   918                     {
       
   919                     aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   920                         iCapabilityChange = param.iCapabilityChange;
       
   921                     }
       
   922             break;
       
   923             
       
   924             case EDpsArgNewJobOk:
       
   925                 value = value >> KShiftLength;
       
   926                 if (EDpsNewJobOkTrue == value)
       
   927                     {
       
   928                     param.iNewJobOk = ETrue;    
       
   929                     }
       
   930                 else if (EDpsNewJobOkFalse == value)
       
   931                     {
       
   932                     param.iNewJobOk = EFalse;   
       
   933                     }
       
   934                 else
       
   935                     {
       
   936                     return KErrArgument;
       
   937                     }
       
   938                 if (reply)
       
   939                     {
       
   940                     iRepParam.iNewJobOk = param.iNewJobOk;
       
   941                     }
       
   942                 else
       
   943                     {
       
   944                     aTrader->Engine()->Event()->iPrinterEvent.iRepParam.
       
   945                         iNewJobOk = param.iNewJobOk;
       
   946                     }    
       
   947             break;
       
   948             
       
   949             default:
       
   950                 IF_DEBUG(Print(_L("***wrong param")));
       
   951                 return KErrArgument;
       
   952             }
       
   953         }
       
   954  
       
   955     IF_DEBUG(Print(_L("<<<TDpsGetPrinterStatus::FillRepArgs")));    
       
   956     return KErrNone;    
       
   957 	}