homescreensrv_plat/sapi_menucontent/src/mcsdsinterface.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17  
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32def.h>
       
    21 #include "mcsdef.h"
       
    22 #include "mcsmenufilter.h"
       
    23 #include "mcsmenuitem.h"
       
    24 #include "mcsmenunotifier.h"
       
    25 
       
    26 #include "serviceerrno.h"
       
    27 #include "mcsservice.h"
       
    28 #include "mcsdsinterface.h"
       
    29 #include "mcscallback.h"
       
    30 #include "mcsconstants.h"
       
    31 
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Two-phased constructor.
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CMCSDSInterface* CMCSDSInterface::NewL(const TDesC& aContent)
       
    38 	{
       
    39   	CMCSDSInterface* self = new (ELeave) CMCSDSInterface();
       
    40   	CleanupStack::PushL( self );
       
    41   	self->ConstructL(aContent);
       
    42   	CleanupStack::Pop( self );
       
    43 	return self;
       
    44 	}
       
    45 // ---------------------------------------------------------------------------
       
    46 // Destructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //	
       
    49 CMCSDSInterface::~CMCSDSInterface()
       
    50 	{
       
    51 	delete iMCSService;
       
    52 	}
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // Constructor
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CMCSDSInterface::CMCSDSInterface()
       
    59 	{
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // Symbian Constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //	
       
    66 void CMCSDSInterface::ConstructL(const TDesC& aContent)
       
    67 	{
       
    68 	iMCSService = CMCSService::NewL(aContent);	
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 //  Executes the SAPI as per params
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CMCSDSInterface::ExecuteCmdL( const TDesC8& aCmdName,
       
    76 					             const CLiwGenericParamList& aInParamList,
       
    77 					             CLiwGenericParamList& aOutParamList,
       
    78 					             TUint aCmdOptions,
       
    79 					             MLiwNotifyCallback* aCallback )
       
    80 	{
       
    81 	TInt errcode = KErrNotSupported;
       
    82 	TInt32 transactionId = -1; 
       
    83 		
       
    84 	aOutParamList.AppendL(TLiwGenericParam( KErrorCode, 
       
    85 							TLiwVariant( ErrCodeConversion( KErrNone ))));		
       
    86 	
       
    87 	if ( !aCallback )
       
    88 		{
       
    89 		// Callback is a null pointer
       
    90 		errcode = KErrArgument;
       
    91 		}
       
    92 	else
       
    93 		{
       
    94 	
       
    95 		if ( aCmdName.CompareF( KCmdAdd ) == 0 ) 
       
    96 			{
       
    97 			TRAP(errcode, AddItemL( aInParamList, aCallback ));
       
    98 			}
       
    99 		else if ( aCmdName.CompareF( KCmdDelete ) == 0 ) 
       
   100 			{
       
   101 			  TRAP(errcode, DeleteL( aInParamList, aCallback ));
       
   102 			}
       
   103 		else if ( aCmdName.CompareF( KCmdGetList ) == 0 ) 
       
   104 			{
       
   105 			TRAP(errcode, GetListL( aInParamList, aCallback ));
       
   106 			}
       
   107 		else if ( aCmdName.CompareF( KCmdReqNotification ) == 0 ) 
       
   108 			{
       
   109 			if( aCallback && !(aCmdOptions & KLiwOptCancel) )
       
   110 	            {
       
   111 	            TRAP(errcode, RequestNotificationL(aInParamList, aCallback));
       
   112 	            }
       
   113 	        if ( aCmdOptions & KLiwOptCancel )
       
   114 	            {
       
   115 	            TRAP(errcode, iMCSService->UnRegisterObserverL());
       
   116 	            }
       
   117 			
       
   118 			}
       
   119 		
       
   120 		// Append transaction id in case of asynchronous requests 
       
   121 		if( ( KLiwOptASyncronous & aCmdOptions ) &&  
       
   122 							( errcode == KErrNone ) && ( transactionId != -1 ) )
       
   123 			{
       
   124 			aOutParamList.AppendL(TLiwGenericParam( KTransactionID, 
       
   125 									TLiwVariant( TInt32( transactionId ))));		
       
   126 			}	
       
   127 		}
       
   128 	
       
   129 	if( errcode != KErrNone )
       
   130 		{
       
   131 		aOutParamList.Reset();
       
   132 		aOutParamList.AppendL(TLiwGenericParam( KErrorCode, 
       
   133 									TLiwVariant(ErrCodeConversion(errcode))));		
       
   134 		}
       
   135 	}
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Closes the interface
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CMCSDSInterface::Close()
       
   142 	{
       
   143 	delete this;
       
   144 	}
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Issues Add a new Item request to MCSService
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CMCSDSInterface::AddItemL( const CLiwGenericParamList& aInParamList, 
       
   151                               MLiwNotifyCallback* aCallback )
       
   152     {
       
   153     TInt32 itemId = 0;
       
   154     TInt32 parentId = 0;
       
   155     TInt32 beforeId = 0;    
       
   156     TInt pos = 0;
       
   157     TPtrC paramvalue;
       
   158 
       
   159     TBuf16<KMenuMaxAttrValueLen> paramValStr;
       
   160     TBuf16<KMenuMaxAttrNameLen> attrname16;
       
   161     TBuf8<KMenuMaxAttrNameLen> attrname;
       
   162     TBuf16<KMenuMaxAttrValueLen> paramType;
       
   163     TLiwVariant param;    
       
   164     
       
   165     const TLiwGenericParam* inParam = aInParamList.FindFirst( pos, KInData );
       
   166     if (inParam)
       
   167         {
       
   168         CLiwMap* inputMap = (CLiwMap*)inParam->Value().AsMap();
       
   169         if ( inputMap )
       
   170            {
       
   171            attrname.Copy(KMenuAttrId());
       
   172            if( inputMap->FindL( attrname, param))
       
   173         	   {
       
   174         	   param.Get(itemId);
       
   175         	   inputMap->Remove( attrname );
       
   176         	   }
       
   177            param.Reset();
       
   178            if( inputMap->FindL( KParentId, param))
       
   179         	   {
       
   180         	   param.Get(parentId);
       
   181         	   inputMap->Remove( KParentId );
       
   182         	   }
       
   183            param.Reset();
       
   184 
       
   185            if( inputMap->FindL( KBeforeId, param))
       
   186         	   {
       
   187         	   param.Get(beforeId);
       
   188         	   inputMap->Remove(KBeforeId);
       
   189         	   }
       
   190            param.Reset();
       
   191            if( inputMap->FindL( KType, param))
       
   192         	   {
       
   193         	   paramType.Copy(param.AsDes());
       
   194         	   inputMap->Remove( KType ); 
       
   195         	   }
       
   196            param.Reset();
       
   197            
       
   198            CMCSCallback* cb = CMCSCallback::NewL(aCallback, aInParamList, 
       
   199                    aCallback->GetTransactionID(), *iMCSService,CMCSCallback::EAddORChange );
       
   200            CleanupStack::PushL(cb);
       
   201            iMCSService->UpdateItemL(cb, paramType, itemId, parentId, beforeId, *inputMap);
       
   202            CleanupStack::Pop(cb);
       
   203            }
       
   204         else
       
   205         	{
       
   206         	User::Leave(KErrArgument);
       
   207         	}
       
   208         }
       
   209     else
       
   210         {             
       
   211        User::Leave(KErrArgument);
       
   212         }
       
   213     }
       
   214            
       
   215 // ---------------------------------------------------------------------------
       
   216 // Issues GetList request to MCSService
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CMCSDSInterface::GetListL( const CLiwGenericParamList& aInParamList, 
       
   220 		                      MLiwNotifyCallback* aCallback )
       
   221 	{
       
   222 	CheckGetListInputListL( aInParamList );
       
   223     CMCSCallback* cb = CMCSCallback::NewL(aCallback, aInParamList, 
       
   224     		aCallback->GetTransactionID(), *iMCSService,CMCSCallback::EGetList );
       
   225     CleanupStack::PushL(cb);
       
   226     iMCSService->GetListL( aInParamList, cb );
       
   227     CleanupStack::Pop(cb);
       
   228 	}
       
   229 // ---------------------------------------------------------------------------
       
   230 // Check if inputlist for getlist is proper
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CMCSDSInterface::CheckGetListInputListL( const CLiwGenericParamList&
       
   234 			aInParamList )
       
   235 	{
       
   236 	TInt pos( 0 );
       
   237 	const TLiwGenericParam* inParam = aInParamList.FindFirst( pos, KInData );
       
   238 	if (inParam)
       
   239 		{
       
   240 		const CLiwMap* inputMap = inParam->Value().AsMap();
       
   241 		if ( inputMap )
       
   242 	        {
       
   243 	        TLiwVariant param;
       
   244 	        // Folder Id
       
   245 	        if( !inputMap->FindL( KMenuAttrId8, param ) )
       
   246 	                {
       
   247 	            	User::Leave( KErrArgument );
       
   248 	                }
       
   249             }
       
   250 	    else
       
   251 		   	{
       
   252         	User::Leave( KErrArgument );
       
   253 		   	}
       
   254 		}
       
   255 	else
       
   256 		{
       
   257     	User::Leave( KErrArgument );
       
   258 		}
       
   259 	}
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // Issues Change Notification request to MCSService
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 void CMCSDSInterface::RequestNotificationL( const CLiwGenericParamList& aInParamList, 
       
   266 					                       			MLiwNotifyCallback* aCallback)
       
   267 													
       
   268 	{
       
   269 	TInt pos = 0;
       
   270 	TInt events = 0;
       
   271     TBuf8<KMenuMaxAttrNameLen> attrname;
       
   272     TInt paramFolderId = 0;
       
   273     TLiwVariant param;
       
   274 	const TLiwGenericParam* inParam = aInParamList.FindFirst( pos, KInData );
       
   275 	if (inParam)
       
   276 	        {
       
   277 	        const CLiwMap* inputMap = inParam->Value().AsMap();
       
   278 	        if ( inputMap )
       
   279 	            {
       
   280 	            // Folder Id
       
   281 	            attrname.Copy(KMenuAttrId());
       
   282 	            if( inputMap->FindL( attrname, param))
       
   283 	                {
       
   284 	                paramFolderId = param.AsTInt32();
       
   285 	                }
       
   286 	            param.Reset();
       
   287 	            if( inputMap->FindL( KAddRemove, param))
       
   288                    {
       
   289                    if (param.AsTBool())
       
   290                        {
       
   291                         events =  events  | RMenuNotifier::EItemsAddedRemoved;
       
   292                        }
       
   293                    }
       
   294                 param.Reset();
       
   295                 if( inputMap->FindL( KReorder, param))
       
   296                    {
       
   297                    if (param.AsTBool())
       
   298                       {
       
   299                        events =  events  | RMenuNotifier::EItemsReordered;
       
   300                       }
       
   301                    }
       
   302                 param.Reset();
       
   303                 if( inputMap->FindL( KAttributeChange, param))
       
   304                    {
       
   305                    if (param.AsTBool())
       
   306                      {
       
   307                       events =  events  | RMenuNotifier::EItemAttributeChanged;
       
   308                      }
       
   309                    }
       
   310                 param.Reset();
       
   311 	            }
       
   312 	        }
       
   313 	
       
   314 	CMCSCallback* cb = CMCSCallback::NewL(aCallback, aInParamList, 
       
   315 	                aCallback->GetTransactionID(), *iMCSService,  CMCSCallback::ERequestNotification );
       
   316 	CleanupStack::PushL( cb );
       
   317 		
       
   318 	// Issue request
       
   319 	if(events)
       
   320 		{
       
   321 		iMCSService->RegisterObserverL(paramFolderId, events, cb );
       
   322 		}
       
   323 	else
       
   324 		{
       
   325         User::Leave(KErrArgument);
       
   326 		}
       
   327 	CleanupStack::Pop( cb );
       
   328 	}
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // Issues Delete an item  request to MCSService
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CMCSDSInterface::DeleteL( const CLiwGenericParamList& aInParamList, 
       
   335                               MLiwNotifyCallback* aCallback )
       
   336     {
       
   337     TInt pos = 0;    
       
   338     TBuf8<KMenuMaxAttrNameLen> attrname;
       
   339     TInt itemId = -1;
       
   340     TLiwVariant param;
       
   341     const TLiwGenericParam* inParam = aInParamList.FindFirst( pos, KInData );
       
   342     if (inParam)
       
   343             {
       
   344             const CLiwMap* inputMap = inParam->Value().AsMap();
       
   345             if ( inputMap )
       
   346                 {
       
   347                 // Item Id
       
   348                 attrname.Copy(KMenuAttrId());
       
   349                 if( inputMap->FindL( attrname, param))
       
   350                     {
       
   351                     itemId = param.AsTInt32();
       
   352                     }
       
   353                 param.Reset();
       
   354                 }
       
   355             }
       
   356 
       
   357     if (itemId == -1)
       
   358         {
       
   359         User::Leave(KErrArgument);
       
   360         }
       
   361     else
       
   362         {
       
   363         CMCSCallback* cb = CMCSCallback::NewL(aCallback, aInParamList, 
       
   364                 aCallback->GetTransactionID(), *iMCSService,CMCSCallback::EDelete );
       
   365         CleanupStack::PushL(cb);
       
   366     
       
   367         iMCSService->DeleteL( cb, itemId );
       
   368         CleanupStack::Pop(cb);
       
   369         }
       
   370     }
       
   371 
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // ErrCode Conversion
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 TInt32 CMCSDSInterface::ErrCodeConversion(TInt code)
       
   378 	{
       
   379 	TInt32 err;
       
   380 	switch (code)
       
   381 		{
       
   382 		case KErrCancel:
       
   383 						// Returning KErrNone incase of KErrCancel
       
   384 		case KErrNone:
       
   385 			err= SErrNone;
       
   386 			break;
       
   387 
       
   388 		case KErrNotFound:
       
   389 			err= SErrNotFound;
       
   390 			break;
       
   391 
       
   392 		case KErrNoMemory:
       
   393 			err = SErrNoMemory;
       
   394 			break;
       
   395 
       
   396 		case KErrInUse:
       
   397 			err = SErrServiceInUse;
       
   398 			break;
       
   399 
       
   400 		case KErrNotSupported:
       
   401 			err = SErrServiceNotSupported;
       
   402 			break;
       
   403 
       
   404 		case KErrBadName:
       
   405 			err = SErrBadArgumentType;
       
   406 			break;
       
   407 						
       
   408 		case KErrArgument: 
       
   409 			err = SErrInvalidServiceArgument;
       
   410 			break;
       
   411 			
       
   412 		case KErrAccessDenied: 
       
   413 				err = SErrAccessDenied;
       
   414 				break;
       
   415 	
       
   416 		default:
       
   417 			err = SErrGeneralError;
       
   418 			break;
       
   419 		}
       
   420 	
       
   421     return err;
       
   422 	}
       
   423 
       
   424 // End of file