|
1 /* |
|
2 * Copyright (c) 2006 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: RLS and Presence XDM, This class represents sphere in a |
|
15 * Presence Condition |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // Includes |
|
23 #include <XdmDocumentNode.h> |
|
24 #include <XdmNodeAttribute.h> |
|
25 #include <xcapappusagedef.h> |
|
26 #include <utf.h> |
|
27 |
|
28 #include "prescondsphere.h" |
|
29 #include "cpresencexdm.h" |
|
30 #include "rlspresxdmlogger.h" |
|
31 #include "rlspresxdmconstsint.h" |
|
32 |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // TPresCondSphere::TPresCondSphere() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C TPresCondSphere::TPresCondSphere(): iPresXDM(NULL) |
|
39 { |
|
40 OPENG_DP(D_OPENG_LIT( "TPresCondSphere::TPresCondSphere()" )); |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // TPresCondSphere::Init() |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 EXPORT_C void TPresCondSphere::Init(CPresenceXDM* const aPresXDM) |
|
48 { |
|
49 OPENG_DP(D_OPENG_LIT( "TPresCondSphere::Init(%d)" ), aPresXDM); |
|
50 iPresXDM = aPresXDM; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // TPresCondSphere::AddOrReplaceSphereL() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C TInt TPresCondSphere::AddOrReplaceSphereL(const TDesC& aRuleID, |
|
58 const TDesC& aSphere) |
|
59 { |
|
60 OPENG_DP(D_OPENG_LIT( "TPresCondSphere::AddOrReplaceSphereL()" ) ); |
|
61 OPENG_DP(D_OPENG_LIT( " aRuleID = %S, aSphere = %S"),&aRuleID, &aSphere); |
|
62 |
|
63 CXdmDocumentNode* sphereNode = GetSphereNodeL(aRuleID, ETrue); |
|
64 if(sphereNode==NULL) |
|
65 return KErrNotFound; |
|
66 |
|
67 CXdmNodeAttribute* valueAttr(NULL); |
|
68 valueAttr = sphereNode->Attribute(KXdmValue); |
|
69 // if Value attribute is not found |
|
70 if (valueAttr==NULL) |
|
71 { |
|
72 valueAttr = sphereNode->CreateAttributeL(KXdmValue); |
|
73 } |
|
74 |
|
75 valueAttr->SetAttributeValueL(aSphere); |
|
76 return KErrNone; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // TPresCondSphere::GetSphereL() |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C TInt TPresCondSphere::GetSphereL(const TDesC& aRuleID, |
|
84 TPtrC& aSphere) |
|
85 { |
|
86 OPENG_DP(D_OPENG_LIT( "TPresCondSphere::GetSphere()" ) ); |
|
87 OPENG_DP(D_OPENG_LIT( " aRuleID = %S"),&aRuleID); |
|
88 |
|
89 CXdmDocumentNode* sphereNode = GetSphereNodeL(aRuleID, EFalse); |
|
90 if(sphereNode==NULL) |
|
91 return KErrNotFound; |
|
92 |
|
93 CXdmNodeAttribute* valueAttr = sphereNode->Attribute(KXdmValue); |
|
94 |
|
95 if(valueAttr) |
|
96 { |
|
97 aSphere.Set(valueAttr->AttributeValue()); |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 return KErrNotFound; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // TPresCondSphere::DeleteSphereL() |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C TInt TPresCondSphere::DeleteSphereL(const TDesC& aRuleID) |
|
109 { |
|
110 OPENG_DP(D_OPENG_LIT( "TPresCondSphere::DeleteSphereL()" ) ); |
|
111 OPENG_DP(D_OPENG_LIT( " aRuleID = %S"),&aRuleID); |
|
112 |
|
113 __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady)); |
|
114 |
|
115 CXdmDocumentNode* sphereNode = GetSphereNodeL(aRuleID, EFalse); |
|
116 if(sphereNode==NULL) |
|
117 return KErrNotFound; |
|
118 |
|
119 iPresXDM->RemoveFromModelL(sphereNode); |
|
120 |
|
121 OPENG_DP(D_OPENG_LIT( " removed")); |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // TPresCondSphere::GetSphereNode() |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 CXdmDocumentNode* TPresCondSphere::GetSphereNodeL(const TDesC& aRuleID, |
|
130 TBool aCreate) |
|
131 { |
|
132 OPENG_DP(D_OPENG_LIT( " TPresCondSphere::GetSphereNodeL()" ) ); |
|
133 OPENG_DP(D_OPENG_LIT( " GetSphereNodeL aRuleID = %S, aCreate = %d"), |
|
134 &aRuleID, aCreate); |
|
135 |
|
136 __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady)); |
|
137 |
|
138 CXdmDocumentNode* conditionNode = iPresXDM->GetRuleChildNodeL(aRuleID, |
|
139 KXdmConditions, aCreate); |
|
140 if (conditionNode==NULL) |
|
141 return conditionNode; |
|
142 |
|
143 RPointerArray<CXdmDocumentNode> nodes; |
|
144 CXdmDocumentNode* sphereNode(NULL); |
|
145 |
|
146 // Finding sphere node |
|
147 conditionNode->Find(KXdmSphere, nodes); |
|
148 OPENG_DP(D_OPENG_LIT( " GetSphereNodeL nodeCount = %d"),nodes.Count()); |
|
149 if(nodes.Count()) // if identity node exist |
|
150 { |
|
151 sphereNode = nodes[0]; // only one sphere node can exist |
|
152 } |
|
153 else if (aCreate) // if asked to create |
|
154 { |
|
155 sphereNode = conditionNode->CreateChileNodeL(KXdmSphere); |
|
156 } |
|
157 |
|
158 nodes.Close(); |
|
159 return sphereNode; |
|
160 } |
|
161 |
|
162 // end of file |
|
163 |