upnp/upnpstack/serviceframework/src/upnpstatevariable.cpp
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:  CUpnpStateVariable
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "upnpstatevariable.h"
       
    22 #include "upnpstring.h"
       
    23 #include "upnpargument.h"
       
    24 #include "upnpserviceimplementation.h"
       
    25 #define KLogFile _L("UPnPStack.txt")
       
    26 #include "upnpcustomlog.h"
       
    27 
       
    28 
       
    29 // logs
       
    30 #include "f32file.h" 
       
    31 #include "s32file.h"
       
    32 
       
    33 // CONSTANTS
       
    34 _LIT8(KUi1, "ui1");
       
    35 _LIT8(KUi2, "ui2");
       
    36 _LIT8(KUi4, "ui4");
       
    37 _LIT8(KI1, "i1");
       
    38 _LIT8(KI2, "i2");
       
    39 _LIT8(KI4, "i4");
       
    40 _LIT8(KInt, "int");
       
    41 _LIT8(KR4, "r4");
       
    42 _LIT8(KR8, "r8");
       
    43 _LIT8(KNumber, "number");
       
    44 _LIT8(KFixed144, "fixed.14.4");
       
    45 _LIT8(KFloat, "float");
       
    46 _LIT8(KChar, "char");
       
    47 _LIT8(KString, "string");
       
    48 _LIT8(KDate, "date");
       
    49 _LIT8(KDateTime, "dateTime");
       
    50 _LIT8(KDateTimeTz, "dateTime.tz");
       
    51 _LIT8(KTime, "time");
       
    52 _LIT8(KTimeTz, "time.tz");
       
    53 _LIT8(KBoolean, "boolean");
       
    54 _LIT8(KBinBase64, "bin.base64");
       
    55 _LIT8(KBinHex, "bin.hex");
       
    56 _LIT8(KUri, "uri");
       
    57 _LIT8(KUuid, "uuid");
       
    58 //_LIT8(KDataType, "dataType");
       
    59 
       
    60 
       
    61 // ============================ MEMBER FUNCTIONS ===============================
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CUpnpStateVariable::CUpnpStateVariable
       
    65 // C++ default constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CUpnpStateVariable::CUpnpStateVariable()
       
    70 {
       
    71 
       
    72 }
       
    73 
       
    74 
       
    75 
       
    76 void CUpnpStateVariable::ConstructL()
       
    77     {
       
    78     iName = HBufC8::NewL(0);
       
    79     iDataType = HBufC8::NewL(0);
       
    80   //  iDefaultValue = HBufC8::NewL(0);
       
    81     iRangeMin = HBufC8::NewL(0);
       
    82     iRangeMax = HBufC8::NewL(0);
       
    83     iRangeStep = HBufC8::NewL(0);
       
    84     iValue = HBufC8::NewL(0);
       
    85     iEventable = HBufC8::NewL(0);
       
    86     
       
    87     iParent = NULL;
       
    88     iMaxEventRate = 0;
       
    89     iCurrentEventTime = 0; 
       
    90     iReadyForEventing = ETrue;
       
    91 
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CUpnpStateVariable::NewL
       
    96 // Two-phased constructor.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CUpnpStateVariable* CUpnpStateVariable::NewL()
       
   100 {
       
   101     CUpnpStateVariable* self = new (ELeave) CUpnpStateVariable();
       
   102     self->ConstructL();
       
   103     return self;
       
   104 }
       
   105 
       
   106 
       
   107 // Destructor
       
   108 CUpnpStateVariable::~CUpnpStateVariable()
       
   109 {
       
   110     delete iName;
       
   111     delete iDataType;
       
   112     delete iDefaultValue;
       
   113     delete iRangeMin;
       
   114     delete iRangeMax;
       
   115     delete iRangeStep;
       
   116     delete iEventable;
       
   117 
       
   118     iAllowedValueList.ResetAndDestroy();
       
   119     iAllowedValueList.Close();
       
   120     delete iValue;
       
   121     
       
   122 }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CUpnpStateVariable::Name
       
   126 //
       
   127 // (other items were commented in a header).
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C const TPtrC8 CUpnpStateVariable::Name()
       
   131 {
       
   132     if ( iName )
       
   133     {
       
   134         return *iName;
       
   135     }
       
   136     else
       
   137     {
       
   138         return KNullDesC8();
       
   139     }
       
   140 }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 EXPORT_C void CUpnpStateVariable::SetNameL( const TDesC8& aName)
       
   144     {
       
   145     HBufC8* tmp = aName.AllocL();
       
   146     delete iName;
       
   147     iName = tmp;
       
   148     }
       
   149 // CUpnpStateVariable::Value
       
   150 //
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C const TPtrC8 CUpnpStateVariable::Value()
       
   155 {
       
   156     LOGS("CUpnpStateVariable::Value()");
       
   157     
       
   158     if ( iValue )
       
   159     {
       
   160         return *iValue;
       
   161     }
       
   162     else
       
   163     {
       
   164         return KNullDesC8();
       
   165     }
       
   166 }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CUpnpStateVariable::SetValueL
       
   170 //
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 EXPORT_C void CUpnpStateVariable::SetValueL(const TDesC8& aValue, TBool aIsModerated)
       
   175 {
       
   176     LOGS("CUpnpStateVariable::SetValueL(const TDesC8&)");
       
   177     
       
   178     if( iValue )
       
   179     {
       
   180         delete iValue; 
       
   181         iValue = NULL;
       
   182     }
       
   183                 
       
   184     iValue = aValue.AllocL();
       
   185     iModerated = aIsModerated;
       
   186     if (iParent)
       
   187     {
       
   188         iParent->AddEventVariable(*this, aIsModerated);
       
   189     }
       
   190 }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CUpnpStateVariable::SetValueL
       
   194 //
       
   195 // (other items were commented in a header).
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CUpnpStateVariable::SetValueL(TInt aValue, TBool aIsModerated)
       
   199 {
       
   200  //   LOGS("CUpnpStateVariable::SetValueL(TInt)");
       
   201     TBuf8<10> num;
       
   202     num.Num(aValue);
       
   203    
       
   204     SetValueL( num, aIsModerated );
       
   205 }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CUpnpStateVariable::Eventable
       
   209 //
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 EXPORT_C const TPtrC8 CUpnpStateVariable::Eventable()
       
   214 {
       
   215     if ( iEventable )
       
   216     {
       
   217         return *iEventable;
       
   218     }
       
   219     else
       
   220     {
       
   221         return KNullDesC8();
       
   222     }
       
   223 }
       
   224 
       
   225 EXPORT_C  void CUpnpStateVariable::SetEventableL(const TDesC8& aEventable)
       
   226     {
       
   227     HBufC8* tmp = aEventable.AllocL();
       
   228     delete iEventable;
       
   229     iEventable = tmp;
       
   230     }
       
   231 // -----------------------------------------------------------------------------
       
   232 // CUpnpStateVariable::GetDefaultValue
       
   233 //
       
   234 // (other items were commented in a header).
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CUpnpStateVariable::GetDefaultValue(TInt& aValue)
       
   238 {
       
   239     if ( iDefaultValue )
       
   240     {
       
   241         TLex8 lex( *iDefaultValue );
       
   242         TInt err = lex.Val( aValue );
       
   243         
       
   244         // Check conversion result
       
   245         if( err != KErrNone )
       
   246                 aValue = err;
       
   247     }
       
   248     else
       
   249     {
       
   250         aValue = KErrNotFound;
       
   251     }
       
   252 }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CUpnpStateVariable::DefaultValue
       
   256 //
       
   257 // (other items were commented in a header).
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 EXPORT_C const TPtrC8 CUpnpStateVariable::DefaultValue()
       
   261 {
       
   262     if ( iDefaultValue )
       
   263     {
       
   264         return *iDefaultValue;
       
   265     }
       
   266     else
       
   267     {
       
   268         return KNullDesC8();
       
   269     }
       
   270 }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CUpnpStateVariable::AllowedValuesLC
       
   274 //
       
   275 // (other items were commented in a header).
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C CDesC8Array* CUpnpStateVariable::AllowedValuesLC()
       
   279 {
       
   280     CDesC8ArrayFlat* values = new (ELeave) CDesC8ArrayFlat(1);
       
   281     CleanupStack::PushL(values);
       
   282     
       
   283     for ( TInt index = 0; index < iAllowedValueList.Count(); index++ )
       
   284     {
       
   285         HBufC8* tmp = iAllowedValueList[index];
       
   286         values->AppendL( *tmp );
       
   287     }
       
   288       
       
   289     return values;
       
   290 }
       
   291 EXPORT_C void CUpnpStateVariable::AddAllowedValueL( const TDesC8& aAllowedValue )
       
   292     {
       
   293     iAllowedValueList.Append( aAllowedValue.AllocL() );
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CUpnpStateVariable::MaxValue
       
   298 //
       
   299 // (other items were commented in a header).
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 EXPORT_C TInt CUpnpStateVariable::MaxValue()
       
   303 {
       
   304     TInt retValue = KErrNotFound;
       
   305     if ( iRangeMax )
       
   306     {
       
   307         TLex8 lex( *iRangeMax );
       
   308         lex.Val( retValue );
       
   309     }
       
   310     return retValue;    
       
   311 }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CUpnpStateVariable::MinValue
       
   315 //
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C TInt CUpnpStateVariable::MinValue()
       
   320 {
       
   321     TInt retValue = KErrNotFound;
       
   322     if ( iRangeMin )
       
   323     {
       
   324         TLex8 lex( *iRangeMin );
       
   325         lex.Val( retValue );
       
   326     }
       
   327     return retValue; 
       
   328 }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CUpnpStateVariable::Step
       
   332 //
       
   333 // (other items were commented in a header).
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 EXPORT_C TInt CUpnpStateVariable::Step()
       
   337 {
       
   338     TInt retValue = KErrNotFound;
       
   339     if ( iRangeStep )
       
   340     {
       
   341         TLex8 lex( *iRangeStep );
       
   342         lex.Val( retValue );
       
   343     }
       
   344     return retValue; 
       
   345 }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CUpnpStateVariable::Type
       
   349 //
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TArgumentType CUpnpStateVariable::Type()
       
   354 {
       
   355     if ( iDataType )
       
   356     {
       
   357         const TPtrC8 value = *iDataType;
       
   358         if (value == KUi1())
       
   359         {
       
   360             return EUi1;
       
   361         }
       
   362         else if (value ==KUi2())
       
   363         {
       
   364             return EUi2;
       
   365         }
       
   366         else if (value ==KUi4())
       
   367         {
       
   368             return EUi4;
       
   369         }  
       
   370         else if (value ==KI1())
       
   371         {
       
   372             return EI1;
       
   373         }
       
   374         else if (value ==KI2())
       
   375         {
       
   376             return EI2;
       
   377         }
       
   378         else if (value ==KI4())
       
   379         {
       
   380             return EI4;
       
   381         }
       
   382         else if (value ==KInt())
       
   383         {
       
   384             return EInt;        
       
   385         }
       
   386         else if (value ==KR4())
       
   387         {
       
   388             return ER4;
       
   389         }
       
   390         else if (value ==KR8())
       
   391         {
       
   392             return ER8;
       
   393         }
       
   394         else if (value ==KNumber())
       
   395         {
       
   396             return ENumber;
       
   397         }
       
   398         else if (value ==KFixed144())
       
   399         {
       
   400             return EFixed144;
       
   401         }
       
   402         else if (value ==KFloat())
       
   403         {
       
   404             return EFloat;
       
   405         }
       
   406         else if (value ==KChar())
       
   407         {
       
   408             return EChar;
       
   409         }
       
   410         else if (value ==KString())
       
   411         {
       
   412             return EString;
       
   413         }   
       
   414         else if (value ==KDate())
       
   415         {
       
   416             return EDate;
       
   417         }
       
   418         else if (value ==KDateTime())
       
   419         {
       
   420             return EDateTime;
       
   421         }
       
   422         else if (value ==KDateTimeTz())
       
   423         {
       
   424             return EDateTimeTz;
       
   425         }
       
   426         else if (value ==KTime())
       
   427         {
       
   428             return ETime;
       
   429         }
       
   430         else if (value ==KTimeTz())
       
   431         {
       
   432             return ETimeTz;
       
   433         }
       
   434         else if (value ==KBoolean())
       
   435         {
       
   436             return EBoolean;
       
   437         }
       
   438         else if (value ==KBinBase64())
       
   439         {
       
   440             return EBinBase64;
       
   441         }
       
   442         else if (value ==KBinHex())
       
   443         {
       
   444             return EBinHex;
       
   445         }
       
   446         else if (value ==KUri())
       
   447         {
       
   448             return EUri;
       
   449         }
       
   450         else if (value ==KUuid())
       
   451         {
       
   452             return EUuid;
       
   453         }
       
   454         else
       
   455         {
       
   456         
       
   457         }
       
   458     }
       
   459 
       
   460     return EUnknown;
       
   461 }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CUpnpStateVariable::SetParentImplementation
       
   465 //
       
   466 // (other items were commented in a header).
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CUpnpStateVariable::SetParentImplementation(CUpnpServiceImplementation &aParent)
       
   470 {
       
   471     iParent = &aParent;
       
   472 }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CUpnpStateVariable::SetParentImplementation
       
   476 //
       
   477 // (other items were commented in a header).
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 TBool CUpnpStateVariable::IsModerated()
       
   481 {
       
   482     return iModerated;
       
   483 }
       
   484 
       
   485 EXPORT_C void CUpnpStateVariable::SetTypeL(const TDesC8& aType)
       
   486     {
       
   487     HBufC8* tmp = aType.AllocL();
       
   488     delete iDataType;
       
   489     iDataType = tmp;
       
   490     }
       
   491 
       
   492 TBool CUpnpStateVariable::ReadyForEventing()
       
   493 {
       
   494     return iReadyForEventing;
       
   495 }       
       
   496 
       
   497 void CUpnpStateVariable::SetMaxEventRate(TInt aMaxRate, TInt aNormalRate)
       
   498 {
       
   499     iMaxEventRate = aMaxRate;
       
   500     iReadyForEventing = ETrue;
       
   501     iCurrentEventTime = aMaxRate;
       
   502     iNormalEventRate = aNormalRate;
       
   503 }
       
   504 
       
   505 TInt CUpnpStateVariable::MaxEventRate()
       
   506 {
       
   507     return iMaxEventRate;
       
   508 }
       
   509 
       
   510 void CUpnpStateVariable::EventTick()
       
   511 {
       
   512     if(iMaxEventRate > 0)
       
   513     {
       
   514         iCurrentEventTime = iCurrentEventTime + iNormalEventRate;
       
   515 
       
   516         if(iCurrentEventTime >= iMaxEventRate)
       
   517         {
       
   518                 iReadyForEventing = ETrue;
       
   519                 iCurrentEventTime = 0;
       
   520 
       
   521                 iEventTime.UniversalTime();
       
   522         }
       
   523         else
       
   524         {
       
   525                 iTime.UniversalTime();
       
   526         
       
   527                 TInt64 int64(iMaxEventRate);
       
   528                 TInt64 diffTime((iTime.MicroSecondsFrom(iEventTime)).Int64());
       
   529 
       
   530                 if(diffTime >= int64)
       
   531                 {
       
   532                         iReadyForEventing = ETrue;
       
   533                         iCurrentEventTime = 0;
       
   534 
       
   535                         iEventTime.UniversalTime();                             
       
   536                 }
       
   537                 else
       
   538                 {
       
   539                         iCurrentEventTime = diffTime;
       
   540                                 
       
   541                         iReadyForEventing = EFalse;                             
       
   542                 }
       
   543         }
       
   544     }
       
   545 }   
       
   546    
       
   547 void CUpnpStateVariable::SetDefaultValueL(const TDesC8& aDefaultValue )
       
   548     {
       
   549     HBufC8* tmp = aDefaultValue .AllocL();
       
   550     delete iDefaultValue; 
       
   551     iDefaultValue = tmp;
       
   552     }
       
   553     
       
   554 void CUpnpStateVariable::SetRangeMinL(const TDesC8& aRangeMin )
       
   555     {
       
   556     if( &aRangeMin )
       
   557        {
       
   558         HBufC8* tmp = aRangeMin.AllocL();
       
   559         delete iRangeMin; 
       
   560         iRangeMin = tmp;
       
   561        }
       
   562     }
       
   563     
       
   564 void CUpnpStateVariable::SetRangeMaxL(const TDesC8& aRangeMax )
       
   565     {
       
   566     if( &aRangeMax )
       
   567        {
       
   568        HBufC8* tmp = aRangeMax.AllocL();
       
   569        delete iRangeMax; 
       
   570        iRangeMax = tmp;
       
   571        }
       
   572     }
       
   573     
       
   574 void CUpnpStateVariable::SetRangeStepL(const TDesC8& aRangeStep )
       
   575     {
       
   576     HBufC8* tmp = aRangeStep.AllocL();
       
   577     delete iRangeStep; 
       
   578     iRangeStep = tmp;
       
   579     }
       
   580     
       
   581 //  End of File