mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsxmlgenerator.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     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:  This class creates the dps xml script. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32debug.h>
       
    20 #include "dpsxmlgenerator.h"
       
    21 #include "pictbridge.h"
       
    22 #include "dpsconst.h"
       
    23 #include "dpsxmlstring.h"
       
    24 #include <e32debug.h>
       
    25 
       
    26 #ifdef _DEBUG
       
    27 #	define IF_DEBUG(t) {RDebug::t;}
       
    28 #else
       
    29 #	define IF_DEBUG(t)
       
    30 #endif
       
    31 
       
    32 const TInt KCodeSize = 4;
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CDpsXmlGenerator* CDpsXmlGenerator::NewL(CDpsEngine* aEngine)
       
    39     {
       
    40     IF_DEBUG(Print(_L("CDpsXmlGenerator::NewL")));
       
    41     CDpsXmlGenerator* self= new (ELeave) CDpsXmlGenerator(aEngine);
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CDpsXmlGenerator::~CDpsXmlGenerator()
       
    50     {
       
    51     IF_DEBUG(Print(_L("~CDpsXmlGenerator")));
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // 
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CDpsXmlGenerator::CDpsXmlGenerator(CDpsEngine* aEngine) : 
       
    59     iEngine(aEngine)
       
    60     {        
       
    61     IF_DEBUG(Print(_L("CDpsXmlGenerator::Ctor")));
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // 
       
    66 // ---------------------------------------------------------------------------
       
    67 //	
       
    68 void CDpsXmlGenerator::CreateResultScriptL(TDpsEvent aEvent,
       
    69 		                     			  RWriteStream& aScript,
       
    70 	           		         			  const TDpsResult& aResult) const
       
    71     {
       
    72     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::CreateResultScript")));    
       
    73     StartDocumentL(aScript);       
       
    74     StartResultL(aScript, aResult);       
       
    75     if (aEvent != EDpsEvtEmpty)
       
    76         {
       
    77         CreateEventL(aScript, aEvent);          
       
    78         }    
       
    79     EndResultL(aScript);    
       
    80     EndDocumentL(aScript);    
       
    81     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::CreateResultScript")));
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // 
       
    86 // ---------------------------------------------------------------------------
       
    87 //	
       
    88 void CDpsXmlGenerator::CreateReplyScriptL(TDpsOperation aOperation, 
       
    89                                          RWriteStream& aScript,
       
    90                                          const TDpsResult& aResult,
       
    91                                          const TDpsArg& aArg) const
       
    92     {
       
    93     StartDocumentL(aScript);
       
    94     StartResultL(aScript, aResult);
       
    95     StartOperationL(aOperation, aScript);
       
    96     CreateArgL(aScript, aArg);
       
    97     EndOperationL(aOperation, aScript);
       
    98     EndResultL(aScript);
       
    99     EndDocumentL(aScript);
       
   100     }                                            
       
   101                                             
       
   102     
       
   103 // ---------------------------------------------------------------------------
       
   104 // 
       
   105 // ---------------------------------------------------------------------------
       
   106 //		           		         		
       
   107 void CDpsXmlGenerator::StartDocumentL(RWriteStream& aScript) const
       
   108 	{
       
   109     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::StatrDocument")));
       
   110     aScript.WriteL(KDpsXmlHeader);
       
   111     aScript.WriteL(KDpsXmlNS);
       
   112     aScript.WriteL(KDpsXmlSpace);
       
   113     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::StartDocument")));	
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CDpsXmlGenerator::EndDocumentL(RWriteStream& aScript) const
       
   121     {
       
   122     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::EndDocument")));
       
   123     aScript.WriteL(KDpsXmlBraceOpen);
       
   124     aScript.WriteL(KDpsXmlSlash);
       
   125     aScript.WriteL(KDpsXml);
       
   126     aScript.WriteL(KDpsXmlBraceClose);
       
   127     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::EndDocument")));		
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CDpsXmlGenerator::StartInputL(RWriteStream& aScript) const
       
   135     {
       
   136     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::StartInput")));
       
   137     aScript.WriteL(KDpsXmlBraceOpen);
       
   138     aScript.WriteL(KDpsXmlInput);
       
   139     aScript.WriteL(KDpsXmlBraceClose);
       
   140     aScript.WriteL(KDpsXmlSpace);
       
   141     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::StartInput")));	
       
   142     }
       
   143   
       
   144 // ---------------------------------------------------------------------------
       
   145 // 
       
   146 // ---------------------------------------------------------------------------
       
   147 //  
       
   148 void CDpsXmlGenerator::EndInputL(RWriteStream& aScript) const
       
   149     {
       
   150     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::EndInput")));
       
   151     aScript.WriteL(KDpsXmlBraceOpen);
       
   152     aScript.WriteL(KDpsXmlSlash);
       
   153     aScript.WriteL(KDpsXmlInput);
       
   154     aScript.WriteL(KDpsXmlBraceClose);
       
   155     aScript.WriteL(KDpsXmlSpace);
       
   156     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::EndInput")));		
       
   157     }
       
   158   
       
   159 // ---------------------------------------------------------------------------
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //  
       
   163 void CDpsXmlGenerator::StartResultL(RWriteStream& aScript, 
       
   164 								   const TDpsResult& aResult) const
       
   165     {
       
   166     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::StartResult")));
       
   167     aScript.WriteL(KDpsXmlBraceOpen);
       
   168     aScript.WriteL(KDpsXmlOutput);
       
   169     aScript.WriteL(KDpsXmlBraceClose);
       
   170     aScript.WriteL(KDpsXmlSpace);
       
   171     aScript.WriteL(KDpsXmlBraceOpen);
       
   172     aScript.WriteL(KDpsXmlResult);
       
   173     aScript.WriteL(KDpsXmlBraceClose);
       
   174     TBuf8<KCodeSize> major;
       
   175     major.NumUC(aResult.iMajorCode, EHex);
       
   176     aScript.WriteL(major);
       
   177     major.Zero();
       
   178     major.NumFixedWidthUC(aResult.iMinorCode, EHex, KCodeSize);
       
   179     aScript.WriteL(major);    
       
   180     aScript.WriteL(KDpsXmlBraceOpen);
       
   181     aScript.WriteL(KDpsXmlSlash);
       
   182     aScript.WriteL(KDpsXmlResult);
       
   183     aScript.WriteL(KDpsXmlBraceClose);
       
   184     aScript.WriteL(KDpsXmlSpace);
       
   185     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::StartResult")));		
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // 
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CDpsXmlGenerator::EndResultL(RWriteStream& aScript) const
       
   193 	{
       
   194     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::EndResult")));
       
   195     aScript.WriteL(KDpsXmlBraceOpen);
       
   196     aScript.WriteL(KDpsXmlSlash);
       
   197     aScript.WriteL(KDpsXmlOutput);
       
   198     aScript.WriteL(KDpsXmlBraceClose);
       
   199     aScript.WriteL(KDpsXmlSpace);
       
   200     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::EndResult")));		
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // 
       
   205 // ---------------------------------------------------------------------------
       
   206 //	
       
   207 void CDpsXmlGenerator::StartOperationL(TDpsOperation aOperation, 
       
   208                                        RWriteStream& aScript, 
       
   209 									   TBool aEnd) const
       
   210     {
       
   211     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::StartOperation %d"), aOperation));
       
   212     aScript.WriteL(KDpsXmlBraceOpen);
       
   213     aScript.WriteL(iEngine->DpsParameters()->
       
   214         iDpsOperationStrings[aOperation - 1]);
       
   215     if (aEnd)
       
   216         {
       
   217         aScript.WriteL(KDpsXmlSlash);
       
   218         }
       
   219     aScript.WriteL(KDpsXmlBraceClose);	
       
   220     aScript.WriteL(KDpsXmlSpace);
       
   221     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::StartOperation")));
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // 
       
   226 // ---------------------------------------------------------------------------
       
   227 //			
       
   228 void CDpsXmlGenerator::EndOperationL(TDpsOperation aOperation, 
       
   229                                      RWriteStream& aScript) const 
       
   230     {
       
   231     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::EndOperation")));
       
   232     aScript.WriteL(KDpsXmlBraceOpen);
       
   233     aScript.WriteL(KDpsXmlSlash);
       
   234     // there is an empty op in the op enum so we must reduce one
       
   235     aScript.WriteL(iEngine->DpsParameters()->
       
   236         iDpsOperationStrings[aOperation - 1]);
       
   237     aScript.WriteL(KDpsXmlBraceClose);	
       
   238     aScript.WriteL(KDpsXmlSpace);
       
   239     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::EndOperation")));
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // 
       
   244 // ---------------------------------------------------------------------------
       
   245 //	
       
   246 void CDpsXmlGenerator::CreateEventL(RWriteStream& aScript, TDpsEvent aEvent) const
       
   247     {
       
   248     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::CreatEvent")));
       
   249     aScript.WriteL(KDpsXmlBraceOpen);
       
   250     aScript.WriteL(iEngine->DpsParameters()->
       
   251         iDpsEventStrings[aEvent - 1]);
       
   252     aScript.WriteL(KDpsXmlSlash);
       
   253     aScript.WriteL(KDpsXmlBraceClose);
       
   254     aScript.WriteL(KDpsXmlSpace);
       
   255     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::CreatEvent")));
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // 
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CDpsXmlGenerator::CreateArgL(RWriteStream& aScript, 
       
   263 								  const TDpsArg& aArgument, 
       
   264 					   			  TDpsAttribute aAttribute) const           
       
   265     {
       
   266     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::CreatArg")));
       
   267     aScript.WriteL(KDpsXmlBraceOpen); //<
       
   268     aScript.WriteL(iEngine->DpsParameters()->
       
   269         iDpsArgStrings[aArgument.iElement]);	
       
   270     if (aAttribute != 0)
       
   271         {
       
   272         aScript.WriteL(KDpsXmlSpace); // space
       
   273         aScript.WriteL(KDpsXmlPaperSize); // paperSize
       
   274         aScript.WriteL(KDpsXmlEqual); // =
       
   275         aScript.WriteL(KDpsXmlQuote); // "
       
   276         // patch the lower four bytes zero
       
   277         aAttribute = aAttribute << KShiftLength;
       
   278         TBuf8<KFullWordWidth> string;
       
   279         string.AppendNumUC(aAttribute, EHex);
       
   280         aScript.WriteL(string); // 12345678
       
   281         aScript.WriteL(KDpsXmlQuote); // "
       
   282         }
       
   283     if (!aArgument.iContent.Compare(KNullDesC8))
       
   284         {
       
   285         aScript.WriteL(KDpsXmlSlash); // /
       
   286         aScript.WriteL(KDpsXmlBraceClose); // >
       
   287         }
       
   288     else
       
   289         {
       
   290         aScript.WriteL(KDpsXmlBraceClose); // >
       
   291         aScript.WriteL(aArgument.iContent); // 123 345 567
       
   292         aScript.WriteL(KDpsXmlBraceOpen); // <
       
   293         aScript.WriteL(KDpsXmlSlash); // /
       
   294         aScript.WriteL(iEngine->DpsParameters()->
       
   295             iDpsArgStrings[aArgument.iElement]);
       
   296         aScript.WriteL(KDpsXmlBraceClose); // >
       
   297         }
       
   298     aScript.WriteL(KDpsXmlSpace);	
       
   299     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::CreatArg")));
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // 
       
   304 // ---------------------------------------------------------------------------
       
   305 //	
       
   306 void CDpsXmlGenerator::StartElementL(TDpsElement aElement, 
       
   307                                      RWriteStream& aScript) const
       
   308     {
       
   309     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::StartElement")));
       
   310     aScript.WriteL(KDpsXmlBraceOpen); //<
       
   311     aScript.WriteL(iEngine->DpsParameters()->
       
   312         iDpsElementStrings[aElement - 1]);	
       
   313     aScript.WriteL(KDpsXmlBraceClose); // >
       
   314     aScript.WriteL(KDpsXmlSpace);
       
   315     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::StartElement")));
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // 
       
   320 // ---------------------------------------------------------------------------
       
   321 //	
       
   322 void CDpsXmlGenerator::EndElementL(TDpsElement aElement, 
       
   323                                    RWriteStream& aScript) const
       
   324     {
       
   325     IF_DEBUG(Print(_L(">>>CDpsXmlGenerator::EndElement")));
       
   326     aScript.WriteL(KDpsXmlBraceOpen); //<
       
   327     aScript.WriteL(KDpsXmlSlash);
       
   328     aScript.WriteL(iEngine->DpsParameters()->
       
   329         iDpsElementStrings[aElement - 1]);	
       
   330     aScript.WriteL(KDpsXmlBraceClose); // >
       
   331     aScript.WriteL(KDpsXmlSpace);
       
   332     IF_DEBUG(Print(_L("<<<CDpsXmlGenerator::EndElement")));
       
   333     }