aboutsummaryrefslogtreecommitdiff
path: root/backends/epoc/S90/ScummVMApp.cpp
blob: 8a83b4ea8ed5e6a1d8e7ad9337da45f224a8b34d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003-2005 Andreas 'Sprawl' Karlsson - Original EPOC port, ESDL
 * Copyright (C) 2003-2005 Lars 'AnotherGuest' Persson - Original EPOC port, Audio System
 * Copyright (C) 2005 Jurgen 'SumthinWicked' Braam - EPOC/CVS maintainer
 * Copyright (C) 2005-2006 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $Header$
 */

#include "ScummVMapp.h"
#include <scummvms90.rsg>
#include <apgcli.h>
#include <eikdll.h>
#include <apgtask.h>

EXPORT_C CApaApplication *NewApplication() {
	return (new CScummVM);
}

CScummVM::CScummVM() {
}

CScummVM::~CScummVM() {
}

CApaDocument *CScummVM::CreateDocumentL() {
	return new (ELeave)CScummVMDoc(*this);
}

TUid CScummVM::AppDllUid() const {
	return TUid::Uid(0x101f9b57);
}

CScummVMDoc::CScummVMDoc(CEikApplication &aApp) : CEikDocument(aApp) {
}

CScummVMDoc::~CScummVMDoc() {
}

CEikAppUi *CScummVMDoc::CreateAppUiL() {
	return new (ELeave)CScummVMUi;
}

void CScummVMUi::HandleForegroundEventL(TBool aForeground) {
	if(aForeground) {
		BringUpEmulatorL();
	}
}

CScummVMUi::CScummVMUi() {
}

CScummVMUi::~CScummVMUi() {
	if(iWatcher) {
		iThreadWatch.LogonCancel(iWatcher->iStatus);
		iWatcher->Cancel();
	}

	delete iWatcher;

	iThreadWatch.Close();
}

void CScummVMUi::ConstructL() {
	BaseConstructL();
	TBuf<128> startFile;
	startFile = iEikonEnv->EikAppUi()->Application()->AppFullName();
	TParse parser;
	parser.Set(startFile,NULL,NULL);

	startFile = parser.DriveAndPath();
#ifndef __WINS__
	startFile.Append( _L("ScummVM.exe"));
#else
	startFile.Append( _L("ScummVM.dll"));
#endif
	CApaCommandLine *cmdLine = CApaCommandLine::NewLC(startFile);
	RApaLsSession lsSession;

	lsSession.Connect();
	CleanupClosePushL(lsSession);
	lsSession.StartApp(*cmdLine, iThreadId);

	CleanupStack::PopAndDestroy();//close lsSession
	CleanupStack::PopAndDestroy(cmdLine);

	User::After(500000);// Let the application start

	TApaTaskList taskList(iEikonEnv->WsSession());

	TApaTask myTask = taskList.FindApp(TUid::Uid(0x101f9b57));
	myTask.SendToBackground();

	TApaTask exeTask = taskList.FindByPos(0);

	iExeWgId=exeTask.WgId();
	exeTask.BringToForeground();

	if(iExeWgId == myTask.WgId()) { // Should n't be the same
		Exit();
	}
	if(iThreadWatch.Open(iThreadId) == KErrNone) {
		iWatcher = new (ELeave)CScummWatcher;
		iWatcher->iAppUi = this;
		iThreadWatch.Logon(iWatcher->iStatus);
	}
}

CScummWatcher::CScummWatcher() : CActive(EPriorityStandard) {
	CActiveScheduler::Add(this);

	iStatus = KRequestPending;
	SetActive();
}

CScummWatcher::~CScummWatcher() {
}

void CScummWatcher::DoCancel() {
}

void CScummWatcher::RunL() {
	iAppUi->HandleCommandL(EEikCmdExit);
}

void CScummVMUi::BringUpEmulatorL() {
	RThread thread;

	if(thread.Open(iThreadId) == KErrNone) {
		thread.Close();
		TApaTask apaTask(iEikonEnv->WsSession());
		apaTask.SetWgId(iExeWgId);
		apaTask.BringToForeground();
	} else {
		iExeWgId = -1;
		Exit();
	}
}

void CScummVMUi::HandleCommandL(TInt aCommand) {
	switch(aCommand) {
	case EEikCmdExit:
		{
			RThread thread;
			if(thread.Open(iThreadId) == KErrNone) {
				thread.Terminate(0);
				thread.Close();
			}
			Exit();
		}
		break;
	}
}

GLDEF_C  TInt E32Dll(TDllReason) {
	return KErrNone;
}