upnpavcontroller/upnpavcontrollerserver/inc/upnpavcontrollerserver.h
changeset 0 7f85d04be362
child 38 5360b7ddc251
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 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:      AV Controller server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef C_CUPNPAVCONTROLLERSERVER_H
       
    24 #define C_CUPNPAVCONTROLLERSERVER_H
       
    25 
       
    26 
       
    27 // INCLUDES
       
    28 #include "upnpavcontrollerserver.pan"
       
    29 
       
    30 #include <upnpaction.h>
       
    31 #include <upnpservice.h>
       
    32 #include <upnpdevice.h>
       
    33 #include <e32base.h>
       
    34 #include <upnpmediaserverclient.h>
       
    35 #include "upnpconnectionmonitorobserver.h"
       
    36 
       
    37 #include "upnpavtimer.h"
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 class CUpnpAVControlPoint;
       
    41 class CUPnPAVDispatcher;
       
    42 class CUPnPConnectionMonitor;
       
    43 class CUPnPDeviceRepository;
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 *  UPnP Media Server container.
       
    49 *  Provides interface for Media Server maintanace purposes.
       
    50 *
       
    51 *  @lib - 
       
    52 *  @since Series 60 3.1
       
    53 */
       
    54 class CUpnpAVControllerServer :  public CPolicyServer,
       
    55                                  public MUPnPAVTimerCallback,
       
    56                                  public MUPnPConnectionMonitorObserver
       
    57     {
       
    58 
       
    59 private: // Internal server state
       
    60 
       
    61     enum TAVControllerServerState
       
    62         {
       
    63         EStateUndefined = 0,
       
    64         EStateStartingUp,
       
    65         EStateRunning,
       
    66         EStateShuttingDown
       
    67         };    
       
    68     
       
    69 public:  // Constructors and destructor
       
    70         
       
    71     /**
       
    72      * Two-phased constructor.
       
    73      */
       
    74     static CUpnpAVControllerServer* NewLC();
       
    75 
       
    76     /**
       
    77      * Destructor.
       
    78      */
       
    79     virtual ~CUpnpAVControllerServer();
       
    80     
       
    81 public: // New functions        
       
    82      
       
    83     /**
       
    84      * Increment the count of the active sessions for this server
       
    85      */
       
    86     void IncrementSessions();
       
    87 
       
    88     /**
       
    89      * Decrement the count of the active sessions for this server. 
       
    90      */
       
    91     void DecrementSessions();
       
    92     
       
    93     /**
       
    94      * Handles UPnP device discoveries.
       
    95      * 
       
    96      * @param aDevice Device that is discovered.
       
    97      */
       
    98     void DeviceDiscoveredL( CUpnpDevice& aDevice);
       
    99 
       
   100     /**
       
   101      * Handles UPnP device disappears.
       
   102      * 
       
   103      * @param aDevice Device that disappeared.
       
   104      */
       
   105     void DeviceDisappearedL( CUpnpDevice& aDevice);
       
   106     
       
   107     /**
       
   108      * Handles UPnP device disappears.
       
   109      * 
       
   110      * @param aUuid Device that disappeared.
       
   111      */
       
   112     void DeviceDisappearedL( const TDesC8& aUuid );
       
   113     
       
   114     /**
       
   115      * Return a reference to the control point
       
   116      *
       
   117      * @return reference to the control point
       
   118      */
       
   119     CUpnpAVControlPoint& ControlPoint();
       
   120 
       
   121     /**
       
   122      * Return a reference to the s60 MS session
       
   123      *
       
   124      * @return reference to the s60 MS session
       
   125      */
       
   126     RUpnpMediaServerClient& MediaServer();
       
   127     
       
   128     /**
       
   129      * Return a reference to the callback dispatcher
       
   130      *
       
   131      * @return reference to the callback dispatcher
       
   132      */
       
   133     CUPnPAVDispatcher& Dispatcher();
       
   134     
       
   135     /**
       
   136      * Return a reference to the device repository
       
   137      *
       
   138      * @return reference to the device repository
       
   139      */
       
   140     CUPnPDeviceRepository& DeviceRepository();
       
   141     
       
   142     TInt IAP();
       
   143     
       
   144          
       
   145     /**
       
   146      * First stage startup for the server thread
       
   147      * 
       
   148      * @return return KErrNone or panics thread
       
   149      */
       
   150     static TInt ThreadFunction();
       
   151     
       
   152     /**
       
   153      * Starts the s60 MS if not started. Increments the reference ocunt
       
   154      * 
       
   155      * @param aMessage message
       
   156      */
       
   157     void StartMediaServerL( const RMessage2& aMessage );
       
   158     
       
   159     /**
       
   160      * Cancels the start
       
   161      * 
       
   162      * @param aMessage message
       
   163      */
       
   164     void CancelStartMediaServerL( const RMessage2& aMessage );
       
   165 
       
   166     /**
       
   167      * Stops the s60 MS if reference count hits 0
       
   168      * 
       
   169      * @param aMessage message
       
   170      */
       
   171     void StopMediaServerL( const RMessage2& aMessage );
       
   172 
       
   173     /**
       
   174      * Returns ETrue if someone is using the local Media Server
       
   175      * 
       
   176      * @param aMessage message
       
   177      */
       
   178     void MSServicesInUse( const RMessage2& aMessage );
       
   179     
       
   180     /**
       
   181      * Observer callback for Connection Manager GetProtocolInfo function.
       
   182      * 
       
   183      * @param aUuid Source device UUID. 
       
   184      * @param aSessionId 
       
   185      * @param aErr UPnP error code.
       
   186      * @param aSource
       
   187      * @param aSink
       
   188      */ 
       
   189     void CmProtocolInfoResponse(
       
   190         const TDesC8& aUuid,
       
   191         TInt aSessionId,
       
   192         TInt aErr,
       
   193         const TDesC8& aSource, 
       
   194         const TDesC8& aSink );
       
   195     
       
   196 protected:  // From CActive
       
   197 
       
   198     /**
       
   199      * Process any errors
       
   200      * @param aError the leave code reported.
       
   201      * @result return KErrNone if leave is handled
       
   202      */
       
   203     TInt RunError( TInt aError );
       
   204     
       
   205 protected: // From MUPnPAVTimerCallback
       
   206 
       
   207     /**
       
   208      * See upnpavtimercallback.h
       
   209      */
       
   210     void UPnPAVTimerCallback( CUPnPAVTimer::TAVTimerType aType ); 
       
   211 
       
   212 protected: // From CUPnPConnectionMonitorObserver
       
   213 
       
   214     /**
       
   215      * See upnpconnectionmonitorobserver.h
       
   216      */
       
   217     void ConnectionLost();
       
   218 
       
   219 private: // 2nd phase construct
       
   220 
       
   221     /**
       
   222      * Constructs the server 
       
   223      *
       
   224      * @param aPriority CServer2 input parameter
       
   225      */
       
   226     CUpnpAVControllerServer(TInt aPriority);
       
   227 
       
   228     /**
       
   229      * Perform the second phase construction of a CUpnpMessageHandler object
       
   230      */
       
   231     void ConstructL() ;
       
   232 
       
   233 public:
       
   234         
       
   235     /**
       
   236      * Perform the second phase startup. Starts up AV Control Point and
       
   237      * Dispatcher
       
   238      */
       
   239     void StartUpL();
       
   240 
       
   241     /**
       
   242      * Perform the second phase startup. Starts up AV Control Point and
       
   243      * Dispatcher
       
   244      */
       
   245     void CancelStartUp();
       
   246     
       
   247 private: // New methods 
       
   248 
       
   249     /**
       
   250      * Panic client. 
       
   251      *
       
   252      * @param aMessage RMessage2
       
   253      * @param aPanic panic code
       
   254      */
       
   255     static void PanicClient( const RMessage2& aMessage,
       
   256         TAVControllerServerPanic aPanic );
       
   257   
       
   258     /**
       
   259      * Panic the server. 
       
   260      *
       
   261      * @param param aPanic the panic code
       
   262      * @return a updateId of container
       
   263      */
       
   264     static void PanicServer(TAVControllerServerPanic aPanic);
       
   265   
       
   266     /**
       
   267      * Second stage startup for the server thread 
       
   268      */
       
   269     static void ThreadFunctionL();
       
   270     
       
   271     /**
       
   272      * Handles embedded discovered device. Recoursive.
       
   273      *
       
   274      * @param aDevice device
       
   275      * @param aDepth device depth
       
   276      */
       
   277     void HandleEmbeddedDiscoveredDevicesL( CUpnpDevice& aDevice,
       
   278         TInt aDepth );
       
   279     
       
   280     /**
       
   281      * Handles embedded disappeared device. Recoursive.
       
   282      *
       
   283      * @param aDevice device
       
   284      * @param aDepth device depth
       
   285      */
       
   286     void HandleEmbeddedDisappearedDevicesL( CUpnpDevice& aDevice,
       
   287         TInt aDepth );
       
   288         
       
   289     /**
       
   290      * Stops the local media server
       
   291      */
       
   292     void StopMediaServer();
       
   293     
       
   294     /**
       
   295      * Error handler for failed protocolinfo-action
       
   296      *
       
   297      * @param aUuid device uuid
       
   298      * @param aDev pointer to the device in repository
       
   299      */
       
   300     void HandleFailedProtocolInfoResponse( const TDesC8& aUuid );                  
       
   301 
       
   302 private: // From CServer
       
   303 
       
   304     /**
       
   305      * Create a time server session, and return a pointer to the created
       
   306      * object
       
   307      * @param aVersion the client version 
       
   308      * @result pointer to new session
       
   309      */
       
   310     CSession2* NewSessionL( const TVersion& aVersion,
       
   311         const RMessage2& aMessage )  const;
       
   312     
       
   313 private:
       
   314     
       
   315     /** @var iSessionCount the number of session owned by this server */
       
   316     TInt iSessionCount;
       
   317     
       
   318     CUpnpAVControlPoint*        iAVControlPoint; // Own
       
   319     RUpnpMediaServerClient      iMediaServer; // Own
       
   320     
       
   321     CUPnPAVDispatcher*          iDispatcher; // Own
       
   322 
       
   323     CUPnPAVTimer*               iServerTimer; // Own
       
   324     
       
   325     CUPnPAVTimer*               iMSTimer; // Own
       
   326 
       
   327     CUPnPConnectionMonitor*     iMonitor; // Own
       
   328     
       
   329     TInt                        iServerUserCount;
       
   330     
       
   331     TBool                       iMediaServerOnline;
       
   332     
       
   333     TBool                       iStartingMS;
       
   334     
       
   335     TBool                       iMSActivatedBeforeStart;
       
   336     
       
   337     RPointerArray<RMessage2>    iStartMessages; // Own
       
   338     
       
   339     CUPnPDeviceRepository*      iDeviceRepository; // Own
       
   340     
       
   341     TInt                        iDiscoveredDeviceCount;    
       
   342     
       
   343     TInt                        iDisappearedDeviceCount;
       
   344     
       
   345     TInt                        iShutdownTimeoutValue;
       
   346     
       
   347     TInt                        iIAP;    
       
   348 
       
   349     TAVControllerServerState    iServerState;
       
   350 
       
   351     
       
   352     };
       
   353 
       
   354 
       
   355 #endif // C_CUPNPAVCONTROLLERSERVER_H