os/mm/mmhais/dvbhreceiverhai/hai/dvbh/teststubs/dvbhreceiverinfo.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Example implementation of CDvbhReceiverInfo
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalComponent
    21  @prototype
    22 */
    23 
    24 #include "dvbhreceiverinfo.h"
    25 #include "dvbhreceiverinfoobserver.h"
    26 #include "dvbhtypes.h"
    27 #include "dvbhstubcommon.h"
    28 #include <in_sock.h>
    29 			
    30 /**
    31 * CDvbhReceiverInfo::CPrivateData contains the (implementation specific) private data of CDvbhReceiverInfo.
    32 */
    33 NONSHARABLE_CLASS(CDvbhReceiverInfo::CPrivateData) : public CBase
    34     {
    35 public:
    36 	~CPrivateData();
    37 public:
    38     // Internal observer classes to monitor for RProperty changes.
    39     CDvbhPropertyObserver*  iStatePropertyObserver;
    40     CDvbhPropertyObserver*	iSignalQualityPropertyObserver;
    41     CDvbhPropertyObserver*	iPlatformPropertyObserver;
    42     CDvbhPropertyObserver*	iNetworkTimePropertyObserver;
    43     CDvbhPropertyObserver*	iFrequencyPropertyObserver;
    44     CDvbhPropertyObserver*	iCellIdPropertyObserver;
    45     CDvbhPropertyObserver*	iNetworkIdPropertyObserver;
    46     CDvbhPropertyObserver*	iExtBatteryPropertyObserver;
    47     CDvbhPropertyObserver*	iExtConnectionPropertyObserver;
    48     CDvbhPropertyObserver*	iMtvAccConnectionPropertyObserver;
    49     CDvbhPropertyObserver*	iMtvAccAntennaConnectionPropertyObserver;
    50 
    51     // Wrappers around the external observer classes. To be called upon
    52     // when a property change is detected.
    53     TDvbhStateNotifier iStateNotifier;
    54 	TDvbhSignalQualityNotifier iSignalQualityNotifier;
    55 	TDvbhPlatformNotifier iPlatformNotifier;	
    56 	TDvbhNetworkTimeNotifier iNetworkTimeNotifier;
    57 	TDvbhFrequencyNotifier iFrequencyNotifier;
    58 	TDvbhCellIdNotifier iCellIdNotifier;
    59 	TDvbhNetworkIdNotifier iNetworkIdNotifier;	
    60     TDvbhExtBatteryStateNotifier iExtBatteryNotifier;
    61     TDvbhExtConnectionStateNotifier iExtConnectionNotifier;
    62     TMtvAccConnectionStateNotifier iMtvAccConnectionNotifier;
    63     TMtvAccAntennaConnectionStateNotifier iMtvAccAntennaConnectionNotifier;
    64     };
    65 
    66 CDvbhReceiverInfo::CPrivateData::~CPrivateData()
    67 	{
    68     delete iStatePropertyObserver;
    69     delete iSignalQualityPropertyObserver;
    70     delete iPlatformPropertyObserver;
    71     delete iNetworkTimePropertyObserver;
    72     delete iFrequencyPropertyObserver;
    73     delete iCellIdPropertyObserver;
    74     delete iNetworkIdPropertyObserver;
    75     delete iExtBatteryPropertyObserver;
    76     delete iExtConnectionPropertyObserver;
    77     delete iMtvAccConnectionPropertyObserver;
    78     delete iMtvAccAntennaConnectionPropertyObserver;
    79 	}
    80 	
    81 /**
    82 * Helper function to check if the current receiver state is EDvbhStateReceiving or EDvbhStateReady.
    83 * If aCheckReceivingOnly is EFalse, then it returns KErrNone if the current state is either EDvbhStateReceiving or EDvbhStateReady.
    84 * If aCheckReceivingOnly is ETrue, then will only return KErrNone if the current state is EDvbhStateReceiving.
    85 *
    86 * @param aCheckReceivingOnly ETrue if you only want to check for EDvbhStateReceiving, otherwise will check for EDvbhStateReceiving or EDvbhStateReady.
    87 * @return KErrNone if the current state equals EDvbhStateReceiving or EDvbhStateReady, and aCheckReceivingOnly equals EFalse.  If aCheckReceivingOnly equals ETrue, the KErrNone only if current state is EDvbhStateReceiving.  Otherwise a system-wide error code.
    88 */
    89 static TInt VerifyReadyOrReceiving(TBool aCheckReceivingOnly = EFalse)
    90 	{
    91 	TDvbhState state = EDvbhStateInactive;
    92 	TInt result = CDvbhReceiverInfo::GetState(state);
    93 	if (result != KErrNone)
    94 		{
    95 		return result;
    96 		}		
    97 		
    98 	if (state != EDvbhStateReceiving && (state != EDvbhStateReady || aCheckReceivingOnly) )
    99 		{
   100 		return KErrNotReady;
   101 		}	
   102 	return KErrNone;
   103 	}
   104 	
   105 /*
   106 * Example implementation of CDvbhReceiverInfo
   107 */
   108 
   109 EXPORT_C CDvbhReceiverInfo* CDvbhReceiverInfo::NewL()
   110 	{
   111 	CDvbhReceiverInfo* self = CDvbhReceiverInfo::NewLC();
   112 	CleanupStack::Pop(self);
   113 	return self;
   114 	}
   115 
   116 
   117 EXPORT_C CDvbhReceiverInfo* CDvbhReceiverInfo::NewLC()
   118 	{
   119 	CDvbhReceiverInfo* self = new (ELeave) CDvbhReceiverInfo;
   120 	CleanupStack::PushL(self);
   121 	self->ConstructL();
   122 	return self;	
   123 	}
   124 
   125 EXPORT_C CDvbhReceiverInfo::CDvbhReceiverInfo()
   126 	{
   127 	}
   128 	
   129 void CDvbhReceiverInfo::ConstructL()
   130 	{
   131 	iData = new (ELeave) CPrivateData;
   132 	}
   133 	
   134 EXPORT_C CDvbhReceiverInfo::~CDvbhReceiverInfo()
   135 	{
   136 	delete iData;
   137 	}
   138 
   139 EXPORT_C TInt CDvbhReceiverInfo::GetState( TDvbhState& aState )
   140 	{
   141 	TInt state = 0;
   142 	TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyState, state);
   143 	if (result == KErrNone)
   144 		{
   145 		aState = static_cast<TDvbhState>(state);
   146 		}
   147 	return result;	
   148 	}
   149 
   150 EXPORT_C TInt CDvbhReceiverInfo::SetStateObserver( MDvbhStateObserver& aObserver )
   151 	{
   152 	delete iData->iStatePropertyObserver;
   153 	iData->iStatePropertyObserver = NULL;
   154 	if ((iData->iStatePropertyObserver = new CDvbhPropertyObserver) == NULL)
   155 		{
   156 		return KErrNoMemory;
   157 		}
   158 
   159 	iData->iStateNotifier.SetExternalObserver(&aObserver);
   160 	return iData->iStatePropertyObserver->SetObserver(&iData->iStateNotifier);
   161 	}
   162 
   163 EXPORT_C TInt CDvbhReceiverInfo::GetSignalQuality( TDvbhSignalQuality& aSignalQuality )
   164 	{
   165 	// API documentation states that this method may only be called if the receiver 
   166 	// is in the Receiving state.
   167 	TInt result = VerifyReadyOrReceiving(ETrue); //ETrue parameter means check for Receiving state only
   168 	if (result != KErrNone)
   169 		{
   170 		return result;
   171 		}
   172 	
   173 	// The receiver is in the correct state so we may proceed.
   174 	TInt quality = 0;
   175 	result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeySignalQuality, quality);
   176 	if (result == KErrNone)
   177 		{
   178 		aSignalQuality = static_cast<TDvbhSignalQuality>(quality);
   179 		}
   180 	return result;
   181 	}
   182 
   183 EXPORT_C TInt CDvbhReceiverInfo::SetSignalQualityObserver( MDvbhSignalQualityObserver& aObserver )
   184 	{
   185 	delete iData->iSignalQualityPropertyObserver;
   186 	iData->iSignalQualityPropertyObserver = NULL;
   187 	if ((iData->iSignalQualityPropertyObserver = new CDvbhPropertyObserver) == NULL)
   188 		{
   189 		return KErrNoMemory;
   190 		}
   191 	iData->iSignalQualityNotifier.SetExternalObserver(&aObserver);
   192 	return iData->iSignalQualityPropertyObserver->SetObserver(&iData->iSignalQualityNotifier);
   193 	}
   194 
   195 EXPORT_C TInt CDvbhReceiverInfo::GetPlatform( TDvbhPlatform& aPlatform, TIp6Addr& aESGRoot )
   196 	{
   197 	// API documentation states that this method may only be called if the receiver 
   198 	// is in the Ready or Receiving state.
   199 	TInt result = VerifyReadyOrReceiving();
   200 	if (result != KErrNone)
   201 		{
   202 		return result;
   203 		}
   204 	
   205 	// The receiver is in the correct state so we may proceed.
   206 	TDvbhPlatformProperty platform;		
   207 	TPckg<TDvbhPlatformProperty> platformPckg(platform);
   208 	result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyPlatform, platformPckg);
   209 	if (result == KErrNone)
   210 		{
   211 		aPlatform.iId = platform.iPlatform.iId;
   212 		aPlatform.iName = platform.iPlatform.iName;
   213 		aESGRoot = platform.iEsgRoot;
   214 		}
   215 	return result;
   216 	}
   217 
   218 EXPORT_C TInt CDvbhReceiverInfo::SetPlatformObserver( MDvbhPlatformObserver& aObserver )
   219 	{
   220 	delete iData->iPlatformPropertyObserver;
   221 	iData->iPlatformPropertyObserver = NULL;
   222 	if ((iData->iPlatformPropertyObserver = new CDvbhPropertyObserver) == NULL)
   223 		{
   224 		return KErrNoMemory;
   225 		}
   226 	iData->iPlatformNotifier.SetExternalObserver(&aObserver);
   227 	return iData->iPlatformPropertyObserver->SetObserver(&iData->iPlatformNotifier);
   228 	}
   229 
   230 EXPORT_C TInt CDvbhReceiverInfo::GetNetworkTime( TTime& aNetworkTime, TBool& aValid )
   231 	{		
   232 	TDvbhNetworkTime networkTime;
   233 	TPckg<TDvbhNetworkTime> timePckg(networkTime);
   234 	TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyNetworkTime, timePckg);
   235 	if (result == KErrNone)
   236 		{
   237 		//API documentation states that KErrNotReady should be returned if a platform has
   238 		//never been set on the receiver.
   239 		if (networkTime.iPlatformId == KDvbhInvalidPlatform)
   240 			{
   241 			result = KErrNotReady;
   242 			}
   243 		else
   244 			{
   245 			//The platform is valid, but it might be old.  It will be old if there is no
   246 			//current platform set, i.e. if the state is not Ready or Receiving.  Set the aValid
   247 			//bool based on whether or not it the platform is old.
   248 			if (VerifyReadyOrReceiving() == KErrNone)
   249 				{
   250 				aValid = ETrue;
   251 				}
   252 			else
   253 				{
   254 				aValid = EFalse;
   255 				}
   256 				
   257 			//Finally, update the time
   258 			aNetworkTime = networkTime.iNetworkTime;	
   259 			}
   260 		}
   261 	return result;
   262 	}
   263 
   264 EXPORT_C TInt CDvbhReceiverInfo::SetNetworkTimeObserver( MDvbhNetworkTimeObserver& aObserver )
   265 	{
   266 	delete iData->iNetworkTimePropertyObserver;
   267 	iData->iNetworkTimePropertyObserver = NULL;
   268 	if ((iData->iNetworkTimePropertyObserver = new CDvbhPropertyObserver) == NULL)
   269 		{
   270 		return KErrNoMemory;
   271 		}
   272 	iData->iNetworkTimeNotifier.SetExternalObserver(&aObserver);
   273 	return iData->iNetworkTimePropertyObserver->SetObserver(&iData->iNetworkTimeNotifier);
   274 	}
   275 
   276 EXPORT_C TInt CDvbhReceiverInfo::GetPerformanceData( TDvbhPerformanceData& aPerformanceData )
   277 	{
   278 	TPckg<TDvbhPerformanceData> performancePckg(aPerformanceData);
   279 	return RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyPerformanceData, performancePckg);
   280 	}
   281 
   282 EXPORT_C TInt CDvbhReceiverInfo::GetFrequency( TDvbhFrequency& aFrequency )
   283 	{
   284 	// API documentation states that this method may only be called if the receiver 
   285 	// is in the Ready or Receiving state.
   286 	TInt result = VerifyReadyOrReceiving();
   287 	if (result != KErrNone)
   288 		{
   289 		return result;
   290 		}
   291 	
   292 	// The receiver is in the correct state so we may proceed.	
   293 	TInt frequency = 0;
   294 	result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyFrequency, frequency);
   295 	if (result == KErrNone)
   296 		{
   297 		aFrequency = static_cast<TDvbhFrequency>(frequency);
   298 		}
   299 	return result;
   300 	}
   301 
   302 EXPORT_C TInt CDvbhReceiverInfo::SetFrequencyObserver( MDvbhFrequencyObserver& aObserver )
   303 	{
   304 	delete iData->iFrequencyPropertyObserver;
   305 	iData->iFrequencyPropertyObserver = NULL;
   306 	if ((iData->iFrequencyPropertyObserver = new CDvbhPropertyObserver) == NULL)
   307 		{
   308 		return KErrNoMemory;
   309 		}
   310 	iData->iFrequencyNotifier.SetExternalObserver(&aObserver);
   311 	return iData->iFrequencyPropertyObserver->SetObserver(&iData->iFrequencyNotifier);
   312 	}
   313 
   314 EXPORT_C TInt CDvbhReceiverInfo::GetCellId( TDvbhCellId& aCellId )
   315 	{
   316 	// API documentation states that this method may only be called if the receiver 
   317 	// is in the Ready or Receiving state.
   318 	TInt result = VerifyReadyOrReceiving();
   319 	if (result != KErrNone)
   320 		{
   321 		return result;
   322 		}
   323 	
   324 	// The receiver is in the correct state so we may proceed.
   325 	TInt cellId = 0;
   326 	result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyCellId, cellId);
   327 	if (result == KErrNone)
   328 		{
   329 		aCellId = static_cast<TDvbhCellId>(cellId);
   330 		}
   331 	return result;
   332 	}
   333 
   334 EXPORT_C TInt CDvbhReceiverInfo::SetCellIdObserver( MDvbhCellIdObserver& aObserver )
   335 	{
   336 	delete iData->iCellIdPropertyObserver;
   337 	iData->iCellIdPropertyObserver = NULL;
   338 	if ((iData->iCellIdPropertyObserver = new CDvbhPropertyObserver) == NULL)
   339 		{
   340 		return KErrNoMemory;
   341 		}
   342 	iData->iCellIdNotifier.SetExternalObserver(&aObserver);
   343 	return iData->iCellIdPropertyObserver->SetObserver(&iData->iCellIdNotifier);
   344 	}
   345 
   346 EXPORT_C TInt CDvbhReceiverInfo::GetNetworkId( TDvbhNetworkId& aNetworkId )
   347 	{
   348 	// API documentation states that this method may only be called if the receiver 
   349 	// is in the Ready or Receiving state.
   350 	TInt result = VerifyReadyOrReceiving();
   351 	if (result != KErrNone)
   352 		{
   353 		return result;
   354 		}
   355 	
   356 	// The receiver is in the correct state so we may proceed.
   357 	TInt networkId = 0;
   358 	result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyNetworkId, networkId);
   359 	if (result == KErrNone)
   360 		{
   361 		aNetworkId = static_cast<TDvbhNetworkId>(networkId);
   362 		}
   363 	return result;
   364 	}
   365 
   366 EXPORT_C TInt CDvbhReceiverInfo::SetNetworkIdObserver( MDvbhNetworkIdObserver& aObserver )
   367 	{
   368 	delete iData->iNetworkIdPropertyObserver;
   369 	iData->iNetworkIdPropertyObserver = NULL;
   370 	if ((iData->iNetworkIdPropertyObserver = new CDvbhPropertyObserver) == NULL)
   371 		{
   372 		return KErrNoMemory;
   373 		}
   374 	iData->iNetworkIdNotifier.SetExternalObserver(&aObserver);
   375 	return iData->iNetworkIdPropertyObserver->SetObserver(&iData->iNetworkIdNotifier);
   376 	}
   377 
   378 EXPORT_C TInt CDvbhReceiverInfo::GetBatteryState( TDvbhExtBatteryState& aState )
   379 	{
   380 	// The receiver is in the correct state so we may proceed.
   381 	TInt state = 0;
   382 	TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyExtBatteryState, state);
   383 	if (result == KErrNone)
   384 		{
   385 		aState = static_cast<TDvbhExtBatteryState>(state);
   386 		}
   387 	return result;
   388 	}
   389 
   390 EXPORT_C TInt CDvbhReceiverInfo::SetBatteryStateObserver( MDvbhExtBatteryStateObserver& aObserver )
   391 	{
   392 	delete iData->iExtBatteryPropertyObserver;
   393 	iData->iExtBatteryPropertyObserver = NULL;
   394 	if ((iData->iExtBatteryPropertyObserver = new CDvbhPropertyObserver) == NULL)
   395 		{
   396 		return KErrNoMemory;
   397 		}
   398 	iData->iExtBatteryNotifier.SetExternalObserver(&aObserver);
   399 	return iData->iExtBatteryPropertyObserver->SetObserver(&iData->iExtBatteryNotifier);
   400 	}
   401     
   402 
   403 EXPORT_C TInt CDvbhReceiverInfo::GetExtConnectionState( TDvbhExtConnectionState& aConnectionState, const TDvbhReceiverType& aReceiver )
   404 	{
   405 	// The receiver is in the correct state so we may proceed.
   406 	TInt state = 0;
   407     TInt result = KErrNone;
   408     switch (aReceiver)
   409         {
   410         case EDvbhReceiverIntegrated:
   411             result = KErrArgument;
   412             break;
   413 	    case EDvbhReceiverBluetooth:
   414             result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyExtConnectionState, state);
   415             break;
   416 	    case EDvbhReceiverUsbAccessory:
   417             result = RProperty::Get(KDvbhPropertyCategory, KMtvAccAttachedKey, state);
   418             break;
   419         default:
   420             result = KErrArgument;
   421             break;
   422         }
   423     aConnectionState = EDvbhExtNotConnected;
   424     if (result == KErrNone)
   425 		{
   426 		aConnectionState = static_cast<TDvbhExtConnectionState>(state);
   427 		}
   428 	result = KErrNone;
   429     return result;
   430 	}
   431 
   432 EXPORT_C TInt CDvbhReceiverInfo::SetExtConnectionStateObserver( MDvbhExtConnectionObserver& aObserver )
   433 	{
   434 	delete iData->iExtConnectionPropertyObserver;
   435 	delete iData->iMtvAccConnectionPropertyObserver;
   436 	iData->iExtConnectionPropertyObserver = NULL;
   437 	iData->iMtvAccConnectionPropertyObserver = NULL;
   438 	if ((iData->iExtConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
   439 		{
   440 		return KErrNoMemory;
   441 		}
   442 	if ((iData->iMtvAccConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
   443 		{
   444 		return KErrNoMemory;
   445 		}
   446 	iData->iExtConnectionNotifier.SetExternalObserver(&aObserver);
   447 	TInt result = iData->iExtConnectionPropertyObserver->SetObserver(&iData->iExtConnectionNotifier);
   448 	if (result == KErrNone)
   449 	    {
   450         iData->iMtvAccConnectionNotifier.SetExternalObserver(&aObserver);
   451         result = iData->iMtvAccConnectionPropertyObserver->SetObserver(&iData->iMtvAccConnectionNotifier);
   452 	    }
   453     return result;
   454 	}
   455 
   456 
   457 EXPORT_C TInt CDvbhReceiverInfo::GetExtAntennaConnectionState( TDvbhExtAntennaConnectionState& aConnectionState, const TDvbhReceiverType& aReceiver )
   458 	{
   459 	// The receiver is in the correct state so we may proceed.
   460 	TInt state = 0;
   461     TInt result = KErrNone;
   462     switch (aReceiver)
   463         {
   464         case EDvbhReceiverIntegrated:
   465             result = KErrArgument;
   466             break;
   467 	    case EDvbhReceiverBluetooth:
   468             result = KErrArgument;
   469             break;
   470 	    case EDvbhReceiverUsbAccessory:
   471             result = RProperty::Get(KDvbhPropertyCategory, KMtvAccAntennaKey, state);
   472             break;
   473         default:
   474             result = KErrArgument;
   475             break;
   476         }
   477     aConnectionState = EDvbhExtAntennaNotConnected;
   478     if (result == KErrNone)
   479 		{
   480 		aConnectionState = static_cast<TDvbhExtAntennaConnectionState>(state);
   481 		}
   482 	result = KErrNone;
   483     return result;
   484 	}
   485 
   486 EXPORT_C TInt CDvbhReceiverInfo::SetExtAntennaConnectionStateObserver( MDvbhExtAntennaConnectionObserver& aObserver )
   487 	{
   488 	delete iData->iMtvAccAntennaConnectionPropertyObserver;
   489 	iData->iMtvAccAntennaConnectionPropertyObserver = NULL;
   490 	if ((iData->iMtvAccAntennaConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
   491 		{
   492 		return KErrNoMemory;
   493 		}
   494 	iData->iMtvAccAntennaConnectionNotifier.SetExternalObserver(&aObserver);
   495     return iData->iMtvAccAntennaConnectionPropertyObserver->SetObserver(&iData->iMtvAccAntennaConnectionNotifier);
   496 	}
   497 
   498 EXPORT_C TInt CDvbhReceiverInfo::GetExtDeviceInfo( TDvbhAccessoryInfo& aDeviceInfo, const TDvbhReceiverType& /*aReceiver*/ )
   499     {
   500 	TPckg<TDvbhAccessoryInfo> devinfoPckg(aDeviceInfo);
   501 	return RProperty::Get(KDvbhPropertyCategory, KMtvAccInfoKey, devinfoPckg);
   502     }