bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp
author hgs
Tue, 19 Oct 2010 15:09:34 +0300
changeset 70 f5508c13dfe0
parent 57 5ebadcda06cb
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     3
* All rights reserved.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     4
* This component and the accompanying materials are made available
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     6
* which accompanies this distribution, and is available
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     8
*
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     9
* Initial Contributors:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    10
* Nokia Corporation - initial contribution.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    11
*
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    12
* Contributors:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    13
*
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    14
* Description: Server class for handling commands from clients, and the 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*                central class in btnotif thread.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
#include "btnotifserver.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
#include <btservices/btdevrepository.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
#include "btnotifsession.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
#include "btnotifconnectiontracker.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
#include "btnotifsettingstracker.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include "btnotificationmanager.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    25
#include "btnotifdeviceselector.h"
57
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
    26
#include "btnotifgeninfonotifier.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
#include "btnotifserversecpolicy.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
#include "btnotifclientserver.h"
57
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
    29
#include "btnotifpowernotifier.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
/**  Panic category */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
_LIT( KBTNotifPanic, "BTNotif panic" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
/**  Timeout (10 sec) for shutting down the server 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    35
 * (when BT power is off and no clients connected). */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
const TInt KBTNtoifShutdownTimeout = 10 * 1000 * 1000;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    37
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
// ======== LOCAL FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
// Start the server.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
static void RunServerL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    47
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    48
    (void) User::RenameThread( KBTNotifServerName );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    49
    // Create and install the active scheduler for this thread.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    50
    CActiveScheduler* scheduler = new( ELeave ) CActiveScheduler();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
    CleanupStack::PushL( scheduler );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
    CActiveScheduler::Install( scheduler );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
    // create the server (and leave it on the cleanup stack)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
    CBTNotifServer* notifServer = CBTNotifServer::NewLC();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
    // Initialisation complete, now signal the client
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    RProcess::Rendezvous( KErrNone );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
        // The server is now up and running.
70
hgs
parents: 57
diff changeset
    58
    BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, _L("[BTNOTIF]\t BTNotif server now up and running" ));
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
    // The active scheduler runs during the lifetime of this thread.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
    CActiveScheduler::Start();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    // Stopping the active scheduler means terminating the thread.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    // Cleanup the server and scheduler.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    CleanupStack::PopAndDestroy( notifServer );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
    CleanupStack::PopAndDestroy( scheduler );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
// Panic the server.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
void PanicServer( TInt aReason )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
    User::Panic( KBTNotifPanic, aReason );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
