|
1 /* |
|
2 * Copyright (c) 2005-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: Object locking features* |
|
15 */ |
|
16 |
|
17 #ifndef __MDSOBJECTLOCKLIST_H__ |
|
18 #define __MDSOBJECTLOCKLIST_H__ |
|
19 |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "mdscommoninternal.h" |
|
23 |
|
24 class TMdSLockEntry; |
|
25 class CMdSServerSession; |
|
26 class CMdsNamespaceDef; |
|
27 |
|
28 /** |
|
29 * Metadata object locking. |
|
30 * When opening objects for modifications, objects |
|
31 * is locked so that no other session can modify the |
|
32 * same object at same time. |
|
33 */ |
|
34 class CMdSObjectLockList : public CBase |
|
35 { |
|
36 public: // Constructors and destructor |
|
37 |
|
38 virtual ~CMdSObjectLockList(); |
|
39 |
|
40 static CMdSObjectLockList* NewL(); |
|
41 static CMdSObjectLockList* NewLC(); |
|
42 |
|
43 private: // Private constructors |
|
44 |
|
45 void ConstructL(); |
|
46 |
|
47 public: // Public functions |
|
48 /** |
|
49 * Locks object for modifying. |
|
50 * @param aSession Session where object is being modified. |
|
51 * @param aNamespace Object's owner namespace |
|
52 * @param aObjId Object id that is being modified. |
|
53 * @return Returns whether object could be locked or not. |
|
54 */ |
|
55 void LockObjectL( const CMdSServerSession& aSession, |
|
56 const CMdsNamespaceDef& aNamespace, const TItemId aObjectId ); |
|
57 |
|
58 /** |
|
59 * Unlocks all locked objects of particular session. |
|
60 * @param aSession Session which locked objects are to be released. |
|
61 */ |
|
62 void UnlockBySession( const CMdSServerSession& aSession ); |
|
63 |
|
64 /** |
|
65 * Unlocks locked object by Id. |
|
66 * @param aNamespace Object's owner namespace |
|
67 * @param aObjId Object id that is being modified. |
|
68 */ |
|
69 void UnlockById( const CMdsNamespaceDef& aNamespace, |
|
70 const TItemId aObjectId ); |
|
71 |
|
72 /** |
|
73 * Checks if object is locked for modifying. |
|
74 * @param aNamespace Object's owner namespace |
|
75 * @param aObjId An objects id which is going to be checked. |
|
76 * @return <code>ETrue</code> if locked. |
|
77 * <code>EFalse</code> if not. |
|
78 */ |
|
79 TBool IsLocked( const CMdsNamespaceDef& aNamespace, |
|
80 const TItemId aObjectId ) const; |
|
81 |
|
82 /** |
|
83 * Empties the object lock list. |
|
84 */ |
|
85 void Reset(); |
|
86 |
|
87 protected: |
|
88 TInt Find( const CMdsNamespaceDef& aNamespace, |
|
89 const TItemId aObjectId ) const; |
|
90 |
|
91 private: |
|
92 /** |
|
93 * Array which have the locked objects. |
|
94 */ |
|
95 RArray<TMdSLockEntry> iLockListArray; |
|
96 }; |
|
97 |
|
98 /** |
|
99 * Internal data structure for storing information about locked objects. |
|
100 */ |
|
101 class TMdSLockEntry |
|
102 { |
|
103 public: |
|
104 /** |
|
105 * Constructs a new lock list object. |
|
106 * |
|
107 * @param aSession session to which object id belongs |
|
108 * @param aNamespace Object's owner namespace |
|
109 * @param aId object id being modified |
|
110 */ |
|
111 TMdSLockEntry( const CMdSServerSession* aSession, |
|
112 const CMdsNamespaceDef& aNamespace, const TItemId aId ) |
|
113 : iSession( aSession ) , iNamespace( aNamespace ), iId( aId ) |
|
114 {} |
|
115 |
|
116 static TInt Compare( const TMdSLockEntry& aFirst, |
|
117 const TMdSLockEntry& aSecond ); |
|
118 public: |
|
119 /* Session where object is being modified */ |
|
120 const CMdSServerSession* iSession; |
|
121 |
|
122 /* Object's owner namespace */ |
|
123 const CMdsNamespaceDef& iNamespace; |
|
124 |
|
125 /* Object's id which is being modified */ |
|
126 TItemId iId; |
|
127 }; |
|
128 |
|
129 #endif // __MDSOBJECTLOCKLIST_H__ |