upnpmediaserver/contentdirectoryservice/src/upnpobjectbean.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  Element table data handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "upnpobjectbean.h"
       
    22 #include "upnpcontentdirectoryglobals.h"
       
    23 #include <upnpobject.h>
       
    24 #include <upnpitem.h>
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CUpnpObjectBean::CUpnpObjectBean
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CUpnpObjectBean::CUpnpObjectBean()
       
    34 {
       
    35     iObjRefId = KUndef;
       
    36 
       
    37 }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CUpnpObjectBean::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CUpnpObjectBean::ConstructL()
       
    45 {
       
    46 
       
    47 }
       
    48 // -----------------------------------------------------------------------------
       
    49 // CUpnpObjectBean::NewLC
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUpnpObjectBean* CUpnpObjectBean::NewLC()
       
    54 {
       
    55     CUpnpObjectBean* self = new( ELeave ) CUpnpObjectBean;
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     return self;
       
    59 }
       
    60 // -----------------------------------------------------------------------------
       
    61 // CUpnpObjectBean::NewLC
       
    62 // Two-phased constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CUpnpObjectBean* CUpnpObjectBean::NewLC(const RDbRowSet& aRowSet)
       
    66 {
       
    67     CUpnpObjectBean* self = NewLC();
       
    68     self->SetL(aRowSet);
       
    69     return self;
       
    70 }    
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUpnpObjectBean::NewL
       
    73 // Two-phased constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpObjectBean* CUpnpObjectBean::NewL(const RDbRowSet& aRowSet)
       
    77 {
       
    78     CUpnpObjectBean* self = NewLC(aRowSet);
       
    79     CleanupStack::Pop();
       
    80     return self;
       
    81 }
       
    82 // -----------------------------------------------------------------------------
       
    83 // CUpnpObjectBean::~CUpnpObjectBean
       
    84 // Destructor
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CUpnpObjectBean::~CUpnpObjectBean()
       
    88 {
       
    89     delete iObjTitle;
       
    90     delete iObjClass;
       
    91 }
       
    92 // -----------------------------------------------------------------------------
       
    93 // CUpnpObjectBean::SetL
       
    94 // (other items were commented in a header).
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CUpnpObjectBean::SetL(const RDbRowSet& aRowSet)
       
    98 {
       
    99     // get cols ids
       
   100     CDbColSet* colSet = aRowSet.ColSetL();
       
   101     CleanupStack::PushL(colSet);
       
   102     const TInt idColNo          = colSet->ColNo(KObjIdColName);
       
   103     const TInt parentIDColNo    = colSet->ColNo(KObjParentIdColName);
       
   104     const TInt titleColNo       = colSet->ColNo(KObjTiltleColName);
       
   105     const TInt classColNo       = colSet->ColNo(KObjClassColName);
       
   106     const TInt restrictedColNo  = colSet->ColNo(KObjRestrictedColName);
       
   107     const TInt searchableColNo  = colSet->ColNo(KObjSearchableColName);
       
   108     const TInt refIDColNo       = colSet->ColNo(KObjRefIdColName);  
       
   109     CleanupStack::PopAndDestroy(colSet);
       
   110     
       
   111     // for each column call setter
       
   112     if( idColNo != KDbNullColNo )
       
   113     {
       
   114         SetObjId( aRowSet.ColInt(idColNo) );
       
   115     }
       
   116     if( parentIDColNo != KDbNullColNo )
       
   117     {
       
   118         SetObjParentId( aRowSet.ColInt(parentIDColNo) );
       
   119     }
       
   120     if( titleColNo != KDbNullColNo )
       
   121     {
       
   122         SetObjTitleL( aRowSet.ColDes8(titleColNo) );
       
   123     }
       
   124     if( classColNo != KDbNullColNo )
       
   125     {
       
   126         SetObjClassL( aRowSet.ColDes8(classColNo) );
       
   127     }
       
   128     if( restrictedColNo != KDbNullColNo )
       
   129     {
       
   130         SetObjRestricted( aRowSet.ColUint8(restrictedColNo) );
       
   131     }
       
   132     if( searchableColNo != KDbNullColNo && !aRowSet.IsColNull(searchableColNo) )
       
   133     {
       
   134         SetObjSearchable( aRowSet.ColUint8(searchableColNo) );
       
   135     }
       
   136     else
       
   137     {
       
   138         SetObjSearchable( KUndef);
       
   139     }
       
   140     if( refIDColNo != KDbNullColNo && !aRowSet.IsColNull(refIDColNo) )
       
   141     {
       
   142         SetObjRefId( aRowSet.ColInt(refIDColNo) );
       
   143     }
       
   144     else
       
   145     {
       
   146         SetObjRefId(KUndef);
       
   147     }
       
   148 }
       
   149 // -----------------------------------------------------------------------------
       
   150 // CUpnpObjectBean::SetObjTitleL
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CUpnpObjectBean::SetObjTitleL(const TDesC8& aObjTitle)
       
   155 {
       
   156     delete iObjTitle;
       
   157     iObjTitle = NULL;
       
   158     iObjTitle = aObjTitle.AllocL();
       
   159 }
       
   160 // -----------------------------------------------------------------------------
       
   161 // CUpnpObjectBean::SetObjClassL
       
   162 // (other items were commented in a header).
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CUpnpObjectBean::SetObjClassL(const TDesC8& aObjClass)
       
   166 {
       
   167     delete iObjClass;
       
   168     iObjClass = NULL;
       
   169     iObjClass = aObjClass.AllocL();
       
   170 }
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUpnpObjectBean::AttachObjectElL
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 TXmlEngElement CUpnpObjectBean::AttachObjectElL(TXmlEngElement aElement)
       
   177 {
       
   178     TXmlEngElement object;
       
   179     
       
   180     // check if the object is a container
       
   181     if( ObjClass().Find( KContainerClass8 ) == 0 ) 
       
   182     { // container
       
   183         object = aElement.AddNewElementSameNsL( KContainer() );
       
   184     }
       
   185     else
       
   186     { // item
       
   187         object = aElement.AddNewElementSameNsL( KItem() );
       
   188     }
       
   189     
       
   190     // add required properties
       
   191     AttachRequiredPropertiesL(object);
       
   192     
       
   193     return object;
       
   194 }
       
   195 // -----------------------------------------------------------------------------
       
   196 // CUpnpObjectBean::AttachRequiredPropertiesL
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CUpnpObjectBean::AttachRequiredPropertiesL(TXmlEngElement aElement)
       
   201 {
       
   202     // id
       
   203     AttachIdL(aElement);
       
   204     // parentId
       
   205     AttachParentIdL(aElement);
       
   206     // restricted
       
   207     AttachRestrictedL(aElement);
       
   208     // title
       
   209     AttachTitleL(aElement);
       
   210     // class
       
   211     AttachClassL(aElement);
       
   212 }
       
   213 // -----------------------------------------------------------------------------
       
   214 // CUpnpObjectBean::AttachWholeObjectElL
       
   215 // (other items were commented in a header).
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TXmlEngElement CUpnpObjectBean::AttachWholeObjectElL(TXmlEngElement aElement)
       
   219 {
       
   220     // object with required properties
       
   221     TXmlEngElement object = AttachObjectElL(aElement);
       
   222     
       
   223     // optional properties:
       
   224     // refId
       
   225     AttachRefIdL(object);
       
   226     // searchable
       
   227     AttachSearchableL(object);
       
   228     
       
   229     return object;
       
   230 }
       
   231 // -----------------------------------------------------------------------------
       
   232 // CUpnpObjectBean::AttachRefIdL
       
   233 // (other items were commented in a header).
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CUpnpObjectBean::AttachRefIdL(TXmlEngElement aElement)
       
   237 {
       
   238     if(ObjRefId() != CUpnpObjectBean::KUndef)
       
   239     {
       
   240         TBuf8<KMaxIntegerLen> num;
       
   241         num.Num(ObjRefId()); 
       
   242         aElement.AddNewAttributeL( KRefID(), num ); 
       
   243     }       
       
   244 }
       
   245 // -----------------------------------------------------------------------------
       
   246 // CUpnpObjectBean::AttachSearchableL
       
   247 // (other items were commented in a header).
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CUpnpObjectBean::AttachSearchableL(TXmlEngElement aElement)
       
   251 {
       
   252     if(ObjSearchable() != CUpnpObjectBean::KUndef)
       
   253     {
       
   254         if( ObjSearchable() )
       
   255         { // true
       
   256             aElement.AddNewAttributeL( KSearchable(), KTrueValue8() );
       
   257         }
       
   258         else
       
   259         { // false
       
   260             aElement.AddNewAttributeL( KSearchable(), KFalseValue8() );
       
   261         }
       
   262     }
       
   263 }
       
   264 // -----------------------------------------------------------------------------
       
   265 // CUpnpObjectBean::AttachIdL
       
   266 // (other items were commented in a header).
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CUpnpObjectBean::AttachIdL(TXmlEngElement aElement)
       
   270 {
       
   271     TBuf8<KMaxIntegerLen> num;
       
   272     num.Num(ObjId()); 
       
   273     aElement.AddNewAttributeL( KIdAttrName(), num );
       
   274 }
       
   275 // -----------------------------------------------------------------------------
       
   276 // CUpnpObjectBean::AttachParentIdL
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CUpnpObjectBean::AttachParentIdL(TXmlEngElement aElement)
       
   281 {
       
   282     TBuf8<KMaxIntegerLen> num;
       
   283     num.Num(ObjParentId()); 
       
   284     aElement.AddNewAttributeL( KParentID(), num );
       
   285 }
       
   286 // -----------------------------------------------------------------------------
       
   287 // CUpnpObjectBean::AttachRestrictedL
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CUpnpObjectBean::AttachRestrictedL(TXmlEngElement aElement)
       
   292 {
       
   293     if( ObjRestricted() )
       
   294     { // true
       
   295         aElement.AddNewAttributeL( KRestricted(), KTrueValue8() );
       
   296     }
       
   297     else
       
   298     { // false
       
   299         aElement.AddNewAttributeL( KRestricted(), KFalseValue8() );
       
   300     }
       
   301 }
       
   302 // -----------------------------------------------------------------------------
       
   303 // CUpnpObjectBean::AttachTitleL
       
   304 // (other items were commented in a header).
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CUpnpObjectBean::AttachTitleL(TXmlEngElement aElement)
       
   308 {
       
   309     aElement.AddNewElementUsePrefixL( KTitle(), KDcNsPrefix() ).SetValueL( ObjTitle() );
       
   310 }
       
   311 // -----------------------------------------------------------------------------
       
   312 // CUpnpObjectBean::AttachClassL
       
   313 // (other items were commented in a header).
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CUpnpObjectBean::AttachClassL(TXmlEngElement aElement)
       
   317 {
       
   318     aElement.AddNewElementUsePrefixL( KClassTagName(), KUpnpNsPrefix() ).SetValueL( ObjClass() );
       
   319 }
       
   320 // -----------------------------------------------------------------------------
       
   321 // CUpnpObjectBean::CopyToUpnpObjectL
       
   322 // (other items were commented in a header).
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CUpnpObjectBean::CopyToUpnpObjectL(CUpnpObject* aObj)
       
   326 {	
       
   327 	HBufC8* id = HBufC8::NewLC(KMaxIntegerLen);
       
   328     id->Des().Num(iObjId);    
       
   329 	aObj->SetIdL(*id);
       
   330 	CleanupStack::PopAndDestroy(id); 
       
   331 	
       
   332 	HBufC8* parentId = HBufC8::NewLC(KMaxIntegerLen);
       
   333     parentId->Des().Num(iObjParentId);    		
       
   334 	aObj->SetParentIdL(*parentId);
       
   335 	CleanupStack::PopAndDestroy(parentId); 
       
   336 	
       
   337 	aObj->SetTitleL(*iObjTitle);
       
   338 	aObj->SetRestricted(iObjRestricted);
       
   339 	aObj->SetObjectClassL(*iObjClass);
       
   340 	if( iObjRefId != KUndef && aObj->ObjectType() == EUPnPItem)
       
   341 	{
       
   342 	    CUpnpItem* item = dynamic_cast<CUpnpItem*>(aObj);
       
   343 	    HBufC8* iObjRefIdString = HBufC8::NewLC(KMaxIntegerLen);
       
   344     	iObjRefIdString->Des().Num(iObjRefId);
       
   345 	    item->SetRefIdL(*iObjRefIdString);
       
   346 	    CleanupStack::PopAndDestroy(iObjRefIdString); 
       
   347 	}
       
   348 }
       
   349 
       
   350 
       
   351 //  End of File