upnpharvester/mdhserver/src/server/mdhconnectionmonitor.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006-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:      UPnP Connection Monitor class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <nifvar.h>
       
    25 
       
    26 #include "mdhconnectionmonitor.h"
       
    27 
       
    28 // ========================== MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CMdHConnectionMonitor::CMdHConnectionMonitor
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CMdHConnectionMonitor::CMdHConnectionMonitor(
       
    37     MMdHConnectionMonitorObserver& aObserver, TInt aAccessPoint ) :
       
    38     iObserver( aObserver ),
       
    39     iAccessPoint( aAccessPoint )
       
    40     {
       
    41     }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CMdHConnectionMonitor::NewL
       
    46 // Two-phased constructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CMdHConnectionMonitor* CMdHConnectionMonitor::NewL(
       
    50     MMdHConnectionMonitorObserver& aObserver, TInt aAccessPoint )
       
    51     {
       
    52     CMdHConnectionMonitor* self = new(ELeave) CMdHConnectionMonitor(
       
    53         aObserver, aAccessPoint );
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop(self);
       
    57     return self;    
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMdHConnectionMonitor::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CMdHConnectionMonitor::ConstructL()
       
    67     {    
       
    68     iConnectionMonitor.ConnectL();
       
    69 
       
    70     iConnectionMonitor.NotifyEventL( *this );
       
    71 
       
    72     // Get the count of connections
       
    73     TRequestStatus status = KRequestPending;
       
    74     TUint connectionCount = 0;
       
    75     iConnectionMonitor.GetConnectionCount(connectionCount, status);
       
    76     User::WaitForRequest( status ); 
       
    77     
       
    78     // Go through available connections and check to see
       
    79     // if connection with iAccessPoint IAP is already running
       
    80     if( status == KErrNone )
       
    81         {
       
    82         for( TUint i=1; i < connectionCount+1;  i++ )
       
    83             {
       
    84             TUint connectionId;
       
    85             TUint subConnectionCount;
       
    86             TUint iapId = 0;
       
    87 
       
    88             iConnectionMonitor.GetConnectionInfo( 
       
    89                                             i,
       
    90                                             connectionId, 
       
    91                                             subConnectionCount);
       
    92 
       
    93             TRequestStatus status = KRequestPending;
       
    94 
       
    95             iConnectionMonitor.GetUintAttribute( 
       
    96                                             connectionId, 
       
    97                                             0, 
       
    98                                             KIAPId, 
       
    99                                             (TUint &) iapId,
       
   100                                             status );
       
   101             User::WaitForRequest( status ); 
       
   102 
       
   103             // Save connectionId if same iap
       
   104             if( status == KErrNone && iAccessPoint == iapId )
       
   105                 {
       
   106                 iConnectionId = connectionId;
       
   107                 }
       
   108             }    
       
   109         }    
       
   110 
       
   111     }
       
   112 
       
   113     
       
   114 // ---------------------------------------------------------------------------
       
   115 // CMdHConnectionMonitor::~CMdHConnectionMonitor()
       
   116 // Destructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CMdHConnectionMonitor::~CMdHConnectionMonitor()
       
   120     {
       
   121     iConnectionMonitor.CancelNotifications();
       
   122 
       
   123     // Disconnect from CM server
       
   124     iConnectionMonitor.Close();
       
   125     }
       
   126 
       
   127 
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CMdHConnectionMonitor::EventL()
       
   131 // Connection monitor observer
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CMdHConnectionMonitor::EventL( const CConnMonEventBase& aConnMonEvent )
       
   135     {
       
   136 
       
   137     TUint connectionId = 0;
       
   138 
       
   139     switch ( aConnMonEvent.EventType() )
       
   140         {
       
   141         case EConnMonCreateConnection:
       
   142             {
       
   143             TUint iapId = 0;
       
   144 
       
   145             const CConnMonCreateConnection* eventCreate; 
       
   146             eventCreate = (const CConnMonCreateConnection*)&aConnMonEvent;
       
   147             connectionId = eventCreate->ConnectionId();
       
   148 
       
   149             TRequestStatus status = KRequestPending;
       
   150 
       
   151             // Get IAP id
       
   152             iConnectionMonitor.GetUintAttribute( 
       
   153                                             eventCreate->ConnectionId(), 
       
   154                                             0, 
       
   155                                             KIAPId, 
       
   156                                             iapId, 
       
   157                                             status );
       
   158             User::WaitForRequest( status ); 
       
   159 
       
   160             // Save connectionId if same iap
       
   161             if( iAccessPoint == iapId )
       
   162                 {
       
   163                 iConnectionId = connectionId;
       
   164                 }
       
   165 
       
   166             break;
       
   167             }
       
   168 
       
   169         // Connection is deleted
       
   170         case EConnMonDeleteConnection:
       
   171             {
       
   172             const CConnMonDeleteConnection* eventDelete; 
       
   173             eventDelete = 
       
   174                     ( const CConnMonDeleteConnection* ) &aConnMonEvent;
       
   175             connectionId = eventDelete->ConnectionId();
       
   176 
       
   177             // If connection id same as in createConnection
       
   178             if( connectionId == iConnectionId )
       
   179                 {
       
   180                 // Callback function
       
   181                 iObserver.ConnectionLost();
       
   182                 }
       
   183 
       
   184             break;
       
   185             }
       
   186          default:
       
   187             {
       
   188             break;
       
   189             }
       
   190         }
       
   191     }
       
   192 
       
   193 // end of file