upnp/upnpstack/messagehandler/inc/upnpmessagehandlerengine.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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:  Defines MessageHandlerEngine class
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef C_CUPNPMESSAGEHANDLERENGINE_H
       
    19 #define C_CUPNPMESSAGEHANDLERENGINE_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <upnpnetworkeventobserver.h>
       
    23 #include "upnpdevicelibrary.h"
       
    24 #include "upnphttpmessage.h"
       
    25 #include "upnphttpserverobserver.h"
       
    26 #include "upnpssdpserverobserver.h"
       
    27 #include "upnpmessagehandlersession.h"
       
    28 #include "upnpmessagehandlerengineobserver.h"
       
    29 #include "upnpcompvariant.hrh"
       
    30 
       
    31 // LITERALS
       
    32 
       
    33 static const TInt KSSDPAddressLength=40;
       
    34 _LIT( KMessagehandlerPanic, "UPnP messagehandler Panic" );
       
    35 _LIT8( KEmptyMessage, " " );
       
    36 _LIT8( KMulticastPacket, " " );
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CUpnpHttpServer;
       
    40 class CUpnpSsdpServer;
       
    41 class MMessageHandlerEngineObserver;
       
    42 class CUpnpMSearchTimer;
       
    43 class CUpnpConnectionManagerProxy;
       
    44 class CUpnpSsdpHandlerBase;
       
    45 class CUpnpSsdpHandlerUp;
       
    46 class CUpnpSsdpHandlerDown;
       
    47 
       
    48 #ifdef RD_UPNP_REMOTE_ACCESS
       
    49 class CUpnpIPFiltering;
       
    50 #endif
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /*! 
       
    55  \brief The UPnP engine of Message Handler
       
    56  
       
    57  The message handler is divided into three modules: 
       
    58  CUpnpMessageHandler (having the server functionality), 
       
    59  CUpnpMessageHandlerSession (having the session functionality) and 
       
    60  CUpnpMessageHandlerEngine (having the actual message handling engine).
       
    61 
       
    62  Thus, this class represents the engine of the message handling. 
       
    63  
       
    64  */
       
    65 class CUpnpMessageHandlerEngine : public CBase,
       
    66     public MUpnpDeviceLibraryObserver, public MUpnpSsdpServerObserver,
       
    67     public MUpnpNetworkEventObserver
       
    68     {
       
    69 private:
       
    70     enum TMessagehandlerPanics
       
    71         {
       
    72         ENullDeviceLibrary,
       
    73         ENullSsdpServer,
       
    74         };
       
    75 public:
       
    76 
       
    77     /**
       
    78      A two-phased constructor function
       
    79      @param aObserver to observe engine
       
    80      @result A new instance of CUpnpMessageHandlerEngine
       
    81      */
       
    82     static CUpnpMessageHandlerEngine* NewL(
       
    83         MMessageHandlerEngineObserver& aObserver );
       
    84     
       
    85     /** 
       
    86      Destructor function
       
    87      */
       
    88     virtual ~CUpnpMessageHandlerEngine();
       
    89 
       
    90 public:
       
    91 
       
    92     /**
       
    93      Starts ssdp
       
    94      @result error
       
    95      */
       
    96     TInt StartSsdpL();
       
    97 
       
    98     /**
       
    99      This function is called from SSDP server after receiving a SSDP message
       
   100      @param aMessage The SSDP message that is just received
       
   101      @result None.
       
   102      */
       
   103     void SsdpEventL( CUpnpSsdpMessage* aMessage );
       
   104     
       
   105     /**
       
   106      * Returns device library     
       
   107      */
       
   108     CUpnpDeviceLibrary* DeviceLibrary();
       
   109     
       
   110     /**
       
   111      Adds a new local device to the device library
       
   112      @param aDevice A structure containing indexes to the data buffer
       
   113      @param aBuffer A data buffer containing the actual information
       
   114      @result KErrNone or one of the system-wide error codes
       
   115      */
       
   116     TInt AddLocalDeviceL( TUpnpAddLocalDevice& aDevice, TDesC8& aBuffer );
       
   117 
       
   118     /**
       
   119      Removes a local device from the device library
       
   120      @param aUuid UUID of the target device
       
   121      @result None.
       
   122      */
       
   123     void RemoveLocalDeviceL( const TDesC8& aUuid, TBool aSilent );
       
   124 
       
   125     /**
       
   126      Adds a new local control point client
       
   127      */
       
   128     TInt AddLocalControlPoint();
       
   129 
       
   130     /**
       
   131      Removes a local control point client
       
   132      */
       
   133     TInt RemoveLocalControlPoint();
       
   134     
       
   135     /**
       
   136      It stops using filtering for a target device
       
   137      @param aUuid UUID of the target device
       
   138      @result None.
       
   139      */
       
   140     void StopFilteringDeviceL( const TDesC8& aUuid );
       
   141 
       
   142     /**
       
   143      Returns the device library elements in a pointer array
       
   144      @result A pointer to an array containing pointers to the device library 
       
   145      elements
       
   146      */
       
   147     RPointerArray<CUpnpDeviceLibraryElement>& DeviceList();
       
   148 
       
   149     /**
       
   150      callback method
       
   151      */
       
   152     void InterfaceDown();
       
   153            
       
   154 public:
       
   155     // From MUpnpDeviceLibraryObserver
       
   156 
       
   157     /**
       
   158      Implementation of MUpnpDeviceLibraryObserver::AdvertiseDevice). 
       
   159      
       
   160      Advertises a device using SSDP server to 
       
   161      send SSDP advertisements to the network.
       
   162      @param aLive Tells whether to use ssdp:alive or ssdp:byebye
       
   163      @param anElement The device to advertise
       
   164      @result None.
       
   165      */
       
   166     void AdvertiseDeviceL( TInt aLive, CUpnpDeviceLibraryElement& aElement );
       
   167 
       
   168     /** 
       
   169      Returns the id of the active IAP. 
       
   170      @result The id of the IAP
       
   171      */
       
   172     TInt ActiveIap() const;
       
   173 
       
   174     /**
       
   175      Makes a SSDP search.
       
   176      @param aSearchString The SSDP search string, that is placed to the 
       
   177      ST header of the SSDP message.
       
   178      @result None.
       
   179      */
       
   180     void SsdpSearchL( TDesC8& aSearchString, TDesC8& aMX );
       
   181 
       
   182     /**
       
   183      Inform observer that device list changed.
       
   184      @result None.
       
   185      */
       
   186     void DeviceListChangedL();
       
   187 
       
   188 #ifdef RD_UPNP_REMOTE_ACCESS
       
   189     void AddAddressL( const TInetAddr& aAddress );
       
   190     void AddAddressL( const RMessage2& aMessage, const TDesC8& aRemoteName );
       
   191     void RemoveAddressL( const TInetAddr& aAddress );
       
   192     void RemoveAddressL( const RMessage2& aMessage, const TDesC8& aRemoteName );
       
   193     void RemoveAll();
       
   194     void StartIPFiltering();
       
   195     void StopIPFiltering();
       
   196     TBool IsIPFilteringStarted() const;
       
   197     TBool IsIPAllowed( const TInetAddr& aAddress ) const;
       
   198     void IPFilteringStatus( TInt& aListSize ) const;
       
   199     const TDesC8& GetIPFilterList();
       
   200 #endif
       
   201 
       
   202 private:    // from MUpnpNetworkEventObserver
       
   203 
       
   204     /**
       
   205      * It is called from bottom layer when network event occurs [callback method]     
       
   206      * @result None
       
   207      */
       
   208     void NetworkEvent( CUpnpNetworkEventBase* aEvent );
       
   209 
       
   210 private:
       
   211 
       
   212     /**
       
   213      Default constructor.
       
   214      @param aObserver to observe engine
       
   215      @param aHandle the message handler thread log handle
       
   216      */
       
   217     CUpnpMessageHandlerEngine( MMessageHandlerEngineObserver& aObserver );
       
   218 
       
   219     /**
       
   220      Default (leaving) constructor.
       
   221      */
       
   222     void ConstructL();
       
   223 
       
   224     /**
       
   225      Create session id property and signal id semaphore.
       
   226      */
       
   227     void CreateSessionIdPropertyL();
       
   228 
       
   229     /**
       
   230      * Callback function used to inform about the timer events
       
   231      */
       
   232     void TimerEventL( CUpnpNotifyTimer* aTimer );
       
   233 
       
   234 private:
       
   235     // current state of ssdp servers
       
   236     CUpnpSsdpHandlerBase* iCurrentSsdpHandler;
       
   237 
       
   238     // ssdp up and runnig state handler 
       
   239     CUpnpSsdpHandlerUp* iSsdpHandlerUp;
       
   240 
       
   241     // ssdp stopped state handler     
       
   242     CUpnpSsdpHandlerDown* iSsdpHandlerDown;
       
   243 
       
   244     // The device library 
       
   245     CUpnpDeviceLibrary* iDeviceLibrary;
       
   246 
       
   247     // The active socket server connection 
       
   248     RSocketServ iSocketServ;
       
   249 
       
   250     // The MessageHandler observer 
       
   251     MMessageHandlerEngineObserver& iObserver;
       
   252 
       
   253     // True if SSDP server is ready for shutdown 
       
   254     TBool iSsdpReadyForShutdown;
       
   255 
       
   256     //Local control points counter 
       
   257     TInt iCPCounter;
       
   258 
       
   259     // Object used for WLAN lost and address change events and getting local address
       
   260     CUpnpConnectionManagerProxy *iConnectionManagerProxy;
       
   261     
       
   262     // session id access semaphore
       
   263     RSemaphore iAccessSemaphore;
       
   264     
       
   265 #ifdef RD_UPNP_REMOTE_ACCESS    
       
   266     //Local control points counter 
       
   267     CUpnpIPFiltering* iIPFilterRepository;
       
   268 #endif    
       
   269     };
       
   270 
       
   271 #endif // C_CUPNPMESSAGEHANDLERENGINE_H