1 /*
2 SDL - Simple DirectMedia Layer
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18
19 */
20
21 #include"appsrv.h"
22 #include"sdlenvdata.h"
23 #include<sdl.h>
24
25 extern EpocSdlEnvData* gEpocEnv;
26 extern void VideoUpdate();
27
28
CSdlAppServ()29 CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id())
30 {
31 }
32
33
Observer()34 MSDLObserver* CSdlAppServ::Observer()
35 {
36 return iObserver;
37 }
38
39
SetObserver(MSDLObserver * aObserver)40 void CSdlAppServ::SetObserver(MSDLObserver* aObserver)
41 {
42 iObserver = aObserver;
43 }
44
ObserverEvent(TInt aEvent,TInt aParam)45 TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam)
46 {
47 if(iObserver != NULL)
48 {
49 if(RThread().Id() == iMainId)
50 {
51 return iObserver->SdlEvent(aEvent, aParam);
52 }
53 else if(RThread().Id() == gEpocEnv->iId && EnvUtils::IsOwnThreaded())
54 {
55 return iObserver->SdlThreadEvent(aEvent, aParam);
56 }
57 else
58 {
59 TWsEvent event;
60 event.SetType(ESDLWsEvent);
61 TInt load[] = {aEvent, aParam};
62 Mem::Copy(event.EventData(), load, sizeof(TInt) * 2);
63 event.SetTimeNow();
64 EpocSdlEnv::EventQueue().Append(event);
65 }
66 }
67 return 0;
68 }
69
PanicMain(TInt aReason)70 void CSdlAppServ::PanicMain(TInt aReason)
71 {
72 iAppThread.Panic(RThread().Name(), aReason);
73 }
74
PanicMain(const TDesC & aInfo,TInt aReason)75 void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason)
76 {
77 iAppThread.Panic(aInfo, aReason);
78 }
79
ConstructL()80 void CSdlAppServ::ConstructL()
81 {
82 CActiveScheduler::Add(this);
83 if(EnvUtils::IsOwnThreaded())
84 User::LeaveIfError(iSema.CreateLocal(1));
85 // iStatus = KRequestPending;
86 // iStatusPtr = &iStatus;
87 // SetActive();
88 }
89
~CSdlAppServ()90 CSdlAppServ::~CSdlAppServ()
91 {
92 Cancel();
93 if(iSema.Handle() != NULL)
94 iSema.Signal();
95 iSema.Close();
96 iAppThread.Close();
97 }
98
Request(TInt aService)99 TInt CSdlAppServ::Request(TInt aService)
100 {
101 if(EnvUtils::IsOwnThreaded())
102 {
103 if(RThread().Id() == iAppThread.Id())
104 return KErrBadHandle;
105 iSema.Wait();
106 }
107
108 // if(iStatusPtr == NULL && !IsActive()) //this is a bit suspicious :-)
109 // SetActive();
110
111 // while(EnvUtils::RunSingleThread() && iStatusPtr == NULL) //has to be in this order for side effects
112 // {}
113
114 while(EnvUtils::RunSingleThread() && IsActive())
115 {
116 }
117
118 if(iService == aService && IsActive())
119 {
120 Cancel();
121 return KErrAlreadyExists;
122 }
123
124 __ASSERT_ALWAYS(!IsActive(), PANIC(KErrNotReady));
125
126 iService = aService;
127
128 iStatus = KRequestPending;
129 iStatusPtr = &iStatus;
130 SetActive();
131
132
133 // __ASSERT_ALWAYS(iStatusPtr != NULL, PANIC(KErrNotReady));
134 iAppThread.RequestComplete(iStatusPtr, KErrNone);
135
136 return KErrNone;
137 }
138
RequestValue(TInt aService)139 TInt CSdlAppServ::RequestValue(TInt aService)
140 {
141 Request(aService);
142 Request(EAppSrvNoop);
143 return iReturnValue;
144 }
145
Init()146 void CSdlAppServ::Init()
147 {
148 PANIC_IF_ERROR(iAppThread.Open(iMainId));
149 }
150
SetParam(TInt aParam)151 void CSdlAppServ::SetParam(TInt aParam)
152 {
153 iReturnValue = aParam;
154 }
155
HandleObserverValue(TInt aService,TInt aReturnValue,TBool aMainThread)156 void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread)
157 {
158 if(iObserver != NULL && aMainThread)
159 {
160 switch(aService)
161 {
162 case MSDLObserver::EEventScreenSizeChanged:
163 /* if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette)
164 EpocSdlEnv::LockPalette(EFalse);*/
165 //EpocSdlEnv::ScreenSizeChanged();
166 break;
167 }
168 }
169 /*if(!aMainThread && aService == MSDLObserver::EEventSuspend)
170 {
171 *if(iObserver == NULL ||
172 (gEpocEnv->iDsa != NULL
173 && gEpocEnv->iDsa->Stopped() &&
174 aReturnValue != MSDLObserver::ESuspendNoSuspend))
175 //{
176 EpocSdlEnv::DoSuspend();
177 // }
178 }*/
179 }
180
RunL()181 void CSdlAppServ::RunL()
182 {
183 if(iStatus == KErrNone)
184 {
185 switch(iService)
186 {
187 case CSdlAppServ::EAppSrvWaitDsa:
188 //EpocSdlEnv::SetWaitDsa();
189 iReturnValue = EpocSdlEnv::IsDsaAvailable();
190 break;
191 /* case CSdlAppServ::EAppSrvStopThread:
192 if(gEpocEnv->iDsa != NULL)
193 gEpocEnv->iDsa->SetSuspend();
194 break;*/
195 case EpocSdlEnv::EDisableKeyBlocking:
196 EnvUtils::DisableKeyBlocking();
197 break;
198
199 case EpocSdlEnv::ESetAppOrientation:
200 iReturnValue = EnvUtils::SetAppOrientation(static_cast<CSDL::TAppOrientation>(iReturnValue));
201 break;
202
203
204 case EAppSrvWindowPointerCursorMode:
205 iReturnValue = gEpocEnv->iDsa != NULL ?
206 gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady;
207 break;
208
209 case EAppSrvDsaStatus:
210 if(gEpocEnv->iDsa != NULL)
211 gEpocEnv->iDsa->Stop();
212 iReturnValue = KErrNone;
213 break;
214 case CDsa::ERequestUpdate:
215 gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete();
216 break;
217 case EVideoUpdate:
218 VideoUpdate();
219 break;
220 case EAppSrvNoop:
221 break;
222 case MSDLObserver::EEventResume:
223 case MSDLObserver::EEventSuspend:
224 case MSDLObserver::EEventScreenSizeChanged:
225 case MSDLObserver::EEventWindowReserved:
226 case MSDLObserver::EEventKeyMapInit:
227 case MSDLObserver::EEventWindowNotAvailable:
228 case MSDLObserver::EEventMainExit:
229 case MSDLObserver::EEventVolumeChange:
230 case MSDLObserver::EEventScreenSurfaceCreated:
231 iReturnValue = ObserverEvent(iService, iReturnValue);
232 HandleObserverValue(iService, iReturnValue, ETrue);
233 break;
234 default:
235 PANIC(KErrNotSupported);
236 }
237 /*
238 iStatus = KRequestPending;
239 iStatusPtr = &iStatus;
240 SetActive();
241 */
242 }
243 if(EnvUtils::IsOwnThreaded())
244 iSema.Signal();
245 }
246
DoCancel()247 void CSdlAppServ::DoCancel()
248 {
249 if(EnvUtils::IsOwnThreaded())
250 iSema.Wait();
251 TRequestStatus* s = &iStatus;
252 iAppThread.RequestComplete(s, KErrCancel);
253 }
254
255
256
257