telephonyserverplugins/simtsy/src/CSimPubSub.cpp
changeset 0 3553901f7fa8
child 19 630d2f34d719
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2004-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 // Implements the CSimPubSub class
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "CSimPubSub.h"
       
    19 #include "Simlog.h"
       
    20 
       
    21 
       
    22 /**
       
    23 Standard two phase construction.
       
    24 
       
    25 @param aPSSimObserver pointer to event observer
       
    26 @param aUid uids of Publish&Subscribe uids to subscribe to.
       
    27 */
       
    28 CSimPubSub* CSimPubSub::NewL(MPSSimObserver* aPSSimObserver, const CSimPubSub::TPubSubProperty aProperty)
       
    29 	{
       
    30 	LOGSCOMMON1(">>CSimPubSub::NewL");
       
    31 	CSimPubSub* pubsub=new(ELeave) CSimPubSub(aPSSimObserver,aProperty);
       
    32 	CleanupStack::PushL(pubsub);
       
    33 	pubsub->ConstructL();
       
    34 	CleanupStack::Pop();
       
    35 	LOGSCOMMON1("<<CSimPubSub::NewL");
       
    36 	return pubsub;
       
    37 	}
       
    38 
       
    39 /**
       
    40 Private constructor used in the first phase of construction.
       
    41  
       
    42 @param aPSSimObserver pointer to event observer
       
    43 @param aUid uids of Publish&Subscribe uids to subscribe to.
       
    44 */
       
    45 CSimPubSub::CSimPubSub(MPSSimObserver* aPSSimObserver, const CSimPubSub::TPubSubProperty aProperty)
       
    46 	: CActive(EPriorityStandard),
       
    47 	iProperty(aProperty),
       
    48 	iPSSimCallBack(aPSSimObserver)
       
    49 	{
       
    50 	}
       
    51 
       
    52 /**
       
    53 2nd phase of construction - subscribe to event.
       
    54 */
       
    55 void CSimPubSub::ConstructL()
       
    56 	{
       
    57 	User::LeaveIfError(iSubscribe.Attach(iProperty.iCategory,iProperty.iKey));
       
    58 	CActiveScheduler::Add(this);
       
    59 	}
       
    60 
       
    61 /**
       
    62 Destructor.  Cancels any outstanding request on P&S.
       
    63 */
       
    64 CSimPubSub::~CSimPubSub()
       
    65 	{
       
    66 	Cancel();
       
    67 	iSubscribe.Close();
       
    68 	}
       
    69 	
       
    70 /**
       
    71 Start the subscription
       
    72 */
       
    73 void CSimPubSub::Start()
       
    74 	{
       
    75 	iSubscribe.Subscribe(iStatus);
       
    76 	SetActive();
       
    77 	}
       
    78 
       
    79 /**
       
    80 Handles completion of our P&S request.
       
    81 Notifies the event observer.
       
    82 */
       
    83 void CSimPubSub::RunL()
       
    84 	{
       
    85 	TInt status = iStatus.Int();
       
    86 	// As described in documentation resubscribe before processing new value to prevent missing updates.
       
    87 	if(status != KErrNone)
       
    88 		User::After(1000000L);	//pause before attempting re-subscribe to avoid a tight-loop.
       
    89 	Start();
       
    90 	//pass new state to observer
       
    91 	if (status==KErrNone)
       
    92 		{
       
    93 		TInt state;
       
    94 		if(iSubscribe.Get(state) == KErrNone)
       
    95 			{
       
    96 			iPSSimCallBack->SimPSEvent(iProperty,state);	
       
    97 			}
       
    98 		}
       
    99 	}
       
   100 
       
   101 /**
       
   102 Handles a request to cancel the state machine.
       
   103 Cancels any P&S subscriptions.
       
   104 */
       
   105 void CSimPubSub::DoCancel()
       
   106 	{
       
   107 	iSubscribe.Cancel();
       
   108 	}
       
   109 
       
   110 /**
       
   111 Empty constructor
       
   112 */
       
   113 CSimPubSub::TPubSubProperty::TPubSubProperty()
       
   114 {
       
   115 }
       
   116 
       
   117 
       
   118 /**
       
   119 Overloaded constructor
       
   120 */
       
   121 CSimPubSub::TPubSubProperty::TPubSubProperty(TUid aCategory, TInt aKey,	TInt aType)
       
   122 : iCategory(aCategory), iKey(aKey), iType(aType)
       
   123 {
       
   124 }
       
   125 
       
   126 
       
   127 /**
       
   128 Compare for equality.
       
   129 */
       
   130 TBool CSimPubSub::TPubSubProperty::operator==(const CSimPubSub::TPubSubProperty& aProperty) const
       
   131 	{
       
   132 	return (iCategory == aProperty.iCategory && iKey == aProperty.iKey	&& iType == aProperty.iType);
       
   133 	}