mmfenh/enhancedmediaclient/Client/src/Components/EffectBase/EffectControlBaseImpl.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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:  Implementation of EffectControlBaseImpl class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <StreamControl.h>
       
    19 #include <MCustomCommand.h>
       
    20 #include <ControlObserver.h>
       
    21 #include <EffectControl.h>
       
    22 #include <VolumeControl.h>
       
    23 
       
    24 #include "CustomInterfaceBuilderTypes.h"
       
    25 #include "EffectControlBaseImpl.h"
       
    26 #include "EffectControlBase.h"
       
    27 
       
    28 const TUid KUidCIFBuilderParser = {0x10207B29};
       
    29 
       
    30 using namespace multimedia;
       
    31 
       
    32 CEffectControlBaseImpl::CEffectControlBaseImpl( CEffectControlBase& aParent, TUid aCIUid )
       
    33 : CActive(CActive::EPriorityStandard),
       
    34   iParent(aParent),
       
    35   iCIUid(aCIUid),
       
    36   iStreamControl(NULL),
       
    37   iCustomCommand(NULL),
       
    38   iEffect(NULL)
       
    39     {
       
    40     CActiveScheduler::Add(this);
       
    41     }
       
    42 
       
    43 CEffectControlBaseImpl::~CEffectControlBaseImpl()
       
    44     {
       
    45     Cancel();
       
    46     // Signal MStreamControl if this effect class is deleted before
       
    47     // removing from it
       
    48     if ( iStreamControl )
       
    49         {
       
    50         iStreamControl->RemoveEffect( *iEffect );
       
    51         };
       
    52     }
       
    53 
       
    54 CEffectControlBaseImpl* CEffectControlBaseImpl::NewL( CEffectControlBase& aParent, TUid aCIUid )
       
    55     {
       
    56     CEffectControlBaseImpl* self = new (ELeave) CEffectControlBaseImpl( aParent, aCIUid );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 void CEffectControlBaseImpl::ConstructL()
       
    64     {
       
    65     // No impl yet
       
    66     }
       
    67 
       
    68 TInt CEffectControlBaseImpl::AddedToStreamControl( MStreamControl& aStreamControl,
       
    69                                                    MCustomCommand& aCustomCommand,
       
    70                                                    MEffectControl& aEffect )
       
    71     {
       
    72     TInt status(KErrAlreadyExists);
       
    73     if ( !iStreamControl )
       
    74         {
       
    75         iStreamControl = &aStreamControl;
       
    76         iCustomCommand = &aCustomCommand;
       
    77         iEffect = &aEffect;
       
    78         status = KErrNone;
       
    79         }
       
    80 
       
    81 	// This is done here to get the MessageHandler if the Controller
       
    82 	// is already loaded, otherwise we dont return an Error from Connect    
       
    83     if(iMsgHndlrHandlePckg().InterfaceId() == KNullUid)
       
    84     	{
       
    85 		status = Connect();
       
    86 		if(status == KErrNone)
       
    87 	        {
       
    88 /*
       
    89 	        // This results in subclasses getting notification asynchronously.
       
    90 	        // In the mean time clients may already start setting attributes on
       
    91 	        // effect objects which will be lost if proxy is not created
       
    92 	        // In order to eliminate this possibility, notify synchronously
       
    93 	        CActive::Cancel();
       
    94 	        CActive::SetActive();
       
    95 	        TRequestStatus* status = &iStatus;
       
    96 			User::RequestComplete( status, EControllerLoaded );			
       
    97 */
       
    98 	        iParent.Event( CEffectControlBase::ECIBuilderCreated );
       
    99 	        }
       
   100 	    else
       
   101 	    	{
       
   102 	    	// This Error is Overwritten because the Connect failed.
       
   103 	    	// Its ok here since we are just checking if the controller
       
   104 	    	// is loaded and the msghandler created.	
       
   105 	    	status = KErrNone;	
       
   106 	    	}    
       
   107         }
       
   108 
       
   109     return status;
       
   110     }
       
   111 
       
   112 TInt CEffectControlBaseImpl::RemovedFromStreamControl( MStreamControl& /*aStreamControl*/ )
       
   113     {
       
   114     Disconnect();	
       
   115     iStreamControl = NULL;
       
   116     iCustomCommand = NULL;
       
   117     iEffect = NULL;
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 void CEffectControlBaseImpl::StreamControlDeleted( MStreamControl& /*aStreamControl*/ )
       
   122     {
       
   123     iStreamControl = NULL;
       
   124     iCustomCommand = NULL;
       
   125     iMsgHndlrHandlePckg().InterfaceId() = KNullUid;
       
   126     }
       
   127 
       
   128 TBool CEffectControlBaseImpl::IsConnected()
       
   129     {
       
   130     if ( iMsgHndlrHandlePckg().InterfaceId() != KNullUid )
       
   131         {
       
   132         return ETrue;
       
   133         }
       
   134     else
       
   135         {
       
   136         return EFalse;
       
   137         }
       
   138     }
       
   139 
       
   140 TInt CEffectControlBaseImpl::Connect()
       
   141     {
       
   142     TInt status(KErrNone);
       
   143 	
       
   144 	// Since the Volume Effect does not have Proxy 
       
   145 	// and message handler we return here only
       
   146 	if(iEffect->Type() == KVolumeEffectControl)
       
   147 		{
       
   148 		return KErrNone;	
       
   149 		}
       
   150 	
       
   151 	if(!iCustomCommand)
       
   152 		{
       
   153 		return KErrNotReady;	
       
   154 		}
       
   155 	
       
   156 	TMMFMessageDestination     destination(KUidCustomInterfaceBuilder);
       
   157 	TMMFMessageDestinationPckg destinationPckg(destination);
       
   158 
       
   159     if ( iMsgHndlrHandlePckg().InterfaceId() == KNullUid )
       
   160         {
       
   161 
       
   162         status = iCustomCommand->CustomCommandSync(destinationPckg, ECibGetBuilder, KNullDesC8, KNullDesC8, iBuilderHandle);
       
   163 
       
   164 		if(iBuilderHandle().InterfaceId() == KNullUid || status != KErrNone)
       
   165 			{
       
   166 			return status;
       
   167 			}
       
   168 		
       
   169         // Get handle to message handler from CI Bldr parser
       
   170         status = BuilderParserMessage(ECIFCreateMessageHandler);
       
   171         if( iMsgHndlrHandlePckg().InterfaceId() == KNullUid )
       
   172             {
       
   173             status = KErrNotSupported;
       
   174             }
       
   175         }
       
   176 
       
   177     return status;
       
   178     }
       
   179 
       
   180 TInt CEffectControlBaseImpl::Disconnect()
       
   181     {
       
   182     TInt status(KErrNotReady);
       
   183     if ( ( iMsgHndlrHandlePckg().InterfaceId() != KNullUid ) && (iCustomCommand) )
       
   184         {
       
   185         // Get handle to message handler from CI Bldr parser
       
   186         status = BuilderParserMessage(ECIFRemoveMessageHandler);
       
   187 		// This is done here since the Interface ID is not set to NULL when
       
   188 		// we set it using KNullUid.
       
   189 		TMMFMessageDestination temp;	    
       
   190         iMsgHndlrHandlePckg() = temp;
       
   191         }
       
   192     return status;
       
   193     }
       
   194 
       
   195 TInt CEffectControlBaseImpl::CustomCommandSync(TInt aFunction,
       
   196                        const TDesC8& aDataTo1,
       
   197                        const TDesC8& aDataTo2,
       
   198                        TDes8& aDataFrom)
       
   199     {
       
   200     return CustomCommandSync( iMsgHndlrHandlePckg,
       
   201                               aFunction,
       
   202                               aDataTo1,
       
   203                               aDataTo2,
       
   204                               aDataFrom );
       
   205     }
       
   206 
       
   207 TInt CEffectControlBaseImpl::CustomCommandSync(TInt aFunction,
       
   208                        const TDesC8& aDataTo1,
       
   209                        const TDesC8& aDataTo2)
       
   210     {
       
   211     return CustomCommandSync( iMsgHndlrHandlePckg,
       
   212                               aFunction,
       
   213                               aDataTo1,
       
   214                               aDataTo2 );
       
   215     }
       
   216 
       
   217 void CEffectControlBaseImpl::CustomCommandAsync(TInt aFunction,
       
   218                         const TDesC8& aDataTo1,
       
   219                         const TDesC8& aDataTo2,
       
   220                         TDes8& aDataFrom,
       
   221                         TRequestStatus& aStatus)
       
   222     {
       
   223     CustomCommandAsync( iMsgHndlrHandlePckg,
       
   224                         aFunction,
       
   225                         aDataTo1,
       
   226                         aDataTo2,
       
   227                         aDataFrom,
       
   228                         aStatus );
       
   229     }
       
   230 
       
   231 void CEffectControlBaseImpl::CustomCommandAsync(TInt aFunction,
       
   232                         const TDesC8& aDataTo1,
       
   233                         const TDesC8& aDataTo2,
       
   234                         TRequestStatus& aStatus)
       
   235     {
       
   236     CustomCommandAsync( iMsgHndlrHandlePckg,
       
   237                         aFunction,
       
   238                         aDataTo1,
       
   239                         aDataTo2,
       
   240                         aStatus );
       
   241     }
       
   242 
       
   243 TInt CEffectControlBaseImpl::CustomCommandSync( const TMMFMessageDestinationPckg& aDestination,
       
   244                                                 TInt aFunction,
       
   245                                                 const TDesC8& aDataTo1,
       
   246                                                 const TDesC8& aDataTo2,
       
   247                                                 TDes8& aDataFrom )
       
   248     {
       
   249     TInt status(KErrNotReady);
       
   250     if ( ( iCustomCommand ) && ( aDestination().InterfaceId() != KNullUid ) )
       
   251         {
       
   252         status = iCustomCommand->CustomCommandSync( aDestination,
       
   253                                                     aFunction,
       
   254                                                     aDataTo1,
       
   255                                                     aDataTo2,
       
   256                                                     aDataFrom );
       
   257         }
       
   258     return status;
       
   259     }
       
   260 
       
   261 TInt CEffectControlBaseImpl::CustomCommandSync( const TMMFMessageDestinationPckg& aDestination,
       
   262                                                 TInt aFunction,
       
   263                                                 const TDesC8& aDataTo1,
       
   264                                                 const TDesC8& aDataTo2 )
       
   265     {
       
   266     TInt status(KErrNotReady);
       
   267     if ( ( iCustomCommand ) && ( aDestination().InterfaceId() != KNullUid ) )
       
   268         {
       
   269         status = iCustomCommand->CustomCommandSync( aDestination,
       
   270                                                     aFunction,
       
   271                                                     aDataTo1,
       
   272                                                     aDataTo2 );
       
   273         }
       
   274     return status;
       
   275     }
       
   276 
       
   277 void CEffectControlBaseImpl::CustomCommandAsync( const TMMFMessageDestinationPckg& aDestination,
       
   278                                                  TInt aFunction,
       
   279                                                  const TDesC8& aDataTo1,
       
   280                                                  const TDesC8& aDataTo2,
       
   281                                                  TDes8& aDataFrom,
       
   282                                                  TRequestStatus& aStatus )
       
   283     {
       
   284     if ( ( iCustomCommand ) && ( aDestination().InterfaceId() != KNullUid ) )
       
   285         {
       
   286         iCustomCommand->CustomCommandAsync( aDestination,
       
   287                                             aFunction,
       
   288                                             aDataTo1,
       
   289                                             aDataTo2,
       
   290                                             aDataFrom,
       
   291                                             aStatus );
       
   292         }
       
   293     else
       
   294         {
       
   295         TRequestStatus* status = &aStatus;
       
   296 		User::RequestComplete(status, KErrNotReady);
       
   297         }
       
   298     }
       
   299 
       
   300 void CEffectControlBaseImpl::CustomCommandAsync( const TMMFMessageDestinationPckg& aDestination,
       
   301                                                  TInt aFunction,
       
   302                                                  const TDesC8& aDataTo1,
       
   303                                                  const TDesC8& aDataTo2,
       
   304                                                  TRequestStatus& aStatus )
       
   305 
       
   306     {
       
   307     if ( ( iCustomCommand ) && ( aDestination().InterfaceId() != KNullUid ) )
       
   308         {
       
   309         iCustomCommand->CustomCommandAsync( aDestination,
       
   310                                             aFunction,
       
   311                                             aDataTo1,
       
   312                                             aDataTo2,
       
   313                                             aStatus );
       
   314         }
       
   315     else
       
   316         {
       
   317         TRequestStatus* status = &aStatus;
       
   318 		User::RequestComplete(status, KErrNotReady);
       
   319         }    
       
   320     }
       
   321 
       
   322 TInt CEffectControlBaseImpl::GetMessageHandle(TMMFMessageDestinationPckg &aPckg)
       
   323 	{
       
   324     TInt status(KErrNone);
       
   325     aPckg = iMsgHndlrHandlePckg;
       
   326     return status;		
       
   327 	}
       
   328 
       
   329 MCustomCommand* CEffectControlBaseImpl::GetCustomCommand()
       
   330 	{
       
   331     return iCustomCommand;
       
   332 	}
       
   333 	
       
   334 void CEffectControlBaseImpl::RunL()
       
   335     {    
       
   336     TInt status(KErrNone);	 
       
   337     if ( iStatus.Int() == EControllerLoaded )
       
   338         {
       
   339         status = Connect();
       
   340         if(status == KErrNone)
       
   341         	{
       
   342         	iParent.Event( CEffectControlBase::ECIBuilderCreated );
       
   343         	}
       
   344         }
       
   345     else if ( iStatus.Int() == EControllerUnloaded )
       
   346         {
       
   347         status = Disconnect();
       
   348         if(status == KErrNone)
       
   349         	{
       
   350         	iParent.Event( CEffectControlBase::EMessageHandlerDeleted );
       
   351         	}
       
   352         }
       
   353     }
       
   354 
       
   355 void CEffectControlBaseImpl::DoCancel()
       
   356     {
       
   357     // Do Nothing
       
   358     }
       
   359 
       
   360 TInt CEffectControlBaseImpl::RunError( TInt /*aError*/ )
       
   361     {
       
   362     // RunL should never leave, if it did that means
       
   363     // the code left during event handling
       
   364     return KErrNone;
       
   365     }
       
   366 
       
   367 void CEffectControlBaseImpl::Event( MControl* /*aControl*/, TUint aEventType, TAny* /*aEventObject*/ )
       
   368     {
       
   369     if ( aEventType == EControllerLoaded )
       
   370         {
       
   371         CActive::Cancel();
       
   372         CActive::SetActive();
       
   373         TRequestStatus* status = &iStatus;
       
   374 		User::RequestComplete( status, EControllerLoaded );
       
   375         }
       
   376     else if ( aEventType == EControllerUnloaded )
       
   377         {
       
   378         CActive::Cancel();
       
   379         CActive::SetActive();
       
   380         TRequestStatus* status = &iStatus;
       
   381 		User::RequestComplete( status, EControllerUnloaded );
       
   382         }
       
   383     }
       
   384 
       
   385 TInt CEffectControlBaseImpl::BuilderParserMessage(CIFBuilderParserFunctions aCommand)
       
   386     {
       
   387     TInt status(KErrNotReady);
       
   388     if ( iCustomCommand )
       
   389         {
       
   390         TMMFMessageDestination     ciBldr(KUidCIFBuilderParser);
       
   391         TMMFMessageDestinationPckg ciBldrPckg(ciBldr);
       
   392         TPckgBuf<TUid> uidPckg;
       
   393         uidPckg() = iCIUid;
       
   394         switch (aCommand)
       
   395             {
       
   396             case ECIFCreateMessageHandler:
       
   397             status = iCustomCommand->CustomCommandSync( iBuilderHandle,
       
   398                                                         ECibBuild,
       
   399                                                         uidPckg,
       
   400                                                         KNullDesC8,
       
   401                                                         iMsgHndlrHandlePckg);
       
   402                 break;
       
   403             case ECIFRemoveMessageHandler:
       
   404             status = iCustomCommand->CustomCommandSync( iBuilderHandle,
       
   405                                                         ECibRemove,
       
   406                                                         iMsgHndlrHandlePckg,
       
   407                                                         KNullDesC8);
       
   408                 break;
       
   409             default:
       
   410                 status = KErrUnknown;
       
   411                 break;
       
   412             };
       
   413         }
       
   414     return status;
       
   415     }
       
   416 
       
   417 
       
   418 // End of file