voipplugins/sipconnectionprovider/ipvoicemailengine/src/ipvmbxbase.cpp
changeset 0 a4daefaec16c
child 10 ed1e38b404e5
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Creates SMS message if Event in MailBox has occurred.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <mceoutevent.h>
       
    21 #include <mcemanager.h>
       
    22 
       
    23 #include "ipvmbxbase.h"
       
    24 #include "ipvmbxlogger.h"
       
    25 #include "ipvmbxpanic.h"
       
    26 #include "ipvmbxengine.h"
       
    27 
       
    28 
       
    29 const TInt KMinReSubscribeDelta = 600; // 10 min
       
    30 const TInt KMaxReSubscribeDelta = 86400; // 24 h
       
    31 const TUint32 KServerRefreshInterval = KMaxReSubscribeDelta;
       
    32 const TInt KSecondsToMicro = 1000000;
       
    33 
       
    34 _LIT8( KEventHeader8, "message-summary" );
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ==============================
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CIpVmbxBase::CIpVmbxBase(
       
    45     CIpVmbxEngine& aVmbxEngine,
       
    46     CMceManager& aMceManager ) :
       
    47         iSipProfile( NULL ),
       
    48         iMceOutEvent( NULL ),
       
    49         iMceManager( aMceManager ),
       
    50         iReSubscribe( NULL ),
       
    51         iVmbxEngine( aVmbxEngine )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CIpVmbxBase::ConstructL( TDesC8& aVoiceMailUri8 )
       
    61     {
       
    62     iReSubscribe = CDeltaTimer::NewL( CActive::EPriorityIdle );
       
    63     if ( iVmbxUri8.MaxLength() >= aVoiceMailUri8.Length() )
       
    64         {
       
    65         iVmbxUri8.Copy( aVoiceMailUri8 );
       
    66         }
       
    67     TCallBack cb( ReSubscribe, this );
       
    68     iUpdateEvent.Set( cb );
       
    69     }
       
    70 
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // Two-phased constructor.
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 CIpVmbxBase* CIpVmbxBase::NewL(
       
    77     CIpVmbxEngine& aVmbxEngine,
       
    78     TDesC8& aVoiceMailUri8,
       
    79     CMceManager& aMceManager )
       
    80     {
       
    81     IPVMEPRINT( "CIpVmbxBase::NewL" );
       
    82 
       
    83     CIpVmbxBase* self = new( ELeave ) CIpVmbxBase(
       
    84         aVmbxEngine,
       
    85         aMceManager );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL( aVoiceMailUri8 );
       
    88     CleanupStack::Pop( self );
       
    89 
       
    90     return self;
       
    91     }
       
    92 
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 CIpVmbxBase::~CIpVmbxBase()
       
    99     {
       
   100     IPVMEPRINT( "CIpVmbxBase::~CIpVmbxBase - IN" );
       
   101 
       
   102     if ( iReSubscribe )
       
   103         {
       
   104         iReSubscribe->Remove( iUpdateEvent );
       
   105         }
       
   106     delete iReSubscribe;
       
   107     delete iMceOutEvent;
       
   108 
       
   109     IPVMEPRINT( "CIpVmbxBase::~CIpVmbxBase - OUT" );
       
   110     }
       
   111 
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 void CIpVmbxBase::Initialize(
       
   118     TUint32 aServiceProviderId,
       
   119     CSIPProfile& aSipProfile )
       
   120     {
       
   121     iServiceProviderId = aServiceProviderId;
       
   122     iSipProfile = &aSipProfile;
       
   123     }
       
   124 
       
   125 
       
   126 // ----------------------------------------------------------------------------
       
   127 //
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 void CIpVmbxBase::SubscribeL( TInt aReSubscribe  )
       
   131     {
       
   132     IPVMEPRINT( "CIpVmbxAppBase::SubscribeL - IN" );
       
   133 
       
   134     if ( aReSubscribe < KMinReSubscribeDelta )
       
   135         {
       
   136         // Resubscribe shouldn't occur too often
       
   137         aReSubscribe = KMinReSubscribeDelta;
       
   138         }
       
   139     else
       
   140         if ( aReSubscribe > KMaxReSubscribeDelta )
       
   141             {
       
   142             // Resubscribe shouldn't occur too infrequently
       
   143             aReSubscribe = KMaxReSubscribeDelta;
       
   144             }
       
   145 
       
   146     iReSubscribePeriod = ( TInt64 ) aReSubscribe * ( TInt64 ) KSecondsToMicro;
       
   147 
       
   148     __ASSERT_DEBUG( !iMceOutEvent, Panic( KErrAlreadyExists ) );
       
   149 
       
   150     if ( !iMceOutEvent )
       
   151         {
       
   152         iMceOutEvent = CMceOutEvent::NewL(
       
   153             iMceManager,
       
   154             *iSipProfile,
       
   155             iVmbxUri8,
       
   156             KEventHeader8,
       
   157             KServerRefreshInterval );
       
   158         }
       
   159     else
       
   160         {
       
   161         User::Leave( KErrAlreadyExists );
       
   162         }
       
   163 
       
   164     if ( CMceEvent::EIdle == iMceOutEvent->State() )
       
   165         {
       
   166         iMceOutEvent->SubscribeL();
       
   167         }
       
   168     else
       
   169         {
       
   170         User::Leave( KErrNotReady );
       
   171         }
       
   172     iState = ESubscribing;
       
   173 
       
   174     IPVMEPRINT( "CIpVmbxAppBase::SubscribeL - OUT" );
       
   175     }
       
   176 
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 void CIpVmbxBase::TerminateEventL()
       
   183     {
       
   184     IPVMEPRINT( "CIpVmbxAppBase::TerminateEventL - IN" );
       
   185 
       
   186     iReSubscribe->Remove( iUpdateEvent );
       
   187     if ( iMceOutEvent && CMceEvent::EActive == iMceOutEvent->State() )
       
   188         {
       
   189         iMceOutEvent->TerminateL();
       
   190         iState = ETerminating;
       
   191         }
       
   192     else
       
   193         {
       
   194         User::Leave( KErrNotReady );
       
   195         }
       
   196 
       
   197     IPVMEPRINT( "CIpVmbxAppBase::TerminateEventL - OUT" );
       
   198     }
       
   199 
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 void CIpVmbxBase::DeleteEvent()
       
   206     {
       
   207     delete iMceOutEvent;
       
   208     iMceOutEvent = NULL;
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TInt CIpVmbxBase::ReSubscribe( TAny* aThis )
       
   217     {
       
   218     CIpVmbxBase* base = reinterpret_cast<CIpVmbxBase*> ( aThis );
       
   219     __ASSERT_DEBUG( base, Panic( KErrArgument ) );
       
   220     IPVMEPRINT2(
       
   221         "CIpVmbxAppBase::ReSubscribeL - IN state: %d",
       
   222         base->iMceOutEvent->State() );
       
   223 
       
   224     if ( base && base->iMceOutEvent )
       
   225         {
       
   226         switch ( base->iMceOutEvent->State() )
       
   227             {
       
   228             case CMceEvent::EActive:
       
   229                 {
       
   230                 TRAPD( err, base->iMceOutEvent->UpdateL( KServerRefreshInterval ) );
       
   231                 if ( err )
       
   232                     {
       
   233                     base->iVmbxEngine.HandleMessage(
       
   234                         base->iServiceProviderId, CIpVmbxEngine::EEngineNetworkError );
       
   235                     }
       
   236                 base->iPendingResubscribeCount = 0;
       
   237                 if ( !base->iReSubscribe->IsActive() )
       
   238                     {
       
   239                     base->iReSubscribe->QueueLong(
       
   240                         base->iReSubscribePeriod,
       
   241                         base->iUpdateEvent );
       
   242                     }
       
   243                 break;
       
   244                 }
       
   245             case CMceEvent::EPending:
       
   246                 {
       
   247                 if ( base->iPendingResubscribeCount++ )
       
   248                     {
       
   249                     // Allows to skip one resubscribe before error occurs
       
   250                     base->iVmbxEngine.HandleMessage(
       
   251                         base->iServiceProviderId,
       
   252                         CIpVmbxEngine::EEngineNetworkLost );
       
   253                     }
       
   254                 break;
       
   255                 }
       
   256             case CMceEvent::EIdle:
       
   257             case CMceEvent::ETerminated:
       
   258                 {
       
   259                 base->iVmbxEngine.HandleMessage(
       
   260                     base->iServiceProviderId,
       
   261                     CIpVmbxEngine::EEngineNetworkLost );
       
   262                 break;
       
   263                 }
       
   264             default:
       
   265                 IPVMEPRINT( "Unhandled message!" );
       
   266             }
       
   267         }
       
   268 
       
   269     IPVMEPRINT( "CIpVmbxAppBase::ReSubscribeL - OUT" );
       
   270     return KErrNone;
       
   271     }
       
   272 
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 // ----------------------------------------------------------------------------
       
   277 //
       
   278 void CIpVmbxBase::Cancel()
       
   279     {
       
   280     iState = EDisabled;
       
   281     iReSubscribe->Remove( iUpdateEvent );
       
   282     }
       
   283 
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 TUint32 CIpVmbxBase::ServiceProviderId() const
       
   290     {
       
   291     return iServiceProviderId;
       
   292     }
       
   293 
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 //
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 const TDesC8& CIpVmbxBase::VmbxUrl() const
       
   300     {
       
   301     return iVmbxUri8;
       
   302     }
       
   303 
       
   304 
       
   305 // ----------------------------------------------------------------------------
       
   306 //
       
   307 // ----------------------------------------------------------------------------
       
   308 //
       
   309 void CIpVmbxBase::SetStateRegistered()
       
   310     {
       
   311     iState = ERegistered;
       
   312     if ( !iReSubscribe->IsActive() )
       
   313         {
       
   314         iReSubscribe->QueueLong( iReSubscribePeriod, iUpdateEvent );
       
   315         }
       
   316     }
       
   317 
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 // ----------------------------------------------------------------------------
       
   322 //
       
   323 CIpVmbxBase::TIpVmbxBaseStates CIpVmbxBase::State() const
       
   324     {
       
   325     return iState;
       
   326     }
       
   327 
       
   328 
       
   329 // ----------------------------------------------------------------------------
       
   330 //
       
   331 // ----------------------------------------------------------------------------
       
   332 //
       
   333 void CIpVmbxBase::SetAccountMessageCount( TInt aTotalCount, TInt aNewCount )
       
   334     {
       
   335     iTotalMessageCount = aTotalCount;
       
   336     iNewMessageCount = aNewCount;
       
   337     }
       
   338 
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 //
       
   342 // ----------------------------------------------------------------------------
       
   343 //
       
   344 void CIpVmbxBase::AccountMessageCount( TInt& aTotalCount, TInt& aNewCount )
       
   345     {
       
   346     aTotalCount = iTotalMessageCount;
       
   347     aNewCount = iNewMessageCount;
       
   348     }
       
   349