upnp/upnpstack_plat/upnp_common_api/inc/upnpdevice.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:  Declares the CUpnpDevice class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CUPNPDEVICE_H
       
    20 #define C_CUPNPDEVICE_H
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include <e32std.h>
       
    25 #include <badesca.h>
       
    26 #include "upnpservice.h"
       
    27 #include "upnpdescriptionproperty.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class TUpnpDevice;
       
    31 class TUpnpService;
       
    32 class CUpnpIcon;
       
    33 class CUpnpDescriptionProperty;
       
    34 
       
    35 // CONSTANTS
       
    36 const TInt KDefaultDescriptionUrlPort = 80;
       
    37 
       
    38 /**
       
    39  *  Device
       
    40  *
       
    41  *  Prior using the CUpnpDevice class, client application has to create the network
       
    42  *  connection. If connection is not up and running, the
       
    43  *  CUpnpDispatcherEngine class construction will fail.
       
    44  *  See UPnP Interface Design document for instuctions.
       
    45  *
       
    46  *  @since Series60 2.6
       
    47  */
       
    48 class CUpnpDevice : public CBase
       
    49     {
       
    50 
       
    51 public:
       
    52     /**
       
    53      * Localization of device (local, home network or remote)
       
    54      */
       
    55     enum TUpnpDeviceNetwork
       
    56         {
       
    57         EUnknown = 0,
       
    58         ELocalDevice,
       
    59         EHomeNetwork,
       
    60         ERemoteDevice
       
    61         };
       
    62 public:
       
    63     // Constructors and destructor
       
    64 
       
    65     /**
       
    66      * Two-phased constructor.
       
    67      * @param aDevice Device to create new device from.
       
    68      * @param aServices Services for the new device.
       
    69      * @return A new CUpnpDevice instance.
       
    70      */
       
    71     IMPORT_C static CUpnpDevice* NewL( const TUpnpDevice* aDevice,
       
    72             const RPointerArray<TUpnpService>& aServices );
       
    73 
       
    74     /**
       
    75      * Destructor.
       
    76      */
       
    77     virtual ~CUpnpDevice();
       
    78 
       
    79 public: // New functions
       
    80 
       
    81     // Device description XML-inferface functions
       
    82 
       
    83     /**
       
    84      * XML-inferface function.
       
    85      * @since Series60 2.6
       
    86      * @return Content of deviceType-tags in device description. KNullDesC8
       
    87      * if not found.
       
    88      */
       
    89     IMPORT_C const TPtrC8 DeviceType();
       
    90 
       
    91     /**
       
    92      * XML-inferface function.
       
    93      * @since Series60 2.6
       
    94      * @return Content of friendlyName-tags in device description.
       
    95      * KNullDesC8 if not found.
       
    96      */
       
    97     IMPORT_C const TPtrC8 DescriptionProperty(const TDesC8& aPropertyName);
       
    98 
       
    99     // servicelist
       
   100 
       
   101     /**
       
   102      * XML-inferface function.
       
   103      * @since Series60 2.6
       
   104      * @return Array of listed servicetyped in device description
       
   105      * service. KNullDesC8 if not found.
       
   106      */
       
   107     IMPORT_C CDesC8Array& ServiceTypesL();
       
   108 
       
   109     /**
       
   110      * XML-inferface function.
       
   111      * @since Series60 2.6
       
   112      * @param aServiceType Type of the service.
       
   113      * @return Content of serviceId-tags in device description of asked
       
   114      * service. KNullDesC8 if not found.
       
   115      */
       
   116     IMPORT_C const TPtrC8 ServiceId( const TDesC8& aServiceType );
       
   117 
       
   118     /**
       
   119      * XML-inferface function.
       
   120      * @since Series60 2.6
       
   121      * @param aServiceType Type of the service.
       
   122      * @return Content of SCDPURL-tags in device description of asked
       
   123      * service. KNullDesC8 if not found.
       
   124      */
       
   125     IMPORT_C const TPtrC8 ServiceDescriptionUrl( const TDesC8& aServiceType );
       
   126 
       
   127     // end servicelist
       
   128 
       
   129     /**
       
   130      * Getter.
       
   131      * @since Series60 2.6
       
   132      * @return iServiceList.
       
   133      */
       
   134     IMPORT_C RPointerArray<CUpnpService>& ServiceList();
       
   135 
       
   136     /**
       
   137      * Getter (embedded devices).
       
   138      * @since Series60 2.6
       
   139      * @return iDeviceList.
       
   140      */
       
   141     IMPORT_C RPointerArray<CUpnpDevice>& DeviceList();
       
   142 
       
   143     /**
       
   144      * Gets whole embedded hierarchy as a flat list.
       
   145      * @since Series60 2.6
       
   146      * @return device list.
       
   147      */
       
   148     IMPORT_C void GetAllDevices( RPointerArray<CUpnpDevice>& aDevices );
       
   149 
       
   150     /**
       
   151      * Getter.
       
   152      * @since Series60 2.6
       
   153      * @return iIcons.
       
   154      */
       
   155     IMPORT_C RPointerArray<CUpnpIcon>& Icons();
       
   156 
       
   157     /**
       
   158      * Getter.
       
   159      * @since Series60 2.6
       
   160      * @return ETrue if alive.
       
   161      */
       
   162     IMPORT_C TBool Alive() const;
       
   163 
       
   164     /**
       
   165      * Setter.
       
   166      * @since Series60 2.6
       
   167      * @param aAlive Desired TBool.
       
   168      */
       
   169     IMPORT_C void SetAlive( TBool aAlive );
       
   170 
       
   171     /**
       
   172      * Getter.
       
   173      * @since Series60 3.2
       
   174      * @return ETrue if device expired.
       
   175      */
       
   176     IMPORT_C TBool Expired() const;
       
   177 
       
   178     /**
       
   179      * Setter.
       
   180      * @since Series60 3.2
       
   181      * @param aAlive Desired TBool.
       
   182      */
       
   183     IMPORT_C void SetExpired( TBool aAlive );
       
   184 
       
   185     /**
       
   186      * Getter.
       
   187      * @since Series60 2.6
       
   188      * @return ETrue if local.
       
   189      */
       
   190     IMPORT_C TBool Local() const;
       
   191 
       
   192     /**
       
   193      * Setter.
       
   194      * @since Series60 2.6
       
   195      * @param aLocal Desired TBool.
       
   196      */
       
   197     IMPORT_C void SetLocal( TBool aLocal );
       
   198 
       
   199     /**
       
   200      * Getter.
       
   201      * @since Series60 5.0
       
   202      * @return ETrue if remote.
       
   203      */
       
   204     IMPORT_C TBool Remote() const;
       
   205 
       
   206     /**
       
   207      * Getter.
       
   208      * @since Series60 5.0
       
   209      * @return Device network type.
       
   210      */
       
   211     IMPORT_C TUpnpDeviceNetwork DeviceNetwork() const;
       
   212 
       
   213     /**
       
   214      * Setter.
       
   215      * @since Series60 5.0
       
   216      * @param aNetworkType Desired network.
       
   217      */
       
   218     IMPORT_C void SetDeviceNetwork( TUpnpDeviceNetwork aNetworkType );
       
   219 
       
   220     /**
       
   221      * Getter.
       
   222      * @since Series60 2.6
       
   223      * @return UUID of the device.
       
   224      */
       
   225     IMPORT_C const TPtrC8 Uuid();
       
   226 
       
   227     /**
       
   228      * Setter.
       
   229      * @since Series60 3.2
       
   230      * @param aUUID New device UUID.
       
   231      */
       
   232     void SetUuidL( const TDesC8& aUUID );
       
   233 	
       
   234 	/**
       
   235      * Adds device
       
   236 	 * @param device 
       
   237      * @since Series60 2.6
       
   238      */
       
   239     void AddDeviceL( CUpnpDevice* device );
       
   240 
       
   241     /**
       
   242      * Getter.
       
   243      * @since Series60 2.6
       
   244      * @return iDescriptionUrl. KNullDesC8 if not set.
       
   245      */
       
   246     IMPORT_C const TDesC8& DescriptionUrl() const;
       
   247 	
       
   248 	/**
       
   249      * Sets description Url
       
   250 	 * @param aDescriptionUrl 
       
   251      * @since Series60 2.6
       
   252      */
       
   253     void SetDescriptionUrlL( const TDesC8& aDescriptionUrl);
       
   254     
       
   255     /**
       
   256      * Getter
       
   257      * @since Series60 2.6
       
   258      * @return DescriptionUrlPath.
       
   259      * 
       
   260      * @note Method for internal use.
       
   261      */
       
   262     IMPORT_C const TPtrC8 DescriptionUrlPath() const;
       
   263 
       
   264     /**
       
   265      * Getter.
       
   266      * @since Series60 2.6
       
   267      * @return DescriptionUrlAddressL.
       
   268      */
       
   269     IMPORT_C TInetAddr DescriptionUrlAddressL() const;
       
   270 
       
   271     /**
       
   272      * Getter.
       
   273      * @since Series60 2.6
       
   274      * @return DescriptionUrlPort. KErrNotFound if invalid.
       
   275      * 
       
   276      * @note Method for internal use.
       
   277      */
       
   278     IMPORT_C TInt DescriptionUrlPort() const;
       
   279 
       
   280     /**
       
   281      * Add service to dispatcher.
       
   282      * @since Series60 2.6
       
   283      * @param aService Attached service.
       
   284      */
       
   285     void AttachServiceL( CUpnpService* aService );
       
   286 
       
   287     /**
       
   288      * Sets the address of this device.
       
   289      * @since Series60 2.6
       
   290      * @param aAddr Address.
       
   291      */
       
   292     IMPORT_C void SetAddress( const TInetAddr& aAddr );
       
   293 
       
   294     /**
       
   295      * Returns the address of this device.
       
   296      * @since Series60 2.6
       
   297      * @return Address of device.
       
   298      */
       
   299     IMPORT_C virtual TInetAddr Address();
       
   300 
       
   301     /**
       
   302      * Adds aSessionId to list, that contains sessionIds
       
   303      * of currently pending service HTTP GET requests.
       
   304      * @since Series60 2.6
       
   305      * @param aSessionId Session ID.
       
   306      */
       
   307     IMPORT_C void WaitServiceDescriptionL( TInt aSessionId );
       
   308 
       
   309     /**
       
   310      * Returns count of currently pending service HTTP GET
       
   311      * requests.
       
   312      * @since Series60 2.6
       
   313      * @return Number of service descriptions which aren't yet received.
       
   314      */
       
   315     IMPORT_C TInt WaitServiceDescriptionCount();
       
   316 
       
   317     /**
       
   318      * Returns a sessionId of HTTP GET in array, that has
       
   319      * index of aIndex.
       
   320      * @since Series60 2.6
       
   321      * @param aIndex Index of sessionId.
       
   322      * @return SessionId.
       
   323      */
       
   324     IMPORT_C TInt WaitServiceDescriptionSessionId(TInt aIndex);
       
   325 
       
   326     /**
       
   327      * Removes session id from device's service receiving list.
       
   328      * This sessionId is in array position of aIndex.
       
   329      * @since Series60 2.6
       
   330      * @param aIndex Index of sessionId.
       
   331      */
       
   332     IMPORT_C void WaitServiceDescriptionRemoveSessionId( TInt aIndex );
       
   333 
       
   334     enum TServiceAdd
       
   335         {
       
   336         ENotServiceAdded,
       
   337         EServiceAdded,
       
   338         EAllServicesAdded
       
   339         };
       
   340 
       
   341     /**
       
   342      * For Control point. State of icon receiving.
       
   343      * @since Series60 2.6
       
   344      * @return Refer to enum TServiceAdd for possible values.
       
   345      */
       
   346     TServiceAdd ServiceDescriptionReceiveState() const
       
   347         {
       
   348         return iServiceDescriptionReceiveState;
       
   349         }
       
   350 
       
   351     /**
       
   352      * Adds aSessionId into list of currently pending icon requests.
       
   353      * @since Series60 2.6
       
   354      * @param aSessionId Session ID.
       
   355      */
       
   356     IMPORT_C void WaitIconL( TInt aSessionId );
       
   357 
       
   358     /**
       
   359      * Adds a service to this device. Returns EAllServicesAdded, if
       
   360      * information about all services on this device has been received.
       
   361      * Else returns EServiceAdded.
       
   362      * @since Series60 2.6
       
   363      * @param aSessionId Session ID.
       
   364      * @param aHttpMsgBody   Body of a HTTP-message.
       
   365      * @return Refer to enum TServiceAdd for possible values.
       
   366      */
       
   367     IMPORT_C TServiceAdd AddServiceL( TInt aSessionId,
       
   368             CUpnpService* aService );
       
   369 
       
   370     enum TIconAdd
       
   371         {
       
   372         ENotIconAdded,
       
   373         EIconAdded,
       
   374         EAllIconsAdded
       
   375         };
       
   376 
       
   377     /**
       
   378      * For Control point. State of icon receiving.
       
   379      * @since Series60 2.6
       
   380      * @return Refer to enum TIconAdd for possible values.
       
   381      */
       
   382     TIconAdd IconReceiveState() const
       
   383         {
       
   384         return iIconReceiveState;
       
   385         }
       
   386 
       
   387     /**
       
   388      * Adds a icon to this device. Returns EAllIconsAdded, if
       
   389      * all icons for this device has been downloaded. Else returns
       
   390      * EIconAdded.
       
   391      * @since Series60 2.6
       
   392      * @param aSessionId Session ID.
       
   393      * @return Refer to enum TIconAdd for possible values.
       
   394      */
       
   395     IMPORT_C TIconAdd AddIcon(TInt aSessionId);
       
   396 
       
   397     /**
       
   398      * Concatenate given URL with URLBase if exists
       
   399      * @param URL to concatanate
       
   400      * @return concatenated URL
       
   401      */
       
   402     IMPORT_C HBufC8* ConcatWithUrlBaseL(const TDesC8& aUrl);
       
   403 
       
   404     /**
       
   405      * Get information from device description.
       
   406      * Given parameter is name of XML-tag in device description.
       
   407      * @param aProperty name of element in device description
       
   408      * @return value of given element or empty value
       
   409      */
       
   410     IMPORT_C TPtrC8 GetProperty(const TDesC8& aProperty);
       
   411 	
       
   412 	/**
       
   413      * Sets type of device
       
   414 	 * @param aType 
       
   415      * @since Series60 2.6
       
   416      */
       
   417     void SetTypeL(const TDesC8& aType);
       
   418 	
       
   419 	/**
       
   420      * Adds a specific device property
       
   421 	 * @param aDeviceProperty 
       
   422      * @since Series60 2.6
       
   423      */
       
   424     void AddDevicePropertyL( CUpnpDescriptionProperty* aDeviceProperty);
       
   425 
       
   426 	/**
       
   427      * Adds icon
       
   428 	 * @param aIcon 
       
   429      * @since Series60 2.6
       
   430      */
       
   431     IMPORT_C void AddIconL( CUpnpIcon* aIcon);
       
   432 
       
   433     /**
       
   434      * Get information about service IDs    
       
   435      * @return array of service ids
       
   436      */
       
   437     IMPORT_C CDesC8Array& ServiceIdL();
       
   438 	
       
   439 	/**
       
   440      * Makes a copy of device
       
   441      * @since Series60 2.6
       
   442      * @return CUpnpDevice
       
   443      */
       
   444     IMPORT_C CUpnpDevice* CloneL();
       
   445 
       
   446     /**
       
   447      * Removes service from iServiceList.
       
   448      * @since Series60 3.2
       
   449      * @param aService Service to detach.
       
   450      */
       
   451     void DetachService( CUpnpService *aService );
       
   452 
       
   453 public: // Functions from base classes
       
   454 
       
   455     /**
       
   456      * Removes IP address in front of the url leaving only path to file.
       
   457      * @since Series60 2.6
       
   458      * @return The path part of url.
       
   459      */
       
   460     static TPtrC8 RemoveIpAddress( const TDesC8& aAddress );
       
   461 	
       
   462 	/**
       
   463      * Marks out that the device is root
       
   464 	 * @param aIsRoot
       
   465      * @since Series60 2.6
       
   466      */
       
   467     void SetRootDevice(TBool aIsRoot);
       
   468 
       
   469     /**
       
   470      * C++ default constructor.
       
   471      */
       
   472     CUpnpDevice();
       
   473 
       
   474 private:
       
   475 
       
   476     /**
       
   477      * By default Symbian 2nd phase constructor is private.
       
   478      */
       
   479     void ConstructL( const TUpnpDevice* aDevice,
       
   480             const RPointerArray<TUpnpService>& aServices );
       
   481 
       
   482     /**
       
   483      * Two-phased constructor.
       
   484      */
       
   485     static CUpnpDevice* NewL( const TDesC8& aDescription );
       
   486 
       
   487     /**
       
   488      * This function is used for removing old icon request session 
       
   489      * id from list and adding a new one.
       
   490      * @since Series60 2.6
       
   491      * @param aOldSessionId Old session id that is to be removed from list.
       
   492      * @param aNewSessionId New session id that is to be added to list.
       
   493      * @return KErrNone if ok, otherwise error code.
       
   494      */
       
   495     TInt ChangeIconSessionIdL( const TInt aOldSessionId,
       
   496             const TInt aNewSessionId );
       
   497 
       
   498     /**
       
   499      * This function checks if given session id exists in 
       
   500      * @since Series60 2.6
       
   501      * @param aSessionId Session id that is searched from the list.
       
   502      * @return index in array or KErrNotFound.
       
   503      */
       
   504     TInt CheckIconSessionIdExist( const TInt aSessionId );
       
   505 
       
   506 public: //Getters for some xml content.
       
   507 
       
   508     /**
       
   509      * This function gives <URLBase> tag value.
       
   510      */
       
   511     IMPORT_C const TPtrC8 UrlBase();
       
   512 
       
   513     /**
       
   514      * This function gives <presentationUrl> value. 
       
   515      */
       
   516     IMPORT_C const TPtrC8 PresentationUrl();
       
   517 
       
   518     /**
       
   519      * This function set UrlBase value if it is empty in xml document.
       
   520      */
       
   521     IMPORT_C void SetUrlBaseL(const TDesC8& aUrlBase);
       
   522 
       
   523     /**
       
   524      *
       
   525      * @since Series S60 3.1
       
   526      * @return ETrue if it is an embbeded device
       
   527      */
       
   528     IMPORT_C TBool IsEmbeddDevice();
       
   529 
       
   530     /**
       
   531      * General initializations, internal usage.
       
   532      * @since Series60 2.6
       
   533      */
       
   534     void Init();
       
   535 
       
   536     /**
       
   537      * Cleanups array
       
   538      * @since Series S60 3.2
       
   539      */
       
   540     void CleanupServiceArray();
       
   541 
       
   542 protected: // Data
       
   543 
       
   544     // time value
       
   545     TInt64 iTimeValue;
       
   546 
       
   547     // list of session IDs of icons not yet arrived
       
   548     RArray<TInt> iIconSessionIds;
       
   549 
       
   550     // list of session IDs of Service Descriptions not yet arrived
       
   551     RArray<TInt> iServiceDescriptionSessionIds;
       
   552 
       
   553     // list of icons this device has.
       
   554     RPointerArray<CUpnpIcon> iIcons;
       
   555 
       
   556     // this is a pointer list to service infos contained in device description
       
   557     // RPointerArray<CUpnpService> iServices;
       
   558 
       
   559     // this is a pointer list to the CUpnpDevice structures
       
   560     // contains embedded devices of this device
       
   561     RPointerArray<CUpnpDevice> iDeviceList;
       
   562 
       
   563     // this is a pointer list to the CUpnpService structures; 
       
   564     // real service structures based on service descriptions
       
   565     RPointerArray<CUpnpService> iServiceList;
       
   566 
       
   567     // State of adding services. When all services has been added
       
   568     // to this device, iServiceDescriptionReceiveState is EAllServicesAdded
       
   569     TServiceAdd iServiceDescriptionReceiveState;
       
   570 
       
   571     // State of adding icons. When all icons has been received,
       
   572     // iIconReceiveState is EAllIconsAdded.
       
   573     TIconAdd iIconReceiveState;
       
   574 
       
   575     // member variables for CUpnpDevice that has the data of device description
       
   576     CDesC8ArrayFlat* iServiceTypes;
       
   577 
       
   578     // alive flag
       
   579     TBool iAlive;
       
   580 
       
   581     // Indicate if device cache-control time expired
       
   582     TBool iExpired;
       
   583 
       
   584     // icons flag
       
   585     TBool iIsAllIconsArrived;
       
   586 
       
   587     // Network type (local, home or remote).
       
   588     TUpnpDeviceNetwork iNetworkType;
       
   589 
       
   590     // Url to this device's Device Description Document.
       
   591     HBufC8* iDescriptionURL;
       
   592 
       
   593     // device type
       
   594     HBufC8* iDeviceType;
       
   595 
       
   596     // domain
       
   597     HBufC8* iDomain;
       
   598 
       
   599     // device UDN without "uuid:"-prefix
       
   600     HBufC8* iUUID;
       
   601 
       
   602     // seq
       
   603     HBufC8* iClockSeq;
       
   604 
       
   605     // address
       
   606     TInetAddr iAddress;
       
   607 
       
   608     // for logging into right thread log
       
   609     TInt iHandle;
       
   610 
       
   611     // root device flag
       
   612     TBool iIsRootDevice;
       
   613 
       
   614     // Device description file information
       
   615     HBufC* iDeviceDescription;
       
   616     // properties
       
   617     RPointerArray<CUpnpDescriptionProperty> iProperties;
       
   618 
       
   619     /*UrlBase valueu if in document is empty*/
       
   620     HBufC8* iUrlBase;
       
   621 
       
   622     // services id     
       
   623     CDesC8ArrayFlat* iServicesId;
       
   624     };
       
   625 
       
   626 #endif  // C_CUPNPDEVICE_H
       
   627 // End of File