messagingfw/senduiservices/src/senduiserviceclient.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Communicates message data to SendUILauncher server application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <aknappui.h>
       
    21 #include <AknServerApp.h>
       
    22 #include <s32mem.h>
       
    23 
       
    24 #include <CMessageData.h>
       
    25 #include <SendUiConsts.h>
       
    26 
       
    27 #include "senduiserviceclient.h"
       
    28 #include "senduiserviceslog.h"
       
    29 #include "senduilauncher.h"
       
    30 #include "senduiservicecommands.h"
       
    31 
       
    32 typedef TBuf8<KTransferBufferSize> TTransferBuf;
       
    33 // ======== LOCAL FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Launch SendUi
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 void RSendUiServiceClient::LaunchSendUiL( 
       
    40     TUid& aServiceUid,
       
    41     TUid& aServiceProviderUid, 
       
    42     TBool& aLaunchEmbedded, 
       
    43     const CMessageData* aMessageData )
       
    44     {
       
    45     CBufBase* buffer = CBufFlat::NewL( KMessageBufferSize );
       
    46     CleanupStack::PushL( buffer );
       
    47     
       
    48     RBufWriteStream bufStream;
       
    49     bufStream.Open( *buffer );
       
    50     
       
    51     bufStream.WriteUint32L( aServiceProviderUid.iUid );
       
    52     TUid dataType(KSenduiMsgDataBase);
       
    53     if ( aMessageData )
       
    54         {
       
    55         dataType = aMessageData->DataType();
       
    56         }
       
    57     bufStream.WriteUint32L( dataType.iUid );
       
    58     bufStream.WriteUint32L( aServiceUid.iUid );
       
    59     bufStream.WriteUint32L( aLaunchEmbedded ? 1 : 0);
       
    60     bufStream.WriteUint32L( aMessageData ? 1 : 0);
       
    61     
       
    62     if ( aMessageData )
       
    63         {
       
    64         aMessageData->ExternalizeL( bufStream );    
       
    65         }
       
    66 
       
    67     bufStream.CommitL();
       
    68     bufStream.Close();
       
    69 
       
    70 
       
    71     LOGTEXT2(_L("RSendUiServiceClient->LaunchSendUiL: buffer size %d"), buffer->Size() );
       
    72     TInt totalSize = buffer->Size();
       
    73     TInt transferredBytes(0);
       
    74     TInt blockSize(0);
       
    75     
       
    76     TTransferBuf transferBuffer;
       
    77     
       
    78     while( transferredBytes < totalSize)
       
    79         {
       
    80         // determine block size
       
    81         if ( transferredBytes + KTransferBufferSize < totalSize )
       
    82             {
       
    83             blockSize = KTransferBufferSize;
       
    84             }
       
    85         else
       
    86             {
       
    87             // the last block size
       
    88             blockSize = totalSize - transferredBytes;
       
    89             }
       
    90         buffer->Read( transferredBytes, transferBuffer, blockSize );
       
    91             
       
    92         TPckgBuf<TTransferBuf> transferBufferPckg( transferBuffer );
       
    93         TPckgBuf<TInt> totalSizePckg( totalSize );
       
    94         TPckgBuf<TInt> blockSizePckg( blockSize );
       
    95             
       
    96         SendReceive( ESendUiDataBlock, 
       
    97             TIpcArgs( &transferBufferPckg, &blockSizePckg, &totalSizePckg ) );
       
    98     
       
    99         transferredBytes += blockSize;
       
   100         } // while..
       
   101     
       
   102     SendReceive( EDataSent );
       
   103 
       
   104     if ( aMessageData )
       
   105     {
       
   106         TInt index(0);
       
   107         TInt fileHandleCount = aMessageData->AttachmentHandleArray().Count();
       
   108         
       
   109         // Transfer filehandles separately
       
   110         while( index < fileHandleCount )
       
   111         {
       
   112             TIpcArgs ipcArgs;
       
   113             aMessageData->AttachmentHandleArray()[index++].TransferToServer(ipcArgs, 0, 1);
       
   114             SendReceive(ECopyFileHandle, ipcArgs);
       
   115         }
       
   116     }
       
   117     SendReceive( ELaunchSendUi );
       
   118   
       
   119     CleanupStack::PopAndDestroy(buffer);
       
   120 }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Return service identifier
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TUid RSendUiServiceClient::ServiceUid() const
       
   127     {
       
   128     return KSendUiLauncherAppServiceUid;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Destructor
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 RSendUiServiceClient::~RSendUiServiceClient() 
       
   136     { 
       
   137     Close(); 
       
   138     }