locationdataharvester/mylocationsengine/src/contactsubscriber.cpp
branchRCL_3
changeset 17 1fc85118c3ae
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
       
     1 /*
       
     2  * Copyright (c) 2010 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: Subscribe source implementation for getting contact status  
       
    15  *              notification from publisher.
       
    16  *
       
    17  */
       
    18 #include "contactsubscriber.h"
       
    19 #include "mylocationlogger.h"
       
    20 #include <locationservicedefines.h>
       
    21 
       
    22 const TUid KContactPropertyCat={0x20022EF9};
       
    23 enum TMyPropertyKeys {EMyPropertyInteger=0x1, EMyPropertyType=0x2};
       
    24 const TInt KBufferSize=16;
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CContactSubscriber::NewL()
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CContactSubscriber* CContactSubscriber::NewL(MNotifyChange* aNotifyChange)
       
    31 {
       
    32     CContactSubscriber* self = CContactSubscriber::NewLC(aNotifyChange);
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35 }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CContactSubscriber::NewLC()
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CContactSubscriber* CContactSubscriber::NewLC(
       
    42         MNotifyChange* aNotifyChange)
       
    43 {
       
    44     CContactSubscriber* self = new (ELeave) CContactSubscriber(
       
    45             aNotifyChange);
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49 }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CContactSubscriber::ConstructL()
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CContactSubscriber::ConstructL()
       
    57 {
       
    58     __TRACE_CALLSTACK;
       
    59     CActiveScheduler::Add(this);
       
    60     TInt ret = iProperty.Attach(KContactPropertyCat, EMyPropertyInteger);
       
    61     if (KErrNone == ret)
       
    62     {
       
    63         SubscribeChangeNotiFication();
       
    64     }
       
    65 }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CContactSubscriber::SubscribeChangeNotiFication()
       
    70 // start subscribe for contact entry
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CContactSubscriber::SubscribeChangeNotiFication()
       
    74 {
       
    75     __TRACE_CALLSTACK;
       
    76     if (IsActive())
       
    77       {
       
    78           Cancel();
       
    79       }
       
    80     // resubscribe before processing new value to prevent missing updates
       
    81     iProperty.Subscribe(iStatus);   
       
    82     SetActive();
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CContactSubscriber::CContactSubscriber()
       
    87 // Default constructor .
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CContactSubscriber::CContactSubscriber(MNotifyChange* aNotifyChange) :
       
    91     CActive(EPriorityStandard),
       
    92     iNotifyChange(*aNotifyChange)
       
    93     
       
    94 {
       
    95 }
       
    96 // -----------------------------------------------------------------------------
       
    97 // CContactSubscriber::~CContactSubscriber()
       
    98 // default destuctor.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CContactSubscriber::~CContactSubscriber()
       
   102 {
       
   103     __TRACE_CALLSTACK;
       
   104     Cancel();
       
   105     iProperty.Close();
       
   106     
       
   107 }
       
   108 // -----------------------------------------------------------------------------
       
   109 // CContactSubscriber::RunL()
       
   110 // Assyncronous request handler , on completion of notification
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CContactSubscriber::RunL()
       
   114 {
       
   115     __TRACE_CALLSTACK;
       
   116     SubscribeChangeNotiFication();
       
   117     // property updated, get new value 
       
   118     TBuf8 <KBufferSize> value; 
       
   119     TPtrC8  id; 
       
   120     TPtrC8  sourceType; 
       
   121     TPtrC8  addressCount; 
       
   122     
       
   123     if ( KErrNone == iProperty.Get( value ) )
       
   124     { 
       
   125         TInt pos =  value.Locate(TChar('-')); 
       
   126         id.Set( value.Left(pos) ); 
       
   127         
       
   128         TPtrC8 ptr = value.Right(3); 
       
   129         sourceType.Set(ptr.Left(1)); 
       
   130         addressCount.Set(ptr.Right(1)); 
       
   131         
       
   132         TInt appId = -1, addressType = -1, addressTypeCount = -1; 
       
   133         TLex8 lex(id); 
       
   134         lex.Val(appId); 
       
   135         
       
   136         TLex8 lex1(sourceType); 
       
   137         lex1.Val( addressType ); 
       
   138         
       
   139         TLex8 lex2(addressCount); 
       
   140         lex2.Val(addressTypeCount); 
       
   141         
       
   142         iNotifyChange.GetChangeNotificationL( appId, addressType,addressTypeCount ); 
       
   143     } 
       
   144 }
       
   145 // -----------------------------------------------------------------------------
       
   146 // CContactSubscriber::DoCancel()
       
   147 // Handels the error condition on assynchronous request
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CContactSubscriber::DoCancel()
       
   151 {
       
   152     iProperty.Cancel();
       
   153 }
       
   154 
       
   155 //End of file
       
   156