contentstorage/srvsrc/casrv.cpp
author hgs
Mon, 24 May 2010 20:50:46 +0300
changeset 95 c739008478cc
parent 94 dbb8300717f7
child 98 d2f833ab7940
permissions -rw-r--r--
201019_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
7feec50967db 201003_02
hgs
parents:
diff changeset
     1
/*
7feec50967db 201003_02
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
7feec50967db 201003_02
hgs
parents:
diff changeset
     3
 * All rights reserved.
7feec50967db 201003_02
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
7feec50967db 201003_02
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
7feec50967db 201003_02
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
7feec50967db 201003_02
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7feec50967db 201003_02
hgs
parents:
diff changeset
     8
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
     9
 * Initial Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
7feec50967db 201003_02
hgs
parents:
diff changeset
    11
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    12
 * Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    13
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    14
 * Description:  ?Description
7feec50967db 201003_02
hgs
parents:
diff changeset
    15
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    16
 */
7feec50967db 201003_02
hgs
parents:
diff changeset
    17
// INCLUDE FILES
86
hgs
parents: 85
diff changeset
    18
#include <sqldb.h>
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
#include <eikenv.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
#include <eikappui.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include "casrv.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
#include "casrvdef.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
#include "casrvsession.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
#include "casrvengutils.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
#include "castorageproxy.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    26
#include "casrvmanager.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
// ==================== LOCAL FUNCTIONS ====================
7feec50967db 201003_02
hgs
parents:
diff changeset
    29
7feec50967db 201003_02
hgs
parents:
diff changeset
    30
/**
7feec50967db 201003_02
hgs
parents:
diff changeset
    31
 * Create a server.
7feec50967db 201003_02
hgs
parents:
diff changeset
    32
 * @param Pointer to created server (if created) returned here.
7feec50967db 201003_02
hgs
parents:
diff changeset
    33
 * @return Error code.
7feec50967db 201003_02
hgs
parents:
diff changeset
    34
 */
7feec50967db 201003_02
hgs
parents:
diff changeset
    35
LOCAL_C TInt CreateServer( CCaSrv*& aServer )
7feec50967db 201003_02
hgs
parents:
diff changeset
    36
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    37
    // The TRAP is not working in the same stack frame where the
7feec50967db 201003_02
hgs
parents:
diff changeset
    38
    // CTrapCleanup was created. This is why we need this function.
7feec50967db 201003_02
hgs
parents:
diff changeset
    39
    TRAPD( err, aServer = CCaSrv::NewL() );
7feec50967db 201003_02
hgs
parents:
diff changeset
    40
    return err;
7feec50967db 201003_02
hgs
parents:
diff changeset
    41
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    42
7feec50967db 201003_02
hgs
parents:
diff changeset
    43
// ==================== GLOBAL FUNCTIONS ====================
7feec50967db 201003_02
hgs
parents:
diff changeset
    44
7feec50967db 201003_02
hgs
parents:
diff changeset
    45
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
    46
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    47
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    48
//
7feec50967db 201003_02
hgs
parents:
diff changeset
    49
EXPORT_C TInt RunCaServer()
7feec50967db 201003_02
hgs
parents:
diff changeset
    50
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    51
    __UHEAP_MARK;
7feec50967db 201003_02
hgs
parents:
diff changeset
    52
    CTrapCleanup* trapCleanup = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
    53
    CActiveScheduler* activeScheduler = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
    54
    CCaSrv* server = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
    55
7feec50967db 201003_02
hgs
parents:
diff changeset
    56
    TInt err = User::RenameThread( KCaSrvName );
7feec50967db 201003_02
hgs
parents:
diff changeset
    57
    if( !err )
7feec50967db 201003_02
hgs
parents:
diff changeset
    58
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    59
        // Create a trap cleanup, make and install an active scheduler.
7feec50967db 201003_02
hgs
parents:
diff changeset
    60
        err = KErrNoMemory;
7feec50967db 201003_02
hgs
parents:
diff changeset
    61
        trapCleanup = CTrapCleanup::New();
7feec50967db 201003_02
hgs
parents:
diff changeset
    62
        if( trapCleanup )
7feec50967db 201003_02
hgs
parents:
diff changeset
    63
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
    64
            activeScheduler = new CActiveScheduler();
7feec50967db 201003_02
hgs
parents:
diff changeset
    65
            if( activeScheduler )
7feec50967db 201003_02
hgs
parents:
diff changeset
    66
                {
7feec50967db 201003_02
hgs
parents:
diff changeset
    67
                CActiveScheduler::Install( activeScheduler );
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
                err = CreateServer( server ); // Not pushed (no leaving).
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
                if( !err )
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
                    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
                    err = server->Start( KCaSrvName );
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
                    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
                }
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
            else
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
                {
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
                err = KErrNoMemory;
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
                }
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
    // Let the caller know how it went.
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
    RProcess::Rendezvous( err );
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
    if( !err )
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
        CActiveScheduler::Start(); // Start off. Exit timer will stop it.
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
    CActiveScheduler::Install( NULL );
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
    delete activeScheduler;
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
    delete server;
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
    delete trapCleanup;
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
    __UHEAP_MARKEND;
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
    return err;
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
// ==================== MEMBER FUNCTIONS ====================
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
    97
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
CCaSrv* CCaSrv::NewL()
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
    CCaSrv* srv = new ( ELeave ) CCaSrv();
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
    CleanupStack::PushL( srv );
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
    srv->ConstructL();
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
    CleanupStack::Pop( srv );
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
    return srv;
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   110
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
CCaSrv::~CCaSrv()
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
    // Cancel requests and delete all sessions first.
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
    // Base class would do it for us but that's too late - our sessions
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
    // call the server back (SessionClosed, RemoveContainer, etc.).
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
    Cancel();
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
    CSession2* session;
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
    iSessionIter.SetToFirst();
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
    while( ( session = iSessionIter++ ) != NULL )
