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