htiui/HtiServicePlugins/HtiScreenshotServicePlugin/src/HtiScreenshotServicePlugin.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     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:  SysInfoPlugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HtiScreenshotServicePlugin.h"
       
    21 #include <HtiDispatcherInterface.h>
       
    22 #include <HTILogging.h>
       
    23 
       
    24 #include <ImageConversion.h>
       
    25 #include <EZCompressor.h>
       
    26 #include <hal.h>
       
    27 
       
    28 // CONSTANTS
       
    29 const static TUid KScreenshotServiceUid = {0x1020DEC3};
       
    30 
       
    31 enum TScreenCommands
       
    32     {
       
    33     // Normal screencapture
       
    34     ECmdScreen                = 0x01,
       
    35     ECmdScreenRegion          = 0x02,
       
    36     ECmdScreenZip             = 0x03,
       
    37     ECmdScreenRegionZip       = 0x04,
       
    38 
       
    39     // Text recognition
       
    40     ECmdTextRcg               = 0x10,
       
    41     ECmdTextRcg_u             = 0x11,
       
    42 
       
    43     // Text bitmap
       
    44     ECmdTextBitmap            = 0x12,
       
    45     ECmdTextBitmap_u          = 0x13,
       
    46 
       
    47     // Screencapture in series
       
    48     ECmdScreenSeries          = 0x21,
       
    49     ECmdScreenRegionSeries    = 0x22,
       
    50     ECmdScreenZipSeries       = 0x23,
       
    51     ECmdScreenRegionZipSeries = 0x24,
       
    52 
       
    53     // Selects the screen to use
       
    54     ECmdSelectScreen          = 0x30,
       
    55 
       
    56     // Gets the current screen size and orientation
       
    57     ECmdScreenMode            = 0x3A,
       
    58 
       
    59     // Screencapture on updated part of screen only
       
    60     ECmdDeltaCaptureMask           = 0x80,
       
    61     ECmdDeltaScreen                = 0x81,
       
    62     ECmdDeltaScreenRegion          = 0x82,
       
    63     ECmdDeltaScreenZip             = 0x83,
       
    64     ECmdDeltaScreenRegionZip       = 0x84,
       
    65     ECmdDeltaScreenReset           = 0x85
       
    66     //ECmdDeltaScreenSeries          = 0xA1,
       
    67     //ECmdDeltaScreenRegionSeries    = 0xA2,
       
    68     //ECmdDeltaScreenZipSeries       = 0xA3,
       
    69     //ECmdDeltaScreenRegionZipSeries = 0xA4
       
    70     };
       
    71 
       
    72 enum TScreenResponse
       
    73     {
       
    74     ERspOk = 0xF0,
       
    75     ERspNotFound = 0xF1
       
    76     };
       
    77 
       
    78 enum THtiFontAttributes
       
    79     {
       
    80     EHtiFontAttBold = 0x01,
       
    81     EHtiFontAttItalic = 0x02,
       
    82     EHtiFontAttNotAA = 0x04,
       
    83     EHtiFontAttPrintPositionFlag = 0x08,
       
    84     EHtiFontAttPrintPositionValue = 0x10
       
    85     };
       
    86 
       
    87 const static TInt KHtiFontAttSuperscriptValue = 0;
       
    88 const static TInt KHtiFontAttSubscriptValue = 1;
       
    89 
       
    90 //1 byte for cmd and 2*4 for 4 coordinates
       
    91 const static TInt KMinScreenRegionCmdLength = 9;
       
    92 const static TInt KScreenDisplayOffset = 1;
       
    93 const static TInt KScreenMIMEOffset = KScreenDisplayOffset + 1;
       
    94 const static TInt KRegionDisplayOffset = KMinScreenRegionCmdLength;
       
    95 const static TInt KRegionMIMEOffset = KRegionDisplayOffset + 1;
       
    96 
       
    97 
       
    98 const static TInt KSeriesDurationOffset = 1;
       
    99 const static TInt KSeriesIntervalOffset = KSeriesDurationOffset + 4;
       
   100 const static TInt KSeriesDisplayOffset = KSeriesIntervalOffset + 4;
       
   101 const static TInt KSeriesMIMEOffset = KSeriesDisplayOffset + 1;
       
   102 const static TInt KMinSeriesCmdLength = KSeriesMIMEOffset;
       
   103 
       
   104 const static TInt KRegionSeriesTlX = KSeriesDisplayOffset + 1;
       
   105 const static TInt KRegionSeriesTlY = KRegionSeriesTlX + 2;
       
   106 const static TInt KRegionSeriesBlX = KRegionSeriesTlY + 2;
       
   107 const static TInt KRegionSeriesBlY = KRegionSeriesBlX + 2;
       
   108 const static TInt KRegionSeriesMIMEOffset = KRegionSeriesBlY + 2;
       
   109 const static TInt KMinRegionSeriesCmdLength = KRegionSeriesMIMEOffset;
       
   110 
       
   111 const static TInt KDeltaResetCmdLength = 1;
       
   112 const static TInt KScreenModeCmdLength = 1;
       
   113 
       
   114 const static TInt KScreenNrOffset = 1;
       
   115 const static TInt KSelectScreenCmdLength = 2;
       
   116 
       
   117 _LIT( KSeriesShotPath, "c:\\Hti\\SeriesShot\\" );
       
   118 
       
   119 //errors' descriptions
       
   120 _LIT8( KErrDescrInvalid, "invalid arguments" );
       
   121 _LIT8( KErrDescrInvalidMode, "invalid color mode" );
       
   122 _LIT8( KErrDescrRegiontEmpty, "region is empty" );
       
   123 _LIT8( KErrDescrRegionNotNormailized, "region is not normalized" );
       
   124 _LIT8( KErrDescrRegionOutOfScreen, "region is out of screen" );
       
   125 _LIT8( KErrDescrUnknownCommand, "unknown command" );
       
   126 _LIT8( KErrDescrFailedConvert, "failed to convert to image format" );
       
   127 _LIT8( KErrDescrFailedCompress, "failed to compress" );
       
   128 _LIT8( KErrDescrMIMENotSupported, "MIME type not supported" );
       
   129 _LIT8( KErrDescrScreenNotSupported, "screen not supported" );
       
   130 
       
   131 _LIT( KScreenshotPanic, "Screenshot plug-in invalid state" );
       
   132 
       
   133 //_LIT(KS60Sans, "Series 60 Sans");
       
   134 //_LIT(KS60SansTitleBold, "Series 60 Sans TitleSmBd");
       
   135 
       
   136 //const TInt KFonHeighMin = 110;
       
   137 //const TInt KFonHeighMax = 190;
       
   138 /*
       
   139 // ----------------------------------------------------------------------------
       
   140 void CHtiScreenshotServicePlugin::InitFontCache()
       
   141     {
       
   142     //temporary
       
   143     //just put harcoded data
       
   144     //should be either external file or auto-defined based on logical fonts
       
   145     //or some test app
       
   146     TFontSpec fs;
       
   147     fs.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
       
   148     //primary font
       
   149     fs.iTypeface.iName = KS60Sans;
       
   150     fs.iHeight = 161;
       
   151     fs.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
   152     iFontCache.Append(fs);
       
   153 
       
   154     fs.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
       
   155 
       
   156     //Series 60 Sans TitleSmBd, 183
       
   157     fs.iTypeface.iName = KS60SansTitleBold;
       
   158     fs.iHeight = 183;
       
   159     iFontCache.Append(fs);
       
   160 
       
   161     //Series 60 Sans TitleSmBd, 172
       
   162     fs.iTypeface.iName = KS60SansTitleBold;
       
   163     fs.iHeight = 172;
       
   164     iFontCache.Append(fs);
       
   165 
       
   166     //Series 60 Sans,           122
       
   167     fs.iTypeface.iName = KS60Sans;
       
   168     fs.iHeight = 122;
       
   169     iFontCache.Append(fs);
       
   170     //Series 60 Sans,           116
       
   171     fs.iTypeface.iName = KS60Sans;
       
   172     fs.iHeight = 116;
       
   173     iFontCache.Append(fs);
       
   174 
       
   175     //Series 60 Sans TitleSmBd, 138
       
   176     fs.iTypeface.iName = KS60SansTitleBold;
       
   177     fs.iHeight = 138;
       
   178     iFontCache.Append(fs);
       
   179     }
       
   180 */
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 TInt ImageDifferenceL( CFbsBitmap* aImage1, CFbsBitmap* aImage2,
       
   184                        CFbsBitmap* &aResult, TRect &aRect )
       
   185     {
       
   186     HTI_LOG_TEXT( "ImageDifferenceL()" );
       
   187 
       
   188     // By default return coordinates of the full image
       
   189     aRect = TRect( 0, 0, aImage2->SizeInPixels().iWidth,
       
   190                   aImage2->SizeInPixels().iHeight );
       
   191 
       
   192 //1. check that aImage1 and aImage2 are valid and can be compared
       
   193     if ( aImage1 == NULL || aImage2 == NULL )
       
   194         {
       
   195         HTI_LOG_TEXT( "return KErrArgument" );
       
   196         return KErrArgument;
       
   197         }
       
   198 
       
   199     if ( aImage1->SizeInPixels() != aImage2->SizeInPixels() )
       
   200         {
       
   201         HTI_LOG_TEXT( "return KErrGeneral (size)" );
       
   202         return KErrGeneral;
       
   203         }
       
   204 
       
   205     if ( aImage1->DisplayMode() != aImage2->DisplayMode() )
       
   206         {
       
   207         HTI_LOG_TEXT( "return KErrGeneral (displaymode)" );
       
   208         return KErrGeneral;
       
   209         }
       
   210 
       
   211 
       
   212 //2. iterate through images from each border and compare to findout outline for diff region
       
   213     TSize orgSize = aImage1->SizeInPixels();
       
   214 
       
   215     TBitmapUtil srcBmpIterator1( aImage1 );
       
   216     TBitmapUtil srcBmpIterator2( aImage2 );
       
   217 
       
   218     srcBmpIterator1.Begin( TPoint( 0, 0 ) );
       
   219     srcBmpIterator2.Begin( TPoint( 0, 0 ), srcBmpIterator1 );
       
   220 
       
   221     TRect diffOutline = TRect( -1, -1, -1, -1 );
       
   222 
       
   223     //2.1 top border iteration
       
   224     TPoint c( 0,0 );
       
   225     for ( ; c.iY < orgSize.iHeight && diffOutline.iTl.iY == -1; ++c.iY )
       
   226         {
       
   227         c.iX = 0;
       
   228         srcBmpIterator1.SetPos( c );
       
   229         srcBmpIterator2.SetPos( c );
       
   230         for ( ; c.iX < orgSize.iWidth && diffOutline.iTl.iY == -1; ++c.iX )
       
   231             {
       
   232             if ( srcBmpIterator1.GetPixel() != srcBmpIterator2.GetPixel() )
       
   233                 {
       
   234                 diffOutline.iTl.iY = c.iY;
       
   235                 }
       
   236 
       
   237             srcBmpIterator1.IncXPos();
       
   238             srcBmpIterator2.IncXPos();
       
   239             }
       
   240         }
       
   241 
       
   242     //2.2 bottom iteration
       
   243     c.SetXY( 0, orgSize.iHeight - 1 );
       
   244     for ( ; c.iY >= diffOutline.iTl.iY && diffOutline.iBr.iY == -1; --c.iY )
       
   245         {
       
   246         c.iX = 0;
       
   247         srcBmpIterator1.SetPos( c );
       
   248         srcBmpIterator2.SetPos( c );
       
   249         for (; c.iX < orgSize.iWidth && diffOutline.iBr.iY == -1; ++c.iX )
       
   250             {
       
   251             if ( srcBmpIterator1.GetPixel() != srcBmpIterator2.GetPixel() )
       
   252                 {
       
   253                 diffOutline.iBr.iY = c.iY;
       
   254                 }
       
   255 
       
   256             srcBmpIterator1.IncXPos();
       
   257             srcBmpIterator2.IncXPos();
       
   258             }
       
   259         }
       
   260 
       
   261     //2.3 left, goes in vertical lines
       
   262     c.SetXY( 0, diffOutline.iTl.iY );
       
   263     for ( ; c.iX < orgSize.iWidth && diffOutline.iTl.iX == -1; ++c.iX )
       
   264         {
       
   265         c.iY = diffOutline.iTl.iY;
       
   266         srcBmpIterator1.SetPos( c );
       
   267         srcBmpIterator2.SetPos( c );
       
   268         for ( ; c.iY <= diffOutline.iBr.iY && diffOutline.iTl.iX == -1; ++c.iY )
       
   269 
       
   270             {
       
   271             if ( srcBmpIterator1.GetPixel() != srcBmpIterator2.GetPixel() )
       
   272                 {
       
   273                 diffOutline.iTl.iX = c.iX;
       
   274                 }
       
   275 
       
   276             srcBmpIterator1.IncYPos();
       
   277             srcBmpIterator2.IncYPos();
       
   278             }
       
   279         }
       
   280     //2.4 right, goes in vertical lines
       
   281     c.SetXY( orgSize.iWidth - 1, diffOutline.iTl.iY );
       
   282     for ( ; c.iX >= diffOutline.iTl.iX && diffOutline.iBr.iX == -1; --c.iX )
       
   283         {
       
   284         c.iY = diffOutline.iTl.iY;
       
   285         srcBmpIterator1.SetPos( c );
       
   286         srcBmpIterator2.SetPos( c );
       
   287         for ( ; c.iY <= diffOutline.iBr.iY && diffOutline.iBr.iX == -1; ++c.iY )
       
   288 
       
   289             {
       
   290             if ( srcBmpIterator1.GetPixel() != srcBmpIterator2.GetPixel() )
       
   291                 {
       
   292                 diffOutline.iBr.iX = c.iX;
       
   293                 }
       
   294 
       
   295             srcBmpIterator1.IncYPos();
       
   296             srcBmpIterator2.IncYPos();
       
   297             }
       
   298         }
       
   299     srcBmpIterator2.End();
       
   300     srcBmpIterator1.End();
       
   301 
       
   302     //3. if there is some diff create CFbsBitmap in aResult and copy outlined image from aImage2
       
   303     if ( diffOutline.iTl.iX == -1 &&
       
   304          diffOutline.iTl.iY == -1 &&
       
   305          diffOutline.iBr.iX == -1 &&
       
   306          diffOutline.iBr.iY == -1 )
       
   307         {
       
   308         // No difference found
       
   309         aRect = TRect( 0, 0, 0, 0 );
       
   310         HTI_LOG_TEXT( "return KErrNotFound" );
       
   311         return KErrNotFound;
       
   312         }
       
   313 
       
   314     aRect = diffOutline;
       
   315 
       
   316     HTI_LOG_FORMAT( "Tlx - %d", aRect.iTl.iX );
       
   317     HTI_LOG_FORMAT( "Tly - %d", aRect.iTl.iY );
       
   318     HTI_LOG_FORMAT( "Bty - %d", aRect.iBr.iX );
       
   319     HTI_LOG_FORMAT( "Bry - %d", aRect.iBr.iY );
       
   320 
       
   321     // The bottom right co-ordinate is not included in the rectange
       
   322     // (see TRect documentation) so we need to stretch the rectange
       
   323     // for BitBlt to get the correct sized image.
       
   324 
       
   325     TRect captureRect( diffOutline.iTl.iX, diffOutline.iTl.iY,
       
   326                        diffOutline.iBr.iX + 1, diffOutline.iBr.iY + 1 );
       
   327 
       
   328     aResult = new (ELeave) CFbsBitmap();
       
   329     User::LeaveIfError( aResult->Create( captureRect.Size(), aImage2->DisplayMode() ) );
       
   330     CleanupStack::PushL( aResult );
       
   331 
       
   332     CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( aResult );
       
   333     CleanupStack::PushL( bmpDevice );
       
   334 
       
   335     CFbsBitGc* bmpCtx;
       
   336     bmpDevice->CreateContext( bmpCtx );
       
   337     bmpCtx->BitBlt( TPoint( 0, 0 ), aImage2, captureRect );
       
   338 
       
   339     delete bmpCtx;
       
   340     bmpCtx = NULL;
       
   341 
       
   342     CleanupStack::PopAndDestroy(); // bmpDevice
       
   343     CleanupStack::Pop(); // aResult
       
   344 
       
   345     HTI_LOG_TEXT( "return KErrNone" );
       
   346     return KErrNone;
       
   347     }
       
   348 
       
   349 // ----------------------------------------------------------------------------
       
   350 CICLHandler::CICLHandler( CImageEncoder* aService, MICLObserver* anObserver ):
       
   351     CActive( EPriorityStandard ),
       
   352     iObserver( anObserver ),
       
   353     iService( aService )
       
   354     {
       
   355     CActiveScheduler::Add( this );
       
   356     }
       
   357 
       
   358 // ----------------------------------------------------------------------------
       
   359 CICLHandler::~CICLHandler()
       
   360     {
       
   361     Cancel();
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 void CICLHandler::Start()
       
   366     {
       
   367     SetActive();
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 void CICLHandler::RunL()
       
   372     {
       
   373     iObserver->ICLComplete( iStatus.Int() );
       
   374     }
       
   375 
       
   376 // ----------------------------------------------------------------------------
       
   377 void CICLHandler::DoCancel()
       
   378     {
       
   379     iService->Cancel();
       
   380     }
       
   381 
       
   382 /*
       
   383 // ----------------------------------------------------------------------------
       
   384 TInt CICLHandler::RunError(TInt aError)
       
   385     {
       
   386 
       
   387     }
       
   388 */
       
   389 
       
   390 // ----------------------------------------------------------------------------
       
   391 // Create instance of concrete ECOM interface implementation
       
   392 CHtiScreenshotServicePlugin* CHtiScreenshotServicePlugin::NewL()
       
   393     {
       
   394     CHtiScreenshotServicePlugin* self = new (ELeave) CHtiScreenshotServicePlugin;
       
   395     CleanupStack::PushL( self );
       
   396     self->ConstructL();
       
   397     CleanupStack::Pop();
       
   398     return self;
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 // Constructor
       
   403 CHtiScreenshotServicePlugin::CHtiScreenshotServicePlugin():
       
   404     iScreen( NULL ),
       
   405     iEncodedBitmap( NULL ),
       
   406     iScreenDevice( NULL ),
       
   407     iBitmapEncoder( NULL ),
       
   408     iICLHandler( NULL ),
       
   409     iCompress( EFalse ),
       
   410     iDeltaCapture( EFalse ),
       
   411     iPreviousBitmap( NULL )
       
   412     {
       
   413     }
       
   414 
       
   415 // ----------------------------------------------------------------------------
       
   416 CHtiScreenshotServicePlugin::~CHtiScreenshotServicePlugin()
       
   417     {
       
   418     HTI_LOG_FUNC_IN( "~CHtiScreenshotServicePlugin" );
       
   419 
       
   420     iFontCache.Close();
       
   421 
       
   422     delete iScreen;
       
   423     delete iEncodedBitmap;
       
   424 
       
   425     delete iICLHandler;
       
   426     delete iBitmapEncoder;
       
   427 
       
   428     delete iScreenDevice;
       
   429 
       
   430     delete iSeriesShot;
       
   431 
       
   432     if ( iPreviousBitmap )
       
   433         delete iPreviousBitmap;
       
   434 
       
   435     iWs.Close();
       
   436     HTI_LOG_FUNC_OUT( "~CHtiScreenshotServicePlugin" );
       
   437     }
       
   438 
       
   439 // ----------------------------------------------------------------------------
       
   440 // Second phase construction.
       
   441 void CHtiScreenshotServicePlugin::ConstructL()
       
   442     {
       
   443     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::ConstructL" );
       
   444     User::LeaveIfError( iWs.Connect() );
       
   445 
       
   446     iScreenDevice = new ( ELeave ) CWsScreenDevice( iWs );
       
   447     User::LeaveIfError( iScreenDevice->Construct() );
       
   448 
       
   449     //InitFontCache();
       
   450 
       
   451     iSeriesShot = CSeriesShot::NewL( this );
       
   452 
       
   453     iPreviousBitmap = new ( ELeave ) CFbsBitmap;
       
   454 
       
   455     //SelectEncoder( KImageTypeBMPUid );
       
   456     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::ConstructL" );
       
   457     }
       
   458 
       
   459 // ----------------------------------------------------------------------------
       
   460 TBool CHtiScreenshotServicePlugin::IsBusy()
       
   461     {
       
   462     if ( iICLHandler )
       
   463         {
       
   464         return iICLHandler->IsActive();
       
   465         }
       
   466 
       
   467     if ( iSeriesShot->IsOngoing() )
       
   468         {
       
   469         return ETrue;
       
   470         }
       
   471 
       
   472     return iEncodedBitmap != NULL;
       
   473     }
       
   474 
       
   475 // ----------------------------------------------------------------------------
       
   476 inline TInt CHtiScreenshotServicePlugin::ParseInt16( const TUint8* aStart )
       
   477     {
       
   478     return aStart[0] + (aStart[1]<<8);
       
   479     }
       
   480 
       
   481 // ----------------------------------------------------------------------------
       
   482 inline TInt CHtiScreenshotServicePlugin::ParseInt32( const TUint8* aStart )
       
   483     {
       
   484     return aStart[0] + (aStart[1]<<8) + (aStart[2]<<16) + (aStart[3]<<24);
       
   485     }
       
   486 
       
   487 // ----------------------------------------------------------------------------
       
   488 void CHtiScreenshotServicePlugin::SendTextRecgReplyL(
       
   489                                     const TBool aResult,
       
   490                                     const TRect& aLocation,
       
   491                                     const TInt aFontIndex)
       
   492     {
       
   493     HTI_LOG_FUNC_IN( "SendTextRecgReplyL" );
       
   494     HBufC8* sendMsg = HBufC8::NewL( 10 );
       
   495     CleanupStack::PushL( sendMsg );
       
   496     if ( aResult )
       
   497         {
       
   498         sendMsg->Des().Append( ERspOk );
       
   499         TUint16 co = aLocation.iTl.iX;
       
   500         sendMsg->Des().Append( (TUint8*)(&co), 2 );
       
   501         co = aLocation.iTl.iY;
       
   502         sendMsg->Des().Append( (TUint8*)(&co), 2 );
       
   503         co = aLocation.iBr.iX;
       
   504         sendMsg->Des().Append( (TUint8*)(&co), 2 );
       
   505         co = aLocation.iBr.iY;
       
   506         sendMsg->Des().Append( (TUint8*)(&co), 2 );
       
   507         sendMsg->Des().Append( (TUint8)aFontIndex );
       
   508         }
       
   509     else
       
   510         {
       
   511         sendMsg->Des().Append( ERspNotFound );
       
   512         sendMsg->Des().AppendFill( 0, 5 );
       
   513         }
       
   514 
       
   515     User::LeaveIfError( iDispatcher->DispatchOutgoingMessage(
       
   516                             sendMsg,
       
   517                             KScreenshotServiceUid) );
       
   518 
       
   519     CleanupStack::Pop();
       
   520     HTI_LOG_FUNC_OUT( "SendTextRecgReplyL" );
       
   521     }
       
   522 
       
   523 // ----------------------------------------------------------------------------
       
   524 void CHtiScreenshotServicePlugin::CopyUnicode( TDes & aTo, const TDesC8& aFrom )
       
   525 {
       
   526     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::CopyUnicode" );
       
   527     //aTo.Copy( reinterpret_cast<const TUint16*>(aFrom.Ptr()), aFrom.Length() );
       
   528     TInt len = aFrom.Length()>>1;
       
   529     aTo.SetLength( len );
       
   530     for ( TInt i = 0; i < len; ++i )
       
   531     {
       
   532         aTo[i] = (TUint16)aFrom[i<<1] + (((TUint16)aFrom[(i<<1)+1])<<8);
       
   533     }
       
   534     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::CopyUnicode" );
       
   535 }
       
   536 
       
   537 // ----------------------------------------------------------------------------
       
   538 TInt CHtiScreenshotServicePlugin::ParseString( const TDesC8& aRequest,
       
   539                                         TInt anOffset,
       
   540                                         TBool aUnicode,
       
   541                                         TDes& aResult)
       
   542     {
       
   543     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::ParseString" );
       
   544     //validate parameters
       
   545     //if offset outside the string return empty string
       
   546     if ( anOffset >= aRequest.Size() )
       
   547         {
       
   548         return anOffset;
       
   549         }
       
   550 
       
   551     TInt len = aRequest[ anOffset ];
       
   552     HTI_LOG_FORMAT( "len %d", len );
       
   553 
       
   554     if ( len> aResult.MaxLength() )
       
   555         {
       
   556         return KErrBadDescriptor;
       
   557         }
       
   558 
       
   559     TInt nextOffset = ( aUnicode ? len * 2 : len ) + anOffset + 1;
       
   560     HTI_LOG_FORMAT( "nextOffset %d", nextOffset );
       
   561     HTI_LOG_FORMAT( "reqSize %d", aRequest.Size() );
       
   562     if ( nextOffset > aRequest.Size() )
       
   563         {
       
   564         return KErrArgument;
       
   565         }
       
   566 
       
   567     if ( aUnicode )
       
   568         {
       
   569         //const TUint8* ptr = aRequest.Mid( anOffset + 1, len * 2 ).Ptr();
       
   570         //aResult.Copy( (const TUint16*)ptr, len );
       
   571         CopyUnicode( aResult, aRequest.Mid( anOffset + 1, len * 2 ) );
       
   572         }
       
   573     else
       
   574         {
       
   575         aResult.Copy( aRequest.Mid( anOffset + 1, len ) );
       
   576         }
       
   577 
       
   578     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::ParseString" );
       
   579     return nextOffset;
       
   580     }
       
   581 
       
   582 // ----------------------------------------------------------------------------
       
   583 TInt CHtiScreenshotServicePlugin::ParseFontSpec( const TDesC8& aRequest,
       
   584                     TInt anOffset,
       
   585                     TBool aUnicode,
       
   586                     TFontSpec& aResult)
       
   587     {
       
   588     if ( anOffset >= aRequest.Size() )
       
   589         {
       
   590         return KErrArgument;
       
   591         }
       
   592 
       
   593     //get font name
       
   594     TPtr tn = aResult.iTypeface.iName.Des();
       
   595     TInt offset = ParseString( aRequest,
       
   596                     anOffset,
       
   597                     aUnicode,
       
   598                     tn );
       
   599 
       
   600     if ( offset > anOffset )
       
   601         {
       
   602         HTI_LOG_DES(aResult.iTypeface.iName);
       
   603         //check that we have valid descr
       
   604         if ( offset + 2 <= aRequest.Size() )
       
   605             {
       
   606             aResult.iHeight = ParseInt16( aRequest.Ptr() + offset );
       
   607             HTI_LOG_FORMAT( "font height %d", aResult.iHeight );
       
   608             //check style byte
       
   609             TUint8 style = aRequest[ offset + 2 ];
       
   610             HTI_LOG_FORMAT( "style %d", style );
       
   611 
       
   612             //stroke bit
       
   613             if ( style & EHtiFontAttBold )
       
   614                 {
       
   615                 aResult.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
   616                 }
       
   617             else
       
   618                 {
       
   619                 aResult.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
       
   620                 }
       
   621             //posture
       
   622             if ( style & EHtiFontAttItalic )
       
   623                 {
       
   624                 aResult.iFontStyle.SetPosture(EPostureItalic);
       
   625                 }
       
   626             else
       
   627                 {
       
   628                 aResult.iFontStyle.SetPosture(EPostureUpright);
       
   629                 }
       
   630             //bitmap glyph type
       
   631             if ( style & EHtiFontAttNotAA )
       
   632                 {
       
   633                 aResult.iFontStyle.SetBitmapType( EMonochromeGlyphBitmap );
       
   634                 }
       
   635             else
       
   636                 {
       
   637                 aResult.iFontStyle.SetBitmapType( EAntiAliasedGlyphBitmap );
       
   638                 }
       
   639             //print position
       
   640             if ( style & EHtiFontAttPrintPositionFlag )
       
   641                 {
       
   642                 TInt printPos = style & EHtiFontAttPrintPositionValue;
       
   643                 if ( printPos == KHtiFontAttSuperscriptValue )
       
   644                     {
       
   645                     aResult.iFontStyle.SetPrintPosition( EPrintPosSuperscript );
       
   646                     }
       
   647                 else if ( printPos == KHtiFontAttSubscriptValue )
       
   648                     {
       
   649                     aResult.iFontStyle.SetPrintPosition( EPrintPosSubscript );
       
   650                     }
       
   651                 }
       
   652             else
       
   653                 {
       
   654                 aResult.iFontStyle.SetPrintPosition( EPrintPosNormal );
       
   655                 }
       
   656             return offset + 3;
       
   657             }
       
   658         else
       
   659             {
       
   660             return KErrArgument;
       
   661             }
       
   662         }
       
   663     else
       
   664         {
       
   665         return offset<0?offset:KErrArgument;
       
   666         }
       
   667     }
       
   668 
       
   669 // ----------------------------------------------------------------------------
       
   670 void CHtiScreenshotServicePlugin::ProcessTextRcgMessageL(
       
   671                                     const TDesC8& aMessage)
       
   672     {
       
   673     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::ProcessTextRcgMessageL" );
       
   674     TBool unicode = aMessage[0] & 0x1;
       
   675 
       
   676     TBuf<0xFF> text;
       
   677 
       
   678     TInt offset = ParseString(aMessage, 1, unicode, text);
       
   679 
       
   680     HTI_LOG_FORMAT( "offset %d ", offset );
       
   681     if ( offset > 1 )
       
   682         {
       
   683         HTI_LOG_DES(text);
       
   684 
       
   685         if ( offset + 1 < aMessage.Size() )
       
   686             {
       
   687             TInt numOfFonts = aMessage[ offset ];
       
   688             HTI_LOG_FORMAT( "num of fonts %d", numOfFonts );
       
   689             iFontCache.Reset();
       
   690             TInt nextOffset  = offset + 1;
       
   691             for ( TInt i = 0; i < numOfFonts; ++i )
       
   692                 {
       
   693                 TFontSpec fontSpec;
       
   694                 nextOffset = ParseFontSpec(aMessage,
       
   695                                             nextOffset,
       
   696                                             unicode,
       
   697                                             fontSpec);
       
   698                 if ( nextOffset < 0 )
       
   699                     {
       
   700                     iDispatcher->DispatchOutgoingErrorMessage(
       
   701                         nextOffset,
       
   702                         KErrDescrInvalid,
       
   703                         KScreenshotServiceUid);
       
   704                     return;
       
   705                     }
       
   706                 else
       
   707                     {
       
   708                     iFontCache.Append( fontSpec );
       
   709                     }
       
   710                 }
       
   711 
       
   712             //parameters parsing END
       
   713             //get screenshot
       
   714             TRect empty;
       
   715             CreateBitmapL( empty, ENone );
       
   716 
       
   717             //call text rcg routines
       
   718             TInt fontIndex;
       
   719             TRect resultRect;
       
   720 
       
   721             //recognize text using fonts from iFontCache
       
   722             TBool result = RecognizeTextL( text, resultRect, fontIndex );
       
   723 
       
   724             SendTextRecgReplyL( result, resultRect, fontIndex );
       
   725 
       
   726             delete iScreen;
       
   727             iScreen = NULL;
       
   728             }
       
   729         else
       
   730             {
       
   731             //no fonts data
       
   732             iDispatcher->DispatchOutgoingErrorMessage(
       
   733                         KErrArgument,
       
   734                         KErrDescrInvalid,
       
   735                         KScreenshotServiceUid);
       
   736 
       
   737             }
       
   738         }
       
   739     else if ( offset == 1 )
       
   740         {
       
   741         //empty text
       
   742         iDispatcher->DispatchOutgoingErrorMessage(
       
   743                         KErrArgument,
       
   744                         KErrDescrInvalid,
       
   745                         KScreenshotServiceUid);
       
   746         }
       
   747     else
       
   748         {
       
   749         //error
       
   750         iDispatcher->DispatchOutgoingErrorMessage(
       
   751                         offset,
       
   752                         KErrDescrInvalid,
       
   753                         KScreenshotServiceUid);
       
   754         }
       
   755     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::ProcessTextRcgMessageL" );
       
   756     }
       
   757 
       
   758 // ----------------------------------------------------------------------------
       
   759 void CHtiScreenshotServicePlugin::ProcessTextBitmapMessageL(
       
   760                                     const TDesC8& aMessage)
       
   761     {
       
   762     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::ProcessTextBitmapMessageL" );
       
   763     TBool unicode = aMessage[0] & 0x1;
       
   764 
       
   765     TDisplayMode displayMode = ENone;
       
   766     //check display
       
   767     if ( aMessage.Size() > KScreenDisplayOffset )
       
   768         {
       
   769         displayMode = (TDisplayMode)aMessage[KScreenDisplayOffset];
       
   770         if ( displayMode >= EColorLast )
       
   771             {
       
   772             iDispatcher->DispatchOutgoingErrorMessage(
       
   773                             KErrArgument,
       
   774                             KErrDescrInvalidMode,
       
   775                             KScreenshotServiceUid);
       
   776             return;
       
   777             }
       
   778         }
       
   779 
       
   780     //check mime
       
   781     TPtrC8 mime;
       
   782     if ( aMessage[KScreenMIMEOffset] > 0 &&
       
   783         ( aMessage[KScreenMIMEOffset] + KScreenMIMEOffset+1 ) < aMessage.Size() )
       
   784         {
       
   785         mime.Set( aMessage.Mid(KScreenMIMEOffset+1, aMessage[KScreenMIMEOffset] ) );
       
   786         if ( !IsMIMETypeSupported( mime ) )
       
   787             {
       
   788             iDispatcher->DispatchOutgoingErrorMessage(
       
   789                             KErrArgument,
       
   790                             KErrDescrMIMENotSupported,
       
   791                             KScreenshotServiceUid);
       
   792             return;
       
   793             }
       
   794         }
       
   795     else if ( aMessage[KScreenMIMEOffset] != 0 )
       
   796         {
       
   797         iDispatcher->DispatchOutgoingErrorMessage(
       
   798                         KErrArgument,
       
   799                         KErrDescrInvalidMode,
       
   800                         KScreenshotServiceUid);
       
   801         return;
       
   802         }
       
   803 
       
   804     TBuf<0xFF> text;
       
   805     TInt preTextOffset = KScreenMIMEOffset + aMessage[KScreenMIMEOffset] + 1;
       
   806     TInt offset = ParseString( aMessage, preTextOffset, unicode, text );
       
   807 
       
   808     HTI_LOG_FORMAT( "offset %d ", offset );
       
   809     if ( offset == preTextOffset )
       
   810         {
       
   811         //empty text
       
   812         iDispatcher->DispatchOutgoingErrorMessage(
       
   813                         KErrArgument,
       
   814                         KErrDescrInvalid,
       
   815                         KScreenshotServiceUid);
       
   816         }
       
   817     else if ( offset < preTextOffset )
       
   818         {
       
   819         //error
       
   820         iDispatcher->DispatchOutgoingErrorMessage(
       
   821                         offset,
       
   822                         KErrDescrInvalid,
       
   823                         KScreenshotServiceUid);
       
   824         }
       
   825 
       
   826     HTI_LOG_DES(text);
       
   827     TFontSpec fontSpec;
       
   828     offset = ParseFontSpec(aMessage,
       
   829                             offset,
       
   830                             unicode,
       
   831                             fontSpec);
       
   832     if ( offset < 0 )
       
   833         {
       
   834         iDispatcher->DispatchOutgoingErrorMessage(
       
   835             offset,
       
   836             KErrDescrInvalid,
       
   837             KScreenshotServiceUid);
       
   838 
       
   839         return;
       
   840         }
       
   841 
       
   842     //check colors
       
   843     HTI_LOG_TEXT( "check colors" );
       
   844     if ( offset + 2*4 != aMessage.Size() )
       
   845         {
       
   846         iDispatcher->DispatchOutgoingErrorMessage(
       
   847             offset,
       
   848             KErrDescrInvalid,
       
   849             KScreenshotServiceUid);
       
   850         return;
       
   851         }
       
   852 
       
   853     //extract colors
       
   854     TUint32 fgColor = ParseInt32( aMessage.Ptr() + offset );
       
   855     TUint32 bgColor = ParseInt32( aMessage.Ptr() + offset + 4 );
       
   856     HTI_LOG_FORMAT( "FG color %d", fgColor );
       
   857     HTI_LOG_FORMAT( "BG color %d", bgColor );
       
   858 
       
   859     //END parsing
       
   860     //generate and return bitmap
       
   861     CFont* useFont;
       
   862 
       
   863     User::LeaveIfError( iScreenDevice->GetNearestFontToDesignHeightInPixels(
       
   864                             useFont, fontSpec ) );
       
   865 
       
   866     TDisplayMode dm = displayMode==ENone || displayMode==0?
       
   867                                         iScreenDevice->DisplayMode():
       
   868                                         displayMode;
       
   869 
       
   870 
       
   871     delete iScreen;
       
   872     iScreen = NULL;
       
   873     iScreen = CHtiTextRcg::GetTextBitmapL(
       
   874                             text,
       
   875                             useFont,
       
   876                             TRgb( fgColor ),
       
   877                             TRgb( bgColor ),
       
   878                             dm );
       
   879 
       
   880     iScreenDevice->ReleaseFont( useFont );
       
   881 
       
   882     //Encode iBitmap
       
   883     iCompress = EFalse;
       
   884     if ( mime.Length() == 0 )
       
   885         {
       
   886         EncodeBitmapL(); //use default encoder BMP
       
   887         }
       
   888     else
       
   889         {
       
   890         HTI_LOG_DES( mime );
       
   891         EncodeBitmapL( mime );
       
   892         }
       
   893 
       
   894     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::ProcessTextBitmapMessageL" );
       
   895     }
       
   896 
       
   897 /*
       
   898 // ----------------------------------------------------------------------------
       
   899 TBool CHtiScreenshotServicePlugin::RecognizeTextAllL(
       
   900                         const TDesC& aText,
       
   901                         TPoint& aResult)
       
   902     {
       
   903     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::RecognizeTextAllL" );
       
   904 
       
   905     TSize screenRect = iScreenDevice->SizeInPixels();
       
   906     TInt nofTF = iScreenDevice->NumTypefaces();
       
   907     HTI_LOG_FORMAT( "Number of typefaces %d", nofTF );
       
   908     TBool returnValue = EFalse;
       
   909     for ( TInt i = 0; i < nofTF; ++i )
       
   910         {
       
   911         TTypefaceSupport tf;
       
   912         iScreenDevice->TypefaceSupport(tf, i);
       
   913 
       
   914         HTI_LOG_DES(tf.iTypeface.iName);
       
   915 
       
   916         if ( tf.iIsScalable )
       
   917             {
       
   918             //iterate throuh heighes
       
   919 
       
   920             HTI_LOG_FORMAT( "num of heighs %d", tf.iNumHeights );
       
   921             HTI_LOG_FORMAT( "min h in tw %d", tf.iMinHeightInTwips );
       
   922             HTI_LOG_FORMAT( "max h in tw %d", tf.iMaxHeightInTwips );
       
   923             HTI_LOG_FORMAT( "scalable %d", tf.iIsScalable );
       
   924 
       
   925             HTI_LOG_TEXT( "-----------------------" );
       
   926 
       
   927             TInt minHeight = Max(tf.iMinHeightInTwips, KFonHeighMin );
       
   928             TInt maxHeight = Min(tf.iMaxHeightInTwips, KFonHeighMax );
       
   929 
       
   930             if ( minHeight > maxHeight )
       
   931                 {
       
   932                 continue;
       
   933                 }
       
   934 
       
   935             for ( TInt v = 0; v < 2; ++v )
       
   936                 {
       
   937                 TInt lastFontHeight = 0;
       
   938                 for ( TInt fh = minHeight; fh <= maxHeight; ++fh )
       
   939                     {
       
   940                     TFontSpec fs( tf.iTypeface.iName, fh );
       
   941                     fs.iFontStyle.SetBitmapType( EAntiAliasedGlyphBitmap );
       
   942                     switch ( v )
       
   943                         {
       
   944                         case 1:
       
   945                             {
       
   946                             fs.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
   947                             HTI_LOG_TEXT( "BOLD" );
       
   948                             }
       
   949                             break;
       
   950                         default:
       
   951                             {
       
   952                             HTI_LOG_TEXT( "DEFAULT" );
       
   953                             }
       
   954                         }
       
   955                     HTI_LOG_FORMAT( "hh  %d", fh );
       
   956 
       
   957                     CFont* useFont = NULL;
       
   958 
       
   959                     iScreenDevice->GetNearestFontToDesignHeightInTwips(useFont, fs);
       
   960 
       
   961                     if ( screenRect.iHeight < useFont->HeightInPixels() ||
       
   962                          screenRect.iWidth < useFont->MaxNormalCharWidthInPixels()
       
   963                         )
       
   964                         {
       
   965                         break;
       
   966                         }
       
   967 
       
   968                     if ( useFont->HeightInPixels() == lastFontHeight )
       
   969                         {
       
   970                         continue;
       
   971                         }
       
   972 
       
   973 
       
   974                     lastFontHeight = useFont->HeightInPixels();
       
   975 
       
   976                     returnValue = iTextRcg.RecognizeTextL(
       
   977                                                 iScreen,
       
   978                                                 aText,
       
   979                                                 useFont,
       
   980                                                 aResult);
       
   981                     //HTI_LOG_TEXT( "ReleaseFont" );
       
   982                     iScreenDevice->ReleaseFont(useFont);
       
   983 
       
   984                     if ( returnValue )
       
   985                         {
       
   986                         HTI_LOG_TEXT( "Found" );
       
   987                         HTI_LOG_DES( aText );
       
   988                         HTI_LOG_DES( tf.iTypeface.iName );
       
   989                         HTI_LOG_FORMAT( "Font height in twips %d", fh );
       
   990                         HTI_LOG_FORMAT( "X %d", aResult.iX );
       
   991                         HTI_LOG_FORMAT( "Y %d", aResult.iY );
       
   992                         return returnValue;
       
   993                         }
       
   994                     }
       
   995                 }
       
   996             }
       
   997         else
       
   998             {//non scal. font
       
   999             TFontSpec fs( tf.iTypeface.iName,0 ); //height doesn't matter for
       
  1000                                                 //not scalable font
       
  1001 
       
  1002             CFont* useFont = NULL;
       
  1003             //HTI_LOG_TEXT( "GetFont" );
       
  1004             iScreenDevice->GetNearestFontToDesignHeightInTwips( useFont, fs );
       
  1005 
       
  1006             returnValue = iTextRcg.RecognizeTextL(
       
  1007                                         iScreen,
       
  1008                                         aText,
       
  1009                                         useFont,
       
  1010                                         aResult );
       
  1011             //HTI_LOG_TEXT( "ReleaseFont" );
       
  1012             iScreenDevice->ReleaseFont( useFont );
       
  1013 
       
  1014             if ( returnValue )
       
  1015                 {
       
  1016                 HTI_LOG_TEXT( "Found" );
       
  1017                 HTI_LOG_DES( aText );
       
  1018                 HTI_LOG_DES(tf.iTypeface.iName );
       
  1019                 HTI_LOG_FORMAT( "X %d", aResult.iX );
       
  1020                 HTI_LOG_FORMAT( "Y %d", aResult.iY );
       
  1021                 return returnValue;
       
  1022                 }
       
  1023             }
       
  1024         }
       
  1025 
       
  1026     //
       
  1027 
       
  1028     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::RecognizeTextAllL" );
       
  1029     //return returnValue;
       
  1030     return EFalse;
       
  1031     }
       
  1032 */
       
  1033 
       
  1034 // ----------------------------------------------------------------------------
       
  1035 TBool CHtiScreenshotServicePlugin::RecognizeTextL(
       
  1036                         const TDesC& aText,
       
  1037                         TRect& aResult,
       
  1038                         TInt& aFontIndex)
       
  1039     {
       
  1040     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::RecognizeTextL" );
       
  1041 
       
  1042     TSize screenRect = iScreenDevice->SizeInPixels();
       
  1043     TInt cacheSize = iFontCache.Count();
       
  1044     HTI_LOG_FORMAT( "Cache size %d", cacheSize );
       
  1045 
       
  1046     TBool returnValue = EFalse;
       
  1047     for ( TInt i = 0; i < cacheSize; ++i )
       
  1048         {
       
  1049         CFont* useFont = NULL;
       
  1050 
       
  1051         User::LeaveIfError(iScreenDevice->GetNearestFontToDesignHeightInPixels(
       
  1052                                 useFont, iFontCache[i] ) );
       
  1053         if ( iFontCache[i].iFontStyle.BitmapType()==EAntiAliasedGlyphBitmap )
       
  1054             {
       
  1055             iTextRcg.SetHint( EHintEdge );
       
  1056             }
       
  1057         else
       
  1058             {
       
  1059             iTextRcg.SetHint( EHintNone );
       
  1060             }
       
  1061 
       
  1062         //check that font in valid size
       
  1063         if ( screenRect.iHeight < useFont->HeightInPixels() ||
       
  1064              screenRect.iWidth < useFont->MaxNormalCharWidthInPixels()
       
  1065             )
       
  1066             {
       
  1067             break;
       
  1068             }
       
  1069 
       
  1070         returnValue = iTextRcg.RecognizeTextL( iScreen, aText, useFont,
       
  1071                 aResult );
       
  1072 
       
  1073         iScreenDevice->ReleaseFont( useFont );
       
  1074 
       
  1075         if ( returnValue )
       
  1076             {
       
  1077             HTI_LOG_FORMAT( "Found! fontIndex %d", i );
       
  1078             HTI_LOG_DES( aText );
       
  1079             HTI_LOG_DES( iFontCache[i].iTypeface.iName );
       
  1080             HTI_LOG_FORMAT( "TL X %d", aResult.iTl.iX );
       
  1081             HTI_LOG_FORMAT( "TL Y %d", aResult.iTl.iY );
       
  1082             HTI_LOG_FORMAT( "BR X %d", aResult.iBr.iX );
       
  1083             HTI_LOG_FORMAT( "BR Y %d", aResult.iBr.iY );
       
  1084             aFontIndex = i;
       
  1085             return returnValue;
       
  1086             }
       
  1087         }
       
  1088 
       
  1089     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::RecognizeTextL" );
       
  1090     return EFalse;
       
  1091     }
       
  1092 
       
  1093 /*
       
  1094 TBool CHtiScreenshotServicePlugin::RecognizeTextL(
       
  1095                         const TDesC& aText,
       
  1096                         const TDesC& aTypeface,
       
  1097                         TPoint& aResult)
       
  1098     {
       
  1099     HTI_LOG_FUNC_IN( "RecognizeTextL typeface" );
       
  1100     //const CFont* fontUsed = NULL;// AknLayoutUtils::FontFromName(aTypeface);
       
  1101     CFont* useFont = NULL;
       
  1102     TFontSpec fs(aTypeface, 0);
       
  1103 
       
  1104     iScreenDevice->GetNearestFontInTwips(useFont, fs);
       
  1105 
       
  1106     TBool returnValue = iTextRcg.RecognizeTextL(iScreen, aText, useFont, aResult);
       
  1107 
       
  1108 HTI_LOG_FUNC_OUT( "RecognizeTextL" );
       
  1109     return returnValue;
       
  1110 }
       
  1111 */
       
  1112 
       
  1113 // ----------------------------------------------------------------------------
       
  1114 void CHtiScreenshotServicePlugin::ProcessMessageL(const TDesC8& aMessage,
       
  1115                 THtiMessagePriority /*aPriority*/)
       
  1116     {
       
  1117     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::ProcessMessage");
       
  1118 
       
  1119     if ( iICLHandler )
       
  1120         {
       
  1121         if ( iICLHandler->IsActive() || iEncodedBitmap)
       
  1122             {
       
  1123             User::Leave( KErrInUse );
       
  1124             }
       
  1125         }
       
  1126 
       
  1127     if ( iSeriesShot->IsOngoing() )
       
  1128         User::Leave( KErrInUse );
       
  1129 
       
  1130     // update the current screen mode
       
  1131     TPixelsAndRotation currentPixelsAndRotation;
       
  1132     iScreenDevice->GetScreenModeSizeAndRotation(
       
  1133             iScreenDevice->CurrentScreenMode(), currentPixelsAndRotation );
       
  1134     iScreenDevice->SetScreenSizeAndRotation( currentPixelsAndRotation );
       
  1135 
       
  1136     if ( aMessage.Length() > 0 )
       
  1137         {
       
  1138         // set/reset delta capture status
       
  1139         iDeltaCapture = ( aMessage[0] & ECmdDeltaCaptureMask ) ? ETrue : EFalse;
       
  1140         if ( iDeltaCapture )
       
  1141             {
       
  1142             HTI_LOG_TEXT( "DeltaCapture ETrue" );
       
  1143             }
       
  1144 
       
  1145         //if text recogn call separate handler
       
  1146         if ( aMessage[0] == ECmdTextRcg ||
       
  1147              aMessage[0] == ECmdTextRcg_u )
       
  1148             {
       
  1149             ProcessTextRcgMessageL( aMessage );
       
  1150             return;
       
  1151             }
       
  1152         else if ( aMessage[0] == ECmdTextBitmap ||
       
  1153                   aMessage[0] == ECmdTextBitmap_u )
       
  1154             {
       
  1155             ProcessTextBitmapMessageL( aMessage );
       
  1156             return;
       
  1157             }
       
  1158 
       
  1159         iCompress = ( aMessage[0] == ECmdScreenZip ) ||
       
  1160                     ( aMessage[0] == ECmdScreenRegionZip ) ||
       
  1161                     ( aMessage[0] == ECmdScreenZipSeries ) ||
       
  1162                     ( aMessage[0] == ECmdScreenRegionZipSeries ) ||
       
  1163                     ( aMessage[0] == ECmdDeltaScreenZip ) ||
       
  1164                     ( aMessage[0] == ECmdDeltaScreenRegionZip );
       
  1165 
       
  1166         HTI_LOG_FORMAT( "cmd 0x%x", aMessage[0] );
       
  1167         TPtrC8 mime;
       
  1168 
       
  1169         switch ( aMessage[0] )
       
  1170             {
       
  1171             case ECmdScreen:
       
  1172             case ECmdScreenZip:
       
  1173             case ECmdDeltaScreen:
       
  1174             case ECmdDeltaScreenZip:
       
  1175                 {
       
  1176                 TRect empty;
       
  1177                 TDisplayMode displayMode = ENone;
       
  1178                 //check display
       
  1179                 if ( aMessage.Length() > KScreenDisplayOffset )
       
  1180                     {
       
  1181                     displayMode = ( TDisplayMode ) aMessage[KScreenDisplayOffset];
       
  1182                     if ( displayMode >= EColorLast )
       
  1183                         {
       
  1184                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1185                                         KErrArgument,
       
  1186                                         KErrDescrInvalidMode,
       
  1187                                         KScreenshotServiceUid );
       
  1188                         return;
       
  1189                         }
       
  1190                     }
       
  1191 
       
  1192                 CreateBitmapL( empty, displayMode );
       
  1193                 //check mime
       
  1194                 if ( aMessage.Length() > KScreenMIMEOffset )
       
  1195                     {
       
  1196                     mime.Set( aMessage.Mid( KScreenMIMEOffset ) );
       
  1197                     if ( !IsMIMETypeSupported( mime ) )
       
  1198                         {
       
  1199                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1200                                         KErrArgument,
       
  1201                                         KErrDescrMIMENotSupported,
       
  1202                                         KScreenshotServiceUid );
       
  1203                         return;
       
  1204                         }
       
  1205                     }
       
  1206                 }
       
  1207                 break;
       
  1208 
       
  1209             case ECmdScreenRegion:
       
  1210             case ECmdScreenRegionZip:
       
  1211             case ECmdDeltaScreenRegion:
       
  1212             case ECmdDeltaScreenRegionZip:
       
  1213                 {
       
  1214                 if ( aMessage.Length() >= KMinScreenRegionCmdLength )
       
  1215                     {
       
  1216                     TRect region;
       
  1217                     const TUint8* ptr = aMessage.Ptr();
       
  1218                     region.iTl.iX = ParseInt16( ptr + 1 );
       
  1219                     region.iTl.iY = ParseInt16( ptr + 3 );
       
  1220                     region.iBr.iX = ParseInt16( ptr + 5 );
       
  1221                     region.iBr.iY = ParseInt16( ptr + 7 );
       
  1222 
       
  1223                     //check empty and normmalizaed
       
  1224                     if ( !region.IsNormalized() )
       
  1225                         {
       
  1226                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1227                                         KErrArgument,
       
  1228                                         KErrDescrRegionNotNormailized,
       
  1229                                         KScreenshotServiceUid );
       
  1230                         return;
       
  1231                         }
       
  1232 
       
  1233                     if ( region.IsEmpty() )
       
  1234                         {
       
  1235                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1236                                         KErrArgument,
       
  1237                                         KErrDescrRegiontEmpty,
       
  1238                                         KScreenshotServiceUid );
       
  1239                         return;
       
  1240                         }
       
  1241 
       
  1242                     TRect screenRect;
       
  1243                     screenRect.iBr = iScreenDevice->SizeInPixels().AsPoint();
       
  1244                     screenRect.iBr.iX++; //TRect::Contains() omitts
       
  1245                     screenRect.iBr.iY++; //right bottom rows
       
  1246 
       
  1247                     TDisplayMode displayMode = ENone;
       
  1248                     if ( aMessage.Length() > KRegionDisplayOffset )
       
  1249                         {
       
  1250                         displayMode = ( TDisplayMode ) aMessage[KRegionDisplayOffset];
       
  1251                         if ( displayMode >= EColorLast )
       
  1252                             {
       
  1253                             iDispatcher->DispatchOutgoingErrorMessage(
       
  1254                                             KErrArgument,
       
  1255                                             KErrDescrInvalidMode,
       
  1256                                             KScreenshotServiceUid );
       
  1257                             return;
       
  1258                             }
       
  1259                         }
       
  1260 
       
  1261                     if ( screenRect.Contains( region.iTl ) &&
       
  1262                          screenRect.Contains( region.iBr ) )
       
  1263                         {
       
  1264                         CreateBitmapL( region, displayMode );
       
  1265                         }
       
  1266                     else
       
  1267                         {
       
  1268                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1269                                         KErrArgument,
       
  1270                                         KErrDescrRegionOutOfScreen,
       
  1271                                         KScreenshotServiceUid );
       
  1272                         return;
       
  1273                         }
       
  1274 
       
  1275                     //check mime
       
  1276                     if ( aMessage.Length() > KRegionMIMEOffset )
       
  1277                         {
       
  1278                         mime.Set( aMessage.Mid( KRegionMIMEOffset ) );
       
  1279                         if ( !IsMIMETypeSupported( mime ) )
       
  1280                             {
       
  1281                             iDispatcher->DispatchOutgoingErrorMessage(
       
  1282                                             KErrArgument,
       
  1283                                             KErrDescrMIMENotSupported,
       
  1284                                             KScreenshotServiceUid );
       
  1285                             return;
       
  1286                             }
       
  1287                         }
       
  1288                     }
       
  1289                 else
       
  1290                     {
       
  1291                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1292                                     KErrArgument,
       
  1293                                     KErrDescrInvalid,
       
  1294                                     KScreenshotServiceUid );
       
  1295                     return;
       
  1296                     }
       
  1297                 }
       
  1298                 break;
       
  1299 
       
  1300             case ECmdScreenSeries:
       
  1301             case ECmdScreenZipSeries:
       
  1302                 {
       
  1303                 if ( aMessage.Length() < KMinSeriesCmdLength )
       
  1304                     {
       
  1305                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1306                                     KErrArgument,
       
  1307                                     KErrDescrInvalid,
       
  1308                                     KScreenshotServiceUid );
       
  1309                     return;
       
  1310                     }
       
  1311                 TInt duration = ParseInt32( aMessage.Ptr() + KSeriesDurationOffset );
       
  1312                 TInt interval = ParseInt32( aMessage.Ptr() + KSeriesIntervalOffset );
       
  1313 
       
  1314                 TDisplayMode displayMode = ( TDisplayMode ) aMessage[KSeriesDisplayOffset];
       
  1315                 if ( displayMode >= EColorLast )
       
  1316                     {
       
  1317                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1318                                     KErrArgument,
       
  1319                                     KErrDescrInvalidMode,
       
  1320                                     KScreenshotServiceUid );
       
  1321                     return;
       
  1322                     }
       
  1323 
       
  1324                 if ( aMessage.Length() > KSeriesMIMEOffset )
       
  1325                     {
       
  1326                     mime.Set( aMessage.Mid( KSeriesMIMEOffset ) );
       
  1327                     if ( !IsMIMETypeSupported( mime ) )
       
  1328                         {
       
  1329                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1330                                         KErrArgument,
       
  1331                                         KErrDescrMIMENotSupported,
       
  1332                                         KScreenshotServiceUid );
       
  1333                         return;
       
  1334                         }
       
  1335                     }
       
  1336 
       
  1337                 TRect empty;
       
  1338                 iSeriesShot->StartL( duration, interval, displayMode, empty, mime );
       
  1339                 }
       
  1340                 return;
       
  1341 
       
  1342             case ECmdScreenRegionSeries:
       
  1343             case ECmdScreenRegionZipSeries:
       
  1344                 {
       
  1345                 if ( aMessage.Length() < KMinRegionSeriesCmdLength )
       
  1346                     {
       
  1347                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1348                                     KErrArgument,
       
  1349                                     KErrDescrInvalid,
       
  1350                                     KScreenshotServiceUid);
       
  1351                     return;
       
  1352                     }
       
  1353                 TInt duration = ParseInt32( aMessage.Ptr() + KSeriesDurationOffset );
       
  1354                 TInt interval = ParseInt32( aMessage.Ptr() + KSeriesIntervalOffset );
       
  1355 
       
  1356                 TDisplayMode displayMode = ( TDisplayMode ) aMessage[KSeriesDisplayOffset];
       
  1357                 if ( displayMode >= EColorLast )
       
  1358                     {
       
  1359                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1360                                     KErrArgument,
       
  1361                                     KErrDescrInvalidMode,
       
  1362                                     KScreenshotServiceUid );
       
  1363                     return;
       
  1364                     }
       
  1365 
       
  1366                 TRect region;
       
  1367                 const TUint8* ptr = aMessage.Ptr();
       
  1368                 region.iTl.iX = ParseInt16( ptr + KRegionSeriesTlX );
       
  1369                 region.iTl.iY = ParseInt16( ptr + KRegionSeriesTlY );
       
  1370                 region.iBr.iX = ParseInt16( ptr + KRegionSeriesBlX );
       
  1371                 region.iBr.iY = ParseInt16( ptr + KRegionSeriesBlY );
       
  1372 
       
  1373                 //check empty and normmalizaed
       
  1374                 if ( !region.IsNormalized() )
       
  1375                     {
       
  1376                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1377                                     KErrArgument,
       
  1378                                     KErrDescrRegionNotNormailized,
       
  1379                                     KScreenshotServiceUid );
       
  1380                     return;
       
  1381                     }
       
  1382 
       
  1383                 if ( region.IsEmpty() )
       
  1384                     {
       
  1385                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1386                                     KErrArgument,
       
  1387                                     KErrDescrRegiontEmpty,
       
  1388                                     KScreenshotServiceUid );
       
  1389                     return;
       
  1390                     }
       
  1391 
       
  1392                 TRect screenRect;
       
  1393                 screenRect.iBr = iScreenDevice->SizeInPixels().AsPoint();
       
  1394                 screenRect.iBr.iX++; //TRect::Contains() omitts
       
  1395                 screenRect.iBr.iY++; //right bottom rows
       
  1396 
       
  1397                 if ( !screenRect.Contains( region.iTl ) ||
       
  1398                      !screenRect.Contains( region.iBr ) )
       
  1399                     {
       
  1400                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1401                                     KErrArgument,
       
  1402                                     KErrDescrRegionOutOfScreen,
       
  1403                                     KScreenshotServiceUid );
       
  1404                     return;
       
  1405                     }
       
  1406 
       
  1407                 if ( aMessage.Length() > KRegionSeriesMIMEOffset )
       
  1408                     {
       
  1409                     mime.Set( aMessage.Mid( KRegionSeriesMIMEOffset ) );
       
  1410                     if ( !IsMIMETypeSupported( mime ) )
       
  1411                         {
       
  1412                         iDispatcher->DispatchOutgoingErrorMessage(
       
  1413                                         KErrArgument,
       
  1414                                         KErrDescrMIMENotSupported,
       
  1415                                         KScreenshotServiceUid );
       
  1416                         return;
       
  1417                         }
       
  1418                     }
       
  1419 
       
  1420                 iSeriesShot->StartL( duration, interval, displayMode, region, mime );
       
  1421                 }
       
  1422                 return;
       
  1423 
       
  1424             case ECmdSelectScreen:
       
  1425                 {
       
  1426                 if ( aMessage.Length() != KSelectScreenCmdLength )
       
  1427                     {
       
  1428                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1429                                     KErrArgument,
       
  1430                                     KErrDescrInvalid,
       
  1431                                     KScreenshotServiceUid );
       
  1432                     return;
       
  1433                     }
       
  1434 
       
  1435                 TInt screenNr = aMessage[KScreenNrOffset];
       
  1436 
       
  1437                 TInt screens;
       
  1438                 TInt ret=HAL::Get( HAL::EDisplayNumberOfScreens, screens );
       
  1439                 if ( ret )
       
  1440                     {
       
  1441                     HTI_LOG_FORMAT( "HAL::Get failed %d", ret );
       
  1442                     User::Leave( ret );
       
  1443                     }
       
  1444 
       
  1445 
       
  1446                 if ( ( screenNr > screens - 1 ) || ( screenNr < 0 ) )
       
  1447                     {
       
  1448                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1449                                     KErrArgument,
       
  1450                                     KErrDescrScreenNotSupported,
       
  1451                                     KScreenshotServiceUid );
       
  1452                     return;
       
  1453                     }
       
  1454 
       
  1455 
       
  1456                 HTI_LOG_FORMAT( "Number of screens %d", screens );
       
  1457                 HTI_LOG_FORMAT( "Setting to screen index %d", screenNr );
       
  1458 
       
  1459                 // Clear the previous delta bitmap to avoid error
       
  1460                 iPreviousBitmap->Reset();
       
  1461 
       
  1462                 // delete old screendevice and create a new one
       
  1463                 delete iScreenDevice;
       
  1464                 iScreenDevice = NULL;
       
  1465                 iScreenDevice = new ( ELeave ) CWsScreenDevice( iWs );
       
  1466                 User::LeaveIfError( iScreenDevice->Construct( screenNr ) );
       
  1467 
       
  1468                 TBuf8<1> okMsg;
       
  1469                 okMsg.Append( ECmdSelectScreen );
       
  1470                 iDispatcher->DispatchOutgoingMessage(
       
  1471                     okMsg.AllocL(), KScreenshotServiceUid );
       
  1472                 }
       
  1473                 return;
       
  1474 
       
  1475             case ECmdDeltaScreenReset:
       
  1476                 {
       
  1477                 if ( aMessage.Length() != KDeltaResetCmdLength )
       
  1478                     {
       
  1479                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1480                                     KErrArgument,
       
  1481                                     KErrDescrInvalid,
       
  1482                                     KScreenshotServiceUid );
       
  1483                     return;
       
  1484                     }
       
  1485 
       
  1486                 iPreviousBitmap->Reset();
       
  1487                 TBuf8<1> okMsg;
       
  1488                 okMsg.Append( ECmdDeltaScreenReset );
       
  1489                 iDispatcher->DispatchOutgoingMessage(
       
  1490                     okMsg.AllocL(), KScreenshotServiceUid );
       
  1491                 }
       
  1492                 return;
       
  1493 
       
  1494             case ECmdScreenMode:
       
  1495                 {
       
  1496                 if ( aMessage.Length() != KScreenModeCmdLength )
       
  1497                     {
       
  1498                     iDispatcher->DispatchOutgoingErrorMessage(
       
  1499                                     KErrArgument,
       
  1500                                     KErrDescrInvalid,
       
  1501                                     KScreenshotServiceUid );
       
  1502                     return;
       
  1503                     }
       
  1504 
       
  1505                 TInt focusScreen = iWs.GetFocusScreen();
       
  1506                 TPixelsAndRotation sizeAndRotation;
       
  1507                 TDisplayMode mode = ENone;
       
  1508                 TInt thisScreen = iScreenDevice->GetScreenNumber();
       
  1509                 iScreenDevice->GetDefaultScreenSizeAndRotation( sizeAndRotation );
       
  1510                 mode = iScreenDevice->DisplayMode();
       
  1511 
       
  1512                 HTI_LOG_FORMAT( "This screen   = %d", thisScreen );
       
  1513                 HTI_LOG_FORMAT( "Screen width  = %d", sizeAndRotation.iPixelSize.iWidth );
       
  1514                 HTI_LOG_FORMAT( "Screen height = %d", sizeAndRotation.iPixelSize.iHeight );
       
  1515                 HTI_LOG_FORMAT( "Rotation      = %d", sizeAndRotation.iRotation );
       
  1516                 HTI_LOG_FORMAT( "Display mode  = %d", mode );
       
  1517                 HTI_LOG_FORMAT( "Focus screen  = %d", focusScreen );
       
  1518                 TBuf8<8> respMsg;
       
  1519                 respMsg.Append( thisScreen );
       
  1520                 respMsg.Append( ( TUint8* )( &( sizeAndRotation.iPixelSize.iWidth ) ), 2 );
       
  1521                 respMsg.Append( ( TUint8* )( &( sizeAndRotation.iPixelSize.iHeight ) ), 2 );
       
  1522                 respMsg.Append( sizeAndRotation.iRotation );
       
  1523                 respMsg.Append( mode );
       
  1524                 respMsg.Append( focusScreen );
       
  1525                 iDispatcher->DispatchOutgoingMessage(
       
  1526                     respMsg.AllocL(), KScreenshotServiceUid );
       
  1527                 }
       
  1528                 return;
       
  1529 
       
  1530             default:
       
  1531                 //Error: unknown command
       
  1532                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1533                                 KErrArgument,
       
  1534                                 KErrDescrUnknownCommand,
       
  1535                                 KScreenshotServiceUid );
       
  1536                 return;
       
  1537             } // switch
       
  1538 
       
  1539         //Encode iBitmap
       
  1540         if ( mime.Length() == 0 )
       
  1541             {
       
  1542             EncodeBitmapL(); //use default encoder BMP
       
  1543             }
       
  1544         else
       
  1545             {
       
  1546             HTI_LOG_DES( mime );
       
  1547             EncodeBitmapL( mime );
       
  1548             }
       
  1549         }
       
  1550     else
       
  1551         {
       
  1552         //error: empty request
       
  1553         iDispatcher->DispatchOutgoingErrorMessage(
       
  1554                         KErrArgument,
       
  1555                         KErrDescrUnknownCommand,
       
  1556                         KScreenshotServiceUid );
       
  1557         }
       
  1558 
       
  1559     HTI_LOG_FUNC_OUT( "HtiScreenshotServicePlugin::ProcessMessage" );
       
  1560     }
       
  1561 
       
  1562 
       
  1563 // ----------------------------------------------------------------------------
       
  1564 void CHtiScreenshotServicePlugin::CreateBitmapL( TRect& aRegion,
       
  1565                                                  TDisplayMode aMode )
       
  1566     {
       
  1567     HTI_LOG_FUNC_IN( "CreateBitmapL" );
       
  1568     //create bitmap
       
  1569     TSize imageSize = aRegion.IsEmpty() ? iScreenDevice->SizeInPixels() :
       
  1570                         aRegion.Size();
       
  1571 
       
  1572     TDisplayMode displayMode = aMode == ENone ?
       
  1573                                         iScreenDevice->DisplayMode() : aMode;
       
  1574 
       
  1575     delete iScreen;//in case ICLComplete was not called
       
  1576     iScreen = NULL;
       
  1577     iScreen = new( ELeave ) CFbsBitmap;
       
  1578     User::LeaveIfError( iScreen->Create( imageSize, displayMode ) );
       
  1579 
       
  1580     if ( aRegion.IsEmpty() )
       
  1581         {
       
  1582         iScreenDevice->CopyScreenToBitmap( iScreen );
       
  1583         }
       
  1584     else
       
  1585         {
       
  1586         iScreenDevice->CopyScreenToBitmap( iScreen, aRegion );
       
  1587         }
       
  1588 
       
  1589 
       
  1590     if ( iDeltaCapture )
       
  1591         {
       
  1592         HTI_LOG_TEXT( "DeltaCapture enabled" );
       
  1593 
       
  1594 
       
  1595         CFbsBitmap* differenceBitmap = NULL;
       
  1596         TInt err = ImageDifferenceL( iPreviousBitmap,
       
  1597                                      iScreen,
       
  1598                                      differenceBitmap,
       
  1599                                      iDeltaRect );
       
  1600 
       
  1601         iPreviousBitmap->Reset();
       
  1602         iPreviousBitmap->Duplicate( iScreen->Handle() );
       
  1603 
       
  1604         if ( err == KErrNone )
       
  1605             {
       
  1606             delete iScreen;
       
  1607             iScreen = differenceBitmap;
       
  1608             }
       
  1609         else if ( err == KErrNotFound )
       
  1610             {
       
  1611             delete iScreen;
       
  1612             iScreen = NULL;
       
  1613 
       
  1614             if ( !iSeriesShot->IsOngoing() )
       
  1615                 {
       
  1616                 // Nothing has changed on the screen.
       
  1617                 // Send just iDeltaRect coordidates
       
  1618                 HBufC8* buf = HBufC8::NewL( 4 * 2 ); // 2 bytes for each coordinate
       
  1619                 buf->Des().SetLength( 4 * 2 );
       
  1620                 TUint16* ptr = (TUint16*) buf->Des().Ptr();
       
  1621                 ptr[0] = (TUint16) iDeltaRect.iTl.iX;
       
  1622                 ptr[1] = (TUint16) iDeltaRect.iTl.iY;
       
  1623                 ptr[2] = (TUint16) iDeltaRect.iBr.iX;
       
  1624                 ptr[3] = (TUint16) iDeltaRect.iBr.iY;
       
  1625                 // Response also sent in ICLComplete
       
  1626                 iDispatcher->DispatchOutgoingMessage( buf, KScreenshotServiceUid );
       
  1627                 }
       
  1628             }
       
  1629         }
       
  1630 
       
  1631     HTI_LOG_FUNC_OUT( "CreateBitmapL" );
       
  1632     }
       
  1633 /*
       
  1634 
       
  1635 // ----------------------------------------------------------------------------
       
  1636 void CleanupRArray( TAny* object )
       
  1637     {
       
  1638     ((RImageTypeDescriptionArray*)object)->ResetAndDestroy();
       
  1639     }
       
  1640 
       
  1641 // ----------------------------------------------------------------------------
       
  1642 void CHtiScreenshotServicePlugin::SelectEncoder( const TUid aEncoderUid )
       
  1643     {
       
  1644     //select encoder
       
  1645     RImageTypeDescriptionArray imageTypeArray;
       
  1646     CImageEncoder::GetImageTypesL( imageTypeArray );
       
  1647     CleanupStack::PushL( TCleanupItem(CleanupRArray, &imageTypeArray) );
       
  1648 
       
  1649     //select specified encoder
       
  1650     TBool found = EFalse;
       
  1651     for ( TInt i = 0; i < imageTypeArray.Count(); ++i )
       
  1652         {
       
  1653         if ( imageTypeArray[i]->ImageType() == aEncoderUid )
       
  1654             {
       
  1655             iImageEncoderType = imageTypeArray[i]->ImageType();
       
  1656             iImageEncoderSubtype = imageTypeArray[i]->SubType();
       
  1657             found = ETrue;
       
  1658             }
       
  1659         }
       
  1660 
       
  1661     if ( !found )
       
  1662         {
       
  1663         User::Leave( KErrNotFound );
       
  1664         }
       
  1665     CleanupStack::PopAndDestroy(); //imageTypeArray
       
  1666     }
       
  1667 */
       
  1668 
       
  1669 // ----------------------------------------------------------------------------
       
  1670 TBool CHtiScreenshotServicePlugin::IsMIMETypeSupported(TDesC8 &aMime)
       
  1671     {
       
  1672     HTI_LOG_DES(aMime);
       
  1673     RFileExtensionMIMETypeArray array;
       
  1674     CImageEncoder::GetFileTypesL(array);
       
  1675     for ( TInt i = 0; i < array.Count(); i++ )
       
  1676         {
       
  1677         if ( array[i]->MIMEType() == aMime )
       
  1678             {
       
  1679             HTI_LOG_TEXT( "MIME supported" );
       
  1680             array.ResetAndDestroy();
       
  1681             return ETrue;
       
  1682             }
       
  1683         }
       
  1684     HTI_LOG_TEXT( "MIME not supported" );
       
  1685     array.ResetAndDestroy();
       
  1686     return EFalse;
       
  1687     }
       
  1688 
       
  1689 
       
  1690 // ----------------------------------------------------------------------------
       
  1691 void CHtiScreenshotServicePlugin::EncodeBitmapL(const TDesC8& aImageTypeMIME )
       
  1692     {
       
  1693     HTI_LOG_FUNC_IN( "EncodeBitmapL" );
       
  1694     delete iBitmapEncoder;
       
  1695     iBitmapEncoder = NULL;
       
  1696     delete iICLHandler;
       
  1697     iICLHandler = NULL;
       
  1698 
       
  1699     if ( iScreen )
       
  1700         {
       
  1701         HTI_LOG_TEXT( "create encoder" );
       
  1702         if ( aImageTypeMIME  == KNullDesC8 )
       
  1703             {
       
  1704             iBitmapEncoder = CImageEncoder::DataNewL( iEncodedBitmap,
       
  1705                                         CImageEncoder::EOptionNone,
       
  1706                                         KImageTypeBMPUid);//,
       
  1707                                         //iImageEncoderSubtype);
       
  1708             }
       
  1709         else
       
  1710             {
       
  1711             iBitmapEncoder = CImageEncoder::DataNewL( iEncodedBitmap,
       
  1712                                         aImageTypeMIME);
       
  1713             }
       
  1714 
       
  1715         HTI_LOG_TEXT( "create CICLHandler" );
       
  1716         iICLHandler = new(ELeave) CICLHandler( iBitmapEncoder, this );
       
  1717         iBitmapEncoder->Convert( &(iICLHandler->iStatus), *iScreen );
       
  1718 
       
  1719         HTI_LOG_TEXT( "CICLHandler start");
       
  1720         iICLHandler->Start();
       
  1721         }
       
  1722     else
       
  1723         {
       
  1724         HTI_LOG_TEXT( "Nothing to encode" );
       
  1725         }
       
  1726 
       
  1727     HTI_LOG_FUNC_OUT( "EncodeBitmapL" );
       
  1728     }
       
  1729 
       
  1730 // ----------------------------------------------------------------------------
       
  1731 TInt CHtiScreenshotServicePlugin::Compress()
       
  1732     {
       
  1733     __ASSERT_ALWAYS(iEncodedBitmap!=NULL,User::Panic(KScreenshotPanic, KErrGeneral));
       
  1734     TInt err = KErrNone;
       
  1735     HBufC8* zippedTemp = NULL;
       
  1736 
       
  1737     HTI_LOG_FORMAT( "image size %d", iEncodedBitmap->Size() );
       
  1738     TInt numOfSteps = 4;
       
  1739     TInt comprBufferIncrease = iEncodedBitmap->Size()/numOfSteps;
       
  1740 
       
  1741     //straight way to handle cases
       
  1742     //when compressed data larger than uncompressed
       
  1743     //try until buffer for compr. data twice bigger than original data
       
  1744     for ( TInt i = 0; i < numOfSteps; ++i )
       
  1745         {
       
  1746         delete zippedTemp;
       
  1747         TRAP( err, zippedTemp = HBufC8::NewL( iEncodedBitmap->Size() +
       
  1748                                               i*comprBufferIncrease ) );
       
  1749         if ( err == KErrNone )
       
  1750             {
       
  1751             //try to zip
       
  1752             HTI_LOG_TEXT( "try to zip" );
       
  1753             TPtr8 zippedTempPtr = zippedTemp->Des();
       
  1754             TRAP( err, CEZCompressor::CompressL( zippedTempPtr,
       
  1755                                                  *iEncodedBitmap ) );
       
  1756             if ( err == KErrNone || err != KEZlibErrBuf )
       
  1757                 {
       
  1758                 break;
       
  1759                 }
       
  1760             }
       
  1761         else
       
  1762             {
       
  1763             break;
       
  1764             }
       
  1765         }
       
  1766 
       
  1767     if ( err == KErrNone )
       
  1768         {
       
  1769         delete iEncodedBitmap;
       
  1770         iEncodedBitmap = zippedTemp;
       
  1771         }
       
  1772     else
       
  1773         {
       
  1774         HTI_LOG_FORMAT( "compre error %d", err );
       
  1775         delete zippedTemp;
       
  1776         }
       
  1777 
       
  1778     return err;
       
  1779     }
       
  1780 
       
  1781 // ----------------------------------------------------------------------------
       
  1782 void CHtiScreenshotServicePlugin::ICLComplete( TInt anError)
       
  1783     {
       
  1784     HTI_LOG_FUNC_IN( "ICLComplete" );
       
  1785 
       
  1786     //delete what we dont need right away
       
  1787     delete iBitmapEncoder;
       
  1788     iBitmapEncoder = NULL;
       
  1789     delete iICLHandler;
       
  1790     iICLHandler = NULL;
       
  1791 
       
  1792 
       
  1793     if ( anError==KErrNone )
       
  1794         {
       
  1795         TInt err = KErrNone;
       
  1796 
       
  1797 
       
  1798         //compress
       
  1799         if ( iCompress )
       
  1800             {
       
  1801             HTI_LOG_TEXT( "compress" );
       
  1802             err = Compress();
       
  1803             }
       
  1804 
       
  1805         //send
       
  1806         if ( err == KErrNone )
       
  1807             {
       
  1808 
       
  1809             if ( !iSeriesShot->IsOngoing() )
       
  1810                 {
       
  1811                 // Not a series shot
       
  1812 
       
  1813                 if ( iDeltaCapture )
       
  1814                     {
       
  1815                     // DeltaCapture on
       
  1816 
       
  1817                     // If we have encoded the bitmap then we
       
  1818                     // also have some difference in the bitmap
       
  1819 
       
  1820                     HTI_LOG_TEXT( "Sending image with coordinates..." );
       
  1821 
       
  1822                     HBufC8* buf = HBufC8::NewL( (4*2) + iEncodedBitmap->Size() );
       
  1823                     buf->Des().SetLength(4*2);
       
  1824                     TUint16* ptr = (TUint16*) buf->Des().Ptr();
       
  1825                     ptr[0] = (TUint16) iDeltaRect.iTl.iX;
       
  1826                     ptr[1] = (TUint16) iDeltaRect.iTl.iY;
       
  1827                     ptr[2] = (TUint16) iDeltaRect.iBr.iX;
       
  1828                     ptr[3] = (TUint16) iDeltaRect.iBr.iY;
       
  1829 
       
  1830                     buf->Des().Append(*iEncodedBitmap);
       
  1831 
       
  1832                     delete iEncodedBitmap;
       
  1833                     iEncodedBitmap = NULL;
       
  1834 
       
  1835                     // Response also sent in CreateBitmapL
       
  1836                     err = iDispatcher->DispatchOutgoingMessage(buf,
       
  1837                                             KScreenshotServiceUid);
       
  1838                     }
       
  1839                 else
       
  1840                     {
       
  1841                     // Normal case
       
  1842                     HTI_LOG_TEXT( "Sending image..." );
       
  1843                     err = iDispatcher->DispatchOutgoingMessage(iEncodedBitmap,
       
  1844                                             KScreenshotServiceUid);
       
  1845                     }
       
  1846 
       
  1847                 if (  err == KErrNoMemory )
       
  1848                     {
       
  1849                     HTI_LOG_TEXT( "wait for memory" );
       
  1850                     iDispatcher->AddMemoryObserver( this );
       
  1851                     }
       
  1852                 else if ( err == KErrNone )
       
  1853                     {
       
  1854                     iEncodedBitmap = NULL;
       
  1855                     }
       
  1856                 else //just drop
       
  1857                     {
       
  1858                     HTI_LOG_TEXT( "ERROR: Impossible to send image" );
       
  1859                     delete iEncodedBitmap;
       
  1860                     iEncodedBitmap = NULL;
       
  1861                     }
       
  1862                 }
       
  1863             }
       
  1864         else
       
  1865             {
       
  1866             iSeriesShot->Cancel();
       
  1867             iDispatcher->DispatchOutgoingErrorMessage(
       
  1868                     err,
       
  1869                     KErrDescrFailedCompress,
       
  1870                     KScreenshotServiceUid);
       
  1871             delete iEncodedBitmap;
       
  1872             iEncodedBitmap = NULL;
       
  1873             }
       
  1874         }
       
  1875     else
       
  1876         {
       
  1877         iSeriesShot->Cancel();
       
  1878         iDispatcher->DispatchOutgoingErrorMessage(
       
  1879                         anError,
       
  1880                         KErrDescrFailedConvert,
       
  1881                         KScreenshotServiceUid);
       
  1882         delete iEncodedBitmap;
       
  1883         iEncodedBitmap = NULL;
       
  1884         }
       
  1885 
       
  1886     if ( iSeriesShot->IsOngoing() )
       
  1887         {
       
  1888         iSeriesShot->SaveImage( iEncodedBitmap, iCompress );
       
  1889         delete iEncodedBitmap;
       
  1890         iEncodedBitmap = NULL;
       
  1891 
       
  1892         // Check if there's still more to do
       
  1893         if ( iSeriesShot->IsOngoing() )
       
  1894             {
       
  1895             iSeriesShot->TriggerNewShot();
       
  1896             }
       
  1897         else
       
  1898             {
       
  1899             // - No, timer still active
       
  1900             // SeriesShot can complete here and in CSeriesShot::TimerExpired
       
  1901             SeriesShotCompletedL(iSeriesShot->ConstructCompletedMessageL());
       
  1902             }
       
  1903         }
       
  1904 
       
  1905     HTI_LOG_FUNC_OUT( "ICLComplete" );
       
  1906     }
       
  1907 
       
  1908 // ----------------------------------------------------------------------------
       
  1909 void CHtiScreenshotServicePlugin::NotifyMemoryChange( TInt aAvailableMemory )
       
  1910     {
       
  1911     if ( iEncodedBitmap )
       
  1912         {
       
  1913         if ( aAvailableMemory>= iEncodedBitmap->Size() )
       
  1914             {
       
  1915             TInt err = iDispatcher->DispatchOutgoingMessage(iEncodedBitmap,
       
  1916                                 KScreenshotServiceUid);
       
  1917 
       
  1918             if ( err == KErrNone)
       
  1919                 {
       
  1920                 iEncodedBitmap = NULL;
       
  1921                 iDispatcher->RemoveMemoryObserver( this );
       
  1922                 }
       
  1923             else if ( err != KErrNoMemory )
       
  1924                 {
       
  1925                 delete iEncodedBitmap;
       
  1926                 iEncodedBitmap = NULL;
       
  1927                 iDispatcher->RemoveMemoryObserver( this );
       
  1928                 }
       
  1929             }
       
  1930         }
       
  1931     else
       
  1932         {
       
  1933         //some error, should not be called
       
  1934         iDispatcher->RemoveMemoryObserver(this);
       
  1935         }
       
  1936     }
       
  1937 
       
  1938 // ----------------------------------------------------------------------------
       
  1939 void CHtiScreenshotServicePlugin::SeriesShotCompletedL(HBufC8* aMsg)
       
  1940     {
       
  1941     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::SeriesShotCompletedL" );
       
  1942     User::LeaveIfError( iDispatcher->DispatchOutgoingMessage(
       
  1943                         aMsg,
       
  1944                         KScreenshotServiceUid) );
       
  1945     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::SeriesShotCompletedL" );
       
  1946     }
       
  1947 
       
  1948 // ----------------------------------------------------------------------------
       
  1949 TBool CHtiScreenshotServicePlugin::StartShotL(TRect aRegion, TDisplayMode aDisplayMode, TDesC8 &aMimeType)
       
  1950     {
       
  1951     HTI_LOG_FUNC_IN( "CHtiScreenshotServicePlugin::StartShot" );
       
  1952     CreateBitmapL( aRegion, aDisplayMode );
       
  1953 
       
  1954     if ( aMimeType.Length()==0 )
       
  1955         EncodeBitmapL(); //use default encoder BMP
       
  1956     else
       
  1957         EncodeBitmapL( aMimeType );
       
  1958 
       
  1959     HTI_LOG_FUNC_OUT( "CHtiScreenshotServicePlugin::StartShot" );
       
  1960     return iScreen ? ETrue : EFalse;
       
  1961     }
       
  1962 
       
  1963 // ----------------------------------------------------------------------------
       
  1964 CSeriesShot* CSeriesShot::NewL( MSeriesShotObserver* aServicePlugin )
       
  1965     {
       
  1966     HTI_LOG_FUNC_IN( "CSeriesShot::NewL" );
       
  1967     CSeriesShot* self = new (ELeave) CSeriesShot( aServicePlugin );
       
  1968     CleanupStack::PushL (self);
       
  1969     self->ConstructL();
       
  1970     CleanupStack::Pop();
       
  1971     HTI_LOG_FUNC_OUT( "CSeriesShot::NewL" );
       
  1972     return self;
       
  1973     }
       
  1974 
       
  1975 // ----------------------------------------------------------------------------
       
  1976 void CSeriesShot::ConstructL()
       
  1977     {
       
  1978     User::LeaveIfError(iFs.Connect());
       
  1979     }
       
  1980 
       
  1981 // ----------------------------------------------------------------------------
       
  1982 CSeriesShot::CSeriesShot( MSeriesShotObserver* aServicePluginObserver ):
       
  1983     iServicePluginObserver( aServicePluginObserver ),
       
  1984     iDurationTimer( NULL ),
       
  1985     iIntervalTimer( NULL ),
       
  1986     isEncoding( EFalse )
       
  1987     {
       
  1988     }
       
  1989 
       
  1990 // ----------------------------------------------------------------------------
       
  1991 CSeriesShot::~CSeriesShot()
       
  1992     {
       
  1993     Cancel();
       
  1994     iFs.Close();
       
  1995     }
       
  1996 
       
  1997 // ----------------------------------------------------------------------------
       
  1998 void CSeriesShot::ClearShots()
       
  1999     {
       
  2000     HTI_LOG_FUNC_IN( "CSeriesShot::ClearShots" );
       
  2001 
       
  2002     iFs.MkDirAll( KSeriesShotPath );
       
  2003 
       
  2004     // Delete all files
       
  2005     TFileName files;
       
  2006     files.Append( KSeriesShotPath );
       
  2007     files.Append( _L( "*.*" ) );
       
  2008     HTI_LOG_DES(files);
       
  2009 
       
  2010 
       
  2011     CFileMan *fileman = CFileMan::NewL( iFs );
       
  2012     TInt err = fileman->Delete( files );
       
  2013     HTI_LOG_FORMAT( "delete %d", err );
       
  2014     if ( err != KErrNotFound )
       
  2015         User::LeaveIfError( err );
       
  2016     delete fileman;
       
  2017 
       
  2018 
       
  2019     HTI_LOG_FUNC_OUT( "CSeriesShot::ClearShots" );
       
  2020     }
       
  2021 
       
  2022 // ----------------------------------------------------------------------------
       
  2023 void CSeriesShot::StartL( TTimeIntervalMicroSeconds32 aDuration,
       
  2024                          TTimeIntervalMicroSeconds32 aInterval,
       
  2025                          TDisplayMode aDisplayMode,
       
  2026                          TRect aRegion,
       
  2027                          TPtrC8 aMime )
       
  2028     {
       
  2029     HTI_LOG_FUNC_IN( "CSeriesShot::StartL" );
       
  2030     HTI_LOG_FORMAT( "Duration      : %d microseconds", aDuration.Int() );
       
  2031     HTI_LOG_FORMAT( "Interval      : %d microseconds", aInterval.Int() );
       
  2032     HTI_LOG_FORMAT( "Displaymode   : %d", aDisplayMode );
       
  2033     HTI_LOG_FORMAT( "TopLeft X     : %d", aRegion.iTl.iX );
       
  2034     HTI_LOG_FORMAT( "TopLeft Y     : %d", aRegion.iTl.iY );
       
  2035     HTI_LOG_FORMAT( "BottomRight X : %d", aRegion.iBr.iX );
       
  2036     HTI_LOG_FORMAT( "BottomRight Y : %d", aRegion.iBr.iY );
       
  2037 
       
  2038     iDisplayMode = aDisplayMode;
       
  2039     iRegion = aRegion;
       
  2040     iIndex = 0;
       
  2041 
       
  2042     iMimeType.Zero();
       
  2043     iMimeType.Append( aMime );
       
  2044     HTI_LOG_DES( iMimeType );
       
  2045 
       
  2046 #ifdef __ENABLE_LOGGING__
       
  2047     HTI_LOG_TEXT( "Supported MIME types:" );
       
  2048     RFileExtensionMIMETypeArray array;
       
  2049     CImageEncoder::GetFileTypesL( array );
       
  2050     for ( TInt i = 0; i < array.Count(); i++ )
       
  2051         HTI_LOG_DES( array[i]->MIMEType() );
       
  2052     array.ResetAndDestroy();
       
  2053 #endif
       
  2054 
       
  2055     iExtension.Zero();
       
  2056     if ( iMimeType.Length() == 0 )
       
  2057         iExtension.Append( _L( ".bmp" ) );
       
  2058     else
       
  2059         GetMIMEExtension( iMimeType, iExtension );
       
  2060 
       
  2061     ClearShots();
       
  2062 
       
  2063     iDurationTimer = CSeriesShotTimer::NewL( this, EDuration, aDuration );
       
  2064     iIntervalTimer = CSeriesShotTimer::NewL( this, EInterval, aInterval );
       
  2065     iDurationTimer->Start();
       
  2066     TimerExpired( EInterval ); // trigger first shot immidietly
       
  2067 
       
  2068     HTI_LOG_FUNC_OUT( "CSeriesShot::StartL" );
       
  2069     }
       
  2070 
       
  2071 void CSeriesShot::TimerExpired( TInt aId )
       
  2072     {
       
  2073     HTI_LOG_FUNC_IN( "CSeriesShot::TimerExpired" );
       
  2074     switch ( aId )
       
  2075         {
       
  2076         case EDuration:
       
  2077             HTI_LOG_TEXT( "EDuration" );
       
  2078 
       
  2079             delete iDurationTimer;
       
  2080             iDurationTimer = NULL;
       
  2081 
       
  2082             if ( iIntervalTimer ) // I'm paranoid
       
  2083                 {
       
  2084                 delete iIntervalTimer;
       
  2085                 iIntervalTimer = NULL;
       
  2086                 }
       
  2087             // SeriesShot can complete here and in CHtiScreenshotServicePlugin::ICLComplete
       
  2088             if ( isEncoding == EFalse )
       
  2089                 iServicePluginObserver->SeriesShotCompletedL( ConstructCompletedMessageL() );
       
  2090 
       
  2091             break;
       
  2092 
       
  2093         case EInterval:
       
  2094             HTI_LOG_TEXT( "EInterval" );
       
  2095 
       
  2096             isEncoding = iServicePluginObserver->StartShotL( iRegion, iDisplayMode, iMimeType );
       
  2097 
       
  2098             break;
       
  2099 
       
  2100         default:
       
  2101             break;
       
  2102         }
       
  2103     HTI_LOG_FUNC_OUT( "CSeriesShot::TimerExpired" );
       
  2104     }
       
  2105 
       
  2106 // ----------------------------------------------------------------------------
       
  2107 TBool CSeriesShot::IsOngoing()
       
  2108     {
       
  2109     // It still might be encoding when duration timer has expired
       
  2110     return ( iDurationTimer || isEncoding ) ? ETrue : EFalse;
       
  2111     }
       
  2112 
       
  2113 // ----------------------------------------------------------------------------
       
  2114 void CSeriesShot::SaveImage( TDesC8* aImage, TBool isCompressed )
       
  2115     {
       
  2116     HTI_LOG_FUNC_IN( "CSeriesShot::SaveImage" );
       
  2117 
       
  2118     isEncoding = EFalse;
       
  2119 
       
  2120     TFileName filename( KSeriesShotPath );
       
  2121     filename.AppendFormat( _L( "%04d" ), iIndex );
       
  2122     iIndex++;
       
  2123     filename.Append( iExtension );
       
  2124     if ( isCompressed )
       
  2125         filename.Append( _L( "z" ) );
       
  2126     HTI_LOG_DES( filename );
       
  2127 
       
  2128     RFile file;
       
  2129     User::LeaveIfError( file.Create( iFs, filename, EFileWrite ) );
       
  2130     User::LeaveIfError( file.Write( *aImage ) );
       
  2131     file.Close();
       
  2132 
       
  2133     HTI_LOG_FUNC_IN( "CSeriesShot::SaveImage" );
       
  2134     }
       
  2135 
       
  2136 // ----------------------------------------------------------------------------
       
  2137 void CSeriesShot::TriggerNewShot()
       
  2138     {
       
  2139     if ( iDurationTimer )
       
  2140         iIntervalTimer->Start();
       
  2141     }
       
  2142 
       
  2143 // ----------------------------------------------------------------------------
       
  2144 void CSeriesShot::Cancel()
       
  2145     {
       
  2146     if ( iDurationTimer )
       
  2147         {
       
  2148         delete iDurationTimer;
       
  2149         iDurationTimer = NULL;
       
  2150         }
       
  2151     if ( iIntervalTimer )
       
  2152         {
       
  2153         delete iIntervalTimer;
       
  2154         iIntervalTimer = NULL;
       
  2155         }
       
  2156     ClearShots();
       
  2157     }
       
  2158 
       
  2159 // ----------------------------------------------------------------------------
       
  2160 void CSeriesShot::EncodeCompleted()
       
  2161     {
       
  2162     isEncoding = EFalse;
       
  2163     }
       
  2164 
       
  2165 // ----------------------------------------------------------------------------
       
  2166 void CSeriesShot::GetMIMEExtension( TDesC8 &aMime, TDes &aExt )
       
  2167     {
       
  2168     RFileExtensionMIMETypeArray array;
       
  2169     CImageEncoder::GetFileTypesL( array );
       
  2170     for ( TInt i = 0; i < array.Count(); i++ )
       
  2171         {
       
  2172         if ( array[i]->MIMEType() == aMime )
       
  2173             aExt.Append( array[i]->FileExtension() );
       
  2174         }
       
  2175     array.ResetAndDestroy();
       
  2176 
       
  2177     if ( aExt == KNullDesC ) // should not happen
       
  2178         aExt.Append( _L( ".xxx" ) );
       
  2179     }
       
  2180 
       
  2181 // ----------------------------------------------------------------------------
       
  2182 HBufC8* CSeriesShot::ConstructCompletedMessageL()
       
  2183     {
       
  2184     HTI_LOG_FUNC_IN( "CSeriesShot::ConstructCompletedMessageL" );
       
  2185     // Serialshot completed send ok message.
       
  2186 
       
  2187     CDir* dir = NULL;
       
  2188     User::LeaveIfError( iFs.GetDir(
       
  2189         KSeriesShotPath, KEntryAttNormal, ESortByName, dir ) );
       
  2190 
       
  2191     TInt msgSize = 0;
       
  2192 
       
  2193     if ( dir->Count() == 0 )
       
  2194         {
       
  2195         HTI_LOG_TEXT( "No shots found! Leaving..." );
       
  2196         User::Leave( KErrNotFound );
       
  2197         }
       
  2198 
       
  2199     for ( TInt i = 0; i < dir->Count(); i++ )
       
  2200         {
       
  2201         msgSize += 1; // for length field
       
  2202         msgSize += KSeriesShotPath().Length();
       
  2203         msgSize += (*dir)[i].iName.Length();
       
  2204         }
       
  2205 
       
  2206     HBufC8* msg = HBufC8::NewL( msgSize );
       
  2207 
       
  2208     for ( TInt i = 0; i < dir->Count(); i++ )
       
  2209         {
       
  2210         msg->Des().Append( KSeriesShotPath().Length() + (*dir)[i].iName.Length() );
       
  2211         msg->Des().Append( KSeriesShotPath );
       
  2212         msg->Des().Append( (*dir)[i].iName );
       
  2213         }
       
  2214 
       
  2215     delete dir;
       
  2216 
       
  2217     HTI_LOG_FUNC_OUT( "CSeriesShot::ConstructCompletedMessageL" );
       
  2218     return msg;
       
  2219     }
       
  2220 
       
  2221 // ----------------------------------------------------------------------------
       
  2222 CSeriesShotTimer* CSeriesShotTimer::NewL( MSeriesShotTimerObserver* aObserver,
       
  2223                                         TInt aId,
       
  2224                                         TTimeIntervalMicroSeconds32 aTime )
       
  2225     {
       
  2226     HTI_LOG_FUNC_IN( "CSeriesShotTimer::NewL" );
       
  2227     CSeriesShotTimer* self = new (ELeave) CSeriesShotTimer( aObserver, aId, aTime );
       
  2228     CleanupStack::PushL( self );
       
  2229     self->ConstructL();
       
  2230     CleanupStack::Pop();
       
  2231     HTI_LOG_FUNC_OUT( "CSeriesShotTimer::NewL" );
       
  2232     return self;
       
  2233     }
       
  2234 
       
  2235 // ----------------------------------------------------------------------------
       
  2236 void CSeriesShotTimer::ConstructL()
       
  2237     {
       
  2238     HTI_LOG_FUNC_IN( "CSeriesShotTimer::ConstructL" );
       
  2239     CTimer::ConstructL();
       
  2240     if ( !IsAdded() ) // CTimer should add it but it seems that it does NOT!
       
  2241         {
       
  2242         CActiveScheduler::Add( this );
       
  2243         }
       
  2244     HTI_LOG_FUNC_OUT( "CSeriesShotTimer::ConstructL" );
       
  2245     }
       
  2246 
       
  2247 // ----------------------------------------------------------------------------
       
  2248 CSeriesShotTimer::CSeriesShotTimer( MSeriesShotTimerObserver* aObserver,
       
  2249                                   TInt aId,
       
  2250                                   TTimeIntervalMicroSeconds32 aTime ):
       
  2251     CTimer( EPriorityStandard ),
       
  2252     iObserver( aObserver ),
       
  2253     iId( aId ),
       
  2254     iTime( aTime )
       
  2255     {
       
  2256     }
       
  2257 
       
  2258 // ----------------------------------------------------------------------------
       
  2259 CSeriesShotTimer::~CSeriesShotTimer()
       
  2260     {
       
  2261     }
       
  2262 
       
  2263 // ----------------------------------------------------------------------------
       
  2264 void CSeriesShotTimer::RunL()
       
  2265     {
       
  2266     iObserver->TimerExpired( iId );
       
  2267     }
       
  2268 
       
  2269 // ----------------------------------------------------------------------------
       
  2270 void CSeriesShotTimer::Start()
       
  2271     {
       
  2272     HTI_LOG_FORMAT( "Start CSeriesShotTimer : %d microseconds", iTime.Int() );
       
  2273     After( iTime );
       
  2274     }