omacpadapters/StreamingAdapter/Src/Streamingadapter.cpp
changeset 42 aa33c2cb9a50
child 67 fdbfe0a95492
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Handles streaming app settings in OMA provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <f32file.h>
       
    21 #include    <CWPCharacteristic.h>
       
    22 #include    <CWPParameter.h>
       
    23 #include    <wpstreamingadapterresource.rsg>
       
    24 #include    <mpsettingsmodel.h>
       
    25 #include    <cmconnectionmethoddef.h>
       
    26 #include    <cmmanagerext.h>
       
    27 #include    "WPAdapterUtil.h"
       
    28 #include    "StreamingAdapter.h"
       
    29 #include    "ProvisioningDebug.h"
       
    30 
       
    31 // CONSTANTS
       
    32 #if ( defined (__WINS__) || defined (__WINSCW) ) // this different on hw
       
    33     _LIT( KAdapterName, "WPStreamingAdapterResource" );
       
    34 #else
       
    35     _LIT( KAdapterName, "WPStreamingAdapter" );
       
    36 #endif
       
    37 _LIT(KMaxBandwidthStr,"MAX-BANDWIDTH");
       
    38 _LIT(KMaxUdpPortStr,"MAX-UDP-PORT");
       
    39 _LIT(KMinUdpPortStr,"MIN-UDP-PORT");
       
    40 _LIT(KStreamingAppId, "554");
       
    41 
       
    42 const TInt KInvalidValue = -1;
       
    43 const TInt KProxyEnabled = 1;
       
    44 
       
    45 const TInt KMinUDPPort = 1024; //6970;
       
    46 const TInt KMaxUDPPort = 65535; //32000;
       
    47 const TInt KDefaultMinUDPPort = 6970;
       
    48 const TInt KDefaultMaxUDPPort = 32000;
       
    49 
       
    50 const TInt KBandwidthValue1 = 9050;
       
    51 const TInt KBandwidthValue2 = 13400;
       
    52 const TInt KBandwidthValue3 = 18100;
       
    53 const TInt KBandwidthValue4 = 26800;
       
    54 const TInt KBandwidthValue5 = 27150;
       
    55 const TInt KBandwidthValue6 = 40200;
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 struct TStreamingAdapterData
       
    59     {
       
    60     TPtrC iName;
       
    61     TInt iMaxBw;
       
    62     TInt iMinUdpPort;
       
    63     TInt iMaxUdpPort;
       
    64     CWPCharacteristic* iNapDef;
       
    65     };
       
    66 
       
    67 // ============================ MEMBER FUNCTIONS ===============================
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CStreamingAdapter::CStreamingAdapter
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CStreamingAdapter::CStreamingAdapter()
       
    76     {
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CStreamingAdapter::ConstructL
       
    81 // Symbian 2nd phase constructor can leave.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CStreamingAdapter::ConstructL()
       
    85     {
       
    86     FLOG( _L( "[Provisioning] CStreamingAdapter::ConstructL:" ) );
       
    87     
       
    88     TFileName fileName;
       
    89     Dll::FileName( fileName );
       
    90     iTitle = WPAdapterUtil::ReadHBufCL( fileName,
       
    91                                         KAdapterName,
       
    92                                         R_STREAMING_ADAPTER_TITLE );
       
    93                                         
       
    94     FLOG( _L( "[Provisioning] CStreamingAdapter::ConstructL: Done" ) );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CStreamingAdapter::NewL
       
    99 // Two-phased constructor.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CStreamingAdapter* CStreamingAdapter::NewL()
       
   103     {
       
   104     CStreamingAdapter* self = new(ELeave) CStreamingAdapter; 
       
   105     CleanupStack::PushL(self);
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop(self);
       
   108 
       
   109     return self;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CStreamingAdapter::~CStreamingAdapter
       
   114 // Destructor
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CStreamingAdapter::~CStreamingAdapter()
       
   118     {
       
   119     delete iTitle;
       
   120     delete iCurrentData;
       
   121     delete iTempData;
       
   122 	delete iModel;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CStreamingAdapter::ItemCount
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TInt CStreamingAdapter::ItemCount() const
       
   130     {
       
   131     // If ItemCount() returns zero, the adapter is unloaded at startup. 
       
   132 	// SummaryTitle(), SummaryText(), SaveL(), SetAsDefaultL() and 
       
   133 	// CanSetAsDefault() are called ItemCount() times
       
   134     return iCurrentData ? 1 : 0;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CStreamingAdapter::SummaryTitle
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 const TDesC16& CStreamingAdapter::SummaryTitle(TInt /*aIndex*/) const
       
   142     {
       
   143     return *iTitle;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CStreamingAdapter::SummaryText
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 const TDesC16& CStreamingAdapter::SummaryText(TInt /*aIndex*/) const
       
   151     {
       
   152     return iCurrentData->iName;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CStreamingAdapter::DetailsL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CStreamingAdapter::DetailsL(TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/)
       
   160     {
       
   161     // Detail view is a feature for later release.
       
   162     return KErrNotSupported;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CStreamingAdapter::SaveL
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CStreamingAdapter::SaveL( TInt /*aItem*/ )
       
   170     {
       
   171     FLOG( _L( "[Provisioning] CStreamingAdapter::SaveL:" ) );
       
   172     
       
   173     __ASSERT_DEBUG( iCurrentData->iNapDef, User::Leave( KErrCorrupt ) );
       
   174 
       
   175     InitSettingsModelL();
       
   176         
       
   177     // Load default values
       
   178     iModel->LoadSettingsL(EConfigDefault);
       
   179 
       
   180     // Set max bandwidth value if valid
       
   181     if (iCurrentData->iMaxBw != KInvalidValue)
       
   182         {
       
   183         iModel->SetMaxBandwidth(iCurrentData->iMaxBw, EBearerGPRS);
       
   184         }
       
   185 
       
   186     // Set udp port range if valid
       
   187     if (iCurrentData->iMinUdpPort != KInvalidValue && 
       
   188         iCurrentData->iMaxUdpPort != KInvalidValue)
       
   189         {
       
   190         iModel->SetMinUDPPort(iCurrentData->iMinUdpPort);
       
   191         iModel->SetMaxUDPPort(iCurrentData->iMaxUdpPort);
       
   192         }
       
   193 
       
   194     // Get the IAP id
       
   195     
       
   196     RCmManagerExt  cmmanagerExt;
       
   197     cmmanagerExt.OpenL();
       
   198     CleanupClosePushL(cmmanagerExt);
       
   199 
       
   200     TPckgBuf<TUint32> uid;
       
   201     TBool proxyDefined(EFalse);
       
   202     TBool apDefined(EFalse);
       
   203     TBool apWithoutProxyDefined(EFalse);
       
   204 
       
   205     for (TInt i(0); iCurrentData->iNapDef->Data(i).Length() == uid.MaxLength()
       
   206         && !(proxyDefined && apWithoutProxyDefined); i++)
       
   207         {
       
   208         uid.Copy(iCurrentData->iNapDef->Data(i));
       
   209         RCmConnectionMethodExt cm;
       
   210         cm = cmmanagerExt.ConnectionMethodL( uid() );
       
   211         CleanupClosePushL( cm );
       
   212 
       
   213         TBool useProxy = cm.GetBoolAttributeL( CMManager::ECmProxyUsageEnabled );
       
   214         
       
   215         if (!apDefined || (!useProxy && !apWithoutProxyDefined))
       
   216             {
       
   217             iModel->SetDefaultAp(uid());
       
   218             apDefined = ETrue;
       
   219 
       
   220             iSavedID.Copy(uid);
       
   221 
       
   222             if (!useProxy)
       
   223                 {
       
   224                 apWithoutProxyDefined = ETrue;
       
   225                 }
       
   226             }
       
   227         
       
   228         if (!proxyDefined && useProxy)
       
   229             {
       
   230            // Get proxy port
       
   231             TUint32 proxyPort = cm.GetIntAttributeL( CMManager::ECmProxyPortNumber );
       
   232             
       
   233 
       
   234             // Get proxy host name
       
   235             const HBufC* proxyHost = cm.GetStringAttributeL( CMManager::ECmProxyServerName );
       
   236 
       
   237             if(*proxyHost != KNullDesC && proxyPort <= 65535)
       
   238                 {
       
   239                 iModel->SetProxyHostNameL(*proxyHost);
       
   240                 iModel->SetProxyPort(static_cast<TInt>(proxyPort));
       
   241                 iModel->SetProxyMode(KProxyEnabled);
       
   242                 
       
   243                 proxyDefined = ETrue;
       
   244                 }
       
   245             delete proxyHost;
       
   246             }
       
   247         CleanupStack::PopAndDestroy();//cm
       
   248         }
       
   249 
       
   250     CleanupStack::PopAndDestroy(); // cmmanagerext
       
   251 
       
   252     iModel->StoreSettingsL();
       
   253     
       
   254     FLOG( _L( "[Provisioning] CStreamingAdapter::SaveL: Done" ) );
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CStreamingAdapter::CanSetAsDefault
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TBool CStreamingAdapter::CanSetAsDefault(TInt /*aItem*/) const
       
   262     {
       
   263     return EFalse;
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CStreamingAdapter::SetAsDefault
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CStreamingAdapter::SetAsDefaultL(TInt /*aItem*/)
       
   271     {
       
   272     // This shouldn't be called because CanSetAsDefault
       
   273     // always returns EFalse.
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CStreamingAdapter::VisitL
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CStreamingAdapter::VisitL(CWPCharacteristic& aCharacteristic)
       
   281     {
       
   282     switch(aCharacteristic.Type())
       
   283         {
       
   284         case KWPApplication:
       
   285             // Create new iTempData
       
   286             if (iTempData)
       
   287                 {
       
   288                 delete iTempData;
       
   289                 iTempData = NULL;
       
   290                 }
       
   291 
       
   292             iTempData = new (ELeave) TStreamingAdapterData;
       
   293 
       
   294             // Initialize iTempData's members
       
   295             iTempData->iName.Set(KNullDesC);
       
   296             iTempData->iMaxBw = KInvalidValue;
       
   297             iTempData->iMinUdpPort = KInvalidValue;
       
   298             iTempData->iMaxUdpPort = KInvalidValue;
       
   299             iTempData->iNapDef = NULL;
       
   300 
       
   301             // Accept characteristic
       
   302             aCharacteristic.AcceptL(*this);
       
   303 
       
   304             // Check iAppId and validate data
       
   305             if (iAppId == KStreamingAppId && IsValid())
       
   306                 {
       
   307                 // iAppId is correct and data is valid
       
   308                 delete iCurrentData;
       
   309                 iCurrentData = iTempData;
       
   310                 iTempData = NULL;
       
   311                 }
       
   312             else
       
   313                 {
       
   314                 // iAppId is incorrect or data is invalid
       
   315                 delete iTempData;
       
   316                 iTempData = NULL;
       
   317                 }
       
   318             break;
       
   319         default:
       
   320             break;
       
   321         }
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // CStreamingAdapter::VisitL
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CStreamingAdapter::VisitL(CWPParameter& aParameter)
       
   329     { 
       
   330     // Check the contents of whole characteristic before overwriting iMaxBw, 
       
   331     // iMinUdpPort and iMaxUdpPort. Might be looking at the wrong application
       
   332 	// characteristic
       
   333     
       
   334     __ASSERT_DEBUG(iTempData, User::Leave(KErrCorrupt));
       
   335     
       
   336     TInt value;
       
   337     switch(aParameter.ID())
       
   338         {
       
   339         case EWPParameterAppID:
       
   340             iAppId.Set(aParameter.Value());
       
   341             break;
       
   342         case EWPParameterName:
       
   343             if (iTempData->iName == KNullDesC)
       
   344                 {
       
   345                 iTempData->iName.Set(aParameter.Value());
       
   346                 }
       
   347             break;
       
   348 		case EWPNamedParameter:
       
   349 			{
       
   350 			if( aParameter.Name().Compare( KMaxBandwidthStr ) == 0
       
   351 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   352 				{							
       
   353 				iTempData->iMaxBw = value;
       
   354 				}
       
   355 			else if( aParameter.Name().Compare( KMaxUdpPortStr ) == 0
       
   356 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   357 				{							
       
   358 				iTempData->iMaxUdpPort = value;
       
   359 				}
       
   360 			else if( aParameter.Name().Compare( KMinUdpPortStr ) == 0
       
   361 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   362 				{							
       
   363                 iTempData->iMinUdpPort = value;
       
   364 				}
       
   365 			break;
       
   366 			}
       
   367         default:
       
   368             break;
       
   369         }
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CStreamingAdapter::VisitLinkL
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CStreamingAdapter::VisitLinkL(CWPCharacteristic& aCharacteristic)
       
   377     { 
       
   378     // Here again, do not overwrite iPXLogical before you're sure
       
   379     // you're looking at the correct APPLICATION
       
   380 
       
   381     __ASSERT_DEBUG(iTempData, User::Leave(KErrCorrupt));
       
   382 
       
   383     switch(aCharacteristic.Type())
       
   384         {
       
   385         //intentional fall-through
       
   386         case KWPNapDef:        
       
   387         case KWPPxLogical:    
       
   388             iTempData->iNapDef = &aCharacteristic;          
       
   389             break;
       
   390         default:
       
   391             break;
       
   392         }
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CStreamingAdapter::ContextExtension
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 TInt CStreamingAdapter::ContextExtension(MWPContextExtension*& aExtension)
       
   400     {
       
   401     aExtension = this;
       
   402     return KErrNone;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CStreamingAdapter::SaveDataL
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 const TDesC8& CStreamingAdapter::SaveDataL(TInt /*aIndex*/) const
       
   410     {
       
   411     return iSavedID;
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CStreamingAdapter::DeleteL
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CStreamingAdapter::DeleteL(const TDesC8& aSaveData)
       
   419     {
       
   420     TUint32 id;
       
   421     
       
   422     InitSettingsModelL();
       
   423     
       
   424     iModel->GetDefaultAp(id);
       
   425 
       
   426     TPckgBuf<TUint32> pckg;
       
   427     pckg.Copy(aSaveData);
       
   428 
       
   429     if (id == pckg())
       
   430         {
       
   431         iModel->LoadSettingsL(EConfigDefault);
       
   432         iModel->StoreSettingsL();
       
   433         }
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CStreamingAdapter::Uid
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TUint32 CStreamingAdapter::Uid() const
       
   441     {
       
   442     return iDtor_ID_Key.iUid;
       
   443     }
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // CStreamingAdapter::IsValid
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 TBool CStreamingAdapter::IsValid()
       
   450     {
       
   451     TBool validity(EFalse);
       
   452     
       
   453     if (iTempData->iNapDef)
       
   454         {
       
   455         // Validity checks for min and max UDP port values
       
   456         if (iTempData->iMinUdpPort < KMinUDPPort)
       
   457             {
       
   458             iTempData->iMinUdpPort = KDefaultMinUDPPort; 
       
   459             }
       
   460 
       
   461         if (iTempData->iMaxUdpPort > KMaxUDPPort)
       
   462             {
       
   463             iTempData->iMaxUdpPort = KDefaultMaxUDPPort; 
       
   464             }
       
   465 
       
   466         if (iTempData->iMinUdpPort > iTempData->iMaxUdpPort)
       
   467             {
       
   468             iTempData->iMinUdpPort = KInvalidValue;
       
   469             iTempData->iMaxUdpPort = KInvalidValue;
       
   470             }
       
   471         
       
   472         // Validity check for max bandwidth value
       
   473         switch (iTempData->iMaxBw)
       
   474             {
       
   475             case KBandwidthValue1:
       
   476             case KBandwidthValue2:
       
   477             case KBandwidthValue3:
       
   478             case KBandwidthValue4:
       
   479             case KBandwidthValue5:
       
   480             case KBandwidthValue6:
       
   481                 // iMaxBw is valid
       
   482                 break;
       
   483             default:
       
   484                 // iMaxBw is invalid
       
   485                 iTempData->iMaxBw = KInvalidValue;
       
   486                 break;
       
   487             }
       
   488 
       
   489         validity = ETrue;
       
   490         }
       
   491             
       
   492     return validity;
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CStreamingAdapter::ParseIntegerL
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 TInt CStreamingAdapter::ParseIntegerL(const TDesC& aPtr, TInt& aInt) 
       
   500     {
       
   501     TLex lex(aPtr);
       
   502     return lex.Val(aInt);
       
   503     }
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // CStreamingAdapter::Cleanup
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CStreamingAdapter::Cleanup( TAny* aAny )
       
   510 	{
       
   511 	RImplInfoPtrArray* implArray = 
       
   512 		reinterpret_cast< RImplInfoPtrArray*> ( aAny );
       
   513 	implArray->ResetAndDestroy();
       
   514 	implArray->Close();
       
   515 	}
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CStreamingAdapter::InitSettingsModelL
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 void CStreamingAdapter::InitSettingsModelL()
       
   522 	{
       
   523 	FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL:" ) );
       
   524 	
       
   525     if ( !iModel )
       
   526         {
       
   527         RImplInfoPtrArray impl; 
       
   528     	CleanupStack::PushL( TCleanupItem( Cleanup, &impl ) );
       
   529     	CMPSettingsModel::ListImplementationsL( impl );
       
   530     	if( impl.Count() > 0 )
       
   531             {
       
   532             FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL: Creating CMPSettingsModel" ) );
       
   533     	    // using the first available implementation
       
   534             iModel= CMPSettingsModel::NewL( impl[0]->ImplementationUid() );
       
   535             FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL: Creating CMPSettingsModel Done" ) );
       
   536         	}
       
   537     	CleanupStack::PopAndDestroy(); // implArray
       
   538         }
       
   539 	}
       
   540 	
       
   541 //  End of File