7feec50967db 201003_02
hgs
parents:
diff changeset
   122
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   123
        delete session;
7feec50967db 201003_02
hgs
parents:
diff changeset
   124
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   125
    delete iSrvManager;
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
    delete iSrvEngUtils;
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
    delete iStorageProxy;
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   131
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
CCaStorageProxy* CCaSrv::GetStorageProxy()
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
    return iStorageProxy;
7feec50967db 201003_02
hgs
parents:
diff changeset
   137
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   138
7feec50967db 201003_02
hgs
parents:
diff changeset
   139
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   140
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   143
CCaSrv::CCaSrv() :
7feec50967db 201003_02
hgs
parents:
diff changeset
   144
    CServer2( EPriorityNormal, CServer2::TServerType( EIpcSession_Sharable ) )
7feec50967db 201003_02
hgs
parents:
diff changeset
   145
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   146
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   147
7feec50967db 201003_02
hgs
parents:
diff changeset
   148
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   149
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   150
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   151
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   152
void CCaSrv::ConstructL()
7feec50967db 201003_02
hgs
parents:
diff changeset
   153
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   154
    iSessionCount = 0;
7feec50967db 201003_02
hgs
parents:
diff changeset
   155
    iStorageProxy = CCaStorageProxy::NewL();
7feec50967db 201003_02
hgs
parents:
diff changeset
   156
    iSrvEngUtils = CCaSrvEngUtils::NewL();
94
hgs
parents: 88
diff changeset
   157
    iSrvManager = CCaSrvManager::NewL(*iStorageProxy, iSrvEngUtils);
hgs
parents: 88
diff changeset
   158
    TInt errCode = iSrvManager->LoadOperationErrorCodeL();
hgs
parents: 88
diff changeset
   159
    if( KSqlErrNotDb <= errCode && errCode <= KSqlErrGeneral )
86
hgs
parents: 85
diff changeset
   160
        {
hgs
parents: 85
diff changeset
   161
        //problem in loading one of plugins, probably data base is corrupted
hgs
parents: 85
diff changeset
   162
        //lets load it from ROM and try again
94
hgs
parents: 88
diff changeset
   163
        delete iSrvManager;
hgs
parents: 88
diff changeset
   164
        iSrvManager = NULL;
86
hgs
parents: 85
diff changeset
   165
        iStorageProxy->LoadDataBaseFromRomL();
hgs
parents: 85
diff changeset
   166
        iSrvManager = CCaSrvManager::NewL( *iStorageProxy, iSrvEngUtils );
hgs
parents: 85
diff changeset
   167
        }
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   168
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   169
7feec50967db 201003_02
hgs
parents:
diff changeset
   170
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   171
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   172
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   173
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   174
CSession2* CCaSrv::NewSessionL( const TVersion& aVersion,
7feec50967db 201003_02
hgs
parents:
diff changeset
   175
        const RMessage2& /*aMessage*/) const
7feec50967db 201003_02
hgs
parents:
diff changeset
   176
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   177
    TVersion version( KCaMajorVersion, KCaMinorVersion, KCaBuild );
7feec50967db 201003_02
hgs
parents:
diff changeset
   178
    if( !User::QueryVersionSupported( version, aVersion ) )
7feec50967db 201003_02
hgs
parents:
diff changeset
   179
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   180
        User::Leave( KErrNotSupported );
7feec50967db 201003_02
hgs
parents:
diff changeset
   181
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   182
    CSession2* session;
7feec50967db 201003_02
hgs
parents:
diff changeset
   183
    session = CCaSrvSession::NewL( const_cast<CCaSrv&> ( *this ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
   184
    return session;
7feec50967db 201003_02
hgs
parents:
diff changeset
   185
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   186
7feec50967db 201003_02
hgs
parents:
diff changeset
   187
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   188
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   189
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   190
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   191
void CCaSrv::IncreaseSessionCount()
7feec50967db 201003_02
hgs
parents:
diff changeset
   192
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   193
    iSessionCount++;
7feec50967db 201003_02
hgs
parents:
diff changeset
   194
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   195
7feec50967db 201003_02
hgs
parents:
diff changeset
   196
// ---------------------------------------------------------
86
hgs
parents: 85
diff changeset
   197
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
   198
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   199
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   200
void CCaSrv::DecreaseSessionCount()
7feec50967db 201003_02
hgs
parents:
diff changeset
   201
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   202
    iSessionCount--;
7feec50967db 201003_02
hgs
parents:
diff changeset
   203
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   204
7feec50967db 201003_02
hgs
parents:
diff changeset
   205
//  End of File