videofeeds/server/IptvNetworkSelection/src/CIptvNetworkSelectionMsgHandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <s32mem.h>
       
    24 
       
    25 #include "IptvClientServerCommon.h"
       
    26 #include "CIptvNetworkSelection.h"
       
    27 #include "CIptvNetworkSelectionMsgHandler.h"
       
    28 #include "MIptvServiceManagementClientObserver.h"
       
    29 #include "CIptvServer.h"
       
    30 #include "IptvDebug.h"
       
    31 
       
    32 // EXTERNAL DATA STRUCTURES
       
    33 // EXTERNAL FUNCTION PROTOTYPES  
       
    34 // CONSTANTS
       
    35 // MACROS
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 // MODULE DATA STRUCTURES
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CIptvNetworkSelectionMsgHandler::CIptvNetworkSelectionMsgHandler
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CIptvNetworkSelectionMsgHandler::CIptvNetworkSelectionMsgHandler(CIptvServer& aServer)
       
    51 : iServer(aServer)
       
    52     {
       
    53     iMsgPending = EIptvEngineNone;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CIptvNetworkSelectionMsgHandler::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CIptvNetworkSelectionMsgHandler* CIptvNetworkSelectionMsgHandler::NewL(CIptvServer& aServer)
       
    62     {
       
    63     CIptvNetworkSelectionMsgHandler* self = 
       
    64         new( ELeave ) CIptvNetworkSelectionMsgHandler( aServer );
       
    65 
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // Destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CIptvNetworkSelectionMsgHandler::~CIptvNetworkSelectionMsgHandler()
       
    74     {
       
    75     delete iIpcMsg;
       
    76     }
       
    77 
       
    78 // ------------------------------------------------------------------
       
    79 // CIptvNetworkSelectionMsgHandler::HandleMsgL
       
    80 // ------------------------------------------------------------------
       
    81 //
       
    82 void CIptvNetworkSelectionMsgHandler::HandleMsgL(const RMessage2& aMessage)
       
    83     {
       
    84     IPTVLOGSTRING_LOW_LEVEL("CIptvNetworkSelectionMsgHandler::HandleMsgL()");
       
    85     
       
    86     switch ( aMessage.Function() )
       
    87         {
       
    88 
       
    89         case EIptvEngineNsSetUsedIap:
       
    90             {
       
    91             /* EIptvEngineNsSetUsedIap message format:
       
    92              * -------------------------------
       
    93              * TUint32 aIapId
       
    94              * TUint32 aServiceId
       
    95              * TUint8  aSetToDefaultForService
       
    96              * -------------------------------
       
    97              */
       
    98          
       
    99             /* EIptvEngineNsSetUsedIap response message format
       
   100              * --------------------
       
   101              * TUint8 aRespStatus
       
   102              * --------------------
       
   103              */
       
   104 
       
   105             /* Get IPC message */
       
   106             TUint32 ipcMsgSize = aMessage.GetDesLengthL(0);
       
   107             HBufC8* ipcMsg;
       
   108             ipcMsg = HBufC8::NewL(ipcMsgSize);
       
   109             CleanupStack::PushL(ipcMsg); // 1->
       
   110             ipcMsg->Des().Zero();
       
   111             TPtr8 ipcMsgPtr(ipcMsg->Des());					
       
   112             aMessage.ReadL(0, ipcMsgPtr, 0);
       
   113 
       
   114             /* read message data */						
       
   115             RDesReadStream readStream;			
       
   116             readStream.Open(ipcMsg->Des());
       
   117             CleanupClosePushL( readStream );
       
   118             TUint32 iapId                 = readStream.ReadInt32L();
       
   119             TUint32 serviceId             = readStream.ReadInt32L();
       
   120             TUint8 setToDefaultForService = readStream.ReadInt8L();
       
   121             CleanupStack::PopAndDestroy( &readStream );
       
   122 
       
   123             CIptvNetworkSelection::TRespStatus resp;
       
   124             
       
   125             //this is trapped in CIptvServerSession::ServiceL()
       
   126             iServer.iNetworkSelection->SetUsedIapL(iapId, serviceId, setToDefaultForService, resp);
       
   127 
       
   128             /* send resp */
       
   129             ipcMsgPtr.Zero();
       
   130             RDesWriteStream writeStream;
       
   131             writeStream.Open(ipcMsgPtr);
       
   132             CleanupClosePushL( writeStream );
       
   133             writeStream.WriteUint8L(static_cast<TUint8>(resp));
       
   134             CleanupStack::PopAndDestroy( &writeStream );
       
   135             aMessage.WriteL(0, ipcMsgPtr, 0);
       
   136             aMessage.Complete(KErrNone);
       
   137             CleanupStack::PopAndDestroy(ipcMsg); // <-1
       
   138             }
       
   139             break;
       
   140             
       
   141         case EIptvEngineNsGetUsedIapReq:
       
   142             {
       
   143             /* EIptvEngineNsGetUsedIapReq message format:
       
   144              * ------------------
       
   145              * TUint32 aServiceId
       
   146              * ------------------
       
   147              */
       
   148         
       
   149             /* EIptvEngineNsGetUsedIapResp message format:
       
   150              * -------------------
       
   151              * TUint8  aRespStatus
       
   152              * TUint32 aIapId
       
   153              * TUint16 aIapNameLength
       
   154              * <aIapNameLength * TUint16> aIapNameData (contains SSID if iapname not found)
       
   155              * TUint8  aConnectionPermission
       
   156              * -------------------
       
   157              */
       
   158 
       
   159             iMsgPending = EIptvEngineNsGetUsedIapReq;
       
   160              
       
   161             //Store aMessage for later use (GetUsedIapResp())
       
   162             iMessage = aMessage;
       
   163             
       
   164             /* Get IPC message */
       
   165             TUint32 ipcMsgSize = aMessage.GetDesLengthL( 0 );
       
   166 
       
   167             delete iIpcMsg;
       
   168             iIpcMsg = NULL;
       
   169 
       
   170             iIpcMsg = HBufC8::NewL( ipcMsgSize );
       
   171             iIpcMsg->Des().Zero();
       
   172             TPtr8 ipcMsgPtr( iIpcMsg->Des() );
       
   173             aMessage.ReadL( 0, ipcMsgPtr, 0 );
       
   174 
       
   175             /* read message data */						
       
   176             RDesReadStream readStream;
       
   177             readStream.Open( iIpcMsg->Des() );
       
   178             CleanupClosePushL( readStream );
       
   179             TUint32 serviceId = readStream.ReadInt32L();
       
   180             CleanupStack::PopAndDestroy( &readStream );
       
   181 
       
   182             /* call network selection */            
       
   183             iGetUsedIapReq.iNsObserver = this;
       
   184             iGetUsedIapReq.iServiceId  = serviceId;
       
   185             iServer.iNetworkSelection->GetUsedIapReqL( &iGetUsedIapReq );
       
   186 
       
   187             if ( iGetUsedIapReq.iRespStatus == CIptvNetworkSelection::EDoingWlanScan )
       
   188                 {
       
   189                 //Start waiting for call to GetUsedIapResp()
       
   190                 //Client shouldnt send anything to us meanwhile
       
   191                 }
       
   192             else
       
   193                 {
       
   194                 //NS responded synchronously, lets handle the resp message
       
   195                 GetUsedIapResp( &iGetUsedIapReq );
       
   196                 }
       
   197             }
       
   198             break;
       
   199         
       
   200         case EIptvEngineNsClearUsedIap:
       
   201             {
       
   202             iServer.iNetworkSelection->ClearUsedIap();
       
   203             aMessage.Complete(KErrNone);
       
   204             }
       
   205             break;
       
   206                 
       
   207         case EIptvEngineNsSetConnectionAllowed:
       
   208             {
       
   209 
       
   210             /* EIptvEngineNsSetConnectionAllowed message format:
       
   211              * --------------------------
       
   212              * TUint8  aConnectionAllowed
       
   213              * TUint32 aIapId
       
   214              * --------------------------
       
   215              */
       
   216          
       
   217             /* response message format:
       
   218              * -------------------
       
   219              * TUint8 aRespStatus
       
   220              * -------------------
       
   221              */
       
   222 
       
   223             /* Get IPC message */
       
   224             TUint32 ipcMsgSize = aMessage.GetDesLengthL(0);
       
   225             HBufC8* ipcMsg;
       
   226             ipcMsg = HBufC8::NewL(ipcMsgSize);
       
   227             CleanupStack::PushL(ipcMsg); // 1->
       
   228             ipcMsg->Des().Zero();
       
   229             TPtr8 ipcMsgPtr(ipcMsg->Des());					
       
   230             aMessage.ReadL(0, ipcMsgPtr, 0);
       
   231 
       
   232             /* read message data */						
       
   233             RDesReadStream readStream;			
       
   234             readStream.Open(ipcMsg->Des());
       
   235             CleanupClosePushL( readStream );
       
   236             TUint8 connectionAllowed = readStream.ReadInt8L();
       
   237             TUint32 iapId            = readStream.ReadInt32L();
       
   238             CleanupStack::PopAndDestroy( &readStream );
       
   239 
       
   240             /* call network selection */
       
   241             CIptvNetworkSelection::TRespStatus respStatus;            
       
   242             iServer.iNetworkSelection->SetConnectionAllowedL(connectionAllowed, iapId, respStatus);
       
   243             
       
   244             /* write resp */
       
   245             ipcMsgPtr.Zero();
       
   246             RDesWriteStream writeStream;
       
   247             writeStream.Open(ipcMsgPtr);
       
   248             CleanupClosePushL( writeStream );
       
   249             writeStream.WriteUint8L(static_cast<TUint8>(respStatus));
       
   250             CleanupStack::PopAndDestroy( &writeStream );
       
   251             aMessage.WriteL(0, ipcMsgPtr, 0);
       
   252             
       
   253             /* send resp */
       
   254             aMessage.Complete(KErrNone);
       
   255             CleanupStack::PopAndDestroy(ipcMsg); // <-1
       
   256             }
       
   257             break;
       
   258            
       
   259         case EIptvEngineNsIsConnectionAllowed:
       
   260             {
       
   261                 
       
   262             /* EIptvEngineNsIsConnectionAllowed message format:
       
   263              * -------------------
       
   264              * TUint32 aServiceId   
       
   265              * -------------------
       
   266              */
       
   267 
       
   268             /* EIptvEngineNsIsConnectionAllowed response message format:
       
   269              * -----------------------------
       
   270              * TUint8  aRespStatus
       
   271              * TUint8  aConnectionPermission
       
   272              * -----------------------------
       
   273              */
       
   274                 
       
   275             /* Get IPC message */
       
   276             TUint32 ipcMsgSize = aMessage.GetDesLengthL(0);
       
   277             HBufC8* ipcMsg;
       
   278             ipcMsg = HBufC8::NewL(ipcMsgSize);
       
   279             CleanupStack::PushL(ipcMsg); // 1->
       
   280             ipcMsg->Des().Zero();
       
   281             TPtr8 ipcMsgPtr(ipcMsg->Des());					
       
   282             aMessage.ReadL(0, ipcMsgPtr, 0);
       
   283 
       
   284             /* read message data */						
       
   285             RDesReadStream readStream;			
       
   286             readStream.Open(ipcMsg->Des());
       
   287             CleanupClosePushL( readStream );
       
   288             TUint32 serviceId = readStream.ReadUint32L();
       
   289             CleanupStack::PopAndDestroy( &readStream );
       
   290 
       
   291             /* call network selection */
       
   292             CIptvNetworkSelection::TRespStatus respStatus = CIptvNetworkSelection::ESucceeded;
       
   293             CIptvNetworkSelection::TConnectionPermission connectionPermission;
       
   294             connectionPermission = iServer.iNetworkSelection->IsConnectionAllowedL(serviceId);
       
   295             
       
   296             /* write resp */
       
   297             RDesWriteStream writeStream;
       
   298             writeStream.Open(ipcMsgPtr);
       
   299             CleanupClosePushL( writeStream );
       
   300             writeStream.WriteUint8L(static_cast<TUint8>(respStatus));
       
   301             writeStream.WriteUint8L(static_cast<TUint8>(connectionPermission));
       
   302             CleanupStack::PopAndDestroy( &writeStream );
       
   303             aMessage.WriteL(0, ipcMsgPtr, 0);
       
   304 
       
   305             /* send resp */
       
   306             aMessage.Complete(KErrNone);
       
   307             CleanupStack::PopAndDestroy(ipcMsg); // <-1
       
   308             }
       
   309             break;
       
   310             
       
   311          case EIptvEngineNsCancel:
       
   312             {
       
   313             switch(iMsgPending)
       
   314                 {
       
   315                 case EIptvEngineNsGetUsedIapReq:
       
   316                     {
       
   317                     TInt err( iServer.iNetworkSelection->CancelGetUsedIapReq( this ) ); 
       
   318                     aMessage.Complete( err );
       
   319                     }
       
   320                     break;
       
   321                     
       
   322                 default:
       
   323                     aMessage.Complete(KErrNotFound);
       
   324                     break;
       
   325                 }
       
   326             iMsgPending = EIptvEngineNone;
       
   327             }
       
   328             break;
       
   329         }
       
   330 
       
   331     IPTVLOGSTRING_LOW_LEVEL("CIptvNetworkSelectionMsgHandler::HandleMsgL() exit");
       
   332     }
       
   333 
       
   334 // ------------------------------------------------------------------
       
   335 // CIptvNetworkSelectionMsgHandler::GetUsedIapResp
       
   336 // ------------------------------------------------------------------
       
   337 //
       
   338 void CIptvNetworkSelectionMsgHandler::GetUsedIapResp(TIptvGetUsedIapReq* /*aRequestOb*/)
       
   339     {
       
   340     IPTVLOGSTRING_LOW_LEVEL("CIptvNetworkSelectionMsgHandler::GetUsedIapResp()");
       
   341 
       
   342     TRAPD( err, GetUsedIapRespL() );
       
   343 
       
   344     IPTVLOGSTRING2_LOW_LEVEL("CIptvNetworkSelectionMsgHandler::GetUsedIapResp() trap err:%d", err);
       
   345     iMessage.Complete( err );
       
   346 
       
   347     iMsgPending = EIptvEngineNone;
       
   348     IPTVLOGSTRING_LOW_LEVEL("CIptvNetworkSelectionMsgHandler::GetUsedIapResp() exit");
       
   349     }
       
   350 
       
   351 // ------------------------------------------------------------------
       
   352 // CIptvNetworkSelectionMsgHandler::GetUsedIapRespL
       
   353 // ------------------------------------------------------------------
       
   354 //
       
   355 void CIptvNetworkSelectionMsgHandler::GetUsedIapRespL()
       
   356     {
       
   357     /* EIptvEngineNsGetUsedIapResp message format:
       
   358      * -------------------
       
   359      * TUint8  aRespStatus
       
   360      * TUint32 aIapId
       
   361      * TUint16 aIapNameLength
       
   362      * <aIapNameLength * TUint16> aIapNameData (contains SSID if iapname not found)
       
   363      * TUint8  aConnectionPermission
       
   364      * TUint8  aWlanWhenGprs
       
   365      * -------------------
       
   366      */
       
   367     
       
   368     TBuf8<1+4+2+(KIptvNsIapNameMaxLength*2)+1> resp;
       
   369     /* write resp */
       
   370     RDesWriteStream writeStream;
       
   371     
       
   372     writeStream.Open( resp );
       
   373     CleanupClosePushL( writeStream ); // 1->        
       
   374     writeStream.WriteUint8L( iGetUsedIapReq.iRespStatus );
       
   375     writeStream.WriteUint32L( iGetUsedIapReq.iIapId );
       
   376 
       
   377     IPTVLOGSTRING2_LOW_LEVEL("CIptvNetworkSelectionMsgHandler:: IAP ID = %d", iGetUsedIapReq.iIapId);
       
   378 
       
   379     //iap name
       
   380     TUint16 iapNameLength = iGetUsedIapReq.iIapName.Length();
       
   381     writeStream.WriteUint16L( iapNameLength );
       
   382     TInt i;
       
   383     for ( i = 0; i < iapNameLength; i++ )
       
   384         {
       
   385         writeStream.WriteUint16L( iGetUsedIapReq.iIapName[i] );
       
   386         }
       
   387 
       
   388     writeStream.WriteUint8L( iGetUsedIapReq.iConnectionPermission );
       
   389 
       
   390     writeStream.WriteUint8L( iGetUsedIapReq.iWLANWhenGPRS );
       
   391      
       
   392     writeStream.Close();
       
   393     CleanupStack::Pop( &writeStream ); // <-1
       
   394 
       
   395     /* send resp */
       
   396     iMessage.WriteL( 0, resp, 0 );
       
   397     }