// Panic the client through the client-side message.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
void PanicClient( const RMessage2& aMessage, TInt aReason )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    aMessage.Panic( KBTNotifPanic, aReason );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
// ======== MEMBER FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
// C++ default constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
CBTNotifServer::CBTNotifServer()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
:   CPolicyServer( EPriorityUserInput, KBTNotifServerPolicy )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
// Symbian 2nd-phase constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
void CBTNotifServer::ConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
    // Add the server to the active scheduler (from CServer2):
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
    StartL( KBTNotifServerName );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    iAsyncCb = new( ELeave ) CAsyncCallBack( EPriorityHigh );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
    TCallBack cb( AsyncConstructCb, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
    iAsyncCb->Set( cb );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
    iAsyncCb->CallBack();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   111
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
// Asynchronous 3rd-phase constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
void CBTNotifServer::AsyncConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
    {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   117
    // The server class owns this registry object and provides it
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   118
    // as a singleton in the whole server process.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   119
    // Server itself does not handle any registry events.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   120
    // Classes that want to receive these events must register
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   121
    // observers via CBtDevRepository interface.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   122
    iDevRep = CBtDevRepository::NewL();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   123
    iNotificationMgr = CBTNotificationManager::NewL( this );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
    iSettingsTracker = CBTNotifSettingsTracker::NewL( this );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   125
    iConnectionTracker = CBTNotifConnectionTracker::NewL( this );
57
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
   126
    iGenInfoNotifier = CBTNotifGenInfoNotifier::NewL( this );
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
   127
    iBTPowerNotifier = CBTNotifPowerNotifier::NewL( this );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   128
    iTimer = CDeltaTimer::NewL(CActive::EPriorityLow);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   129
    TCallBack shutdownCb( ShutdownTimeout, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
    iShutdownTimerEntry.Set( shutdownCb );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   131
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   132
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   133
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   134
// Callback for asynchronous construction.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
TInt CBTNotifServer::AsyncConstructCb( TAny* aPtr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
    TRAPD( err, ( (CBTNotifServer*) aPtr )->AsyncConstructL() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
    return err;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   141
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   142
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   145
// NewLC.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   146
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
CBTNotifServer* CBTNotifServer::NewLC()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
    CBTNotifServer* self = new( ELeave ) CBTNotifServer();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
    CleanupStack::PushL( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
    self->ConstructL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
    return self;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   157
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   158
// Destructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   159
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
CBTNotifServer::~CBTNotifServer()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
    delete iDevSelector;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
    delete iSettingsTracker;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
    delete iConnectionTracker;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
    delete iNotificationMgr;
57
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
   167
    delete iGenInfoNotifier;
5ebadcda06cb 201035_7
hgs
parents: 42
diff changeset
   168
    delete iBTPowerNotifier;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
    delete iAsyncCb;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
    delete iTimer;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
    delete iDevRep;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
// Handle a change in BT power state.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
void CBTNotifServer::HandlePowerStateChangeL( TBTPowerStateValue aState )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
    CheckIdle( aState );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
// Increase the session count.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
void CBTNotifServer::AddSession()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   188
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
    ++iSessionCount;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   190
    iTimer->Remove( iShutdownTimerEntry );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
// Decrease the session count.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   196
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
void CBTNotifServer::RemoveSession()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
    if ( iSessionCount > 0 )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
        // session counter can't be less than 0
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
        --iSessionCount;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
    CheckIdle( iSettingsTracker->GetPowerState() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   206
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   207
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   208
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   209
// get the singleton instance of device repository
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   210
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   211
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   212
CBtDevRepository& CBTNotifServer::DevRepository()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   213
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   214
    return *iDevRep;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   215
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   216
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   217
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
// get the singleton instance of device search notifier
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   220
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   221
CBTNotifDeviceSelector& CBTNotifServer::DeviceSelectorL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   222
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   223
    if ( ! iDevSelector )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   224
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
        iDevSelector = CBTNotifDeviceSelector::NewL( *this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
    return *iDevSelector;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
// From class CPolicyServer.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
// Create a new session object.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   234
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   235
CSession2* CBTNotifServer::NewSessionL( const TVersion& aVersion, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
    const RMessage2& aMessage ) const
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
    (void) aMessage;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
    // Compare our version with client-side version, CServer2 requires that 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
    // we leave if they are not compatible. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
    TVersion srvVersion( KBTNotifServerVersionMajor, KBTNotifServerVersionMinor, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
                          KBTNotifServerVersionBuild );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
    if( !User::QueryVersionSupported( aVersion, srvVersion ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
        // EFalse is returned if our version is not less than or 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
        // equal to the client version.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   248
        User::Leave( KErrNotSupported );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   250
    return CBTNotifSession::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   251
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
void CBTNotifServer::CheckIdle( TBTPowerStateValue aState )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
    // In special scenarios, we do not have to remove the timer and queue it 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
    // again, but these scenarios rarely happen in end-user use cases. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
    iTimer->Remove( iShutdownTimerEntry );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
    if ( iSessionCount == 0 && aState == EBTPowerOff )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
        // BT power is off, start the shutdown timer.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
        TTimeIntervalMicroSeconds32 interval = KBTNtoifShutdownTimeout;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
        iTimer->Queue( interval, iShutdownTimerEntry );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   264
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   265
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   266
TInt CBTNotifServer::ShutdownTimeout( TAny* aPtr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   267
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   268
    (void) aPtr;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   269
    CActiveScheduler::Stop();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   270
    return KErrNone;    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   271
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   272
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   273
// ======== GLOBAL FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   274
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   275
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   276
// Main function of the executable.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   277
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   278
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   279
GLDEF_C TInt E32Main()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   280
    {
42
hgs
parents: 31
diff changeset
   281
    // Disabled until memory leak in QT/Open C are fixed
hgs
parents: 31
diff changeset
   282
    // __UHEAP_MARK;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
    CTrapCleanup* cleanup = CTrapCleanup::New();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   284
    TInt err = KErrNoMemory;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   285
    if ( cleanup )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   286
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   287
        TRAP( err, RunServerL() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   288
        delete cleanup;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   289
        }
42
hgs
parents: 31
diff changeset
   290
    // Disabled until memory leak in QT/Open C are fixed
hgs
parents: 31
diff changeset
   291
    // __UHEAP_MARKEND;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   292
    return err;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   293
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   294
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   295