upnpframework/upnpcommand/inc/upnptaskresourceallocator.h
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2007 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:  A class that allocates resources for a task
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef UPNP_TASKRESOURCEALLOCATOR_H
       
    20 #define UPNP_TASKRESOURCEALLOCATOR_H
       
    21 
       
    22 // INCLUDES
       
    23 // System
       
    24 #include <e32base.h>
       
    25 
       
    26 // upnpframework / avcontroller api
       
    27 #include "upnpavdeviceobserver.h" // base class
       
    28 #include "upnpavbrowsingsessionobserver.h" // base class
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CUPnPCommonUI;
       
    32 class CUpnpNoteHandler;
       
    33 class MUPnPAVController;
       
    34 class CUpnpAVDevice;
       
    35 class MUPnPAVBrowsingSession;
       
    36 class CUpnpNoteHandler;
       
    37 
       
    38 /**
       
    39  * A helper class that makes a method async.
       
    40  */
       
    41 class CUpnpTaskResourceAllocator
       
    42     : public CAsyncOneShot
       
    43     , public MUPnPAVDeviceObserver
       
    44     , public MUPnPAVBrowsingSessionObserver
       
    45     {
       
    46     public:
       
    47 
       
    48         /**
       
    49          * List of upnp resource types available.
       
    50          * These types can be combined by masking.
       
    51          */
       
    52         enum TUpnpResourceTypes
       
    53             {
       
    54             // open AV controller resource
       
    55             EResourceAvController            = 0x0001,
       
    56             // start local mediaserver
       
    57             EResourceLocalMediaServer        = 0x0002,
       
    58             // select an image-capable renderer
       
    59             EResourceSelectImageRenderer     = 0x0100,
       
    60             // select a copy-capable server
       
    61             EResourceSelectCopyServer        = 0x0200,
       
    62             // select a copy-capable server (display move title)
       
    63             EResourceSelectMoveServer        = 0x0400,
       
    64             // a mask, USED ONLY INTERNALLY !!!
       
    65             EResourceSelectDevice            = 0xFF00,
       
    66             };
       
    67 
       
    68         /**
       
    69          * static constructor
       
    70          * @param aCommonUI common UI reference to use
       
    71          * @param aNoteHandler note handler reference to use
       
    72          * @param aMode which resources are needed
       
    73          */
       
    74         static CUpnpTaskResourceAllocator* NewL(
       
    75             CUPnPCommonUI& aCommonUI,
       
    76             TInt aMode );
       
    77 
       
    78         /**
       
    79          * destructor
       
    80          */
       
    81         virtual ~CUpnpTaskResourceAllocator();
       
    82          
       
    83     private:
       
    84 
       
    85         /**
       
    86          * constructor
       
    87          */
       
    88         CUpnpTaskResourceAllocator(
       
    89             CUPnPCommonUI& aCommonUI,
       
    90             TInt aMode );
       
    91 
       
    92     public: // the interface
       
    93         
       
    94         /**
       
    95          * Allocates the resources, returns when complete.
       
    96          * A wait note will be displayed during the process.
       
    97          * displays any necessary errors that occur during the process
       
    98          */
       
    99         void AllocateL();
       
   100 
       
   101         /**
       
   102          * returns the AVController resource after allocation.
       
   103          * Note: This method panics if EResourceAvController was not set.
       
   104          */
       
   105         MUPnPAVController& AVController();
       
   106 
       
   107         /**
       
   108          * returns the selected device
       
   109          * Note: the method panics if neither EResourceSelectRenderer nor
       
   110          * EResourceSelectServer was set.
       
   111          */
       
   112         const CUpnpAVDevice& SelectedDevice();
       
   113         
       
   114         
       
   115          /**
       
   116          * Sets the pointer to the note handler. The ownership of the pointer
       
   117          * is not transfered.
       
   118          *
       
   119          * Leaves with KErrArgument, if the provided pointer is invalid.
       
   120          *
       
   121          * @since S60 3.2
       
   122          * @param aNoteHandler (CUpnpNoteHandler*) the pointer to the note
       
   123          *        handler
       
   124          */
       
   125         void SetNoteHandlerL( CUpnpNoteHandler* aNoteHandler );
       
   126         
       
   127          
       
   128     public: // from CAsyncOneShot
       
   129         
       
   130         /**
       
   131          * Asynchronous execution
       
   132          */
       
   133         void RunL();
       
   134 
       
   135         /**
       
   136          * Execution of the error branch
       
   137          */
       
   138         TInt RunError( TInt aError );
       
   139 
       
   140     private: // own methods
       
   141 
       
   142         /**
       
   143          * cleans up all resources
       
   144          */
       
   145         void Cleanup();
       
   146 
       
   147         /**
       
   148          * creates the AVController resource
       
   149          */
       
   150         void StartAvControllerL();
       
   151 
       
   152         /**
       
   153          * Starts the local mediaserver
       
   154          */
       
   155         void StartLocalMediaServerL();
       
   156 
       
   157 
       
   158         /**
       
   159          * shows a device selection popup
       
   160          */
       
   161         void SelectDeviceL();
       
   162 
       
   163         /**
       
   164          * sets an asynchronous error code
       
   165          */
       
   166         void SetErrorCode( TInt aError );
       
   167 
       
   168     public: // Call back methods of MUPnPAVDeviceObserver
       
   169 
       
   170         void UPnPDeviceDiscovered( const CUpnpAVDevice& aDevice );
       
   171 
       
   172         void UPnPDeviceDisappeared( const CUpnpAVDevice& aDevice );
       
   173 
       
   174         void WLANConnectionLost();
       
   175        
       
   176         
       
   177     public: // Call back methods of MUPnPAVBrowsingSessionObserver
       
   178 
       
   179         void BrowseResponse(
       
   180             const TDesC8& aBrowseResponse,
       
   181             TInt aError,
       
   182             TInt aMatches,
       
   183             TInt aTotalCount,
       
   184             const TDesC8& aUpdateId
       
   185             );
       
   186 
       
   187         void SearchResponse( 
       
   188             const TDesC8& aSearchResponse,
       
   189             TInt aError,
       
   190             TInt aMatches,
       
   191             TInt aTotalCount,
       
   192             const TDesC8& aUpdateId
       
   193             );
       
   194 
       
   195         void SearchCapabilitiesResponse( 
       
   196             TInt aError,
       
   197             const TDesC8& aSearchCapabilities 
       
   198             );
       
   199 
       
   200         void CreateContainerResponse( TInt aError, 
       
   201             const TDesC8& aObjectId );
       
   202 
       
   203         void DeleteObjectResponse( TInt aError );
       
   204 
       
   205         void MediaServerDisappeared(
       
   206             TUPnPDeviceDisconnectedReason aReason );
       
   207 
       
   208         void ReserveLocalMSServicesCompleted( TInt aError );
       
   209 
       
   210     protected:
       
   211 
       
   212         /**
       
   213          * states of the allocator
       
   214          */
       
   215         enum TAllocatorState
       
   216             {
       
   217             EStateIdle = 0, // class constructed, allocation not started yet
       
   218             EStateAllocating, // allocation in progress
       
   219             EStateWaitingForLMS, // rest done,waiting for local media server
       
   220             EStateReady, // allocation succesful
       
   221             EStateError  // allocation failed
       
   222             };
       
   223 
       
   224     private:
       
   225 
       
   226         // internal state
       
   227         TAllocatorState               iState;
       
   228     
       
   229         // the common UI resource
       
   230         CUPnPCommonUI&                iCommonUI;
       
   231 
       
   232         // the note handler
       
   233         CUpnpNoteHandler*             iNoteHandler;
       
   234 
       
   235         // resource allocation mode
       
   236         TInt                          iMode;
       
   237 
       
   238         // avcontroller resource
       
   239         MUPnPAVController*            iAVController;
       
   240 
       
   241         // selected device
       
   242         CUpnpAVDevice*                iSelectedDevice;
       
   243 
       
   244         // the mediaserver keepalive browsing session
       
   245         MUPnPAVBrowsingSession*       iMediaServerSession;
       
   246 
       
   247         // error occurred in some asynchronous operation
       
   248         TInt                          iErrorCode;
       
   249 
       
   250         // flag for local mediaserver start state
       
   251         TBool                         iLocalMSStarted;
       
   252 
       
   253         // flag for local mediaserver callback
       
   254         TBool                         iLocalMSSCompleted;
       
   255 
       
   256         
       
   257     };
       
   258 
       
   259 
       
   260 #endif // UPNP_TASKRESOURCEALLOCATOR_H
       
   261 
       
   262 // End of File