First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Example implementation of CDvbhReceiverInfo
24 #include "dvbhreceiverinfo.h"
25 #include "dvbhreceiverinfoobserver.h"
26 #include "dvbhtypes.h"
27 #include "dvbhstubcommon.h"
31 * CDvbhReceiverInfo::CPrivateData contains the (implementation specific) private data of CDvbhReceiverInfo.
33 NONSHARABLE_CLASS(CDvbhReceiverInfo::CPrivateData) : public CBase
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;
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;
66 CDvbhReceiverInfo::CPrivateData::~CPrivateData()
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;
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.
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.
89 static TInt VerifyReadyOrReceiving(TBool aCheckReceivingOnly = EFalse)
91 TDvbhState state = EDvbhStateInactive;
92 TInt result = CDvbhReceiverInfo::GetState(state);
93 if (result != KErrNone)
98 if (state != EDvbhStateReceiving && (state != EDvbhStateReady || aCheckReceivingOnly) )
106 * Example implementation of CDvbhReceiverInfo
109 EXPORT_C CDvbhReceiverInfo* CDvbhReceiverInfo::NewL()
111 CDvbhReceiverInfo* self = CDvbhReceiverInfo::NewLC();
112 CleanupStack::Pop(self);
117 EXPORT_C CDvbhReceiverInfo* CDvbhReceiverInfo::NewLC()
119 CDvbhReceiverInfo* self = new (ELeave) CDvbhReceiverInfo;
120 CleanupStack::PushL(self);
125 EXPORT_C CDvbhReceiverInfo::CDvbhReceiverInfo()
129 void CDvbhReceiverInfo::ConstructL()
131 iData = new (ELeave) CPrivateData;
134 EXPORT_C CDvbhReceiverInfo::~CDvbhReceiverInfo()
139 EXPORT_C TInt CDvbhReceiverInfo::GetState( TDvbhState& aState )
142 TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyState, state);
143 if (result == KErrNone)
145 aState = static_cast<TDvbhState>(state);
150 EXPORT_C TInt CDvbhReceiverInfo::SetStateObserver( MDvbhStateObserver& aObserver )
152 delete iData->iStatePropertyObserver;
153 iData->iStatePropertyObserver = NULL;
154 if ((iData->iStatePropertyObserver = new CDvbhPropertyObserver) == NULL)
159 iData->iStateNotifier.SetExternalObserver(&aObserver);
160 return iData->iStatePropertyObserver->SetObserver(&iData->iStateNotifier);
163 EXPORT_C TInt CDvbhReceiverInfo::GetSignalQuality( TDvbhSignalQuality& aSignalQuality )
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)
173 // The receiver is in the correct state so we may proceed.
175 result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeySignalQuality, quality);
176 if (result == KErrNone)
178 aSignalQuality = static_cast<TDvbhSignalQuality>(quality);
183 EXPORT_C TInt CDvbhReceiverInfo::SetSignalQualityObserver( MDvbhSignalQualityObserver& aObserver )
185 delete iData->iSignalQualityPropertyObserver;
186 iData->iSignalQualityPropertyObserver = NULL;
187 if ((iData->iSignalQualityPropertyObserver = new CDvbhPropertyObserver) == NULL)
191 iData->iSignalQualityNotifier.SetExternalObserver(&aObserver);
192 return iData->iSignalQualityPropertyObserver->SetObserver(&iData->iSignalQualityNotifier);
195 EXPORT_C TInt CDvbhReceiverInfo::GetPlatform( TDvbhPlatform& aPlatform, TIp6Addr& aESGRoot )
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)
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)
211 aPlatform.iId = platform.iPlatform.iId;
212 aPlatform.iName = platform.iPlatform.iName;
213 aESGRoot = platform.iEsgRoot;
218 EXPORT_C TInt CDvbhReceiverInfo::SetPlatformObserver( MDvbhPlatformObserver& aObserver )
220 delete iData->iPlatformPropertyObserver;
221 iData->iPlatformPropertyObserver = NULL;
222 if ((iData->iPlatformPropertyObserver = new CDvbhPropertyObserver) == NULL)
226 iData->iPlatformNotifier.SetExternalObserver(&aObserver);
227 return iData->iPlatformPropertyObserver->SetObserver(&iData->iPlatformNotifier);
230 EXPORT_C TInt CDvbhReceiverInfo::GetNetworkTime( TTime& aNetworkTime, TBool& aValid )
232 TDvbhNetworkTime networkTime;
233 TPckg<TDvbhNetworkTime> timePckg(networkTime);
234 TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyNetworkTime, timePckg);
235 if (result == KErrNone)
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)
241 result = KErrNotReady;
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)
257 //Finally, update the time
258 aNetworkTime = networkTime.iNetworkTime;
264 EXPORT_C TInt CDvbhReceiverInfo::SetNetworkTimeObserver( MDvbhNetworkTimeObserver& aObserver )
266 delete iData->iNetworkTimePropertyObserver;
267 iData->iNetworkTimePropertyObserver = NULL;
268 if ((iData->iNetworkTimePropertyObserver = new CDvbhPropertyObserver) == NULL)
272 iData->iNetworkTimeNotifier.SetExternalObserver(&aObserver);
273 return iData->iNetworkTimePropertyObserver->SetObserver(&iData->iNetworkTimeNotifier);
276 EXPORT_C TInt CDvbhReceiverInfo::GetPerformanceData( TDvbhPerformanceData& aPerformanceData )
278 TPckg<TDvbhPerformanceData> performancePckg(aPerformanceData);
279 return RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyPerformanceData, performancePckg);
282 EXPORT_C TInt CDvbhReceiverInfo::GetFrequency( TDvbhFrequency& aFrequency )
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)
292 // The receiver is in the correct state so we may proceed.
294 result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyFrequency, frequency);
295 if (result == KErrNone)
297 aFrequency = static_cast<TDvbhFrequency>(frequency);
302 EXPORT_C TInt CDvbhReceiverInfo::SetFrequencyObserver( MDvbhFrequencyObserver& aObserver )
304 delete iData->iFrequencyPropertyObserver;
305 iData->iFrequencyPropertyObserver = NULL;
306 if ((iData->iFrequencyPropertyObserver = new CDvbhPropertyObserver) == NULL)
310 iData->iFrequencyNotifier.SetExternalObserver(&aObserver);
311 return iData->iFrequencyPropertyObserver->SetObserver(&iData->iFrequencyNotifier);
314 EXPORT_C TInt CDvbhReceiverInfo::GetCellId( TDvbhCellId& aCellId )
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)
324 // The receiver is in the correct state so we may proceed.
326 result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyCellId, cellId);
327 if (result == KErrNone)
329 aCellId = static_cast<TDvbhCellId>(cellId);
334 EXPORT_C TInt CDvbhReceiverInfo::SetCellIdObserver( MDvbhCellIdObserver& aObserver )
336 delete iData->iCellIdPropertyObserver;
337 iData->iCellIdPropertyObserver = NULL;
338 if ((iData->iCellIdPropertyObserver = new CDvbhPropertyObserver) == NULL)
342 iData->iCellIdNotifier.SetExternalObserver(&aObserver);
343 return iData->iCellIdPropertyObserver->SetObserver(&iData->iCellIdNotifier);
346 EXPORT_C TInt CDvbhReceiverInfo::GetNetworkId( TDvbhNetworkId& aNetworkId )
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)
356 // The receiver is in the correct state so we may proceed.
358 result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyNetworkId, networkId);
359 if (result == KErrNone)
361 aNetworkId = static_cast<TDvbhNetworkId>(networkId);
366 EXPORT_C TInt CDvbhReceiverInfo::SetNetworkIdObserver( MDvbhNetworkIdObserver& aObserver )
368 delete iData->iNetworkIdPropertyObserver;
369 iData->iNetworkIdPropertyObserver = NULL;
370 if ((iData->iNetworkIdPropertyObserver = new CDvbhPropertyObserver) == NULL)
374 iData->iNetworkIdNotifier.SetExternalObserver(&aObserver);
375 return iData->iNetworkIdPropertyObserver->SetObserver(&iData->iNetworkIdNotifier);
378 EXPORT_C TInt CDvbhReceiverInfo::GetBatteryState( TDvbhExtBatteryState& aState )
380 // The receiver is in the correct state so we may proceed.
382 TInt result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyExtBatteryState, state);
383 if (result == KErrNone)
385 aState = static_cast<TDvbhExtBatteryState>(state);
390 EXPORT_C TInt CDvbhReceiverInfo::SetBatteryStateObserver( MDvbhExtBatteryStateObserver& aObserver )
392 delete iData->iExtBatteryPropertyObserver;
393 iData->iExtBatteryPropertyObserver = NULL;
394 if ((iData->iExtBatteryPropertyObserver = new CDvbhPropertyObserver) == NULL)
398 iData->iExtBatteryNotifier.SetExternalObserver(&aObserver);
399 return iData->iExtBatteryPropertyObserver->SetObserver(&iData->iExtBatteryNotifier);
403 EXPORT_C TInt CDvbhReceiverInfo::GetExtConnectionState( TDvbhExtConnectionState& aConnectionState, const TDvbhReceiverType& aReceiver )
405 // The receiver is in the correct state so we may proceed.
407 TInt result = KErrNone;
410 case EDvbhReceiverIntegrated:
411 result = KErrArgument;
413 case EDvbhReceiverBluetooth:
414 result = RProperty::Get(KDvbhPropertyCategory, KDvbhPropertyKeyExtConnectionState, state);
416 case EDvbhReceiverUsbAccessory:
417 result = RProperty::Get(KDvbhPropertyCategory, KMtvAccAttachedKey, state);
420 result = KErrArgument;
423 aConnectionState = EDvbhExtNotConnected;
424 if (result == KErrNone)
426 aConnectionState = static_cast<TDvbhExtConnectionState>(state);
432 EXPORT_C TInt CDvbhReceiverInfo::SetExtConnectionStateObserver( MDvbhExtConnectionObserver& aObserver )
434 delete iData->iExtConnectionPropertyObserver;
435 delete iData->iMtvAccConnectionPropertyObserver;
436 iData->iExtConnectionPropertyObserver = NULL;
437 iData->iMtvAccConnectionPropertyObserver = NULL;
438 if ((iData->iExtConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
442 if ((iData->iMtvAccConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
446 iData->iExtConnectionNotifier.SetExternalObserver(&aObserver);
447 TInt result = iData->iExtConnectionPropertyObserver->SetObserver(&iData->iExtConnectionNotifier);
448 if (result == KErrNone)
450 iData->iMtvAccConnectionNotifier.SetExternalObserver(&aObserver);
451 result = iData->iMtvAccConnectionPropertyObserver->SetObserver(&iData->iMtvAccConnectionNotifier);
457 EXPORT_C TInt CDvbhReceiverInfo::GetExtAntennaConnectionState( TDvbhExtAntennaConnectionState& aConnectionState, const TDvbhReceiverType& aReceiver )
459 // The receiver is in the correct state so we may proceed.
461 TInt result = KErrNone;
464 case EDvbhReceiverIntegrated:
465 result = KErrArgument;
467 case EDvbhReceiverBluetooth:
468 result = KErrArgument;
470 case EDvbhReceiverUsbAccessory:
471 result = RProperty::Get(KDvbhPropertyCategory, KMtvAccAntennaKey, state);
474 result = KErrArgument;
477 aConnectionState = EDvbhExtAntennaNotConnected;
478 if (result == KErrNone)
480 aConnectionState = static_cast<TDvbhExtAntennaConnectionState>(state);
486 EXPORT_C TInt CDvbhReceiverInfo::SetExtAntennaConnectionStateObserver( MDvbhExtAntennaConnectionObserver& aObserver )
488 delete iData->iMtvAccAntennaConnectionPropertyObserver;
489 iData->iMtvAccAntennaConnectionPropertyObserver = NULL;
490 if ((iData->iMtvAccAntennaConnectionPropertyObserver = new CDvbhPropertyObserver) == NULL)
494 iData->iMtvAccAntennaConnectionNotifier.SetExternalObserver(&aObserver);
495 return iData->iMtvAccAntennaConnectionPropertyObserver->SetObserver(&iData->iMtvAccAntennaConnectionNotifier);
498 EXPORT_C TInt CDvbhReceiverInfo::GetExtDeviceInfo( TDvbhAccessoryInfo& aDeviceInfo, const TDvbhReceiverType& /*aReceiver*/ )
500 TPckg<TDvbhAccessoryInfo> devinfoPckg(aDeviceInfo);
501 return RProperty::Get(KDvbhPropertyCategory, KMtvAccInfoKey, devinfoPckg);