activityfw/activitydatabase/hsactivitydbserver/src/activityserver.cpp
branchGCC_SURGE
changeset 105 e7325f632549
parent 81 5ef31a21fdd5
parent 104 9b022b1f357c
equal deleted inserted replaced
81:5ef31a21fdd5 105:e7325f632549
     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 "activityserver.h"
       
    18 #include "activitysession.h"
       
    19 #include "activitystorage.h"
       
    20 #include "activitytask.h"
       
    21 
       
    22 #include <fbs.h>
       
    23 
       
    24 _LIT( KActivityServerName, "hsactivitydbserver" );
       
    25 _LIT(KObserverAlreadyExists, "Observer task exists");
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CActivityServer::CActivityServer()
       
    32 :
       
    33 CServer2( EPriorityStandard )
       
    34 {
       
    35     // No implementation required
       
    36 }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CActivityServer::~CActivityServer()
       
    43 {
       
    44     delete mStorage;
       
    45     mFsSession.Close();
       
    46     mObservers.ResetAndDestroy();
       
    47     RFbsSession::Disconnect();
       
    48 }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CActivityServer* CActivityServer::NewLC()
       
    55 {
       
    56     CActivityServer* self = new (ELeave) CActivityServer();
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     return self;
       
    60 }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CActivityServer::ConstructL()
       
    67 {
       
    68     StartL(KActivityServerName);
       
    69     User::LeaveIfError(mFsSession.Connect());
       
    70     User::LeaveIfError(RFbsSession::Connect(mFsSession));
       
    71     mStorage = CActivityStorage::NewL(mFsSession);
       
    72     mObservers.Array();
       
    73 }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CSession2* CActivityServer::NewSessionL(const TVersion &, const RMessage2&) const
       
    80 {
       
    81     return CActivitySession::NewL(const_cast<CActivityServer*>(this)->mFsSession, 
       
    82                                   *const_cast<CActivityServer*>(this), 
       
    83                                   *mStorage);
       
    84 }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CActivityServer::PushL(CActivityTask * task)
       
    91 {
       
    92     (KErrNotFound == mObservers.Find(task)) ?
       
    93      mObservers.AppendL(task) :
       
    94      User::Panic(KObserverAlreadyExists, KErrAlreadyExists);
       
    95 }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CActivityServer::Pop(CActivityTask *task)
       
   102 {
       
   103     const TInt offset(mObservers.Find(task));
       
   104     if (KErrNotFound != offset) {
       
   105         mObservers.Remove(offset);
       
   106     }
       
   107 }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 const RPointerArray<CActivityTask>& CActivityServer::StorageData() const
       
   114 {
       
   115     return mObservers;
       
   116 }