locationtriggering/ltclientlib/src/lbttriggerconditionarea.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2007 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: Implementation of data class for trigger 
       
    15 * condition based on the geographical area and movement of 
       
    16 * the terminal
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "lbttriggerconditionbase.h"
       
    22 #include "lbttriggerconditionarea.h"
       
    23 #include "lbtgeocircle.h"
       
    24 #include "lbtgeoareabase.h"
       
    25 #include "lbtgeocell.h"
       
    26 #include "lbtgeorect.h"
       
    27 #include "lbtgeohybrid.h"
       
    28 #include "lbterrors.h"
       
    29 
       
    30 
       
    31 // ======== LOCAL FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CLbtTriggerConditionArea::CLbtTriggerConditionArea()
       
    35 // Default constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CLbtTriggerConditionArea::CLbtTriggerConditionArea()
       
    39     {
       
    40 	
       
    41 	}
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CLbtTriggerConditionArea::~CLbtTriggerConditionArea()
       
    45 // Destructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CLbtTriggerConditionArea::~CLbtTriggerConditionArea()
       
    49     {
       
    50     if( iArea )
       
    51         {
       
    52         delete iArea;
       
    53         iArea = NULL;
       
    54         }
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CLbtTriggerConditionArea::NewL()
       
    59 //
       
    60 // (other items were commented in a header).
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CLbtTriggerConditionArea* CLbtTriggerConditionArea::NewL( 
       
    64             CLbtGeoAreaBase* aArea,
       
    65             TDirection aDirection )
       
    66     {
       
    67 	CLbtTriggerConditionArea* self = new( ELeave ) CLbtTriggerConditionArea;	
       
    68 	CleanupStack::PushL( self );
       
    69 	self->ConstructL(aArea,aDirection);
       
    70 	CleanupStack::Pop( self );  
       
    71 	return self;
       
    72     }
       
    73             
       
    74 // ---------------------------------------------------------------------------
       
    75 // CLbtTriggerConditionArea::NewL()
       
    76 //
       
    77 // (other items were commented in a header).
       
    78 // ---------------------------------------------------------------------------
       
    79 //            
       
    80 EXPORT_C  CLbtTriggerConditionArea* CLbtTriggerConditionArea::NewL( )
       
    81     {
       
    82 	CLbtTriggerConditionArea* self = new( ELeave ) CLbtTriggerConditionArea;	
       
    83 	CleanupStack::PushL( self );
       
    84 	self->ConstructL();
       
    85 	CleanupStack::Pop( self );  
       
    86 	return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CLbtTriggerConditionArea::NewLC()
       
    91 //
       
    92 // (other items were commented in a header).
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C  CLbtTriggerConditionArea* CLbtTriggerConditionArea::NewLC( )
       
    96     {
       
    97 	CLbtTriggerConditionArea* self = new( ELeave ) CLbtTriggerConditionArea;	
       
    98 	CleanupStack::PushL( self );
       
    99 	self->ConstructL();
       
   100 	return self;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CLbtTriggerConditionArea::Direction()
       
   105 //
       
   106 // (other items were commented in a header).
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C CLbtTriggerConditionArea::TDirection CLbtTriggerConditionArea::Direction() const
       
   110     {
       
   111  	return iDirection;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CLbtTriggerConditionArea::SetDirection()
       
   116 //
       
   117 // (other items were commented in a header).
       
   118 // ---------------------------------------------------------------------------
       
   119 //  
       
   120 EXPORT_C void CLbtTriggerConditionArea::SetDirection( 
       
   121             TDirection aDirection )
       
   122     {
       
   123   	iDirection=aDirection;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CLbtTriggerConditionArea::TriggerArea()
       
   128 //
       
   129 // (other items were commented in a header).
       
   130 // ---------------------------------------------------------------------------
       
   131 //            
       
   132 EXPORT_C CLbtGeoAreaBase* CLbtTriggerConditionArea::TriggerArea() const
       
   133     {
       
   134  	return iArea;
       
   135     }   
       
   136 // ---------------------------------------------------------------------------
       
   137 // CLbtTriggerConditionArea::SetTriggerArea()
       
   138 //
       
   139 // (other items were commented in a header).
       
   140 // ---------------------------------------------------------------------------
       
   141 // 
       
   142 EXPORT_C void CLbtTriggerConditionArea::SetTriggerArea( 
       
   143             CLbtGeoAreaBase* aArea )
       
   144     {
       
   145  	CLbtGeoAreaBase::TGeoAreaType areaType;
       
   146  	areaType=aArea->Type();
       
   147  	if(areaType ==CLbtGeoAreaBase::ERectangular)
       
   148  			User::Panic(KLbtClientPanicCategory,ELbtErrArgument);
       
   149  	if( iArea )
       
   150  	    {
       
   151  	    delete iArea;
       
   152  	    iArea = NULL;
       
   153  	    }
       
   154  	iArea=aArea;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CLbtTriggerConditionArea::ConstructL()
       
   159 // Symbian 2nd phase constructor can leave.
       
   160 // ---------------------------------------------------------------------------
       
   161 // 
       
   162 void CLbtTriggerConditionArea::ConstructL()
       
   163     {
       
   164     iArea = NULL;
       
   165  	iDirection=EFireOnEnter;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CLbtTriggerConditionArea::ConstructL()
       
   170 // Symbian 2nd phase constructor can leave.
       
   171 // ---------------------------------------------------------------------------
       
   172 // 
       
   173 void CLbtTriggerConditionArea::ConstructL(CLbtGeoAreaBase* aArea,
       
   174             TDirection aDirection)
       
   175     {
       
   176  	CLbtGeoAreaBase::TGeoAreaType areaType;
       
   177  	areaType=aArea->Type();
       
   178  	if(areaType ==CLbtGeoAreaBase::ERectangular)
       
   179  			User::Panic(KLbtClientPanicCategory,ELbtErrArgument);
       
   180  	iArea=aArea;
       
   181  	iDirection=aDirection;
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CLbtTriggerConditionArea::Type()
       
   186 //
       
   187 // (other items were commented in a header).
       
   188 // ---------------------------------------------------------------------------
       
   189 // 
       
   190 CLbtTriggerConditionBase::TType CLbtTriggerConditionArea::Type() const
       
   191     {
       
   192  	return CLbtTriggerConditionBase::ETriggerConditionArea;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CLbtTriggerConditionArea::DoInternalizeL()
       
   197 //
       
   198 // (other items were commented in a header).
       
   199 // ---------------------------------------------------------------------------
       
   200 // 
       
   201 void CLbtTriggerConditionArea::DoInternalizeL( RReadStream& aStream )
       
   202     {
       
   203  	TInt areaType=aStream.ReadInt8L();
       
   204  	if(areaType==1)
       
   205  	    {
       
   206  		CLbtGeoCircle* area= CLbtGeoCircle::NewL();
       
   207  		area->InternalizeL(aStream);
       
   208  		SetTriggerArea(area);
       
   209  		}
       
   210  	else if(areaType==2)
       
   211  	    {
       
   212  		CLbtGeoRect* area=CLbtGeoRect::NewL();
       
   213  		area->InternalizeL(aStream);
       
   214  		SetTriggerArea(area);
       
   215  	    }
       
   216  	else if( areaType==3 )
       
   217  	    {
       
   218  	    CLbtGeoCell* area=CLbtGeoCell::NewL();
       
   219  		area->InternalizeL(aStream);
       
   220  		SetTriggerArea(area);
       
   221  	    }
       
   222  	else if( areaType==4)
       
   223         {
       
   224         CLbtGeoHybrid* area=CLbtGeoHybrid::NewL();
       
   225         area->InternalizeL(aStream);
       
   226         SetTriggerArea(area);
       
   227         }
       
   228  	
       
   229  	TInt direction;
       
   230  	direction=aStream.ReadInt16L();
       
   231 	if(direction==1)
       
   232 	 iDirection=EFireOnEnter;
       
   233 	
       
   234 	else if(direction==2)
       
   235 	 iDirection=EFireOnExit;
       
   236  	}
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // CLbtTriggerConditionArea::DoExternalizeL()
       
   240 //
       
   241 // (other items were commented in a header).
       
   242 // ---------------------------------------------------------------------------
       
   243 // 
       
   244 void CLbtTriggerConditionArea:: DoExternalizeL( RWriteStream& aStream ) const
       
   245     {
       
   246  	CLbtGeoAreaBase::TGeoAreaType areaType;
       
   247  	
       
   248  	if(iArea)
       
   249  	    {
       
   250  	    areaType=iArea->Type();
       
   251  	    if(areaType==CLbtGeoAreaBase::ECircle)
       
   252  		    aStream.WriteInt8L(1);
       
   253  	    else if( areaType==CLbtGeoAreaBase::ERectangular )
       
   254  		    aStream.WriteInt8L(2);
       
   255  	    else if( areaType==CLbtGeoAreaBase::ECellular )
       
   256  	        aStream.WriteInt8L(3);
       
   257  	        
       
   258  	    else if( areaType==CLbtGeoAreaBase::EHybrid )
       
   259  	       aStream.WriteInt8L(4); 
       
   260  	    iArea->ExternalizeL(aStream);
       
   261  	    }
       
   262  	else
       
   263         {
       
   264         aStream.WriteInt8L(0);
       
   265         }
       
   266              	
       
   267  	aStream.WriteInt16L(iDirection);
       
   268     }
       
   269