|
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: Object locking features |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mdsobjectlocklist.h" |
|
19 #include "mdsnamespacedef.h" |
|
20 |
|
21 CMdSObjectLockList* CMdSObjectLockList::NewL() |
|
22 { |
|
23 CMdSObjectLockList* self = CMdSObjectLockList::NewLC(); |
|
24 CleanupStack::Pop( self ); |
|
25 return self; |
|
26 } |
|
27 |
|
28 |
|
29 CMdSObjectLockList* CMdSObjectLockList::NewLC() |
|
30 { |
|
31 CMdSObjectLockList* self = new ( ELeave ) CMdSObjectLockList(); |
|
32 CleanupStack::PushL( self ); |
|
33 self->ConstructL(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 void CMdSObjectLockList::ConstructL() |
|
38 { |
|
39 iLockListArray.Reset(); |
|
40 } |
|
41 |
|
42 CMdSObjectLockList::~CMdSObjectLockList() |
|
43 { |
|
44 iLockListArray.Close(); |
|
45 } |
|
46 |
|
47 void CMdSObjectLockList::LockObjectL( const CMdSServerSession& aSession, |
|
48 const CMdsNamespaceDef& aNamespace, const TItemId aObjectId ) |
|
49 { |
|
50 User::LeaveIfError( iLockListArray.InsertInOrder( |
|
51 TMdSLockEntry( &aSession, aNamespace, aObjectId ), |
|
52 TLinearOrder<TMdSLockEntry>(TMdSLockEntry::Compare) ) ); |
|
53 } |
|
54 |
|
55 void CMdSObjectLockList::UnlockBySession( const CMdSServerSession& aSession ) |
|
56 { |
|
57 for (TInt i = iLockListArray.Count() - 1; i >= 0; --i) |
|
58 { |
|
59 if ( iLockListArray[i].iSession == &aSession ) // pointer comparision |
|
60 { |
|
61 iLockListArray.Remove(i); |
|
62 } |
|
63 } |
|
64 } |
|
65 |
|
66 void CMdSObjectLockList::UnlockById( const CMdsNamespaceDef& aNamespace, |
|
67 const TItemId aObjectId ) |
|
68 { |
|
69 TInt position = Find( aNamespace, aObjectId ); |
|
70 if (position >= 0) |
|
71 { |
|
72 iLockListArray.Remove(position); |
|
73 } |
|
74 |
|
75 } |
|
76 |
|
77 TBool CMdSObjectLockList::IsLocked( const CMdsNamespaceDef& aNamespace, |
|
78 const TItemId aObjectId ) const |
|
79 { |
|
80 const TInt position = Find( aNamespace, aObjectId ); |
|
81 if (position >= 0) |
|
82 { |
|
83 return ETrue; |
|
84 } |
|
85 return EFalse; |
|
86 } |
|
87 |
|
88 TInt CMdSObjectLockList::Find( const CMdsNamespaceDef& aNamespace, |
|
89 const TItemId aObjectId ) const |
|
90 { |
|
91 TInt position; |
|
92 TInt err = iLockListArray.FindInOrder( TMdSLockEntry( |
|
93 (const CMdSServerSession*)NULL, aNamespace, aObjectId ), |
|
94 position, TLinearOrder<TMdSLockEntry>(TMdSLockEntry::Compare) ); |
|
95 |
|
96 if (err != KErrNone) |
|
97 { |
|
98 position = -1; |
|
99 } |
|
100 return position; |
|
101 } |
|
102 |
|
103 void CMdSObjectLockList::Reset() |
|
104 { |
|
105 iLockListArray.Reset(); |
|
106 } |
|
107 |
|
108 TInt TMdSLockEntry::Compare( const TMdSLockEntry& aFirst, const |
|
109 TMdSLockEntry& aSecond ) |
|
110 { |
|
111 TInt result = aFirst.iNamespace.GetId() - aSecond.iNamespace.GetId(); |
|
112 if ( result ) |
|
113 { |
|
114 return result; |
|
115 } |
|
116 return aFirst.iId - aSecond.iId; |
|
117 } |