locationmanager/client/src/rlocationobjectmanipulator.cpp
changeset 0 c53acadfccc6
child 7 3cebc1a84278
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-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:  An interface to Location Object
       
    15 *
       
    16 */
       
    17 
       
    18 #include "locationdatatype.h"
       
    19 #include "rlocationobjectmanipulator.h"
       
    20 #include "locationmanagerdefs.h"
       
    21 #include "locationmanagerdebug.h"
       
    22 #include "mdsutils.h"
       
    23 #include <locationeventdef.h>
       
    24 #include "mdcserializationbuffer.h"
       
    25 
       
    26 // --------------------------------------------------------------------------
       
    27 // RLocationObjectManipulator::CreateLocationObject
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C TInt RLocationObjectManipulator::CreateLocationObject( TLocationData& aLocationData,
       
    31 									TItemId aObjectId )
       
    32 	{
       
    33 	LOG( "RLocationObject::CreateLocationObject begin" );
       
    34     TInt ret( KErrDisconnected );
       
    35     TPckg<TLocationData> locationData( aLocationData );
       
    36     TPckg<TItemId> objectId( aObjectId );    
       
    37     if ( iHandle )
       
    38         {
       
    39         ret = SendReceive( ELocManCreateLocationObject, TIpcArgs( &locationData,  &objectId) );
       
    40         }
       
    41     LOG( "RLocationObject::CreateLocationObject end" );
       
    42     return ret;
       
    43 	}
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // RLocationObjectManipulator::LocationSnapshot
       
    47 // --------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C TInt RLocationObjectManipulator::LocationSnapshot(	TItemId aObjectId )
       
    50 	{
       
    51 	LOG( "RLocationObject::LocationSnapshot begin" );
       
    52     TInt ret( KErrDisconnected );
       
    53     TPckg<TItemId> objectId( aObjectId );    
       
    54     if ( iHandle )
       
    55         {
       
    56         ret = SendReceive( ELocManLocationSnapshot, TIpcArgs( &objectId ) );
       
    57         }
       
    58     LOG( "RLocationObject::LocationSnapshot end" );
       
    59     return ret;
       
    60 	}
       
    61 
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // RLocationObjectManipulator::RemoveLocationObject
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C TInt RLocationObjectManipulator::RemoveLocationObject( TItemId aObjId )
       
    68 	{
       
    69 	LOG( "RLocationObject::RemoveLocationObject begin" );
       
    70 	TInt ret( KErrDisconnected );
       
    71 	TPckg<TItemId> objId( aObjId );
       
    72 	if ( iHandle )
       
    73         {
       
    74         ret = SendReceive( ELocManRemoveLocationObject, TIpcArgs( &objId ));
       
    75         }
       
    76 	LOG( "RLocationObject::RemoveLocationObject end" );
       
    77 	return ret;
       
    78 	}
       
    79 // --------------------------------------------------------------------------
       
    80 // RLocationObjectManipulator::CopyLocationData
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C void RLocationObjectManipulator::CopyLocationData (TItemId aSourceId, 
       
    84 												RArray<TItemId>& aTargetIds,
       
    85 												TRequestStatus& aStatus)
       
    86 	{
       
    87 	LOG( "RLocationObject::CopyLocationData begin" );
       
    88 	
       
    89 	TPckg<TItemId> sourceId( aSourceId );
       
    90 	// serializing RArray, must deserialize in server side
       
    91 
       
    92 	HBufC8* paramBuf = NULL;   
       
    93     TRAPD( err, paramBuf = SerializeArrayL( aTargetIds ) );
       
    94     // was serializing failed
       
    95     if ( err != KErrNone )
       
    96     	{
       
    97         LOG1 ( "RLocationObject::CopyLocationData - cannot create serialized objectIds for sending, error: %d", err );
       
    98         delete paramBuf;
       
    99         paramBuf = NULL;
       
   100         CompleteRequest( aStatus, err );
       
   101 
       
   102         return;
       
   103     	}
       
   104     
       
   105     if ( iHandle )
       
   106         {
       
   107        	TIpcArgs args( &sourceId, paramBuf );
       
   108         const TInt result = SendReceive( ELocManCopyLocationDataById, args );
       
   109         CompleteRequest( aStatus, result );
       
   110         }
       
   111     else
       
   112         {
       
   113         CompleteRequest( aStatus, KErrDisconnected );
       
   114         }
       
   115     
       
   116     delete paramBuf;
       
   117 	LOG( "RLocationObject::CopyLocationData end" );
       
   118 	}
       
   119 // --------------------------------------------------------------------------
       
   120 // RLocationObjectManipulator::CopyLocationData
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void RLocationObjectManipulator::CopyLocationData (TDesC& aSourceURI, 
       
   124 								RPointerArray<TDesC>& aTargetURIs,
       
   125 								TRequestStatus& aStatus)
       
   126 	{
       
   127 	LOG( "RLocationObject::CopyLocationData begin" );
       
   128 
       
   129     TInt32 uriCount = aTargetURIs.Count();
       
   130 	
       
   131 	// Required size for serialized URI buffer, count
       
   132     TInt urisRequiredSize = CMdCSerializationBuffer::KRequiredSizeForTInt32;
       
   133 
       
   134     // and URIs
       
   135     for( TInt i = 0; i < uriCount; i++ )
       
   136     	{
       
   137     	urisRequiredSize += CMdCSerializationBuffer::RequiredSize( *aTargetURIs[i] );
       
   138     	}
       
   139 
       
   140    	// serializing URIs
       
   141     CMdCSerializationBuffer* uriBuffer( NULL );
       
   142     TRAPD( error, uriBuffer = CMdCSerializationBuffer::NewL( urisRequiredSize ); 
       
   143                           uriBuffer->InsertL( uriCount ) );
       
   144     
       
   145     if( error != KErrNone )
       
   146         {
       
   147         LOG( "RLocationObject::CopyLocationData CMdCSerializationBuffer creation failed" );
       
   148         delete uriBuffer;
       
   149         CompleteRequest( aStatus, error );
       
   150         return;
       
   151         }
       
   152 
       
   153     for( TInt i = 0; i < uriCount; i++ )
       
   154 		{
       
   155 		TRAPD( err, uriBuffer->InsertL( *aTargetURIs[i] ) );
       
   156 		
       
   157 	    // was serializing failed
       
   158 	    if ( err != KErrNone )
       
   159 	    	{
       
   160 	        LOG1 ( "RLocationObject::CopyLocationData - cannot create serialized objectIds for sending, error: %d", err );
       
   161 	        delete uriBuffer;
       
   162 	        uriBuffer = NULL;
       
   163 	        CompleteRequest( aStatus, err );
       
   164 	        return;
       
   165 	    	}
       
   166 		}
       
   167     
       
   168     if ( iHandle )
       
   169         {
       
   170         TIpcArgs args( &aSourceURI, uriBuffer->BufferConstPtr() );
       
   171         const TInt result = SendReceive( ELocManCopyLocationDataByUri, args );
       
   172         CompleteRequest( aStatus, result );
       
   173         }
       
   174     else
       
   175         {
       
   176         CompleteRequest( aStatus, KErrDisconnected );
       
   177         }
       
   178     
       
   179     delete uriBuffer;
       
   180     LOG( "RLocationObject::CopyLocationData end" );
       
   181 	}
       
   182