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