📄 contextnotifysession.cpp
字号:
/*
002 Copyright (C) 2004 Mika Raento - Renaud Petit
003
004 This program is free software; you can redistribute it and/or modify
005 it under the terms of the GNU General Public License as published by
006 the Free Software Foundation; either version 2 of the License, or
007 (at your option) any later version.
008
009 This program is distributed in the hope that it will be useful,
010 but WITHOUT ANY WARRANTY; without even the implied warranty of
011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 GNU General Public License for more details.
013
014 You should have received a copy of the GNU General Public License
015 along with this program; if not, write to the Free Software
016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017
018
019 email: mraento@cs.helsinki.fi - petit@cs.helsinki.fi
020 */
021
022
023 //CContextNotifySession.cpp
024
025 #include "ContextNotifySession.h"
026 #include "NotifyCommon.h"
027 #include <e32svr.h>
028 #include <flogger.h>
029 #include "symbian_auto_ptr.h"
030
031 bool ClientAlive(TInt ThreadId)
032 {
033 if (ThreadId==0) return false;
034
035 RThread c; bool ret = false;
036 if (c.Open(ThreadId) != KErrNone) return false;
037 if (c.ExitType() == EExitPending) ret=true;
038 c.Close();
039 return ret;
040 }
041
042
043 CContextNotifySession::CContextNotifySession(RThread& aClient, CContextNotify& aServer) : CSession(aClient), iServer(aServer)
044 {
045
046 }
047
048 CContextNotifySession::~CContextNotifySession()
049 {
050 if (iIds) {
051 CList<TInt>::Node* n;
052 for (n=iIds->iFirst; n; n=n->Next) {
053 iServer.RemoveIcon(n->Item);
054 }
055 }
056 delete iIds;
057 iServer.DecrementSessions();
058 }
059
060 void CContextNotifySession::CompleteMessage(TInt Code)
061 {
062 if (ClientAlive(iMessageThreadId)) {
063 iMessage.Complete(Code);
064 }
065 SetMessage(RMessage());
066 }
067
068 void CContextNotifySession::ServiceL(const RMessage& aMessage)
069 {
070 if (aMessage.Function()!=ECancel) SetMessage(aMessage);
071
072 switch (aMessage.Function())
073 {
074 case ETerminateContextNotify:
075 CompleteMessage(ERequestCompleted);
076 iServer.TerminateContextNotify();
077 break;
078
079 case EAddIcon:
080 AddIcon();
081 break;
082 case ERemoveIcon:
083 RemoveIcon();
084 break;
085 case EChangeIcon:
086 ChangeIcon();
087 break;
088 case ECancel:
089 {
090 RMessage prev=iMessage;
091 CompleteMessage(KErrCancel);
092 iServer.CancelRequest(prev);
093 aMessage.Complete(0);
094 break;
095 }
096
097 default :
098 PanicClient(EBadRequest);
099 }
100
101 }
102
103 void CContextNotifySession::AddIcon()
104 {
105 TInt handle, mask, id=-1;
106 handle=(TInt)iMessage.Ptr0();
107 mask=(TInt)iMessage.Ptr1();
108 TInt err;
109 TRAP(err, id=iServer.AddIconL(handle, mask));
110 if (err==KErrNone) {
111 TPckgC<TInt> idp(id);
112 TRAP(err, iMessage.WriteL(iMessage.Ptr2(), idp, 0));
113 }
114 if (err==KErrNone) {
115 TRAP(err, iIds->AppendL(id));
116 }
117 if (err!=KErrNone) {
118 iServer.RemoveIcon(id);
119 }
120 CompleteMessage(err);
121 }
122
123 void CContextNotifySession::RemoveIcon()
124 {
125 TInt id;
126 id=(TInt)iMessage.Ptr0();
127 iServer.RemoveIcon(id);
128 CompleteMessage(KErrNone);
129 }
130
131 void CContextNotifySession::ChangeIcon()
132 {
133 TInt handle, mask, id;
134 id=(TInt)iMessage.Ptr2();
135 handle=(TInt)iMessage.Ptr0();
136 mask=(TInt)iMessage.Ptr1();
137 TRAPD(err, iServer.ChangeIconL(id, handle, mask));
138 CompleteMessage(err);
139 }
140
141 void CContextNotifySession::PanicClient(TInt aPanic) const
142 {
143 Panic(KContextNotify, aPanic) ; // Note: this panics the client thread, not server
144 }
145
146 CContextNotifySession* CContextNotifySession::NewL(RThread& aClient, CContextNotify& aServer)
147 {
148 CContextNotifySession* self = CContextNotifySession::NewLC(aClient, aServer) ;
149 CleanupStack::Pop(self) ;
150 return self ;
151 }
152
153 CContextNotifySession* CContextNotifySession::NewLC(RThread& aClient, CContextNotify& aServer)
154 {
155 CContextNotifySession* self = new (ELeave) CContextNotifySession(aClient, aServer);
156 CleanupStack::PushL(self) ;
157 self->ConstructL() ;
158 return self ;
159 }
160
161 void CContextNotifySession::ConstructL()
162 {
163 iIds=CList<TInt>::NewL();
164 iServer.IncrementSessions();
165 }
166
167 //------------------------------------------------------------------------
168
169 void CContextNotifySession::TerminateContextNotify(const RMessage& /*aMessage*/)
170 {
171 CompleteMessage(ERequestCompleted);
172 iServer.TerminateContextNotify();
173 }
174
175 void CContextNotifySession::SetMessage(const RMessage& aMessage)
176 {
177 if (aMessage==RMessage()) {
178 iMessageThreadId=0;
179 } else {
180 iMessageThreadId=aMessage.Client().Id();
181 }
182 iMessage=aMessage;
183 }
184
185 void CContextNotifySession::NotifyEvent(CContextNotify::TEvent aEvent)
186 {
187 if (!ClientAlive(iMessageThreadId)) return;
188
189 if (aEvent==CContextNotify::ETerminated) {
190 CompleteMessage(EContextNotifyTerminated);
191 }
192 }
193
194 void CContextNotifySession::ReportError(TContextNotifyRqstComplete aErrorType,
195 TDesC & /*aErrorCode*/, TDesC & /*aErrorValue*/)
196 {
197 CompleteMessage(aErrorType);
198 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -