upnp/upnpstack/controlpointbase/src/upnpcpbdevicerepository.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2007-2007 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 storage for devices known by control point.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #include <upnpdevice.h>
       
    24 
       
    25 #include "upnpcpbdevicerepository.h"
       
    26 #include "upnpcpbdevicelistutils.h"
       
    27 
       
    28 #define KLogFile _L("UPnPControlPoint.txt")
       
    29 #include <upnpcustomlog.h>
       
    30 
       
    31 static const TInt KDTargetDeviceTypesGranularity = 1;
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CUpnpCpbDeviceRepository::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CUpnpCpbDeviceRepository* CUpnpCpbDeviceRepository::NewL(const CDesC8Array& aTargetDeviceTypes)
       
    41     {
       
    42     LOG_FUNC_NAME;
       
    43     CUpnpCpbDeviceRepository* self = new (ELeave) CUpnpCpbDeviceRepository();
       
    44 
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL(aTargetDeviceTypes);
       
    47     CleanupStack::Pop(self);
       
    48 
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CUpnpCpbDeviceRepository::~CUpnpCpbDeviceRepository
       
    54 // C++ default destructor
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CUpnpCpbDeviceRepository::~CUpnpCpbDeviceRepository()
       
    58     {
       
    59     LOG_FUNC_NAME;
       
    60 
       
    61     TInt i;
       
    62     // only root devices should be deleted
       
    63     // subdevices are removed from all lists
       
    64     for(i=(iDiscoveredDevices.Count());i;i--)
       
    65         {
       
    66         if ( iDiscoveredDevices[i-1]->IsEmbeddDevice() )
       
    67             {
       
    68             iDiscoveredDevices.Remove(i-1);
       
    69             }
       
    70         }
       
    71 
       
    72     for(i=(iUninterestingDevices.Count());i;i--)
       
    73         {
       
    74         if (iUninterestingDevices[i-1]->IsEmbeddDevice())
       
    75             {
       
    76             iUninterestingDevices.Remove(i-1);
       
    77             }
       
    78         }
       
    79 
       
    80     for(i=(iUnneededDevices.Count());i;i--)
       
    81         {
       
    82         if (iUnneededDevices[i-1]->IsEmbeddDevice())
       
    83             {
       
    84             iUnneededDevices.Remove(i-1);
       
    85            }
       
    86         }
       
    87 
       
    88     iDiscoveredDevices.ResetAndDestroy();
       
    89     iDiscoveredDevices.Close();
       
    90 
       
    91     iUninterestingDevices.ResetAndDestroy();
       
    92     iUninterestingDevices.Close();
       
    93 
       
    94     iUnneededDevices.ResetAndDestroy();
       
    95     iUnneededDevices.Close();
       
    96 
       
    97     iIncomliteRootDevices.ResetAndDestroy();
       
    98     iIncomliteRootDevices.Close();
       
    99 
       
   100     iIncomingDevices.ResetAndDestroy();
       
   101     iIncomingDevices.Close();
       
   102 
       
   103     // Delete target devices list
       
   104     if ( iTargetDeviceTypes )
       
   105         {
       
   106         iTargetDeviceTypes->Reset();
       
   107         delete iTargetDeviceTypes;
       
   108         }
       
   109 
       
   110     LOGS("CUpnpCpbDeviceRepository::CUpnpCpbDeviceRepository - END");
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CUpnpCpbDeviceRepository::MatchTargetDevice
       
   115 // Check if device match target types
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TBool CUpnpCpbDeviceRepository::MatchTargetDevice(const TDesC8& aDeviceType )
       
   119     {
       
   120     TBool result = FALSE;
       
   121     if(iTargetDeviceTypes)
       
   122         {
       
   123         if((*iTargetDeviceTypes)[0].Find(_L8("*")) != KErrNotFound) 
       
   124             {
       
   125             result = TRUE;
       
   126             return result;
       
   127             }
       
   128         for(TInt i(0); i < iTargetDeviceTypes->Count(); i++)
       
   129             {
       
   130             if(aDeviceType.Find((*iTargetDeviceTypes)[i]) != KErrNotFound)
       
   131                 {
       
   132                 result = TRUE;
       
   133                 break;
       
   134                 }
       
   135             }
       
   136         }
       
   137     return result;
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CUpnpCpbDeviceRepository::IsKnownDevice
       
   142 // Check if device is in repository
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TBool CUpnpCpbDeviceRepository::IsKnownDevice(const TDesC8& aDeviceUuid)
       
   146     {
       
   147     return (IsDiscoveredDevice(aDeviceUuid) || IsUninterestingDevice(aDeviceUuid)
       
   148                     || IsUnneededDevice(aDeviceUuid));
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CUpnpCpbDeviceRepository::IsDiscoveredDevice
       
   153 // Check if device is discovered already
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TBool CUpnpCpbDeviceRepository::IsDiscoveredDevice(const TDesC8& aDeviceUuid)
       
   157     {
       
   158     return UpnpCpbDeviceListUtils::ExistOnList(aDeviceUuid, iDiscoveredDevices);
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CUpnpCpbDeviceRepository::IsUninterestingDevice
       
   163 // Check if device is discovered but type is not matching
       
   164 // needed devices types
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TBool CUpnpCpbDeviceRepository::IsUninterestingDevice(const TDesC8& aDeviceUuid)
       
   168     {
       
   169     return UpnpCpbDeviceListUtils::ExistOnList(aDeviceUuid, iUninterestingDevices);
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CUpnpCpbDeviceRepository::IsUnneededDevice
       
   174 // Check if device is unneded (type is different then needed).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TBool CUpnpCpbDeviceRepository::IsUnneededDevice(const TDesC8& aDeviceUuid)
       
   178     {
       
   179     return UpnpCpbDeviceListUtils::ExistOnList(aDeviceUuid, iUnneededDevices);
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CUpnpCpbDeviceRepository::AddDiscoveredDeviceL
       
   185 // Add device to discovered device list
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TBool CUpnpCpbDeviceRepository::AddDiscoveredDeviceL(CUpnpDevice* aDevice)
       
   189     {
       
   190     return UpnpCpbDeviceListUtils::AddDeviceL(aDevice, iDiscoveredDevices);
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CUpnpCpbDeviceRepository::AddUnnededDeviceL
       
   195 // Add device to discovered device list
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CUpnpCpbDeviceRepository::AddUnneddedDeviceL(CUpnpDevice* aDevice)
       
   199     {
       
   200     return UpnpCpbDeviceListUtils::AddDeviceL(aDevice, iUnneededDevices);
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CUpnpCpbDeviceRepository::AddIncompliteDeviceL
       
   205 // Add device to discovered device list
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TBool CUpnpCpbDeviceRepository::AddIncompliteDeviceL(CUpnpDevice* aDevice)
       
   209     {
       
   210     return UpnpCpbDeviceListUtils::AddDeviceL(aDevice, iIncomliteRootDevices);
       
   211     }
       
   212 
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CUpnpCpbDeviceRepository::AddIncomingDeviceL
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TBool CUpnpCpbDeviceRepository::AddIncomingDeviceL( CUpnpDevice* aDevice )
       
   219     {
       
   220     CUpnpDevice* device = RemoveIncomingDevice( aDevice->Uuid() );
       
   221     if ( device )
       
   222         {
       
   223         delete device;
       
   224         }
       
   225     return UpnpCpbDeviceListUtils::AddDeviceL( aDevice, iIncomingDevices );
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CUpnpCpbDeviceRepository::RemoveIncomingDeviceL
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 CUpnpDevice* CUpnpCpbDeviceRepository::RemoveIncomingDevice( const TDesC8& aUuid )
       
   233     {
       
   234     CUpnpDevice* res = NULL;
       
   235     for ( TInt i = 0; i < iIncomingDevices.Count(); i++ )
       
   236         {
       
   237         if ( iIncomingDevices[i]->Uuid().Compare( aUuid )  ==  0 )
       
   238             {
       
   239             res = iIncomingDevices[i];
       
   240             iIncomingDevices.Remove(i);
       
   241             break;
       
   242             }
       
   243         }
       
   244     return res;
       
   245     }
       
   246 
       
   247 
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CUpnpCpbDeviceRepository::AddUnnededDeviceL
       
   251 // Add device to discovered device list
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CUpnpCpbDeviceRepository::AddDiscoveredDevicesL(RPointerArray<CUpnpDevice>& aDevices)
       
   255     {
       
   256     UpnpCpbDeviceListUtils::AddDevicesL(aDevices, iDiscoveredDevices);
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CUpnpCpbDeviceRepository::AddUnnededDeviceL
       
   261 // Add device to uninteresting device list
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CUpnpCpbDeviceRepository::AddUninterestingDevicesL(RPointerArray<CUpnpDevice>& aDevices)
       
   265     {
       
   266     UpnpCpbDeviceListUtils::AddDevicesL(aDevices, iUninterestingDevices);
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CUpnpCpbDeviceRepository::AddUnnededDeviceL
       
   271 // Add device to unneded device list
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CUpnpCpbDeviceRepository::AddUnneddedDevicesL(RPointerArray<CUpnpDevice>& aDevices)
       
   275     {
       
   276     UpnpCpbDeviceListUtils::AddDevicesL(aDevices, iUnneededDevices);
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // Return discovered device list
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 const RPointerArray<CUpnpDevice>& CUpnpCpbDeviceRepository::DiscoveredDeviceList() const
       
   284     {
       
   285     return iDiscoveredDevices;
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // Return discovered device list
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 const RPointerArray<CUpnpDevice>& CUpnpCpbDeviceRepository::UnneddedDeviceList() const
       
   293     {
       
   294     return iUnneededDevices;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // Return discovered device list
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 const RPointerArray<CUpnpDevice>& CUpnpCpbDeviceRepository::UninterestingDeviceList() const
       
   302     {
       
   303     return iUninterestingDevices;
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // Return discovered device list
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 const RPointerArray<CUpnpDevice>& CUpnpCpbDeviceRepository::IncompliteDeviceList() const
       
   311     {
       
   312     return iIncomliteRootDevices;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CUpnpCpbDeviceRepository::FindIncompliteDevice
       
   317 // Find incomplite device in repository
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 CUpnpDevice* CUpnpCpbDeviceRepository::FindIncompliteDevice(const TDesC8& aDeviceUuid)
       
   321     {
       
   322     CUpnpDevice* res = NULL;
       
   323     res = UpnpCpbDeviceListUtils::GetFromList(aDeviceUuid, iIncomliteRootDevices);
       
   324     return res;
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CUpnpCpbDeviceRepository::FindDevice
       
   329 // Find device in repository
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 CUpnpDevice* CUpnpCpbDeviceRepository::FindDevice(const TDesC8& aDeviceUuid)
       
   333     {
       
   334     CUpnpDevice* res = NULL;
       
   335     res = UpnpCpbDeviceListUtils::GetFromList(aDeviceUuid, iDiscoveredDevices);
       
   336     if(res)
       
   337         {
       
   338         return res;
       
   339         }
       
   340     res = UpnpCpbDeviceListUtils::GetFromList(aDeviceUuid, iUnneededDevices);
       
   341     if(res)
       
   342         {
       
   343         return res;
       
   344         }
       
   345     res = UpnpCpbDeviceListUtils::GetFromList(aDeviceUuid, iUninterestingDevices);
       
   346     if(res)
       
   347         {
       
   348         return res;
       
   349         }
       
   350     res = UpnpCpbDeviceListUtils::GetFromList(aDeviceUuid, iIncomliteRootDevices);
       
   351     if(res)
       
   352         {
       
   353         return res;
       
   354         }
       
   355     return res;
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // Finds root of given device among dicovered and being discovered devices
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 CUpnpDevice* CUpnpCpbDeviceRepository::FindRoot( const TDesC8& aDeviceUuid )
       
   363     {
       
   364     CUpnpDevice* res = NULL;
       
   365     res = UpnpCpbDeviceListUtils::GetRootFromList( aDeviceUuid, iDiscoveredDevices );
       
   366     if ( res )
       
   367         {
       
   368         return res;
       
   369         }
       
   370     res = UpnpCpbDeviceListUtils::GetRootFromList( aDeviceUuid, iUnneededDevices );
       
   371     if ( res )
       
   372         {
       
   373         return res;
       
   374         }
       
   375     res = UpnpCpbDeviceListUtils::GetRootFromList( aDeviceUuid, iUninterestingDevices );
       
   376     if ( res )
       
   377         {
       
   378         return res;
       
   379         }
       
   380     res = UpnpCpbDeviceListUtils::GetRootFromList( aDeviceUuid, iIncomliteRootDevices );
       
   381     if ( res )
       
   382         {
       
   383         return res;
       
   384         }
       
   385     return res;
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CUpnpCpbDeviceRepository::RemoveDevice
       
   390 // Remove device from all list
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CUpnpCpbDeviceRepository::RemoveDevice(CUpnpDevice* aDevice)
       
   394     {
       
   395     TInt i = iDiscoveredDevices.Find(aDevice);
       
   396     if (i !=KErrNotFound)
       
   397         {
       
   398         iDiscoveredDevices.Remove( i );
       
   399         }
       
   400     else
       
   401         {
       
   402         // check unneded device list
       
   403         i = iUnneededDevices.Find(aDevice);
       
   404         if ( i != KErrNotFound)
       
   405             {
       
   406             iUnneededDevices.Remove( i );
       
   407             }
       
   408         else
       
   409             {
       
   410             // check unninteresting device list
       
   411             i = iUninterestingDevices.Find(aDevice);
       
   412             if ( i != KErrNotFound)
       
   413                 {
       
   414                 iUninterestingDevices.Remove( i );
       
   415                 }
       
   416             else
       
   417                 {
       
   418                 // check root devices with errors
       
   419                 i = iIncomliteRootDevices.Find(aDevice);
       
   420                 if ( i != KErrNotFound)
       
   421                     {
       
   422                     iIncomliteRootDevices.Remove( i );
       
   423                     }
       
   424                 }
       
   425             }
       
   426         }
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // CUpnpCpbDeviceRepository::CUpnpCpbDeviceRepository
       
   431 // Constructor
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 CUpnpCpbDeviceRepository::CUpnpCpbDeviceRepository()
       
   435     {
       
   436     LOG_FUNC_NAME;
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CUpnpCpbDeviceRepository::ConstructL
       
   441 // Second phase constructor
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CUpnpCpbDeviceRepository::ConstructL(const CDesC8Array& aTargetDeviceTypes)
       
   445     {
       
   446     LOG_FUNC_NAME;
       
   447     // coping target device
       
   448     iTargetDeviceTypes = new( ELeave ) CDesC8ArrayFlat( KDTargetDeviceTypesGranularity );
       
   449     for ( TInt i( 0 ); i < aTargetDeviceTypes.Count(); i++ )
       
   450         {
       
   451         iTargetDeviceTypes->AppendL( aTargetDeviceTypes[i]);
       
   452         }
       
   453     }
       
   454 
       
   455 //  End of File