upnpmpxplugins/upnpplaybackplugins/inc/upnpsingleton.h
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 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:      Singleton class for main upnp related services
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef C_UPNPSINGLETON_H
       
    24 #define C_UPNPSINGLETON_H
       
    25 
       
    26 // INCLUDES
       
    27 #include <e32base.h>
       
    28 #include "upnpavdeviceobserver.h"
       
    29 #include "upnpmusicperiodizer.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class MUPnPAVController;
       
    33 class MUPnPRendererSelectorObserver;
       
    34 class CUpnpAVDevice;
       
    35 class CUpnpAVDeviceList;
       
    36 class MUPnPAVRenderingSession;
       
    37 
       
    38 /**
       
    39  * A singleton class that provides main upnp services
       
    40  *
       
    41  * The class owns the AVController client session. Plugins that
       
    42  * use this singleton class may then share the same session, or
       
    43  * start rendering sessions in it.
       
    44  *
       
    45  * The class also provides device discovery routines.
       
    46  *
       
    47  * @lib upnpmusicplugins.lib
       
    48  * @since S60 v3.1
       
    49  */
       
    50 class CUPnPSingleton : public CBase,
       
    51                        public MUPnPAVDeviceObserver,
       
    52                        public MUPnPMusicPeriodizerObserver
       
    53     {
       
    54 
       
    55 private:
       
    56 
       
    57     /**
       
    58      * State of renderer selection subprocess
       
    59      *
       
    60      * @since Series 60 3.1
       
    61      */   
       
    62     enum TSelectorState
       
    63         {
       
    64         EStateWaiting, // waiting in device discovery phase
       
    65         EStateComplete, // device discovery complete, still updating list
       
    66         EStateReady, // steady state - list is untouched
       
    67         EStateError, // WLAN connection lost
       
    68         };
       
    69     
       
    70 public:
       
    71 
       
    72     /**
       
    73      * Singleton constructor
       
    74      *
       
    75      * @since Series 60 3.1
       
    76      * @return a new instance
       
    77      */
       
    78     static CUPnPSingleton* GetInstanceL();
       
    79 
       
    80     /**
       
    81      * Singleton destructor
       
    82      *
       
    83      * @since Series 60 3.1
       
    84      * @param aInstance the instance pointer to lose
       
    85      */
       
    86     static void LoseInstance( CUPnPSingleton* aInstance );
       
    87 
       
    88     /**
       
    89      * Destructor
       
    90      *
       
    91      * @since Series 60 3.1
       
    92      */
       
    93     ~CUPnPSingleton();
       
    94 
       
    95     /**
       
    96      * Get list of renderers from AVController. Returns names (async)
       
    97      *
       
    98      * @param aObserver the observer to receive the response
       
    99      * @since Series 60 3.1
       
   100      */
       
   101     void GetRendererNamesL( MUPnPRendererSelectorObserver& aObserver );
       
   102 
       
   103     /**
       
   104      * Cancels an asynchronous query if it is pending
       
   105      */
       
   106     void CancelGetRendererNames();
       
   107 
       
   108     /**
       
   109      * Selects renderer by index
       
   110      *
       
   111      * @since Series 60 3.1
       
   112      * @param aIndex Index of renderer to be selected
       
   113      */
       
   114     const CUpnpAVDevice* SelectRendererByIndexL( TInt aIndex );
       
   115 
       
   116     /**
       
   117      * Return used renderer device
       
   118      *
       
   119      * @since Series 60 3.1
       
   120      * @return CUpnpAVDevice used renderer device
       
   121      */
       
   122     const CUpnpAVDevice* DefaultDevice();
       
   123 
       
   124     /**
       
   125      * Provides reference to the AVController resource
       
   126      */
       
   127     MUPnPAVController& AVC();
       
   128 
       
   129     
       
   130 protected: // From MUPnPAVDeviceObserver
       
   131 
       
   132     /**
       
   133      * See MUPnPAVDeviceObserver
       
   134      */
       
   135      void UPnPDeviceDiscovered( const CUpnpAVDevice& aDevice );
       
   136 
       
   137     /**
       
   138      * See MUPnPAVDeviceObserver
       
   139      */
       
   140      void UPnPDeviceDisappeared( const CUpnpAVDevice& aDevice );
       
   141      
       
   142     /**
       
   143      * See MUPnPAVDeviceObserver
       
   144      */
       
   145      void WLANConnectionLost();
       
   146 
       
   147 protected: // From MUPnPMusicPeriodizerObserver 
       
   148 
       
   149     /**
       
   150      * See MUPnPMusicPeriodizerObserver
       
   151      */
       
   152     void HandlePeriod();
       
   153     
       
   154 private:
       
   155 
       
   156     /**
       
   157      * Clears the current device cache and copies the renderer list again
       
   158      * from AVController
       
   159      */
       
   160     void CacheRendererListL();
       
   161 
       
   162     /**
       
   163      * Sends an asynchronous response for subplayer names to observer.
       
   164      * Uses the class members as parameters.
       
   165      * @param aComplete the complete parameter to use in callback
       
   166      * @param aError the error code to be transmitted
       
   167      */
       
   168     void DeliverNamesToObserverL( TBool aComplete, TInt aError = KErrNone );
       
   169 
       
   170     /**
       
   171      * Checks if the device is available. If a device is not available, it
       
   172      * has been disappeared. The method uses a proprietary flag.
       
   173      * @param aDevice the device to check
       
   174      * @return EFalse if the device has disappeared.
       
   175      */
       
   176     TBool IsAvailable( const CUpnpAVDevice& aDevice ) const;
       
   177 
       
   178     /**
       
   179      * Sets a device availability flag. If a device is not available, it
       
   180      * has been disappeared. The method uses a proprietary flag.
       
   181      * @param aDevice the device to set
       
   182      * @param aAvailable if false, the device has disappeared.
       
   183      */
       
   184     void SetAvailable( CUpnpAVDevice& aDevice, TBool aAvailable ) const;
       
   185 
       
   186     /**
       
   187      * Private default constructor
       
   188      *
       
   189      * @since Series 60 3.1
       
   190      */
       
   191     CUPnPSingleton();
       
   192 
       
   193     /**
       
   194      * 2nd phase constructor
       
   195      *
       
   196      * @since Series 60 3.1
       
   197      */
       
   198     void ConstructL();
       
   199 
       
   200 private: // data
       
   201 
       
   202     /**
       
   203      * Reference count
       
   204      */
       
   205     static TInt                         iInstanceCount;
       
   206 
       
   207     /**
       
   208      * The singleton
       
   209      */
       
   210     static CUPnPSingleton*              iInstance;
       
   211 
       
   212     /**
       
   213      * Pointer to AVController
       
   214      */
       
   215     MUPnPAVController*                  iAVController;
       
   216 
       
   217     /**
       
   218      * Temporary pointer to renderer selector observer 
       
   219      */
       
   220     MUPnPRendererSelectorObserver*      iRendererselectorObserver;
       
   221 
       
   222     /**
       
   223      * default device index
       
   224      */
       
   225     static TInt                         iDefaultRendererIndex;
       
   226     
       
   227     /**
       
   228      * Timer support
       
   229      */
       
   230     CUPnPMusicPeriodizer*               iPeriodizer;
       
   231                        
       
   232     /**
       
   233      * Array of renderer
       
   234      */        
       
   235     RPointerArray<CUpnpAVDevice>        iMediaRenderers;
       
   236 
       
   237     /**
       
   238      * Current selector state
       
   239      */
       
   240     TSelectorState                      iSelectorState;
       
   241 
       
   242     /**
       
   243      * Indicator for activity during next call to GetSubplayerNames
       
   244      */
       
   245     TSelectorState                      iStateChangeDuringNextCall;
       
   246 
       
   247     };
       
   248 
       
   249 
       
   250 #endif // C_UPNPSINGLETON_H