upnpmediaserver/mediaserverclient/src/upnpmediaservernotifier.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:  Media Server notification handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "upnpmediaservernotifier.h"
       
    21 #include "upnpfiletransferevent.h"
       
    22 #include "upnpfiletransfereventlist.h"
       
    23 #include "upnpmediaserverobserver.h"
       
    24 
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CUpnpMediaServerNotifier::CUpnpMediaServerNotifier
       
    28 // Constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CUpnpMediaServerNotifier::CUpnpMediaServerNotifier( MUpnpMediaServerObserver* aObserver) :
       
    32                           CActive(EPriorityStandard),
       
    33                           iObserver(aObserver),
       
    34                           iRespBufSizePkg(iRespBufSize),
       
    35                           iReceiveBufferPtr(0,0)
       
    36     {
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CUpnpMediaServerNotifier::~CUpnpMediaServerNotifier()
       
    41 // Destructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CUpnpMediaServerNotifier::~CUpnpMediaServerNotifier()
       
    45     {
       
    46     iMediaServerClient.UnsubscribeEvents();
       
    47     Cancel();
       
    48     iMediaServerClient.Close();
       
    49     delete iReceiveBuffer;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CUpnpMediaServerNotifier::ConstructL
       
    54 // Two-phase constructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CUpnpMediaServerNotifier::ConstructL()
       
    58     {
       
    59     CActiveScheduler::Add( this );
       
    60     User::LeaveIfError(iMediaServerClient.Connect());
       
    61     iMediaServerClient.SubscribeEvents( iStatus );
       
    62     iPendingAction = ESubscribe;
       
    63     SetActive();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CUpnpMediaServerNotifier::NewLC
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CUpnpMediaServerNotifier* CUpnpMediaServerNotifier::NewLC(
       
    72                                         MUpnpMediaServerObserver* aObserver )
       
    73     {
       
    74     CUpnpMediaServerNotifier* self = new( ELeave ) CUpnpMediaServerNotifier( aObserver );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpnpMediaServerNotifier::NewL
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CUpnpMediaServerNotifier* CUpnpMediaServerNotifier::NewL(
       
    86                                         MUpnpMediaServerObserver* aObserver  )
       
    87     {
       
    88     CUpnpMediaServerNotifier* self = NewLC( aObserver );
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CUpnpMediaServerNotifier::RunL
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CUpnpMediaServerNotifier::RunL()
       
    98     {
       
    99     if (iStatus.Int() < 0)
       
   100         {
       
   101         iObserver->NotifierError(iStatus.Int());
       
   102         return;
       
   103         }
       
   104 
       
   105     switch ( iPendingAction )
       
   106         {
       
   107         case ESubscribe:
       
   108             {
       
   109             //starts listening for single events list,
       
   110             //this request may wait for response for a long time
       
   111             iMediaServerClient.ListenTransferEvent(iRespBufSizePkg, iStatus);
       
   112             SetActive();
       
   113             iPendingAction = EListenEvent;
       
   114             break;
       
   115             }
       
   116         case EListenEvent:
       
   117             {
       
   118             //alocates buffer using size returned by ListenTransferEvent()
       
   119             delete iReceiveBuffer;
       
   120             iReceiveBuffer = NULL;
       
   121             iReceiveBuffer = HBufC8::NewL( iRespBufSize );
       
   122             iReceiveBufferPtr.Set( iReceiveBuffer->Des() );
       
   123 
       
   124             //requests events list body
       
   125             iMediaServerClient.GetTransferEventBody(iReceiveBufferPtr, iStatus);
       
   126             SetActive();
       
   127             iPendingAction = EGetEventBody;
       
   128             break;
       
   129             }
       
   130         case EGetEventBody:
       
   131             {
       
   132             //internalizes events list from buffer
       
   133             CUpnpFileTransferEventList* eventList = CUpnpFileTransferEventList::NewLC();
       
   134             RDesReadStream stream( iReceiveBufferPtr );
       
   135             CleanupClosePushL( stream );
       
   136             stream >> *eventList;
       
   137             CleanupStack::PopAndDestroy( &stream );
       
   138 
       
   139             //listens next events
       
   140             iMediaServerClient.ListenTransferEvent(iRespBufSizePkg, iStatus);
       
   141             SetActive();
       
   142             iPendingAction = EListenEvent;
       
   143 
       
   144             //notifies observer
       
   145             TInt count = eventList->GetPointerArray().Count();    
       
   146             for (TInt i=0; i<count; i++ )
       
   147                 {            
       
   148                 iObserver->FileTransferEvent( 
       
   149                     ( CUpnpFileTransferEvent* ) eventList->GetPointerArray()[0] );
       
   150                 eventList->GetPointerArray().Remove(0);
       
   151                 }
       
   152                 
       
   153             CleanupStack::PopAndDestroy(eventList);
       
   154             break;
       
   155             }
       
   156         default:
       
   157             {
       
   158             break;
       
   159             }
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CUpnpMediaServerNotifier::DoCancel
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CUpnpMediaServerNotifier::DoCancel( )
       
   168     {
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CUpnpMediaServerNotifier::RunError
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 TInt CUpnpMediaServerNotifier::RunError(TInt aError)
       
   176     {
       
   177     iObserver->NotifierError(aError);
       
   178     return KErrNone;
       
   179     }
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187