upnp/upnpstack/serviceframework/inc/upnpdispatcherengine.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:  Message dispacther engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CUPNPDISPATCHERENGINE_H
       
    20 #define C_CUPNPDISPATCHERENGINE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include "upnpdispatchersession.h"
       
    25 #include "upnpdevice.h"
       
    26 #include "upnphttpserver.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CUpnpDispatcherRequest;
       
    30 class MDispatcherEngineObserver;
       
    31 class CUpnpHttpServerSession;
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 @brief A message dispatcher unit cooperating with Message Handler
       
    37 
       
    38 This class represents a logical unit between UPnP devices / control points
       
    39 and Message Handler. Message Handler is a Symbian Server - thus, dispatcher
       
    40 follows the same client/server framework and is a client that opens a session
       
    41 to Message Handler. This is not done by class CUpnpDispatcherEngine;
       
    42 the class RUpnpDispatcherSession represents the client interface.
       
    43 
       
    44 Using AddCustomer/RemoveCustomer functions it is possible to set the active
       
    45 services. Dispatcher is able to forward messages to its customers.
       
    46 
       
    47 Also SendMessage function is very essential part of the dispatcher.
       
    48  */
       
    49 class CUpnpDispatcherEngine : public CActive, public MUpnpHttpServerObserver
       
    50     {
       
    51 public:
       
    52     /**
       
    53     * Create a CUpnpDispatcherEngine object using two phase construction,
       
    54     *and return a pointer to the created object.
       
    55     *
       
    56     * A session with Message Handler is initiated during the construction.
       
    57     *
       
    58     * @param aObserver
       
    59     * @return a pointer to the created instance of CUpnpDispatcherEngine
       
    60     */
       
    61     static CUpnpDispatcherEngine* NewL( MDispatcherEngineObserver& aObserver );
       
    62 
       
    63     /**
       
    64     * Create a CUpnpDispatcherEngine object using two phase construction,
       
    65     * and return a pointer to the created object
       
    66     *
       
    67     * A session with Message Handler is initiated during the construction.
       
    68     *
       
    69     * @param aObserver
       
    70     * @return a pointer to the created instance of CUpnpDispatcherEngine
       
    71     */
       
    72     static CUpnpDispatcherEngine* NewLC( MDispatcherEngineObserver& aObserver );
       
    73 
       
    74     /**
       
    75     * Destroy the object and release all memory objects
       
    76     */
       
    77     virtual ~CUpnpDispatcherEngine();
       
    78 
       
    79 private:
       
    80     /**
       
    81     * CUpnpDispatcherEngine
       
    82     *
       
    83     * @discussion Perform the first phase of two phase construction
       
    84     * @param aParent the object to be used to handle updates from the server
       
    85     * @param aObserver
       
    86     */
       
    87     CUpnpDispatcherEngine( MDispatcherEngineObserver& aObserver );
       
    88 
       
    89     /**
       
    90     * ConstructL performs the second phase construction of a CUpnpDispatcherEngine
       
    91     * object
       
    92     */
       
    93     void ConstructL();
       
    94 
       
    95     /**
       
    96     * Creates http server
       
    97     */    
       
    98     void ConstructHttpL();
       
    99 
       
   100 public:
       
   101 
       
   102     /**
       
   103     * Send a message. This function pushes the message to the Message Handler.
       
   104     * @param aMessage The message to be sent.
       
   105     */
       
   106     void SendMessageL( CUpnpHttpMessage* aMessage );
       
   107 
       
   108     /**
       
   109     * Add a customer to the customer list of this dispatcher. In practice,
       
   110     * means that messages start being forwarded to that customer.
       
   111     * @param aCustomer The customer to be added.
       
   112     */
       
   113     void AddCustomer( const MUpnpDispatcherCustomer& aCustomer );
       
   114 
       
   115     /**
       
   116     * Remove a customer from the customer list of this dispatcher. In practice,
       
   117     * means that messages stop being forwarded to that customer.
       
   118     * @param aCustomer The customer to be removed.
       
   119     */
       
   120     void RemoveCustomer( const MUpnpDispatcherCustomer& aCustomer );
       
   121 
       
   122     /**
       
   123     *Starts http server
       
   124     *@since Series60
       
   125     *@param aRegister determines if starting error in message handler process will be checked
       
   126     *@param aPort starts server on fixed port    
       
   127     */
       
   128     void StartHttpServerL( TBool aRegister, const TInt aPort );
       
   129 
       
   130     /**
       
   131     *Stops http server
       
   132     *@since Series60
       
   133     */
       
   134 
       
   135     void StopHttpServer();
       
   136 
       
   137 public: // from CActive
       
   138 
       
   139     /**
       
   140     * Active object RunL, pending request completed.
       
   141     */
       
   142     void RunL();
       
   143 
       
   144     /**
       
   145     * Active object RunL, pending request completed.
       
   146     * @param aError code from RunL.
       
   147     * @result KErrNone.
       
   148     */
       
   149     TInt RunError( TInt aError );
       
   150 
       
   151     /**
       
   152     * Active object DoCancel, cancel pending requests.
       
   153     */
       
   154     void DoCancel();
       
   155 
       
   156 public:
       
   157 
       
   158     // Enum that is used when finding out last request
       
   159     enum TDispatcherRequest
       
   160     {
       
   161     EUnknown = -1,
       
   162     ENewDevices,
       
   163     EDeviceList
       
   164     };
       
   165 
       
   166 
       
   167     /**
       
   168     * Return the MAC addess of this CUpnpDispatcherEngine's HTTP server.
       
   169     * @result Buffer that will contain the MAC address.
       
   170     */
       
   171     const HBufC8* MacAddressL();
       
   172 
       
   173     /**
       
   174     * Removes a device from Message Handler's device library,
       
   175     * which has an UUID of aUuid.
       
   176     * @param aUuid UUID of device that is to be removed.
       
   177     * @result None.
       
   178     */
       
   179     void RemoveLocalDeviceL( const TDesC8& aUuid, TBool aSilent );
       
   180 
       
   181     /**
       
   182     * Return the IP addess of this CUpnpDispatcherEngine's HTTP server.
       
   183     * @result TInetAddr that will contain the IP address of the server.
       
   184     */
       
   185     TInetAddr HttpServerAddress();
       
   186 
       
   187     /**
       
   188     * Callback from HTTP server that a HTTP message has been received.
       
   189     * @param aMessage Received message.
       
   190     * @result None.
       
   191     */
       
   192     void HttpEventLD( CUpnpHttpMessage* aMessage );
       
   193 
       
   194     /**
       
   195     * Sends a SSDP search for aString
       
   196     * @param aString Search message we want to send
       
   197     * @result None.
       
   198     */
       
   199     void SsdpSearchL( const TDesC8& aString );
       
   200 
       
   201     /**
       
   202     * Sends a SSDP uuids that should not be filtered
       
   203     * @param aString Uuids
       
   204     */
       
   205     void SsdpStopFilteringL( const TDesC8& aString );
       
   206 
       
   207     /**
       
   208     * Adds a local device to Message Handler's device library with
       
   209     * given information.
       
   210     * @param aUuid UUID of the device
       
   211     * @param aDeviceType Device type of the device
       
   212     * @param aDescriptionPath URL to this device's desctiption
       
   213     * @param aServices List of services provided by this device.
       
   214     * @param aIsRootDevice ETrue, if this device is UPnP root device, \
       
   215     *       EFalse otherwise.
       
   216     * @result None.
       
   217     */
       
   218     void AddLocalDeviceL( const TDesC8& aUuid,
       
   219                           const TDesC8& aDeviceType,
       
   220                           const TDesC8& aDescriptionPath,
       
   221                           const CDesC8Array& aServices,
       
   222                           const TBool aIsRootDevice );
       
   223 
       
   224      /**
       
   225     * Add control point client to message handler.
       
   226     */
       
   227     void AddControlPointClientL( );
       
   228 
       
   229      /**
       
   230     * Add control point client to message handler.
       
   231     */
       
   232     void RemoveControlPointClientL( );
       
   233 
       
   234     /**
       
   235     * This requests Message Handler for new device list.
       
   236     * @param aUpdateId Dispatcher's last known update id.
       
   237     */
       
   238     void UpdateDevicesL( TInt aUpdateId );
       
   239 
       
   240     /**
       
   241     * Returns a list of new devices found on last query.
       
   242     * @return List of CUpnpDevice's.
       
   243     */
       
   244     const RPointerArray<CUpnpDevice>& NewDevices() const;
       
   245 
       
   246     /**
       
   247     * Clears the list of newly found devices.
       
   248     * @result None.
       
   249     */
       
   250     void RemoveDevices();
       
   251 
       
   252     /**
       
   253     * Deletes current request from list of requests.
       
   254     * @result KErrNone, if successful. KErrNotFound if no requests
       
   255     *       in list.
       
   256     */
       
   257     TInt RemoveHandledRequest();
       
   258 
       
   259     /**
       
   260     * Cancels current pending request, if there is a need to send
       
   261     * for example a SSDP search.
       
   262     * @result None.
       
   263     */
       
   264     void StopRequestL();
       
   265   
       
   266     /**
       
   267     * This function sets handle to transaction creator interface.
       
   268     * @since Series60 5.0 
       
   269     * @param aTransactionCreator pointer to object implementing MUpnpHttpServerTransactionCreator
       
   270     *     interface.
       
   271     **/
       
   272     void SetTransactionCreator( MUpnpHttpServerTransactionCreator* aTransactionCreator );
       
   273 
       
   274 private:
       
   275     /**
       
   276     * Makes a request for devices to Message Handler.
       
   277     * @return ENewDevices, if request is made for new devices,
       
   278     * returns EDeviceList, if request is made for new devices list size.
       
   279     */
       
   280     TDispatcherRequest GetDevicesL();
       
   281 
       
   282     /**
       
   283     * Function gets called when new devices are found.
       
   284     * @return Last update id.
       
   285     */
       
   286     TInt DevicesReceivedL();
       
   287 
       
   288     /**
       
   289     * Sets the Dispatcher to handle next request and remove
       
   290     * the old one.
       
   291     */
       
   292     void HandlePendingRequestL();
       
   293 
       
   294     /**
       
   295     *Check if start was succesfull
       
   296     *@sience Series60 5.0
       
   297     *@param aRegister
       
   298     */
       
   299     void CheckErrorL( TBool aRegister );
       
   300 
       
   301 private:
       
   302 
       
   303     /*! @var iHttpServerSession Pointer to this dispatcher's HTTP server session*/
       
   304     CUpnpHttpServerSession* iHttpServerSession;
       
   305 
       
   306     /*! @var iSession the message handler session */
       
   307     RUpnpDispatcherSession                  iSession;
       
   308 
       
   309     /*! @var iCustomers list of dispatcher customers */
       
   310     RPointerArray<MUpnpDispatcherCustomer>  iCustomers;
       
   311 
       
   312     /*! @var iNewDevices List of new devices that were found on this query */
       
   313     RPointerArray<CUpnpDevice>              iNewDevices;
       
   314 
       
   315     /*! @var iAddLocalDevice Struct of TInt's that will \
       
   316         inform what is the length of each value in the data buffer */
       
   317     TUpnpAddLocalDevice                     iAddLocalDevice;
       
   318 
       
   319     /*! @var iAddLocalPtr Pointer to buffer that will contain device \
       
   320        information. */
       
   321     TPtr8                   iAddLocalPtr;
       
   322 
       
   323     /*! @var iAddLocalBuffer Buffer that holds the information about \
       
   324         device to be added to Message Handler's device library. */
       
   325     HBufC8*                 iAddLocalBuffer;
       
   326 
       
   327     enum TGetDeviceListState
       
   328     {
       
   329         EGetListSize = 0,
       
   330         EGetList,
       
   331         EListReceived,
       
   332         EOtherOperation,
       
   333         ENoOperation,
       
   334     };
       
   335 
       
   336     /*! @var iDeviceGet Current state of DispatcherEngine. */
       
   337     TGetDeviceListState                    iDeviceGetState;
       
   338 
       
   339     /*! @var iSize Structure that holds information \
       
   340         about number of new services and devices. */
       
   341     TUpnpGetDeviceListSize                 iSize;
       
   342 
       
   343     /*! @var iDevs Pointer to list of new devices. */
       
   344     TUpnpDevice*                           iDevs;
       
   345 
       
   346     /*! @var iServs Pointer to list of new services. */
       
   347     TUpnpService*                          iServs;
       
   348 
       
   349     /*! @var iOldUpdateId Last known update id of this CUpnpDispatcher. */
       
   350     TInt                                   iOldUpdateId;
       
   351 
       
   352     /*! @var iObserver Reference to this CUpnpDispatcherEngine's parent for \
       
   353         callbacks. */
       
   354     MDispatcherEngineObserver&             iObserver;
       
   355 
       
   356     /*! @var iPendingRequests List of requests to Message Handler that \
       
   357         ahve not yet been sent. */
       
   358     RPointerArray<CUpnpDispatcherRequest>  iPendingRequests;
       
   359 
       
   360     /*! @var iActiveRequest Request that is currently active \
       
   361         to Message Handler. */
       
   362     CUpnpDispatcherRequest*                iActiveRequest;
       
   363 
       
   364     /*! @var iSearch Buffer that holds a search string that will be \
       
   365         sent as SSDP message. */
       
   366     HBufC8*                                iSearch;
       
   367 
       
   368     /*! @var iGetDevPtr Pointer that is used to receive new devices \
       
   369         from Message Handler. */
       
   370     TPtr8                                  iGetDevPtr;
       
   371 
       
   372     /*! @var iGetServPtr Pointer that is used to receive new services \
       
   373         from Message Handler. */
       
   374     TPtr8                                  iGetServPtr;
       
   375 
       
   376     /*! @var iRemoveUuid Pointer to list of new services. */
       
   377     HBufC8*                                iRemoveUuid;
       
   378 
       
   379     /*! @var iRemoveUuidPtr Buffer that is used to hold UUID of the \
       
   380         device that needs to be removed from Message Handler's device \
       
   381         library. */
       
   382     TPtrC8                                 iRemoveUuidPtr;
       
   383 
       
   384     /* @var Handle counts for logging */
       
   385     TInt                iProcessHandlesInStart;
       
   386     //
       
   387     TInt                iThreadHandlesInStart;
       
   388     //
       
   389     TInt                iReqsInStart;
       
   390     //
       
   391     TInt                iProcessHandlesInEnd;
       
   392     //
       
   393 
       
   394     TInt                iThreadHandlesInEnd;
       
   395     //
       
   396     TInt                iReqsInEnd;
       
   397 
       
   398     HBufC8* iMXString;
       
   399 
       
   400     HBufC8* iUuids;
       
   401 
       
   402     TBool iIsSessionOpen;
       
   403     };
       
   404 
       
   405 #endif // C_CUPNPDISPATCHERENGINE_H
       
   406 
       
   407 // End of File