qtinternetradio/irqnetworkcontroller/src/irqnetworkcontroller.cpp
changeset 0 09774dfdd46b
child 11 f683e24efca3
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #include <QStringList>
       
    18 
       
    19 #include "irqnetworkcontroller.h"
       
    20 #include "irqnetworkcontrollerbody.h" 
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // IRQNetworkController::openInstance()
       
    24 // Static function to get a singleton instance of IRQNetworkController
       
    25 // @return IRQNetworkController *
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C IRQNetworkController* IRQNetworkController::openInstance()
       
    29 {
       
    30     // Get singleton instance
       
    31     IRQNetworkController* irqnetworkcontroller =
       
    32                            reinterpret_cast<IRQNetworkController*>(Dll::Tls());
       
    33 
       
    34     if (NULL == irqnetworkcontroller)
       
    35     {
       
    36         TRAPD(error, irqnetworkcontroller = createInstanceL());
       
    37         if (KErrNone != error)
       
    38         {
       
    39             delete irqnetworkcontroller;
       
    40             irqnetworkcontroller = NULL;
       
    41             Dll::SetTls(NULL);
       
    42         }
       
    43     }
       
    44     else
       
    45     {
       
    46         irqnetworkcontroller->iSingletonInstances++;
       
    47     }
       
    48 
       
    49     return irqnetworkcontroller;
       
    50 }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // IRQNetworkController::closeInstance()
       
    54 // Close a singleton instance of IRQNetworkController
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void IRQNetworkController::closeInstance()
       
    58 {
       
    59     iSingletonInstances--;
       
    60 
       
    61     if (0 == iSingletonInstances)
       
    62     {
       
    63         Dll::SetTls(NULL);
       
    64         delete this;
       
    65     }
       
    66 }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // IRQNetworkController::GetNetworkStatus()
       
    70 // Returns the variable which indicates if connection is active or not
       
    71 // @return bool
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C bool IRQNetworkController::getNetworkStatus() const
       
    75 {
       
    76     return iBody->getNetworkStatus();
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // IRQNetworkController::getIAPId()
       
    81 // Gets the IAP Id of the chosen IAP
       
    82 // @return IRQError
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C IRQError IRQNetworkController::getIAPId(unsigned long& aIapId) const
       
    86 {
       
    87     return iBody->getIAPId(aIapId);
       
    88 }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // IRQNetworkController::getAccessPointList()
       
    92 // Returns the list of available access points
       
    93 // @return QStringList &aList specifying the access point names
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void IRQNetworkController::getAccessPointList(QStringList &aList)
       
    97 {
       
    98     iBody->getAccessPointList(aList);
       
    99 }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // IRQNetworkController::getApIdList()
       
   103 // Returns the list of iap ids for available access points
       
   104 // @return QList<unsigned long> &aList specifying the iap ids
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void IRQNetworkController::getApIdList(QList<unsigned long> &aList)
       
   108 {
       
   109     iBody->getApIdList(aList);
       
   110 }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // IRQNetworkController::getBearerList()
       
   114 // Returns the list of bearer ids for available access points
       
   115 // @return QList<unsigned long> &aList specifying the bearer ids
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C void IRQNetworkController::getBearerList(QList<unsigned long> &aList)
       
   119 {
       
   120     iBody->getBearerList(aList);
       
   121 }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // IRQNetworkController::getNetworkList()
       
   125 // Returns the list of network ids for available access points
       
   126 // @return QList<unsigned long> &aList specifying the network ids
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C void IRQNetworkController::getNetworkList(QList<unsigned long> &aList)
       
   130 {
       
   131     iBody->getNetworkList(aList);
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // IRQNetworkController::chooseAccessPoint()
       
   136 // Configures the Access Point which is used by all the components for network
       
   137 // connectivity
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C void IRQNetworkController::chooseAccessPoint()
       
   141 {
       
   142     iBody->chooseAccessPoint();
       
   143 }
       
   144 
       
   145 /*
       
   146  * Cancel configuring access point
       
   147  */
       
   148 EXPORT_C void IRQNetworkController::cancelConnecting()
       
   149 {
       
   150     iBody->cancelConnecting();
       
   151     iBody->resetConnectionStatus();
       
   152 }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // IRQNetworkController::isOfflineMode()
       
   156 // Indicates if the phone is in offline mode
       
   157 // @return True if the phone is in offline mode else False
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C bool IRQNetworkController::isOfflineMode()
       
   161 {
       
   162     return iBody->isOfflineMode();
       
   163 }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // IRQNetworkController::isWlanSupported()
       
   167 // Indicates if the phone supports WLan usage
       
   168 // @return True if the phone supports else False
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C bool IRQNetworkController::isWlanSupported() const
       
   172 {
       
   173     return iBody->isWlanSupported();
       
   174 }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // IRQNetworkController::resetConnectionStatus()
       
   178 // Resets the connection status to Disconnected state
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C void IRQNetworkController::resetConnectionStatus()
       
   182 {
       
   183     iBody->resetConnectionStatus();
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // IRQNetworkController::identifyConnectionType()
       
   188 // Indicates the type of connection
       
   189 // @return enum describing the type of connection ( GPRS/3G/WiFi )
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 EXPORT_C IRQConnectionType IRQNetworkController::identifyConnectionType() const
       
   193 {
       
   194     return iBody->identifyConnectionType();
       
   195 }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // IRQNetworkController::notifyActiveNetworkObservers()
       
   199 // Notifies all observers whose network request is active to reissue the request
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C void IRQNetworkController::notifyActiveNetworkObservers(IRQNetworkEvent aEvent)
       
   203 {
       
   204     iBody->notifyActiveNetworkObservers(aEvent);
       
   205 }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // IRQNetworkController::isHandlingOverConnection()
       
   209 // Indicates if the hand over of network connection has happened
       
   210 // @return bool
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 EXPORT_C bool IRQNetworkController::isHandlingOverConnection()
       
   214 {
       
   215     return iBody->isHandlingOverConnection();
       
   216 }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // IRQNetworkController::isConnectRequestIssued()
       
   220 // Indicates if chooseAccessPoint is called
       
   221 // @return bool
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 EXPORT_C bool IRQNetworkController::isConnectRequestIssued() const
       
   225 {
       
   226     return iBody->isConnectRequestIssued();
       
   227 }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // IRQNetworkController::IRQNetworkController()
       
   231 // Default constructor
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 IRQNetworkController::IRQNetworkController()
       
   235 {
       
   236 }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // IRQNetworkController::~IRQNetworkController()
       
   240 // Destructor
       
   241 //
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 IRQNetworkController::~IRQNetworkController()
       
   245 {
       
   246     delete iBody;
       
   247     iBody = NULL;
       
   248 }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // IRQNetworkController::constructL()
       
   252 // Two-Phase Constructor.
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void IRQNetworkController::constructL()
       
   256 {
       
   257     iBody = new (ELeave) IRQNetworkControllerBody();
       
   258     Q_ASSERT(iBody);
       
   259     iBody->initL();
       
   260     
       
   261     connect(iBody, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
   262             this, SIGNAL(networkRequestNotified(IRQNetworkEvent)));
       
   263     connect(iBody, SIGNAL(pendingRequestsReset(bool)),
       
   264             this, SIGNAL(pendingRequestsReset(bool)));
       
   265     connect(iBody, SIGNAL(networkEventNotified(IRQNetworkEvent)),
       
   266             this, SIGNAL(networkEventNotified(IRQNetworkEvent)));
       
   267     connect(iBody, SIGNAL(errorOccured(IRQError)),
       
   268             this, SIGNAL(errorOccured(IRQError)));
       
   269 }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // IRQNetworkController::createInstanceL()
       
   273 // Creates IRQNetworkController instance
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 IRQNetworkController* IRQNetworkController::createInstanceL()
       
   277 {
       
   278     IRQNetworkController* nwkController = new (ELeave) IRQNetworkController();
       
   279     nwkController->constructL();
       
   280     User::LeaveIfError(Dll::SetTls(nwkController));
       
   281     nwkController->iSingletonInstances = 1;
       
   282     return nwkController;
       
   283 }