localconnectivityservice/locod/src/locodaemon.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     1 /*
       
     2 * Copyright (c) 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:  Daemon class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <startupdomainpskeys.h>
       
    20 
       
    21 #include <featmgr.h>
       
    22 #include <locodplugin.hrh>
       
    23 #include <locodbearerplugin.h>
       
    24 
       
    25 #include "locodaemon.h"
       
    26 #include "locodserviceman.h"
       
    27 #include "utils.h"
       
    28 #include "debug.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // NewLC
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CLocoDaemon* CLocoDaemon::NewLC()
       
    37     {
       
    38     CLocoDaemon* self = new (ELeave) CLocoDaemon();
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // C++ destrctor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CLocoDaemon::~CLocoDaemon()
       
    49     {
       
    50     FeatureManager::UnInitializeLib();    
       
    51     Cancel();
       
    52     iSystemPS.Close();
       
    53     delete iServiceMan;
       
    54     iBearers.ResetAndDestroy();
       
    55     iBearers.Close();
       
    56     REComSession::FinalClose();
       
    57     TRACE_FUNC
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // Called when the status of system pubsub keys are 
       
    62 // changed. Normally this is called after the system boot.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CLocoDaemon::RunL()
       
    66     {
       
    67     TRACE_INFO((_L(" RunL %d"), iStatus.Int()))
       
    68     if (iStatus == KErrNone)
       
    69         {
       
    70 		iSystemPS.Subscribe(iStatus);
       
    71 		SetActive();
       
    72 
       
    73         TRACE_INFO((_L(" [SYSTEM] prev %d"), iSystemState))
       
    74         LEAVE_IF_ERROR(iSystemPS.Get(iSystemState));
       
    75         TRACE_INFO((_L(" [SYSTEM] now %d"), iSystemState))
       
    76         
       
    77         if (iSystemState == ESwStateNormalRfOn ||
       
    78              iSystemState == ESwStateNormalRfOff ||
       
    79             iSystemState == ESwStateCharging ||  
       
    80             iSystemState == ESwStateNormalBTSap)
       
    81             { // System is up, construct service man and load bearers.
       
    82             if(!iServiceMan)
       
    83                 {
       
    84                 iServiceMan = CLocodServiceMan::NewL();
       
    85                 }
       
    86             if (!iBearers.Count())
       
    87                 {
       
    88                 LoadBearesL();
       
    89                 }
       
    90             }
       
    91   /*
       
    92      ESwStateShuttingDown and  ESWStateShuttingDown event is received when 
       
    93      the device is about to shut down
       
    94   */
       
    95         else if (iSystemState == ESwStateShuttingDown)
       
    96             {
       
    97             TRACE_INFO((_L(" [SYSTEM] Shuting down and deleting")))
       
    98             delete iServiceMan;
       
    99             iServiceMan = NULL;
       
   100             iBearers.ResetAndDestroy();
       
   101             return;
       
   102             }        
       
   103         }
       
   104         RProcess::Rendezvous(KErrNone);
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CActive method cancel listening pubsub keys
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CLocoDaemon::DoCancel()
       
   112     {
       
   113     TRACE_FUNC
       
   114     iSystemPS.Cancel();
       
   115     }
       
   116   
       
   117 // ---------------------------------------------------------------------------
       
   118 // CActive method
       
   119 // ---------------------------------------------------------------------------
       
   120 //  
       
   121 TInt CLocoDaemon::RunError(TInt /*aReason*/)
       
   122     {
       
   123     TRACE_FUNC
       
   124     return KErrNone;
       
   125     }
       
   126   
       
   127 // ---------------------------------------------------------------------------
       
   128 // C++ Constructor
       
   129 // ---------------------------------------------------------------------------
       
   130 //  
       
   131 CLocoDaemon::CLocoDaemon() : CActive(CActive::EPriorityStandard)
       
   132     {
       
   133     CActiveScheduler::Add(this);
       
   134     TRACE_FUNC_THIS
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // 2nd phase construction
       
   139 // ---------------------------------------------------------------------------
       
   140 //    
       
   141 void CLocoDaemon::ConstructL()
       
   142     {
       
   143     FeatureManager::InitializeLibL();
       
   144     LEAVE_IF_ERROR(iSystemPS.Attach(KPSUidStartup, KPSGlobalSystemState));
       
   145     iStatus = KRequestPending;
       
   146     SetActive();
       
   147     TRequestStatus* sta = &iStatus;
       
   148     User::RequestComplete(sta, KErrNone);
       
   149     TRACE_FUNC
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // LoadBearesL Loads the bearer plug ins
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CLocoDaemon::LoadBearesL()
       
   157     {
       
   158     TRACE_FUNC_ENTRY
       
   159     TRACE_INFO((_L("Load interface 0x%08X"), KLOCODBEARERINTERFACEUID))
       
   160 	const TUid KBearerPluginInterface = TUid::Uid(KLOCODBEARERINTERFACEUID);
       
   161 	RImplInfoPtrArray implementations;
       
   162 	const TEComResolverParams noResolverParams;
       
   163 	REComSession::ListImplementationsL(KBearerPluginInterface, 
       
   164 		noResolverParams,
       
   165 		KRomOnlyResolverUid,
       
   166 		implementations);
       
   167 	CleanupResetDestroyClosePushL(implementations);
       
   168 	const TUint count = implementations.Count();
       
   169     TRACE_INFO((_L(" Bearer count = %d"), count))
       
   170 	for ( TUint ii = 0 ; ii < count ; ++ii )
       
   171 		{
       
   172 		CImplementationInformation* impl = implementations[ii];
       
   173 		TRACE_INFO((_L("Bearer: feature %d, name '%S', ROM only %d"), 
       
   174 		    impl->ImplementationUid().iUid, &(impl->DisplayName()), impl->RomOnly()))
       
   175     	if (FeatureManager::FeatureSupported(impl->ImplementationUid().iUid))
       
   176     		{
       
   177     		TRACE_INFO((_L("Feature found")))
       
   178     		TLocodBearerPluginParams params(impl->ImplementationUid(), *iServiceMan);
       
   179     		CLocodBearerPlugin* bearer = CLocodBearerPlugin::NewL(params);
       
   180     		CleanupStack::PushL(bearer);
       
   181     		iBearers.AppendL(bearer);
       
   182     		CleanupStack::Pop(bearer);
       
   183     		}
       
   184 		}
       
   185 	CleanupStack::PopAndDestroy(&implementations);
       
   186     TRACE_FUNC_EXIT
       
   187     }
       
   188