mmfenh/enhancedmediaclient/Client/src/Components/AudioEffects/SourceLocationEffectImpl.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:  Project file for EnhancedMediaClient Utility
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "SourceLocationEffectImpl.h"
       
    20 #include <SourceLocationBase.h>
       
    21 #include <ControlObserver.h>
       
    22 
       
    23 using namespace multimedia;
       
    24 
       
    25 CSourceLocationEffect::CSourceLocationEffect()
       
    26     {
       
    27     // No Impl
       
    28     }
       
    29 
       
    30 CSourceLocationEffect::~CSourceLocationEffect()
       
    31     {
       
    32 	delete iPrevSourceLocationProxy;
       
    33 	delete  iSourceLocationProxy;
       
    34 	iObservers.Close();
       
    35     }
       
    36 
       
    37 TInt CSourceLocationEffect::PostConstructor()
       
    38     {
       
    39     TRAPD( status, CEffectControlBase::ConstructL(KUidSourceLocationEffect) );
       
    40     return status;
       
    41     }
       
    42 
       
    43 // From MControl begins
       
    44 TInt CSourceLocationEffect::AddObserver( MControlObserver& aObserver )
       
    45     {
       
    46     return iObservers.Append(&aObserver);
       
    47     }
       
    48 
       
    49 TInt CSourceLocationEffect::RemoveObserver( MControlObserver& aObserver )
       
    50     {
       
    51 	TInt index = iObservers.Find(&aObserver);
       
    52 	if( index != KErrNotFound )
       
    53 		{
       
    54 		iObservers.Remove(index);
       
    55 		}
       
    56 	return index;
       
    57     }
       
    58 
       
    59 TUid CSourceLocationEffect::Type()
       
    60     {
       
    61     return KSourceLocationEffectControl;
       
    62     }
       
    63 
       
    64 TControlType CSourceLocationEffect::ControlType()
       
    65     {
       
    66 	return EEffectControl;
       
    67     }
       
    68 
       
    69 // From MControl ends
       
    70 
       
    71 // From MEffectControl begins
       
    72 TInt CSourceLocationEffect::Apply()
       
    73     {
       
    74     return DoApply();
       
    75     }
       
    76 
       
    77 // From MEffectControl ends
       
    78 
       
    79 TInt CSourceLocationEffect::DoApply()
       
    80     {
       
    81     TInt error(KErrNone);    
       
    82 	if(iSourceLocationProxy)
       
    83 		{
       
    84 		TRAP(error,iSourceLocationProxy->ApplyL());	
       
    85 		}	
       
    86 	else
       
    87 		{
       
    88 		error = KErrNotReady;	
       
    89 		}			
       
    90     return error;    
       
    91     }
       
    92 
       
    93 // From MSourceLocationEffect begins
       
    94 /**
       
    95 * Gets the cartesian coordinates for the location of the position.
       
    96 * @since 5.0
       
    97 * @param aX The x-coordinate of the position (in millimeters)
       
    98 * @param aY The y-coordinate of the position (in millimeters)
       
    99 * @param aZ The z-coordinate of the position (in millimeters)
       
   100 * @return -
       
   101 */
       
   102 
       
   103 TInt CSourceLocationEffect::LocationCartesian( TInt& aX, TInt& aY, TInt& aZ )
       
   104 	{
       
   105 	TInt status(KErrNone);
       
   106 	if(iSourceLocationProxy)
       
   107 		{
       
   108 		TInt32 a,b,c;
       
   109 		iSourceLocationProxy->LocationCartesian(a,b,c);	
       
   110 		aX = a;
       
   111 		aY = b;
       
   112 		aZ = c;	
       
   113 		}	
       
   114 	else
       
   115 		{
       
   116 		status = KErrNotReady;	
       
   117 		}			
       
   118 	return status;			
       
   119 	}
       
   120 
       
   121 /**
       
   122 * Gets the spherical coordinates for the location of the position.
       
   123 * @since 5.0
       
   124 * @param aAzimuth The Azimuth of the position (thousandths of radians)
       
   125 * @param aElevation The elevation of the position (thousandths of radians)
       
   126 * @param aRadius The radius of the position (thousandths of radians)
       
   127 * @return -
       
   128 */
       
   129 TInt CSourceLocationEffect::LocationSpherical( TInt& aAzimuth, TInt& aElevation, TInt& aRadius )
       
   130 	{
       
   131 	TInt status(KErrNone);
       
   132 	if(iSourceLocationProxy)
       
   133 		{
       
   134 		TInt32 a,b,c;
       
   135 		iSourceLocationProxy->LocationSpherical(a,b,c);	
       
   136 		aAzimuth = a;
       
   137 		aElevation = b;
       
   138 		aRadius = c;	
       
   139 		}	
       
   140 	else
       
   141 		{
       
   142 		status = KErrNotReady;	
       
   143 		}			
       
   144 	return status;			
       
   145 	}
       
   146 
       
   147 /**
       
   148 * Sets the cartesian coordinates for the location of the position.
       
   149 * @since 5.0
       
   150 * @param aX The x-coordinate of the position
       
   151 * @param aY The y-coordinate of the position
       
   152 * @param aZ The z-coordinate of the position
       
   153 * @return -
       
   154 */
       
   155 TInt CSourceLocationEffect::SetLocationCartesian( TInt aX, TInt aY, TInt aZ )
       
   156 	{
       
   157 	TInt status(KErrNone);
       
   158 	if(iSourceLocationProxy)
       
   159 		{
       
   160 		TInt32 a,b,c;	
       
   161 		a = aX;
       
   162 		b = aY;
       
   163 		c = aZ;
       
   164 		TRAP(status,iSourceLocationProxy->SetLocationCartesianL(a,b,c));	
       
   165 		}	
       
   166 	else
       
   167 		{
       
   168 		status = KErrNotReady;	
       
   169 		}			
       
   170 	return status;	
       
   171 	}
       
   172 
       
   173 /**
       
   174 * Sets the spherical coordinates for the location of the position.
       
   175 * @since 5.0
       
   176 * @param aAzimuth The Azimuth of the position (thousandths of radians)
       
   177 * @param aElevation The elevation of the position (thousandths of radians)
       
   178 * @param aRadius The radius of the position (thousandths of radians)
       
   179 * @return -
       
   180 */
       
   181 TInt CSourceLocationEffect::SetLocationSpherical( TInt aAzimuth, TInt aElevation, TInt aRadius )
       
   182 	{
       
   183 	TInt status(KErrNone);
       
   184 	if(iSourceLocationProxy)
       
   185 		{
       
   186 		TInt32 a,b,c;	
       
   187 		a = aAzimuth;
       
   188 		b = aElevation;
       
   189 		c = aRadius;
       
   190 		TRAP(status,iSourceLocationProxy->SetLocationSphericalL(a,b,c));	
       
   191 		}	
       
   192 	else
       
   193 		{
       
   194 		status = KErrNotReady;	
       
   195 		}			
       
   196 	return status;	
       
   197 	}
       
   198 
       
   199 // From MSourceLocationEffect ends
       
   200 
       
   201 // From MAudioEffectControl
       
   202 /**
       
   203 * Disable the effect
       
   204 * @since 5.0
       
   205 */
       
   206 TInt CSourceLocationEffect::Disable()
       
   207 	{
       
   208 	TInt status(KErrNone);
       
   209 	if(iSourceLocationProxy)
       
   210 		{
       
   211 		TRAP(status,iSourceLocationProxy->DisableL());	
       
   212 		}	
       
   213 	else
       
   214 		{
       
   215 		status = KErrNotReady;	
       
   216 		}			
       
   217 	return status;				
       
   218 	}
       
   219 
       
   220 /**
       
   221 * Enable the effect
       
   222 * @since 5.0
       
   223 */
       
   224 TInt CSourceLocationEffect::Enable()
       
   225 	{
       
   226 	TInt status(KErrNone);
       
   227 	RDebug::Print(_L("CSourceLocationEffect::Enable() [%x]"),iSourceLocationProxy);
       
   228 	if(iSourceLocationProxy)
       
   229 		{
       
   230 		TRAP(status,iSourceLocationProxy->EnableL());	
       
   231 		}	
       
   232 	else
       
   233 		{
       
   234 		status = KErrNotReady;	
       
   235 		}			
       
   236 	return status;					
       
   237 	}
       
   238 
       
   239 /**
       
   240 * Enforce the effect.
       
   241 * @since 5.0
       
   242 * @param aEnforced Indicate the effect is to be enforced or not. ETrue = Enforced.
       
   243 */
       
   244 TInt CSourceLocationEffect::Enforce( TBool &aEnforced )
       
   245 	{
       
   246 	TInt status(KErrNone);
       
   247 	if(iSourceLocationProxy)
       
   248 		{
       
   249 		TRAP(status,iSourceLocationProxy->EnforceL(aEnforced));	
       
   250 		}	
       
   251 	else
       
   252 		{
       
   253 		status = KErrNotReady;	
       
   254 		}					
       
   255 	return status;		
       
   256 	}
       
   257 
       
   258 /**
       
   259 * Check if this effect object currently has update rights.
       
   260 * A client can lose update rights in some hardware platforms where there are a limited
       
   261 * number of instances of an effect that can exist at the same time. When an effect instance
       
   262 * has lost update rights the user can still change settings, but any calls to Apply the
       
   263 * settings will be deferred until update rights are regained.
       
   264 * @since 5.0
       
   265 * @return ETrue if this object currently has rights to update the settings of this effect,
       
   266 *         EFalse otherwise.
       
   267 */
       
   268 TInt CSourceLocationEffect::HaveUpdateRights(TBool &aHaveUpdateRights)
       
   269 	{
       
   270 	TInt status(KErrNone);
       
   271 	if(iSourceLocationProxy)
       
   272 		{
       
   273 		aHaveUpdateRights = iSourceLocationProxy->HaveUpdateRights();	
       
   274 		}	
       
   275 	else
       
   276 		{
       
   277 		status = KErrNotReady;	
       
   278 		}			
       
   279 	return status;	
       
   280 	}
       
   281 
       
   282 /**
       
   283 * Check if the effect is enabled
       
   284 * @since 5.0
       
   285 * @return ETrue if the effect is enabled, EFalse if the effect is disabled.
       
   286 */
       
   287 TInt CSourceLocationEffect::IsEnabled(TBool &aEnabled)
       
   288 	{
       
   289 	TInt status(KErrNone);
       
   290 	if(iSourceLocationProxy)
       
   291 		{
       
   292 		aEnabled = iSourceLocationProxy->IsEnabled();	
       
   293 		}	
       
   294 	else
       
   295 		{
       
   296 		status = KErrNotReady;	
       
   297 		}			
       
   298 	return status;			
       
   299 	}
       
   300 
       
   301 /**
       
   302 * Check if the effect is enforced.
       
   303 * @since 5.0
       
   304 * @return ETrue if the effect is enforced, EFalse if the effect isn ot enforced.
       
   305 */
       
   306 TInt CSourceLocationEffect::IsEnforced(TBool &aEnforced)
       
   307 	{
       
   308 	TInt status(KErrNone);
       
   309 	if(iSourceLocationProxy)
       
   310 		{
       
   311 		aEnforced = iSourceLocationProxy->IsEnforced();	
       
   312 		}	
       
   313 	else
       
   314 		{
       
   315 		status = KErrNotReady;	
       
   316 		}			
       
   317 	return status;			
       
   318 	}
       
   319 
       
   320 /*
       
   321 * Get the unique identifier of the audio effect
       
   322 * @since 5.0
       
   323 * @return Unique identifier of the audio effect object.
       
   324 */
       
   325 TInt CSourceLocationEffect::Uid(TUid &aUid)
       
   326 	{
       
   327 	TInt status(KErrNone);
       
   328 	if(iSourceLocationProxy)
       
   329 		{
       
   330 		aUid = iSourceLocationProxy->Uid();	
       
   331 		}	
       
   332 	else
       
   333 		{
       
   334 		status = KErrNotReady;	
       
   335 		}			
       
   336 	return status;			
       
   337 	}
       
   338 // From MAudioEffectControl Ends
       
   339 
       
   340 
       
   341 // From CEffectControlBase begins
       
   342 void CSourceLocationEffect::Event( TEffectControlEvent aEvent )
       
   343     {
       
   344 	TInt status(KErrNone);    	
       
   345     // Controller Loaded with ECIBuilderCreated
       
   346     if ( aEvent == ECIBuilderCreated )
       
   347         {
       
   348     	RDebug::Print(_L("Deleting Proxy"));	
       
   349 		status = DeleteEffectProxy();
       
   350 		RDebug::Print(_L("Deleting Proxy [%d]"),status);	
       
   351 		status = CreateEffectProxy();	
       
   352 		RDebug::Print(_L("Creating Proxy [%d]"),status);	
       
   353 		if(status == KErrNone)
       
   354 			{
       
   355 			SavePreviousSettings();	
       
   356 			}
       
   357 		else
       
   358 			{
       
   359 			for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   360 				{
       
   361 				iObservers[i]->Event(this,MAudioEffectControl::KDisabled,NULL);
       
   362 				} 		
       
   363 			}	
       
   364         }
       
   365     else if ( aEvent == EMessageHandlerDeleted )
       
   366         {
       
   367         if(status == KErrNone)
       
   368         	{
       
   369         	DeleteEffectProxy();	
       
   370         	}
       
   371         }
       
   372     }
       
   373 
       
   374 // From CEffectControlBase ends
       
   375 
       
   376 TInt CSourceLocationEffect::CreateEffectProxy()
       
   377 	{
       
   378 	TInt status(KErrNone);
       
   379 	status = GetMessageHandle(iMsgHndlrHandlePckg);
       
   380 	if(status != KErrNone)
       
   381 		{
       
   382 		return status;	
       
   383 		}
       
   384 	iCustomCommand = GetCustomCommand();		
       
   385 	if(!iCustomCommand)
       
   386 		{
       
   387 		return KErrNotReady;	
       
   388 		}
       
   389 
       
   390 	TRAP(status,iSourceLocationProxy = CSourceLocationProxy::NewL(iMsgHndlrHandlePckg, *iCustomCommand, NULL));	
       
   391 	if(status == KErrNone)
       
   392 		{
       
   393 		TRAP(status,iSourceLocationProxy->RegisterObserverL(*this));	
       
   394 		}		
       
   395 
       
   396 	return status;
       
   397 	}
       
   398 
       
   399 TInt CSourceLocationEffect::DeleteEffectProxy()
       
   400 	{
       
   401 	TInt status(KErrNone);	
       
   402 	if(iSourceLocationProxy)
       
   403 		{
       
   404 		iPrevSourceLocationProxy = iSourceLocationProxy;	
       
   405 		}
       
   406 	iSourceLocationProxy = NULL;	
       
   407 	return status;
       
   408 	}
       
   409 
       
   410 TInt CSourceLocationEffect::SavePreviousSettings()
       
   411 	{
       
   412 	TInt status(KErrNone);	
       
   413 	if(iPrevSourceLocationProxy)
       
   414 		{
       
   415 		TBool enforce = iPrevSourceLocationProxy->IsEnforced();
       
   416 		iSourceLocationProxy->EnforceL(enforce);	
       
   417 
       
   418 		TBool enable = iPrevSourceLocationProxy->IsEnabled();
       
   419 		if(enable)
       
   420 			{
       
   421 			iSourceLocationProxy->EnableL();	
       
   422 			}
       
   423 
       
   424 		delete iPrevSourceLocationProxy;
       
   425 		iPrevSourceLocationProxy = NULL;
       
   426 		}				
       
   427 	return status;	
       
   428 	}
       
   429 
       
   430  void CSourceLocationEffect::EffectChanged( const CAudioEffect* /*aObservedEffect*/, TUint8 aEvent )
       
   431  	{
       
   432 	for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   433 		{
       
   434 		iObservers[i]->Event(this,aEvent,NULL);
       
   435 		} 		
       
   436  	}
       
   437 
       
   438 // End of file