upnpmediaserver/mediaserverclient/src/upnpmediaserverstatuswatcher.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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 class for UPnP File Sharing class
       
    15 *
       
    16 */
       
    17 #include "upnpmediaserverstatuswatcher.h"
       
    18 
       
    19 // ======== MEMBER FUNCTIONS ========
       
    20 
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // Two-phase constructor
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 EXPORT_C CUpnpMediaServerStatusWatcher* CUpnpMediaServerStatusWatcher::NewL( 
       
    27         MUpnpMediaServerStatusObserver& aObserver )
       
    28     {
       
    29     CUpnpMediaServerStatusWatcher *self = new ( ELeave ) 
       
    30                                      CUpnpMediaServerStatusWatcher( aObserver );
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36     
       
    37 // ---------------------------------------------------------------------------
       
    38 // Two-phase constructor
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CUpnpMediaServerStatusWatcher* CUpnpMediaServerStatusWatcher::NewL( 
       
    42         RUpnpMediaServerClient& aClient, MUpnpMediaServerStatusObserver& aObserver )
       
    43     {
       
    44     CUpnpMediaServerStatusWatcher *self = new ( ELeave )
       
    45                                      CUpnpMediaServerStatusWatcher( aClient, aObserver );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Destructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //                                 
       
    56 CUpnpMediaServerStatusWatcher::~CUpnpMediaServerStatusWatcher()   
       
    57     {
       
    58     Cancel();
       
    59     if ( iSessionOwner )
       
    60         {
       
    61         iMediaServerClient.Close();
       
    62         }
       
    63     }
       
    64     
       
    65 // ---------------------------------------------------------------------------
       
    66 // Constructor
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CUpnpMediaServerStatusWatcher::CUpnpMediaServerStatusWatcher( 
       
    70     RUpnpMediaServerClient& aClient, MUpnpMediaServerStatusObserver& aObserver )
       
    71     : CActive( CActive::EPriorityStandard ), iMediaServerClient( aClient ),
       
    72       iStatusEventObserver( aObserver )
       
    73     {    
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Constructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CUpnpMediaServerStatusWatcher::CUpnpMediaServerStatusWatcher( 
       
    81     MUpnpMediaServerStatusObserver& aObserver )
       
    82     : CActive( CActive::EPriorityStandard ), iSessionOwner( ETrue ),
       
    83       iStatusEventObserver( aObserver )
       
    84     {
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Two-phase constructor
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CUpnpMediaServerStatusWatcher::ConstructL()
       
    92     {
       
    93     if ( iSessionOwner )
       
    94         {
       
    95         User::LeaveIfError( iMediaServerClient.Connect() );
       
    96         }
       
    97     User::LeaveIfError( iMediaServerClient.Status( iMediaServerStatus ) ); 
       
    98     CActiveScheduler::Add( this );
       
    99     Subscribe();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CUpnpMediaServerStatusWatcher::Subscribe
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 EXPORT_C void CUpnpMediaServerStatusWatcher::Subscribe()
       
   107     {
       
   108     if ( !IsActive() )
       
   109         {
       
   110         iMediaServerClient.StatusChangeNotify( iStatus );
       
   111         SetActive();
       
   112         }
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CUpnpMediaServerStatusWatcher::DispatchResponseStatusEvent
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CUpnpMediaServerStatusWatcher::DispatchResponseStatusEvent( TInt aStatus )
       
   120     {
       
   121     if ( iMediaServerStatus != aStatus )
       
   122         {
       
   123         iMediaServerStatus = aStatus;
       
   124         iStatusEventObserver.StatusChanged( 
       
   125             static_cast<MUpnpMediaServerStatusObserver::TServerState>( iMediaServerStatus ) );
       
   126         }    
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CUpnpMediaServerStatusWatcher::RunL
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CUpnpMediaServerStatusWatcher::RunL()
       
   134     {
       
   135     if ( iStatus >= KErrNone )
       
   136         {
       
   137         Subscribe();
       
   138         TInt newStatus;
       
   139         TInt error  = iMediaServerClient.Status( newStatus );
       
   140         if ( error != KErrNone )
       
   141             {
       
   142             iStatusEventObserver.SubscribeError( error );
       
   143             return;
       
   144             }
       
   145         DispatchResponseStatusEvent( newStatus );        
       
   146         }
       
   147     else
       
   148         {
       
   149         iStatusEventObserver.SubscribeError( iStatus.Int() );
       
   150         }    
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CUpnpMediaServerStatusWatcher::RunError
       
   155 // ---------------------------------------------------------------------------
       
   156 //    
       
   157 TInt CUpnpMediaServerStatusWatcher::RunError( TInt /*aError*/ )
       
   158     {
       
   159     return KErrNone;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CUpnpMediaServerStatusWatcher::DoCancel
       
   164 // ---------------------------------------------------------------------------
       
   165 //        
       
   166 void CUpnpMediaServerStatusWatcher::DoCancel()
       
   167     {
       
   168     iMediaServerClient.CancelStatusChangeNotify();
       
   169     }    
       
   170 
       
   171 // End of file