36 |
36 |
37 |
37 |
38 using namespace Messages; |
38 using namespace Messages; |
39 using namespace ESock; |
39 using namespace ESock; |
40 |
40 |
|
41 CMCPrPubSubSubscriber* CMCPrPubSubSubscriber::NewL(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
|
42 { |
|
43 CMCPrPubSubSubscriber* self = new (ELeave) CMCPrPubSubSubscriber(aProvBase,aStopCode); |
|
44 CleanupStack::PushL(self); |
|
45 self->StartL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
41 CMCPrPubSubSubscriber::CMCPrPubSubSubscriber(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
50 CMCPrPubSubSubscriber::CMCPrPubSubSubscriber(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
42 : CActive(EPriorityNormal), |
51 : CActive(EPriorityNormal), |
43 iNode(aProvBase), |
52 iNode(aProvBase), |
44 iStopCode(aStopCode) |
53 iStopCode(aStopCode) |
45 { |
54 { |
46 } |
55 } |
47 |
56 |
|
57 void CMCPrPubSubSubscriber::StartAvailabilityMonitoringL(const Messages::TNodeCtxId& aAvailabilityActivity) |
|
58 { |
|
59 iAvailabilityActivity = aAvailabilityActivity; |
|
60 TInt score = TAvailabilityStatus::EUnknownAvailabilityScore; |
|
61 |
|
62 TInt result = iProperty.Attach(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId()); |
|
63 if(result != KErrNone) |
|
64 { |
|
65 User::LeaveIfError(iProperty.Define(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId(), RProperty::EInt)); |
|
66 User::LeaveIfError(iProperty.Attach(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId())); |
|
67 } |
|
68 |
|
69 iProperty.Subscribe(iStatus); |
|
70 SetActive(); |
|
71 iProperty.Get(score); //If Get() is unsuccessful score must not be modified! |
|
72 |
|
73 if (score != TAvailabilityStatus::EUnknownAvailabilityScore) |
|
74 { |
|
75 //Send the intial availability status. |
|
76 TAvailabilityStatus status(score); |
|
77 RClientInterface::OpenPostMessageClose(NodeId(), iAvailabilityActivity, |
|
78 TCFAvailabilityControlClient::TAvailabilityNotification(status).CRef()); |
|
79 } |
|
80 } |
|
81 |
|
82 void CMCPrPubSubSubscriber::CancelAvailabilityMonitoring() |
|
83 { |
|
84 iAvailabilityActivity = Messages::TNodeCtxId::NullId(); |
|
85 } |
48 |
86 |
49 void CMCPrPubSubSubscriber::StartL() |
87 void CMCPrPubSubSubscriber::StartL() |
50 { |
88 { |
51 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubSubscriber::StartL"))); |
89 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubSubscriber::StartL"))); |
52 CActiveScheduler::Add(this); |
90 CActiveScheduler::Add(this); |
|
91 } |
|
92 |
|
93 void CMCPrPubSubSubscriber::RunL() |
|
94 { |
|
95 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubSubscriber::RunL"))); |
|
96 User::LeaveIfError(iStatus.Int()); |
|
97 |
|
98 // resubscribe immediately |
|
99 iProperty.Subscribe(iStatus); |
|
100 SetActive(); |
|
101 |
|
102 // then process |
|
103 TInt value; |
|
104 User::LeaveIfError(iProperty.Get(value)); |
|
105 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubSubscriber subscribed value now %d"),value)); |
|
106 |
|
107 ASSERT(!iAvailabilityActivity.IsNull()); //maybe a bit defensive, but this is test code after all. The test changes availability when nobody is listenning; Surely test is wrong? |
|
108 RClientInterface::OpenPostMessageClose(Id(), iAvailabilityActivity, |
|
109 TCFAvailabilityControlClient::TAvailabilityNotification(value).CRef()); |
53 } |
110 } |
54 |
111 |
55 TInt CMCPrPubSubSubscriber::RunError(TInt /*aError*/) |
112 TInt CMCPrPubSubSubscriber::RunError(TInt /*aError*/) |
56 { |
113 { |
57 //path uncovered. |
114 //path uncovered. |
67 /*virtual*/ CMCPrPubSubSubscriber::~CMCPrPubSubSubscriber() |
124 /*virtual*/ CMCPrPubSubSubscriber::~CMCPrPubSubSubscriber() |
68 { |
125 { |
69 this->Cancel(); // object must be stoppable by destcruction due to cleanup restrictions |
126 this->Cancel(); // object must be stoppable by destcruction due to cleanup restrictions |
70 iProperty.Close(); |
127 iProperty.Close(); |
71 } |
128 } |
72 |
|
73 // |
|
74 |
|
75 CMCPrPubSubAvailability* CMCPrPubSubAvailability::NewL(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
|
76 { |
|
77 CMCPrPubSubAvailability* self = new (ELeave) CMCPrPubSubAvailability(aProvBase,aStopCode); |
|
78 CleanupStack::PushL(self); |
|
79 self->StartL(); |
|
80 CleanupStack::Pop(self); |
|
81 return self; |
|
82 } |
|
83 |
|
84 CMCPrPubSubAvailability::CMCPrPubSubAvailability(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
|
85 : CMCPrPubSubSubscriber(aProvBase,aStopCode) |
|
86 { |
|
87 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubAvailability ctor"))); |
|
88 } |
|
89 |
|
90 void CMCPrPubSubAvailability::StartAvailabilityMonitoringL(const Messages::TNodeCtxId& aAvailabilityActivity) |
|
91 { |
|
92 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubSubscriber::StartAvailabilityMonitoringL"))); |
|
93 |
|
94 iAvailabilityActivity = aAvailabilityActivity; |
|
95 TInt score = TAvailabilityStatus::EUnknownAvailabilityScore; |
|
96 |
|
97 TInt result = iProperty.Attach(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId()); |
|
98 if(result != KErrNone) |
|
99 { |
|
100 User::LeaveIfError(iProperty.Define(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId(), RProperty::EInt)); |
|
101 User::LeaveIfError(iProperty.Attach(TUid::Uid(EAvailabilityTestingPubSubUid), iNode.ProviderInfo().APId())); |
|
102 } |
|
103 |
|
104 iProperty.Subscribe(iStatus); |
|
105 SetActive(); |
|
106 iProperty.Get(score); //If Get() is unsuccessful score must not be modified! |
|
107 |
|
108 if (score != TAvailabilityStatus::EUnknownAvailabilityScore) |
|
109 { |
|
110 //Send the intial availability status. |
|
111 TAvailabilityStatus status(score); |
|
112 RClientInterface::OpenPostMessageClose(NodeId(), iAvailabilityActivity, |
|
113 TCFAvailabilityControlClient::TAvailabilityNotification(status).CRef()); |
|
114 } |
|
115 } |
|
116 |
|
117 void CMCPrPubSubAvailability::CancelAvailabilityMonitoring() |
|
118 { |
|
119 iAvailabilityActivity = Messages::TNodeCtxId::NullId(); |
|
120 } |
|
121 |
|
122 void CMCPrPubSubAvailability::RunL() |
|
123 { |
|
124 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubAvailability::RunL"))); |
|
125 User::LeaveIfError(iStatus.Int()); |
|
126 |
|
127 // resubscribe immediately |
|
128 iProperty.Subscribe(iStatus); |
|
129 SetActive(); |
|
130 |
|
131 // then process |
|
132 TInt value; |
|
133 User::LeaveIfError(iProperty.Get(value)); |
|
134 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubAvailability subscribed value now %d"),value)); |
|
135 |
|
136 __ASSERT_DEBUG(!iAvailabilityActivity.IsNull(), User::Panic(KSpecAssert_DummyPrStopSubsc, 1)); //maybe a bit defensive, but this is test code after all. The test changes availability when nobody is listenning; Surely test is wrong? |
|
137 RClientInterface::OpenPostMessageClose(Id(), iAvailabilityActivity, |
|
138 TCFAvailabilityControlClient::TAvailabilityNotification(value).CRef()); |
|
139 } |
|
140 |
|
141 // |
|
142 |
|
143 CMCPrPubSubStopTrigger* CMCPrPubSubStopTrigger::NewL(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
|
144 { |
|
145 CMCPrPubSubStopTrigger* self = new (ELeave) CMCPrPubSubStopTrigger(aProvBase,aStopCode); |
|
146 CleanupStack::PushL(self); |
|
147 self->StartL(); |
|
148 CleanupStack::Pop(self); |
|
149 return self; |
|
150 __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_DummyPrStopSubsc, 2)); |
|
151 |
|
152 } |
|
153 |
|
154 CMCPrPubSubStopTrigger::CMCPrPubSubStopTrigger(const ESock::CMetaConnectionProviderBase& aProvBase, TUint aStopCode) |
|
155 : CMCPrPubSubSubscriber(aProvBase,aStopCode), |
|
156 iNodeId(aProvBase.Id()) |
|
157 { |
|
158 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubStopTrigger ctor"))); |
|
159 } |
|
160 |
|
161 void |
|
162 CMCPrPubSubStopTrigger::StartL() |
|
163 { |
|
164 CMCPrPubSubSubscriber::StartL(); |
|
165 TInt result = iProperty.Attach(TUid::Uid(EStopTriggeringPubSubUid), 1); |
|
166 if(result != KErrNone) |
|
167 { |
|
168 User::LeaveIfError(iProperty.Define(TUid::Uid(EStopTriggeringPubSubUid), 1, RProperty::EInt)); |
|
169 User::LeaveIfError(iProperty.Attach(TUid::Uid(EStopTriggeringPubSubUid), 1)); |
|
170 } |
|
171 iProperty.Subscribe(iStatus); |
|
172 SetActive(); |
|
173 } |
|
174 |
|
175 void CMCPrPubSubStopTrigger::RunL() |
|
176 { |
|
177 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubStopTrigger::RunL"))); |
|
178 User::LeaveIfError(iStatus.Int()); |
|
179 |
|
180 // resubscribe immediately |
|
181 iProperty.Subscribe(iStatus); |
|
182 SetActive(); |
|
183 |
|
184 // then process |
|
185 TInt value; |
|
186 User::LeaveIfError(iProperty.Get(value)); |
|
187 __CFLOG_VAR((KDummyMCprTag, KDummyMCprSubTag, _L8("CMCPrPubSubStopTrigger subscribed value now %d"),value)); |
|
188 |
|
189 CMetaConnectionProviderBase* provider = const_cast<CMetaConnectionProviderBase*>(static_cast<const CMetaConnectionProviderBase*>(&iNode)); |
|
190 __ASSERT_DEBUG(provider, User::Panic(KSpecAssert_DummyPrStopSubsc, 3)); |
|
191 |
|
192 if(value==KStart) |
|
193 { |
|
194 if(iBlocking) |
|
195 { |
|
196 // Decrement semaphore to stop the provider from being destroyed once all of it's children have been stopped. |
|
197 provider->DecrementBlockingDestroy(); |
|
198 iBlocking = false; |
|
199 } |
|
200 |
|
201 TCFServiceProvider::TStart msg; |
|
202 RClientInterface::OpenPostMessageClose(iNodeId, iNodeId, msg); |
|
203 } |
|
204 else |
|
205 if((value==KBlockingStop || value==KStop) && iNode.ServiceProvider() != NULL) |
|
206 { |
|
207 if(!iBlocking && value==KBlockingStop) |
|
208 { |
|
209 // Increment semaphore to stop the provider from being destroyed once all of it's children have been stopped. |
|
210 provider->IncrementBlockingDestroy(); |
|
211 iBlocking = true; |
|
212 } |
|
213 |
|
214 TCFServiceProvider::TStop msg(iStopCode); |
|
215 RClientInterface::OpenPostMessageClose(iNodeId, iNodeId, msg); |
|
216 } |
|
217 } |
|
218 |
|