locationtriggering/ltclientlib/src/lbttriggerentry.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2009 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: Base class implementation of trigger entries.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 #include <lbterrors.h>
       
    21 #include "lbttriggerentry.h"
       
    22 #include "lbttriggerconditionbase.h"
       
    23 
       
    24 // ======== LOCAL FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CLbtTriggerEntry::Id()
       
    28 //
       
    29 // (other items were commented in a header).
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C  const TLbtTriggerId&  CLbtTriggerEntry::Id() const 
       
    33     {
       
    34 	return iId;
       
    35     }
       
    36 // ---------------------------------------------------------------------------
       
    37 // CLbtTriggerEntry::SetId()
       
    38 //
       
    39 // (other items were commented in a header).
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C void CLbtTriggerEntry::SetId( TLbtTriggerId aId )
       
    43     {
       
    44 	iId=aId;
       
    45     }
       
    46 // ---------------------------------------------------------------------------
       
    47 // CLbtTriggerEntry::Name()
       
    48 //
       
    49 // (other items were commented in a header).
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C const TDesC& CLbtTriggerEntry::Name() const
       
    53     {
       
    54     if(!iName)
       
    55         {
       
    56         return KNullDesC;
       
    57         }
       
    58     else
       
    59         {
       
    60         return *iName;    
       
    61         }
       
    62     }
       
    63 // ---------------------------------------------------------------------------
       
    64 // CLbtTriggerEntry::SetNameL()
       
    65 //
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C void CLbtTriggerEntry::SetNameL( const TDesC& aName )
       
    70     {
       
    71 	if(aName.Length()>KLbtMaxNameLength)
       
    72 		User::Leave(KErrArgument);
       
    73 	else
       
    74     	{
       
    75     	if( iName )
       
    76     	    {
       
    77     	    delete iName;
       
    78     	    iName = NULL;
       
    79     	    }
       
    80     	iName=HBufC::NewL(aName.Length());
       
    81     	TPtr NamPtr=iName->Des();
       
    82     	NamPtr.Copy(aName);	
       
    83     	}
       
    84 	}
       
    85 // ---------------------------------------------------------------------------
       
    86 // CLbtTriggerEntry::SetTimeToRearm()
       
    87 //
       
    88 // (other items were commented in a header).
       
    89 // ---------------------------------------------------------------------------
       
    90 //    
       
    91 EXPORT_C void CLbtTriggerEntry::SetTimeToRearm( TInt aSeconds )
       
    92     {
       
    93     if( aSeconds < KLbtMinTimeToRearm || aSeconds > KLbtMaxTimeToRearm )
       
    94         
       
    95         User::Panic(KLbtClientPanicCategory,ELbtErrArgument);
       
    96         
       
    97     iRearmTime = aSeconds;
       
    98     }	
       
    99 // ---------------------------------------------------------------------------
       
   100 // CLbtTriggerEntry::State()
       
   101 //
       
   102 // (other items were commented in a header).
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C CLbtTriggerEntry::TLbtTriggerState CLbtTriggerEntry::State() const
       
   106     {
       
   107   	return iState;
       
   108     }
       
   109 // ---------------------------------------------------------------------------
       
   110 // CLbtTriggerEntry::SetState()
       
   111 //
       
   112 // (other items were commented in a header).
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C void CLbtTriggerEntry::SetState( TLbtTriggerState aState )
       
   116     {
       
   117 	iState=aState;
       
   118     }
       
   119 // ---------------------------------------------------------------------------
       
   120 // CLbtTriggerEntry::TimeToRearm()
       
   121 //
       
   122 // (other items were commented in a header).
       
   123 // ---------------------------------------------------------------------------
       
   124 //    
       
   125 EXPORT_C TInt CLbtTriggerEntry::TimeToRearm() const
       
   126     {
       
   127     return iRearmTime;
       
   128     }
       
   129     
       
   130 // ---------------------------------------------------------------------------
       
   131 // CLbtTriggerEntry::GetRequestorsL()
       
   132 //
       
   133 // (other items were commented in a header).
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C void CLbtTriggerEntry::GetRequestorsL( RRequestorStack& aRequestors ) const
       
   137     {
       
   138     aRequestors.Reset();
       
   139     TInt count = iRequestor.Count();
       
   140     for( TInt i=0;i<count;i++ )
       
   141         {
       
   142         CRequestor *Requestor = CRequestor::NewL(iRequestor[i]->RequestorType(),
       
   143                                                  iRequestor[i]->RequestorFormat(),
       
   144                                                  iRequestor[i]->RequestorData());
       
   145         aRequestors.Append( Requestor );
       
   146         }
       
   147     }
       
   148     
       
   149 // ---------------------------------------------------------------------------
       
   150 // CLbtTriggerEntry::SetRequestorsL()
       
   151 //
       
   152 // (other items were commented in a header).
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CLbtTriggerEntry::SetRequestorsL( const RRequestorStack& aRequestors ) 
       
   156     {
       
   157     TInt count = aRequestors.Count();
       
   158     if( count>0 )
       
   159         {
       
   160         for( TInt i=0;i<count;i++ )
       
   161             {
       
   162             CRequestor *Requestor = CRequestor::NewL(aRequestors[i]->RequestorType(),
       
   163                                                      aRequestors[i]->RequestorFormat(),
       
   164                                                      aRequestors[i]->RequestorData());
       
   165             iRequestor.Append( Requestor );
       
   166             }
       
   167         }
       
   168     else
       
   169         {
       
   170         User::Leave(KErrArgument);
       
   171         }
       
   172     }
       
   173 // ---------------------------------------------------------------------------
       
   174 // CLbtTriggerEntry::SetRequestorL()
       
   175 //
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C void CLbtTriggerEntry::SetRequestorL( 
       
   180             CRequestor::TRequestorType aType,
       
   181             CRequestor::TRequestorFormat aFormat,
       
   182             const TDesC& aData )
       
   183     {
       
   184     CRequestor *Requestor=CRequestor::NewL(aType,aFormat,aData);
       
   185 	iRequestor.Append(Requestor);
       
   186     }            
       
   187             
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CLbtTriggerEntry::ManagerUi()
       
   191 //
       
   192 // (other items were commented in a header).
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C TUid CLbtTriggerEntry::ManagerUi() const
       
   196     {
       
   197 	return iManagerUi;
       
   198     }
       
   199 // ---------------------------------------------------------------------------
       
   200 // CLbtTriggerEntry::SetManagerUi()
       
   201 //
       
   202 // (other items were commented in a header).
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CLbtTriggerEntry::SetManagerUi( TUid aUid )
       
   206     {
       
   207     iManagerUi=aUid;
       
   208     }
       
   209 // ---------------------------------------------------------------------------
       
   210 // CLbtTriggerEntry::GetCondition()
       
   211 //
       
   212 // (other items were commented in a header).
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 EXPORT_C CLbtTriggerConditionBase* CLbtTriggerEntry::GetCondition()
       
   216     {
       
   217 	return iTriggerCondition;
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CLbtTriggerEntry::GetCondition()
       
   222 //
       
   223 // (other items were commented in a header).
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C const CLbtTriggerConditionBase* CLbtTriggerEntry::GetCondition() const
       
   227     {
       
   228 	return iTriggerCondition;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CLbtTriggerEntry::SetCondition()
       
   233 //
       
   234 // (other items were commented in a header).
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CLbtTriggerEntry::SetCondition( CLbtTriggerConditionBase* aCondition )
       
   238     {
       
   239   if( iTriggerCondition )
       
   240   	{
       
   241   	delete iTriggerCondition;	 
       
   242   	iTriggerCondition = NULL;
       
   243   	} 	
       
   244 	iTriggerCondition=aCondition;
       
   245 	}
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CLbtTriggerEntry::InternalizeL()
       
   250 //
       
   251 // (other items were commented in a header).
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 EXPORT_C void CLbtTriggerEntry::InternalizeL( RReadStream& aStream )
       
   255     {
       
   256     iRequestor.InternalizeL( aStream );
       
   257     DoInternalizeL(aStream);
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CLbtTriggerEntry::ExternalizeL()
       
   262 //
       
   263 // (other items were commented in a header).
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C void CLbtTriggerEntry::ExternalizeL( RWriteStream& aStream ) const
       
   267     {
       
   268     iRequestor.ExternalizeL( aStream );
       
   269     DoExternalizeL(aStream);
       
   270     }	
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CLbtTriggerEntry::CLbtTriggerEntry()
       
   274 // Default constructor
       
   275 // ---------------------------------------------------------------------------
       
   276 //   
       
   277 CLbtTriggerEntry::CLbtTriggerEntry()
       
   278     {
       
   279 	iName = NULL;
       
   280 	iTriggerCondition = NULL;
       
   281 	iRearmTime = KLbtDefaultTimeToRearm;
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CLbtTriggerEntry::~CLbtTriggerEntry()
       
   286 // Destructor
       
   287 // ---------------------------------------------------------------------------
       
   288 // 
       
   289 CLbtTriggerEntry::~CLbtTriggerEntry()
       
   290     {
       
   291     if( iTriggerCondition )
       
   292         {
       
   293         delete iTriggerCondition;
       
   294         iTriggerCondition = NULL;
       
   295         }
       
   296     if( iName )
       
   297         {
       
   298         delete iName;
       
   299         iName = NULL;
       
   300         }
       
   301 	iRequestor.ResetAndDestroy();
       
   302 	iRequestor.Close();
       
   303 	}
       
   304 
       
   305 
       
   306