menucontentsrv/srvsrc/menusrvsession.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:
       
    15 *
       
    16 */
       
    17 #include "menusrvsession.h"
       
    18 #include "menusrvstream.h"
       
    19 #include "menusrvoperation.h"
       
    20 #include "menusrvobjectfilter.h"
       
    21 #include "mcsmenunotifier.h" // for the notifier events
       
    22 #include "menusrvnotifier.h"
       
    23 #include "menusrvbuf.h"
       
    24 #include "menumsg.h"
       
    25 #include "menusrvdef.h"
       
    26 #include "mcsmenuitem.h"
       
    27 #include "mcsmenufilter.h"
       
    28 #include "menuutil.h"
       
    29 #include "menueng.h"
       
    30 #include "menusrveng.h"
       
    31 #include "menuengobject.h"
       
    32 #include <s32buf.h>
       
    33 #include <s32strm.h>
       
    34 
       
    35 
       
    36 const TInt KParamIndAttrName = 1;
       
    37 const TInt KParamIndAttrEx = 2;
       
    38 const TInt KParamIndAttrVal = 3;
       
    39 const TInt KParamIndBuf = 2;
       
    40 const TInt KParamIndStream = 3;
       
    41 const TInt KParamIndOp = 3;
       
    42 const TInt KParamIndNotif = 3;
       
    43 
       
    44 const TInt KGetListDescriptorPos = 0;
       
    45 const TInt KGetListReturnPos = 1;
       
    46 
       
    47 //const TInt KIconSize = 74;
       
    48 
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CMenuSrvSession::~CMenuSrvSession
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CMenuSrvSession::~CMenuSrvSession()
       
    57     {
       
    58     delete iNotifierIx;
       
    59     delete iStreamIx;
       
    60     delete iOperationIx;
       
    61     iMenuSrv.RemoveContainer( iObjectCon );
       
    62     if ( iSharedEng )
       
    63         {
       
    64         iSharedEng->RemoveSession( this ); // Ownership release.
       
    65         }
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CMenuSrvSession::NewL
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CMenuSrvSession* CMenuSrvSession::NewL( CMenuSrv& aMenuSrv )
       
    73     {
       
    74     CMenuSrvSession* sess = new (ELeave) CMenuSrvSession( aMenuSrv );
       
    75     CleanupStack::PushL( sess );
       
    76     sess->ConstructL();
       
    77     CleanupStack::Pop( sess );
       
    78     return sess;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CMenuSrvSession::CMenuSrvSession
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CMenuSrvSession::CMenuSrvSession( CMenuSrv& aMenuSrv )
       
    86 : iMenuSrv( aMenuSrv )
       
    87     {
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CMenuSrvSession::ConstructL
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CMenuSrvSession::ConstructL()
       
    95     {
       
    96     iObjectCon = iMenuSrv.NewContainerL();
       
    97     iNotifierIx = CObjectIx::NewL();
       
    98     iStreamIx = CObjectIx::NewL();
       
    99     iOperationIx = CObjectIx::NewL();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // CMenuSrvSession::CountResources
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 TInt CMenuSrvSession::CountResources()
       
   107     {
       
   108     return iObjectCon->Count();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CMenuSrvSession::ServiceL
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CMenuSrvSession::ServiceL( const RMessage2& aMessage )
       
   116     {
       
   117     if( !ServiceCapabilityTestL( aMessage ) )
       
   118     	{
       
   119         // The rest of the functions does not work with a dead engine.
       
   120         if ( iEngineDead )
       
   121             {
       
   122             User::Leave( KErrDisconnected );
       
   123             }
       
   124         
       
   125         if( !ServiceCapReadL( aMessage ) )
       
   126         	{
       
   127         	if( !ServiceCapWriteL( aMessage) )
       
   128         		{
       
   129     			//Function was not serviced
       
   130         		aMessage.Complete( KErrNotSupported ); // Sync request -> complete it now.
       
   131         		}
       
   132         	}
       
   133     	}
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CMenuSrvSession::ServiceCapabilityTestL
       
   138 // Handles functions with test capability
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 TBool CMenuSrvSession::ServiceCapabilityTestL( const RMessage2& aMessage )
       
   142 	{
       
   143 	// These debug functions work even with a dead engine.
       
   144 	TBool serviced = ETrue;
       
   145 	switch( aMessage.Function() )
       
   146 	    {
       
   147 	    case EMenuResourceMarkStart:
       
   148 	        {
       
   149 	        ResourceCountMarkStart();
       
   150 	        aMessage.Complete( KErrNone );
       
   151 	        break;
       
   152 	        }
       
   153 	
       
   154 	    case EMenuResourceMarkEnd:
       
   155 	        {
       
   156 	        ResourceCountMarkEnd( aMessage );
       
   157 	        aMessage.Complete( KErrNone );
       
   158 	        break;
       
   159 	        }
       
   160 	
       
   161 	    case EMenuResourceCount:
       
   162 	        {
       
   163 	        aMessage.Complete( CountResources() );
       
   164 	        break;
       
   165 	        }
       
   166 	
       
   167 	    case EMenuSetHeapFailure:
       
   168 	        {
       
   169 	        User::__DbgSetAllocFail
       
   170 	            (
       
   171 	            RAllocator::EUser,
       
   172 	            STATIC_CAST( RAllocator::TAllocFail, aMessage.Int0() ),
       
   173 	            aMessage.Int1()
       
   174 	            );
       
   175 	        aMessage.Complete( KErrNone );
       
   176 	        break;
       
   177 	        }
       
   178 	
       
   179 	    default:
       
   180 	        {
       
   181 	        // Not a debug function.
       
   182 	        serviced = EFalse;
       
   183 	        break;
       
   184 	        }
       
   185 	    }
       
   186 	return serviced;
       
   187 	}
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CMenuSrvSession::ServiceCapReadWriteL
       
   191 // Handles functions with read device data capability
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 TBool CMenuSrvSession::ServiceCapReadL( const RMessage2& aMessage )
       
   195 	{
       
   196 	TBool serviced = ETrue;
       
   197 	switch( aMessage.Function() )
       
   198         {
       
   199 		case EMenuConstructSession:
       
   200             {
       
   201             __ASSERT_ALWAYS( !iSharedEng, PanicClientL( aMessage ) );
       
   202             RBuf name;
       
   203             name.CreateL( aMessage.GetDesLengthL( 0 ) );
       
   204             CleanupClosePushL( name );
       
   205             aMessage.ReadL( 0, name );
       
   206             // Get the shared engine and open it.
       
   207             CMenuSrvEng* sharedEng = iMenuSrv.GetEngineL( name );
       
   208             CleanupClosePushL( *sharedEng );
       
   209             sharedEng->AddSessionL( this ); // Ownership transfer.
       
   210             // No leaving after this point.
       
   211             CleanupStack::Pop( sharedEng );
       
   212             iSharedEng = sharedEng;
       
   213             CleanupStack::PopAndDestroy( &name );
       
   214             break;
       
   215             };
       
   216 
       
   217         case EMenuRootFolder:
       
   218             {
       
   219             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   220             TPckgBuf<TInt> root;
       
   221             TInt id;
       
   222             iSharedEng->Engine().RootFolderL( id );
       
   223             root() = id;
       
   224             aMessage.WriteL( 0, root );
       
   225             break;
       
   226             }
       
   227 
       
   228         case EMenuStreamClose:
       
   229             {
       
   230             TInt handle = aMessage.Int3();
       
   231             StreamL( handle ); // Check that handle is valid.
       
   232             iStreamIx->Remove( handle );
       
   233             break;
       
   234             };
       
   235 
       
   236         case EMenuStreamOpen:
       
   237             {
       
   238             NewStreamL( *(HMenuSrvBuf::NewL()), aMessage );
       
   239             break;
       
   240             }
       
   241 
       
   242         case EMenuStreamRead:
       
   243             {
       
   244             TInt handle = aMessage.Int3();
       
   245             TInt len;
       
   246             StreamL( handle ).ReadL( aMessage, len );
       
   247             break;
       
   248             }
       
   249 
       
   250         case EMenuStreamWrite:
       
   251             {
       
   252             TInt handle = aMessage.Int3();
       
   253             StreamL( handle ).WriteL( aMessage );
       
   254             break;
       
   255             }
       
   256 
       
   257         case EMenuGetHdr:
       
   258             {
       
   259             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   260             TInt id = aMessage.Int0();
       
   261             TPckgBuf<TMenuItem> hdr;
       
   262             iSharedEng->Engine().GetItemL( id, hdr() );
       
   263             aMessage.WriteL( 1, hdr );
       
   264             break;
       
   265             }
       
   266 
       
   267         case EMenuGetItems:
       
   268             {
       
   269             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   270             HMenuSrvBuf* streamBuf = HMenuSrvBuf::NewLC();
       
   271             RWriteStream stream( streamBuf );
       
   272             TInt folder = aMessage.Int0();
       
   273             TBool recursive = aMessage.Int1();
       
   274             RArray<TMenuItem> items;
       
   275             CleanupClosePushL( items );
       
   276             iSharedEng->Engine().GetItemsL( items, folder, NULL, recursive );
       
   277             MenuUtil::ExternalizeL( items, stream );
       
   278             stream.CommitL();
       
   279             CleanupStack::PopAndDestroy( &items );
       
   280             CleanupStack::Pop( streamBuf );
       
   281             NewStreamL( *(stream.Sink()), aMessage );
       
   282             break;
       
   283             }
       
   284 
       
   285         case EMenuGetRunningApps:
       
   286             {
       
   287             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   288             HMenuSrvBuf* streamBuf = HMenuSrvBuf::NewLC();
       
   289             RWriteStream stream( streamBuf );
       
   290             RArray<TUid> items;
       
   291             CleanupClosePushL( items );
       
   292             iSharedEng->GetRunningAppsL( items );
       
   293             MenuUtil::ExternalizeL( items, stream );
       
   294             stream.CommitL();
       
   295             CleanupStack::PopAndDestroy( &items );
       
   296             CleanupStack::Pop( streamBuf );
       
   297             NewStreamL( *(stream.Sink()), aMessage );
       
   298             break;
       
   299             }            
       
   300             
       
   301         case EMenuGetItemsFiltered:
       
   302             {
       
   303             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   304             TInt folder = aMessage.Int0();
       
   305             TBool recursive = aMessage.Int1();
       
   306             TInt bufHandle = aMessage.Int2();
       
   307             RArray<TMenuItem> items;
       
   308             CleanupClosePushL( items );
       
   309             MStreamBuf& buf = StreamL( bufHandle ).Host();
       
   310             RReadStream rs( &buf );
       
   311             CMenuFilter* filter = CMenuFilter::NewLC();
       
   312             filter->InternalizeL( rs );
       
   313             TMenuSrvObjectFilter engFilter( *filter );
       
   314             iSharedEng->Engine().GetItemsL
       
   315                 ( items, folder, &engFilter, recursive );
       
   316             CleanupStack::PopAndDestroy( filter );
       
   317             RWriteStream stream( &buf );
       
   318             MenuUtil::ExternalizeL( items, stream );
       
   319             stream.CommitL();
       
   320             CleanupStack::PopAndDestroy( &items );
       
   321             break;
       
   322             }
       
   323             
       
   324         case EMenuGetListSize:
       
   325             {
       
   326             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   327             TInt deslen = aMessage.GetDesLength( KGetListDescriptorPos );
       
   328             HBufC8* buffer = HBufC8::NewLC( deslen );
       
   329             TPtr8 tempDes = buffer->Des( );
       
   330             aMessage.Read( KGetListDescriptorPos, tempDes );
       
   331             TInt size = iSharedEng->GetListSizeL( *buffer );
       
   332             TPckg<TInt> sizeDes( size );
       
   333             aMessage.WriteL( KGetListReturnPos, sizeDes );
       
   334             CleanupStack::PopAndDestroy( buffer );
       
   335             break;
       
   336             }   
       
   337 
       
   338         case EMenuGetListData:
       
   339             {
       
   340             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   341             aMessage.WriteL( KGetListDescriptorPos, 
       
   342             		iSharedEng->GetListDataL() );
       
   343             iSharedEng->CloseOutputBuffer();
       
   344             break;
       
   345             }              
       
   346                         
       
   347             
       
   348         case EMenuItemGetAttribute:
       
   349             {
       
   350             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   351             TInt id = aMessage.Int0();
       
   352             RBuf name;
       
   353             name.CreateL( aMessage.GetDesLengthL( KParamIndAttrName ) );
       
   354             CleanupClosePushL( name );
       
   355             aMessage.ReadL( KParamIndAttrName, name );
       
   356             TPckgBuf<TBool> attrExistsBuf;
       
   357             TBool attrExists(EFalse);
       
   358         	RBuf attrVal;
       
   359         	attrVal.CleanupClosePushL();
       
   360         	attrVal.CreateL(KMenuMaxAttrValueLen);
       
   361         	iSharedEng->GetAttributeL( id, name, attrExists, attrVal);
       
   362             attrExistsBuf() = attrExists;
       
   363             aMessage.WriteL( KParamIndAttrEx, attrExistsBuf );
       
   364             
       
   365             if ( attrExists )
       
   366                 {
       
   367                 aMessage.WriteL( KParamIndAttrVal, attrVal );
       
   368                 }
       
   369         	CleanupStack::PopAndDestroy( &attrVal );
       
   370             CleanupStack::PopAndDestroy( &name );
       
   371             break;
       
   372             }
       
   373             
       
   374         case EMenuItemGetAttributeList:
       
   375             {
       
   376             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   377             TInt id = aMessage.Int0();
       
   378             TInt bufHandle = aMessage.Int2();
       
   379             HMenuSrvBuf* streamBuf = HMenuSrvBuf::NewLC();
       
   380             RWriteStream ws( streamBuf );
       
   381             RArray<TPtrC> attributeList;
       
   382         	CleanupClosePushL(attributeList);
       
   383             
       
   384             iSharedEng->GetAttributeListL( id, attributeList );
       
   385 
       
   386             for ( TInt ndx = 0; ndx < attributeList.Count(); ndx++ )
       
   387                 {
       
   388                 TPtrC name;
       
   389                 name.Set( attributeList[ndx] );
       
   390                 ws.WriteInt32L( name.Length() );
       
   391                 ws.WriteL( name );
       
   392                 }
       
   393             ws.WriteInt32L( 0 );
       
   394             ws.CommitL();
       
   395 
       
   396         	CleanupStack::PopAndDestroy(&attributeList);
       
   397             CleanupStack::Pop( streamBuf );
       
   398             NewStreamL( *(ws.Sink()), aMessage );
       
   399 
       
   400             break;
       
   401             }
       
   402 
       
   403         case EMenuNotifierClose:
       
   404             {
       
   405             TInt handle = aMessage.Int3();
       
   406             NotifierL( handle ); // Check that handle is valid.
       
   407             iNotifierIx->Remove( handle );
       
   408             break;
       
   409             };
       
   410 
       
   411         case EMenuNotifierOpen:
       
   412             {
       
   413             NewNotifierL( aMessage );
       
   414             break;
       
   415             }
       
   416 
       
   417         case EMenuNotifierNotify:
       
   418             {
       
   419             TInt handle = aMessage.Int3();
       
   420             CMenuSrvNotifier& notifier( NotifierL( handle ) );
       
   421             notifier.NotifyL( aMessage.Int0(), aMessage.Int1(), aMessage );
       
   422             // No leaving after this point!
       
   423             return ETrue; // Async request -> the object will complete it.
       
   424             }
       
   425 
       
   426         case EMenuNotifierNotifyCancel:
       
   427             {
       
   428             TInt handle = aMessage.Int3();
       
   429             NotifierL( handle ).Cancel();
       
   430             break;
       
   431             }
       
   432             
       
   433 	    default:
       
   434 	        {
       
   435 	        serviced = EFalse;
       
   436 	        break;
       
   437 	        }
       
   438         }
       
   439 	if( serviced )
       
   440 		{
       
   441 		aMessage.Complete( KErrNone );// Sync request -> complete it now.
       
   442 		}
       
   443 	return serviced;
       
   444 	}
       
   445 
       
   446 // ---------------------------------------------------------
       
   447 // CMenuSrvSession::ServiceCapWriteL
       
   448 // Handles functions with write device data capability
       
   449 // ---------------------------------------------------------
       
   450 //
       
   451 TBool CMenuSrvSession::ServiceCapWriteL( const RMessage2& aMessage )
       
   452 	{
       
   453 	TBool serviced = ETrue;
       
   454 	switch( aMessage.Function() )
       
   455         {
       
   456         case EMenuOperationClose:
       
   457             {
       
   458             TInt handle = aMessage.Int3();
       
   459             OperationL( handle ); // Check that handle is valid.
       
   460             iOperationIx->Remove( handle );
       
   461             break;
       
   462             };
       
   463 
       
   464         case EMenuOperationCreateRemove:
       
   465             {
       
   466             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   467             CMenuSrvOperation* op = new (ELeave) CMenuSrvRemoveOperation
       
   468                 ( iSharedEng->Engine(), aMessage.Int0() );
       
   469             AddOperationL( op, aMessage ); // Ownership taken before adding.
       
   470             break;
       
   471             }
       
   472 
       
   473         case EMenuOperationCreateMoveToFolder:
       
   474             {
       
   475             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   476             TInt bufHandle = aMessage.Int0();
       
   477             MStreamBuf& buf = StreamL( bufHandle ).Host();
       
   478             RReadStream rs( &buf );
       
   479             CMenuSrvOperation* op = CMenuSrvMoveToFolderOperation::NewL
       
   480                 ( iSharedEng->Engine(), rs, aMessage.Int1(), aMessage.Int2() );
       
   481             AddOperationL( op, aMessage ); // Ownership taken before adding.
       
   482             break;
       
   483             }
       
   484 
       
   485         case EMenuOperationCreateReorder:
       
   486             {
       
   487             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   488             CMenuSrvOperation* op = new (ELeave) CMenuSrvReorderOperation
       
   489                 ( iSharedEng->Engine(), aMessage.Int0(), aMessage.Int1() );
       
   490             AddOperationL( op, aMessage ); // Ownership taken before adding.
       
   491             break;
       
   492             }
       
   493 
       
   494         case EMenuOperationCreateAdd:
       
   495             {
       
   496             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   497             TBuf<KMenuMaxTypeLen> type;
       
   498             __ASSERT_ALWAYS( aMessage.GetDesLength( 0 ) <= type.MaxLength(), \
       
   499                 User::Leave( KErrBadDescriptor ) ); // Panic the client.
       
   500             aMessage.ReadL( 0, type );
       
   501             TInt bufHandle = aMessage.Int1();
       
   502             MStreamBuf& buf = StreamL( bufHandle ).Host();
       
   503             RReadStream rs( &buf );
       
   504             CMenuSrvAddOperation* op = CMenuSrvAddOperation::NewL
       
   505                 ( iSharedEng->Engine(), type, rs );
       
   506             CleanupStack::PushL( op ); // Leaving calls before AddOperationL.
       
   507             // Send the ID back. Object not yet added to engine!
       
   508             TPckgBuf<TInt> id;
       
   509             id() = op->ObjectId();
       
   510             __ASSERT_DEBUG( id(), User::Invariant() ); // We must have the ID already!
       
   511             aMessage.WriteL( 2, id );
       
   512             CleanupStack::Pop( op );
       
   513             AddOperationL( op, aMessage ); // Ownership taken before adding.
       
   514             break;
       
   515             }
       
   516 
       
   517         case EMenuOperationCreateUpdate:
       
   518             {
       
   519             __ASSERT_ALWAYS( iSharedEng, PanicClientL( aMessage ) );
       
   520             TInt bufHandle = aMessage.Int1();
       
   521             MStreamBuf& buf = StreamL( bufHandle ).Host();
       
   522             RReadStream rs( &buf );
       
   523             CMenuSrvOperation* op = CMenuSrvUpdateOperation::NewL
       
   524                 ( iSharedEng->Engine(), aMessage.Int0(), rs );
       
   525             AddOperationL( op, aMessage ); // Ownership taken before adding.
       
   526             break;
       
   527             }
       
   528 
       
   529         case EMenuOperationCancel:
       
   530             {
       
   531             TInt handle = aMessage.Int3();
       
   532             OperationL( handle ).Cancel();
       
   533             break;
       
   534             }
       
   535 
       
   536         case EMenuOperationStart:
       
   537             {
       
   538             TInt handle = aMessage.Int3();
       
   539             OperationL( handle ).StartL( aMessage );
       
   540             // No leaving after this point!
       
   541             return ETrue; // Async request -> the object will complete it.
       
   542             }
       
   543         default:
       
   544             {
       
   545             serviced = EFalse;
       
   546             break;
       
   547             }
       
   548         }
       
   549 	if( serviced )
       
   550 		{
       
   551 		aMessage.Complete( KErrNone );// Sync request -> complete it now.
       
   552 		}
       
   553 	return serviced;
       
   554 	}
       
   555 
       
   556 // ---------------------------------------------------------
       
   557 // CMenuSrvSession::ServiceError
       
   558 // ---------------------------------------------------------
       
   559 //
       
   560 void CMenuSrvSession::ServiceError( const RMessage2& aMessage, TInt aError )
       
   561     {
       
   562     // A bad descriptor / bad handle error implies a badly programmed client,
       
   563     // so panic it; otherwise use the default handling (report the error to
       
   564     // the client).
       
   565     if ( aError == KErrBadDescriptor || aError == KErrBadHandle )
       
   566         {
       
   567         aMessage.Panic( KMenuSrvName, aError );
       
   568         }
       
   569     if ( aError == KErrNoMemory )
       
   570     	{
       
   571     	iSharedEng->CloseOutputBuffer();
       
   572     	iSharedEng->CleanAttributeCache();
       
   573     	}
       
   574     CSession2::ServiceError( aMessage, aError );
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------
       
   578 // CMenuSrvSession::EngineEvents
       
   579 // ---------------------------------------------------------
       
   580 //
       
   581 void CMenuSrvSession::EngineEvents( TInt aFolder, TInt aEvents )
       
   582     {
       
   583     for ( TInt i = 0; i < iNotifierIx->Count(); i++ )
       
   584         {
       
   585         CMenuSrvNotifier* notif = (CMenuSrvNotifier*)(*iNotifierIx)[i];
       
   586         notif->HandleEvents( aFolder, aEvents );
       
   587         }
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------
       
   591 // CMenuSrvSession::EngineError
       
   592 // ---------------------------------------------------------
       
   593 //
       
   594 void CMenuSrvSession::EngineError( TInt /*aErr*/ )
       
   595     {
       
   596     // Unrecoverable engine error. The engine is dead and will be deleted.
       
   597     // This session has already been removed from the shared engine's list.
       
   598     // This session became useless now; it rejects all messages and is
       
   599     // waiting to be closed.
       
   600     iSharedEng = NULL;
       
   601     iEngineDead = ETrue;
       
   602     }
       
   603 // ---------------------------------------------------------
       
   604 // CMenuSrvSession::NewStreamL
       
   605 // ---------------------------------------------------------
       
   606 //
       
   607 void CMenuSrvSession::NewStreamL
       
   608 ( MStreamBuf& aHost, const RMessage2& aMessage )
       
   609     {
       
   610     aHost.PushL();
       
   611     TInt len = Min( aHost.SizeL(), KMenuStreamBufSize );
       
   612     if ( len )
       
   613         {
       
   614         // We already have some data; send it.
       
   615         TPckgBuf<TMenuBuf> buf;
       
   616         aHost.ReadL( buf().iData, len );
       
   617         buf().iLen = len;
       
   618         aMessage.WriteL( KParamIndBuf, buf );
       
   619         }
       
   620     // Create the stream, it takes ownership of aHost.
       
   621     CMenuSrvStream* obj = new (ELeave) CMenuSrvStream( aHost );
       
   622     CleanupStack::Pop( &aHost );
       
   623     CleanupStack::PushL( obj );
       
   624     iObjectCon->AddL( obj );
       
   625     TInt handle = iStreamIx->AddL( obj );
       
   626     CleanupStack::Pop( obj ); // Now we manage the stream by handle.
       
   627     TPckgC<TInt> handlePckg( handle );
       
   628     TInt err = aMessage.Write( KParamIndStream, handlePckg );
       
   629     if ( err )
       
   630         {
       
   631         iStreamIx->Remove( handle );
       
   632         User::Leave( err );
       
   633         }
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------
       
   637 // CMenuSrvSession::StreamL
       
   638 // ---------------------------------------------------------
       
   639 //
       
   640 CMenuSrvStream& CMenuSrvSession::StreamL( TInt aHandle )
       
   641     {
       
   642     CMenuSrvStream* obj = (CMenuSrvStream*)iStreamIx->AtL( aHandle );
       
   643     if ( !obj )
       
   644         {
       
   645         User::Leave( KErrBadHandle );
       
   646         }
       
   647     return *obj;
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------
       
   651 // CMenuSrvSession::AddOperationL
       
   652 // ---------------------------------------------------------
       
   653 //
       
   654 void CMenuSrvSession::AddOperationL
       
   655 ( CMenuSrvOperation* aOperation, const RMessage2& aMessage )
       
   656     {
       
   657     CleanupStack::PushL( aOperation );
       
   658     iObjectCon->AddL( aOperation );
       
   659     TInt handle = iOperationIx->AddL( aOperation );
       
   660     CleanupStack::Pop( aOperation ); // Now we manage the operation by handle.
       
   661     TPckgC<TInt> handlePckg( handle );
       
   662     TInt err = aMessage.Write( KParamIndOp, handlePckg );
       
   663     if ( err )
       
   664         {
       
   665         iOperationIx->Remove( handle ); // Deletes the operation.
       
   666         User::Leave( err );
       
   667         }
       
   668     }
       
   669 
       
   670 // ---------------------------------------------------------
       
   671 // CMenuSrvSession::OperationL
       
   672 // ---------------------------------------------------------
       
   673 //
       
   674 CMenuSrvOperation& CMenuSrvSession::OperationL( TInt aHandle )
       
   675     {
       
   676     CMenuSrvOperation* obj = (CMenuSrvOperation*)iOperationIx->AtL( aHandle );
       
   677     if ( !obj )
       
   678         {
       
   679         User::Leave( KErrBadHandle );
       
   680         }
       
   681     return *obj;
       
   682     }
       
   683 
       
   684 // ---------------------------------------------------------
       
   685 // CMenuSrvSession::NewNotifierL
       
   686 // ---------------------------------------------------------
       
   687 //
       
   688 void CMenuSrvSession::NewNotifierL( const RMessage2& aMessage )
       
   689     {
       
   690     CMenuSrvNotifier* obj = new (ELeave) CMenuSrvNotifier;
       
   691     CleanupStack::PushL( obj );
       
   692     iObjectCon->AddL( obj );
       
   693     TInt handle = iNotifierIx->AddL( obj );
       
   694     CleanupStack::Pop( obj ); // Now we manage the notifier by handle.
       
   695     TPckgC<TInt> handlePckg( handle );
       
   696     TInt err = aMessage.Write( KParamIndNotif, handlePckg );
       
   697     if ( err )
       
   698         {
       
   699         iNotifierIx->Remove( handle );
       
   700         User::Leave( err );
       
   701         }
       
   702     }
       
   703 
       
   704 // ---------------------------------------------------------
       
   705 // CMenuSrvSession::NotifierL
       
   706 // ---------------------------------------------------------
       
   707 //
       
   708 CMenuSrvNotifier& CMenuSrvSession::NotifierL( TInt aHandle )
       
   709     {
       
   710     CMenuSrvNotifier* obj = (CMenuSrvNotifier*)iNotifierIx->AtL( aHandle );
       
   711     if ( !obj )
       
   712         {
       
   713         User::Leave( KErrBadHandle );
       
   714         }
       
   715     return *obj;
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------
       
   719 // CMenuSrvSession::PanicClientL
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 void CMenuSrvSession::PanicClientL( const RMessage2& aMessage )
       
   723     {
       
   724     // Client error. Panic client and leave.
       
   725     // Use an error code (KErrGeneral) which does not cause ServiceError
       
   726     // to panic the client again!
       
   727     aMessage.Panic( KMenuSrvName, KErrGeneral );
       
   728     User::Leave( KErrGeneral );
       
   729     }
       
   730 
       
   731 //  End of File