/*
SDL_Main.cpp
Symbian OS services for SDL
Markus Mertama
*/
#include "epoc_sdl.h"
#include"sdlepocapi.h"
#include <e32base.h>
#include <estlib.h>
#include <stdio.h>
#include <badesca.h>
#include "vectorbuffer.h"
#include <w32std.h>
#include <aknappui.h>
#include <aknapp.h>
#include "SDL_epocevents_c.h"
#include "SDL_keysym.h"
#include "dsa.h"
#ifdef SYMBIANC
#include <reent.h>
#endif
//Markus Mertama
extern SDLKey* KeyMap();
extern void ResetKeyMap();
class CCurrentAppUi;
//const TUid KSDLUid = { 0xF01F3D69 };
NONSHARABLE_CLASS(EnvUtils)
{
public:
static void DisableKeyBlocking();
static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus);
};
TInt Panic(TInt aErr, TInt aLine)
{
TBuf<64> b;
b.Format(_L("Main at %d"), aLine);
User::Panic(b, aErr);
return 0;
}
NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi
{
public:
static CCurrentAppUi* Cast(CEikAppUi* aUi);
void DisableKeyBlocking();
};
CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi)
{
return static_cast<CCurrentAppUi*>(aUi);
}
void CCurrentAppUi::DisableKeyBlocking()
{
SetKeyBlockMode(ENoKeyBlock);
}
class CEventQueue : public CBase, public MEventQueue
{
public:
static CEventQueue* NewL();
~CEventQueue();
public:
TInt Append(const TWsEvent& aEvent);
const TWsEvent& Shift();
void Lock();
void Unlock();
TBool HasData();
private:
TVector<TWsEvent, 64> iVector;
RCriticalSection iCS;
};
CEventQueue* CEventQueue::NewL()
{
CEventQueue* q = new (ELeave) CEventQueue();
CleanupStack::PushL(q);
User::LeaveIfError(q->iCS.CreateLocal());
CleanupStack::Pop();
return q;
}
CEventQueue::~CEventQueue()
{
iCS.Close();
}
TInt CEventQueue::Append(const TWsEvent& aEvent)
{
iCS.Wait();
const TInt err = iVector.Append(aEvent);
iCS.Signal();
return err;
}
TBool CEventQueue::HasData()
{
return iVector.Size() > 0;
}
void CEventQueue::Lock()
{
iCS.Wait();
}
void CEventQueue::Unlock()
{
iCS.Signal();
}
const TWsEvent& CEventQueue::Shift()
{
const TWsEvent& event = iVector.Shift();
return event;
}
TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) :
iOperation(aOperation), iItem(aItem), iThread(RThread().Id())
{
}
class CEikonEnv;
class CSdlAppServ;
NONSHARABLE_CLASS(EpocSdlEnvData)
{
public:
void Free();
CEventQueue* iEventQueue;
TMainFunc iMain;
TInt iEpocEnvFlags;
int iArgc;
char** iArgv;
CDsa* iDsa;
CSdlAppServ* iAppSrv;
TThreadId iId;
CArrayFix<TSdlCleanupItem>* iCleanupItems;
CEikAppUi* iAppUi;
CSDL* iSdl;
};
EpocSdlEnvData* gEpocEnv;
#define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;}
MAINFUNC(1)
MAINFUNC(2)
MAINFUNC(3)
MAINFUNC(4)
MAINFUNC(5)
MAINFUNC(6)
EXPORT_C TMainFunc::TMainFunc()
{
Mem::FillZ(iMainFunc, sizeof(iMainFunc));
}
const void* TMainFunc::operator[](TInt aIndex) const
{
return iMainFunc[aIndex];
}
NONSHARABLE_CLASS(CSdlAppServ) : public CActive
{
public:
enum
{
EAppSrvNoop = CDsa::ELastDsaRequest,
EAppSrvWindowWidth,
EAppSrvWindowHeight,
EAppSrvWindowDisplayMode,
EAppSrvWindowPointerCursorMode,
EAppSrvDsaStatus,
EAppSrvStopThread,
EAppSrvWaitDsa
};
CSdlAppServ();
void ConstructL();
~CSdlAppServ();
TInt Request(TInt aService);
TInt RequestValue(TInt aService);
void Init();
void PanicMain(TInt aReason);
void PanicMain(const TDesC& aInfo, TInt aReason);
void SetObserver(MSDLObserver* aObserver);
TInt ObserverEvent(TInt aEvent, TInt aParam);
void SetParam(TInt aParam);
void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread);
MSDLObserver* Observer();
private:
void RunL();
void DoCancel();
private:
const TThreadId iMainId;
RThread iAppThread;
TInt iService;
TInt iReturnValue;
RSemaphore iSema;
MSDLObserver* iObserver;
TRequestStatus* iStatusPtr;
};
CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id())
{
}
MSDLObserver* CSdlAppServ::Observer()
{
return iObserver;
}
void CSdlAppServ::SetObserver(MSDLObserver* aObserver)
{
iObserver = aObserver;
}
TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam)
{
if(iObserver != NULL)
{
if(RThread().Id() == gEpocEnv->iId)
{
return iObserver->SdlThreadEvent(aEvent, aParam);
}
else if(RThread().Id() == iMainId)
{
return iObserver->SdlEvent(aEvent, aParam);
}
PANIC(KErrNotSupported);
}
return 0;
}
void CSdlAppServ::PanicMain(TInt aReason)
{
iAppThread.Panic(RThread().Name(), aReason);
}
void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason)
{
iAppThread.Panic(aInfo, aReason);
}
void CSdlAppServ::ConstructL()
{
CActiveScheduler::Add(this);
User::LeaveIfError(iSema.CreateLocal(1));
iStatus = KRequestPending;
iStatusPtr = &iStatus;
SetActive();
}
CSdlAppServ::~CSdlAppServ()
{
Cancel();
if(iSema.Handle() != NULL)
iSema.Signal();
iSema.Close();
iAppThread.Close();
}
TInt CSdlAppServ::Request(TInt aService)
{
if(RThread().Id() != iAppThread.Id())
{
iSema.Wait();
iService = aService;
iAppThread.RequestComplete(iStatusPtr, KErrNone);
return KErrNone;
}
return KErrBadHandle;
}
TInt CSdlAppServ::RequestValue(TInt aService)
{
Request(aService);
Request(EAppSrvNoop);
return iReturnValue;
}
void CSdlAppServ::Init()
{
PANIC_IF_ERROR(iAppThread.Open(iMainId));
}
void CSdlAppServ::SetParam(TInt aParam)
{
iReturnValue = aParam;
}
void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread)
{
if(iObserver != NULL && aMainThread)
{
switch(aService)
{
case MSDLObserver::EEventScreenSizeChanged:
if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette)
EpocSdlEnv::LockPalette(EFalse);
break;
}
}
if(!aMainThread && aService == MSDLObserver::EEventSuspend)
{
if(iObserver == NULL ||
(gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend))
{
EpocSdlEnv::Suspend();
}
}
}
void CSdlAppServ::RunL()
{
if(iStatus == KErrNone)
{
switch(iService)
{
case CSdlAppServ::EAppSrvWaitDsa:
EpocSdlEnv::SetWaitDsa();
iReturnValue = EpocSdlEnv::IsDsaAvailable();
// }
// gEpocEnv->iDsa->Stop();
// gEpocEnv->iDsa->RestartL();
break;
case CSdlAppServ::EAppSrvStopThread:
gEpocEnv->iDsa->SetSuspend();
break;
case EpocSdlEnv::EDisableKeyBlocking:
EnvUtils::DisableKeyBlocking();
break;
case EAppSrvWindowPointerCursorMode:
iReturnValue = gEpocEnv->iDsa != NULL ?
gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady;
break;
case EAppSrvDsaStatus:
gEpocEnv->iDsa->Stop();
iReturnValue = KErrNone;
break;
case CDsa::ERequestUpdate:
gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete();
break;
case EAppSrvNoop:
break;
SDL_main.rar_it
版权申诉
101 浏览量
2022-09-20
22:09:55
上传
评论
收藏 7KB RAR 举报
局外狗
- 粉丝: 66
- 资源: 1万+
最新资源
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