syncmlfw/common/sosserver/src/NSmlDataProvider.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Symbian OS Server source.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nsmlsosserver.h"
       
    20 #include "nsmldshostclient.h"
       
    21 
       
    22 // --------------------------------------------------------------------------
       
    23 // CNSmlDataProvider::CNSmlDataProvider( const TInt aId )
       
    24 // --------------------------------------------------------------------------
       
    25 //
       
    26 CNSmlDataProvider::CNSmlDataProvider( const TInt aId, CNSmlSOSSession& aSession ) 
       
    27 : iId(aId), iDataPtr(NULL, 0, 0), iSession(aSession) 
       
    28     {    
       
    29     }
       
    30 
       
    31 // --------------------------------------------------------------------------
       
    32 // CNSmlDataProvider::~CNSmlDataProvider()
       
    33 // --------------------------------------------------------------------------
       
    34 //
       
    35 CNSmlDataProvider::~CNSmlDataProvider()
       
    36     {
       
    37     delete iBuffer;
       
    38     }
       
    39 
       
    40 // --------------------------------------------------------------------------
       
    41 // void CNSmlDataProvider::FetchDataL()
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 void CNSmlDataProvider::FetchDataL()
       
    45     {
       
    46 
       
    47     RArray<TInt> idArray;
       
    48     RArray<TInt> resultArray;
       
    49     CleanupClosePushL(resultArray);
       
    50     CleanupClosePushL(idArray);
       
    51     idArray.AppendL(iId);
       
    52     
       
    53     iSession.HostClient().CreateDataProvidersL( idArray, resultArray );
       
    54 
       
    55     TInt res = resultArray[0];
       
    56     User::LeaveIfError( res );
       
    57 
       
    58     CleanupStack::PopAndDestroy(&idArray);
       
    59     CleanupStack::PopAndDestroy(&resultArray);
       
    60 
       
    61 	TInt err = KErrNone;
       
    62 	TNSmlDPInformation* dpInfo = iSession.HostClient().DataProviderInformationL( iId, err );
       
    63     User::LeaveIfError( err );
       
    64     
       
    65     HBufC* defds = iSession.HostClient().DefaultStoreL( iId, err );
       
    66     User::LeaveIfError( err );
       
    67     
       
    68     CDesCArray* dsArray = new (ELeave) CDesCArrayFlat(1);
       
    69     CleanupStack::PushL(dsArray);
       
    70 
       
    71     iSession.HostClient().ListStoresL( dsArray, iId, err );
       
    72     User::LeaveIfError( err );
       
    73     
       
    74     TInt mimeCount = dpInfo->iMimeTypes->Count();
       
    75     
       
    76     TInt mimelen = 0;
       
    77     TInt mverlen = 0;
       
    78     for (TInt mime = 0; mime < mimeCount; ++mime )
       
    79     	{
       
    80     	mimelen += ( *dpInfo->iMimeTypes )[ mime ].Size(); // mime type text length
       
    81     	mimelen += KSizeofTInt32; // mime type length value
       
    82     	mverlen += ( *dpInfo->iMimeVersions )[ mime ].Size(); // mime version text length
       
    83     	mverlen += KSizeofTInt32; // mime version length value
       
    84     	}
       
    85     	
       
    86     TInt dnamlen = dpInfo->iDisplayName->Size();
       
    87     TInt defdslen = defds->Size();
       
    88 
       
    89     CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
       
    90 	CleanupStack::PushL( buffer );
       
    91 	RBufWriteStream stream( *buffer );  
       
    92     
       
    93     CleanupClosePushL(stream); 
       
    94  
       
    95     stream.WriteInt32L( dpInfo->iVersion.iMajor );    // Version major
       
    96     stream.WriteInt32L( dpInfo->iVersion.iMinor );    // Version minor
       
    97     stream.WriteInt32L( dpInfo->iVersion.iBuild );    // Version build
       
    98     stream.WriteInt8L( (TInt8)dpInfo->iProtocolVer ); // Req protocol version
       
    99 
       
   100     // display name
       
   101     stream.WriteInt32L( dnamlen );
       
   102     stream << dpInfo->iDisplayName->Des();
       
   103 
       
   104 	// mime type count
       
   105     stream.WriteInt32L( mimeCount );
       
   106 	
       
   107     // mime types
       
   108     for ( TInt type = 0; type < mimeCount; ++type )
       
   109     	{
       
   110         stream.WriteInt32L( ( *dpInfo->iMimeTypes )[ type ].Size() );
       
   111         stream << ( *dpInfo->iMimeTypes )[ type ];
       
   112     	}
       
   113 
       
   114     // mime versions
       
   115     for ( TInt ver = 0; ver < mimeCount; ++ver )
       
   116     	{
       
   117         stream.WriteInt32L( ( *dpInfo->iMimeVersions )[ ver ].Size() );
       
   118         stream << ( *dpInfo->iMimeVersions )[ ver ];
       
   119     	}
       
   120 
       
   121     TInt count = dsArray->Count() + 1; // default ds + others.
       
   122 
       
   123     stream.WriteInt8L( count ); // Amount of datastores.
       
   124 
       
   125     // default datastore
       
   126     stream.WriteInt32L( defdslen );   
       
   127     stream << defds->Des();
       
   128    
       
   129     for ( TInt i(0) ; i < dsArray->Count() ; i++ )
       
   130         {
       
   131             stream.WriteInt32L( dsArray->operator[](i).Size() ); 
       
   132             stream << dsArray->operator[](i);
       
   133         }
       
   134 
       
   135     // Allow multible datastores
       
   136     stream.WriteInt8L( iSession.HostClient().SupportsOperationL( KUidSmlSupportMultipleStores, iId, err ) ); 
       
   137     User::LeaveIfError( err );
       
   138 
       
   139     stream.CommitL();
       
   140     
       
   141     CleanupStack::PopAndDestroy(&stream);
       
   142     delete iBuffer;
       
   143 	iBuffer = buffer;
       
   144 	CleanupStack::Pop( buffer );    
       
   145     CleanupStack::PopAndDestroy(dsArray);
       
   146     
       
   147     delete defds;
       
   148     delete dpInfo->iDisplayName;
       
   149     delete dpInfo->iMimeTypes;
       
   150     delete dpInfo->iMimeVersions;
       
   151     delete dpInfo;
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // TInt CNSmlDataProvider::DataSize()
       
   156 // --------------------------------------------------------------------------
       
   157 //
       
   158 TInt CNSmlDataProvider::DataSize()
       
   159     {
       
   160     return iBuffer->Size();
       
   161     }
       
   162 
       
   163 // --------------------------------------------------------------------------
       
   164 // const TPtr8& CNSmlDataProvider::ReadData()
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 const TPtr8& CNSmlDataProvider::ReadData()
       
   168     {
       
   169     if ( iBuffer )
       
   170         {
       
   171         iDataPtr.Set( iBuffer->Ptr(0) );    
       
   172         }    
       
   173     return iDataPtr;
       
   174     }