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 <fbs.h> |
|
18 |
|
19 #include "afserver.h" |
|
20 #include "afsession.h" |
|
21 #include "afstorage.h" |
|
22 #include "aftask.h" |
|
23 |
|
24 _LIT( KActivityServerName, "hsactivitydbserver" ); |
|
25 _LIT(KObserverAlreadyExists, "Observer task exists"); |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 /** |
|
29 * Constructor for performing 1st stage construction |
|
30 */ |
|
31 CAfServer::CAfServer() |
|
32 : |
|
33 CServer2( EPriorityStandard ) |
|
34 { |
|
35 // No implementation required |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 /** |
|
40 * Destructor. |
|
41 */ |
|
42 CAfServer::~CAfServer() |
|
43 { |
|
44 delete mStorage; |
|
45 mFsSession.Close(); |
|
46 mObservers.ResetAndDestroy(); |
|
47 RFbsSession::Disconnect(); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 /** |
|
52 * Two-phased constructor. |
|
53 */ |
|
54 CAfServer* CAfServer::NewLC() |
|
55 { |
|
56 CAfServer* self = new (ELeave) CAfServer(); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 /** |
|
64 * Default constructor for performing 2nd stage construction |
|
65 */ |
|
66 void CAfServer::ConstructL() |
|
67 { |
|
68 StartL(KActivityServerName); |
|
69 User::LeaveIfError(mFsSession.Connect()); |
|
70 User::LeaveIfError(RFbsSession::Connect(mFsSession)); |
|
71 mStorage = CAfStorage::NewL(mFsSession); |
|
72 mObservers.Array(); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 /** |
|
77 * Interface implementation |
|
78 * @see CServer2::NewSessionL(const TVersion&, const RMessage2&) |
|
79 */ |
|
80 CSession2* CAfServer::NewSessionL(const TVersion &, const RMessage2&) const |
|
81 { |
|
82 return CAfSession::NewL(const_cast<CAfServer*>(this)->mFsSession, |
|
83 *const_cast<CAfServer*>(this), |
|
84 *mStorage); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 /** |
|
89 * Interface implementation |
|
90 * @see MAfTaskStorage::PushL(CAfTask *) |
|
91 */ |
|
92 void CAfServer::PushL(CAfTask * task) |
|
93 { |
|
94 (KErrNotFound == mObservers.Find(task)) ? |
|
95 mObservers.AppendL(task) : |
|
96 User::Panic(KObserverAlreadyExists, KErrAlreadyExists); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 /** |
|
101 * Interface implementation |
|
102 * @see MAfTaskStorage::Pop(CActivityTask *) |
|
103 */ |
|
104 void CAfServer::Pop(CAfTask *task) |
|
105 { |
|
106 const TInt offset(mObservers.Find(task)); |
|
107 if (KErrNotFound != offset) { |
|
108 mObservers.Remove(offset); |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 /** |
|
114 * Interface implementation |
|
115 * @see MAfTaskStorage::StorageData() |
|
116 */ |
|
117 const RPointerArray<CAfTask>& CAfServer::StorageData() const |
|
118 { |
|
119 return mObservers; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 /** |
|
124 * Removes not valid task |
|
125 */ |
|
126 void CAfServer::RemoveNotValidTasks(const CSession2* session) |
|
127 { |
|
128 for (TInt i=mObservers.Count()-1; i>=0; --i) { |
|
129 if( mObservers[i]->IsSessionTask(session) ) { |
|
130 delete mObservers[i]; |
|
131 mObservers.Remove(i); |
|
132 } |
|
133 } |
|
134 } |
|