33
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* Header for the external player main class.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef __EXTERNAL_PLAYER_H__
|
|
20 |
#define __EXTERNAL_PLAYER_H__
|
|
21 |
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <e32msgqueue.h>
|
|
24 |
#include <w32std.h>
|
|
25 |
|
|
26 |
#include "PlayerWindow.h"
|
|
27 |
|
|
28 |
// Note: the executable name is also used as the message queue name.
|
|
29 |
_LIT( KExternalPlayerExe, "externalplayer.exe" );
|
|
30 |
_LIT( KExternalPlayerExe2, "externalplayer2.exe" );
|
|
31 |
|
|
32 |
enum TExternalPlayerCommands
|
|
33 |
{
|
|
34 |
EExternalPlayer_StartPlayback,
|
|
35 |
EExternalPlayer_ExecuteOperation,
|
|
36 |
EExternalPlayer_MoveWindow,
|
|
37 |
EExternalPlayer_Shutdown
|
|
38 |
};
|
|
39 |
|
|
40 |
struct TStartPlayback
|
|
41 |
{
|
|
42 |
TInt x;
|
|
43 |
TInt y;
|
|
44 |
TInt width;
|
|
45 |
TInt height;
|
|
46 |
TInt idOfParentWindowGroup;
|
|
47 |
bool locationIsFilename;
|
|
48 |
TInt length;
|
|
49 |
unsigned char name[200];
|
|
50 |
};
|
|
51 |
|
|
52 |
struct TStartPlaybackReturn
|
|
53 |
{
|
|
54 |
TInt windowGroupId;
|
|
55 |
};
|
|
56 |
|
|
57 |
struct TExecuteOperation
|
|
58 |
{
|
|
59 |
TInt operation;
|
|
60 |
};
|
|
61 |
|
|
62 |
struct TMoveWindow
|
|
63 |
{
|
|
64 |
TInt centerX;
|
|
65 |
TInt centerY;
|
|
66 |
};
|
|
67 |
|
|
68 |
_LIT( KMsgQueuePrefix, "-msg=" );
|
|
69 |
|
|
70 |
// This is the client-side class for launching and controlling an external player executable.
|
|
71 |
|
|
72 |
class CExternalPlayer : public CBase, public MPlayerCommands
|
|
73 |
{
|
|
74 |
public:
|
|
75 |
|
|
76 |
~CExternalPlayer()
|
|
77 |
{
|
|
78 |
Terminate();
|
|
79 |
}
|
|
80 |
|
|
81 |
CExternalPlayer( RWsSession& aWs ) : iWs( aWs )
|
|
82 |
{
|
|
83 |
}
|
|
84 |
|
|
85 |
TInt SendMsg( TExternalPlayerCommands aMsg )
|
|
86 |
{
|
|
87 |
TRequestStatus status;
|
|
88 |
status = KRequestPending;
|
|
89 |
iProcess.Rendezvous( status );
|
|
90 |
|
|
91 |
iMsgQueue.SendBlocking( aMsg );
|
|
92 |
|
|
93 |
User::WaitForRequest( status );
|
|
94 |
|
|
95 |
return status.Int();
|
|
96 |
}
|
|
97 |
|
|
98 |
TInt Launch( const TDesC& aExeName,
|
|
99 |
RWindowGroup& aParentWindowGroup,
|
|
100 |
const TDesC& aLocation,
|
|
101 |
bool aLocationIsFilename, // false means location is URL
|
|
102 |
TPoint aTopRight,
|
|
103 |
TSize aSize )
|
|
104 |
{
|
|
105 |
// The base name for message queue and chunk is the name of the executable followed by the address of this instance.
|
|
106 |
TBuf<80> nameBase;
|
|
107 |
nameBase.Copy( aExeName );
|
|
108 |
nameBase.AppendFormat(_L("%08x"), this );
|
|
109 |
|
|
110 |
TBuf<100> commandLineArguments;
|
|
111 |
commandLineArguments.Copy( KMsgQueuePrefix );
|
|
112 |
commandLineArguments.Append( nameBase );
|
|
113 |
|
|
114 |
TInt err = iProcess.Create( aExeName, commandLineArguments );
|
|
115 |
|
|
116 |
if( err == KErrNone )
|
|
117 |
{
|
|
118 |
aParentWindowGroup.AllowProcessToCreateChildWindowGroups( iProcess.SecureId() );
|
|
119 |
|
|
120 |
iProcess.Resume();
|
|
121 |
|
|
122 |
TRequestStatus status;
|
|
123 |
status = KRequestPending;
|
|
124 |
iProcess.Rendezvous( status );
|
|
125 |
User::WaitForRequest( status );
|
|
126 |
|
|
127 |
err = status.Int();
|
|
128 |
|
|
129 |
if( err == KErrNone )
|
|
130 |
{
|
|
131 |
err = iMsgQueue.OpenGlobal( nameBase );
|
|
132 |
}
|
|
133 |
|
|
134 |
if( err == KErrNone )
|
|
135 |
{
|
|
136 |
nameBase.Append( _L("_chunk") );
|
|
137 |
err = iChunk.OpenGlobal( nameBase, EFalse );
|
|
138 |
}
|
|
139 |
|
|
140 |
if( err == KErrNone )
|
|
141 |
{
|
|
142 |
iActive = true;
|
|
143 |
|
|
144 |
// Send the start messages to the external player.
|
|
145 |
|
|
146 |
TStartPlayback* chunk = (TStartPlayback*)iChunk.Base();
|
|
147 |
|
|
148 |
TPtr8 filename( chunk->name, 0, 200 );
|
|
149 |
filename.Copy( aLocation );
|
|
150 |
chunk->length = filename.Length();
|
|
151 |
chunk->locationIsFilename = aLocationIsFilename;
|
|
152 |
|
|
153 |
chunk->x = aTopRight.iX;
|
|
154 |
chunk->y = aTopRight.iY;
|
|
155 |
chunk->width = aSize.iWidth;
|
|
156 |
chunk->height = aSize.iHeight;
|
|
157 |
chunk->idOfParentWindowGroup = aParentWindowGroup.Identifier();
|
|
158 |
err = SendMsg( EExternalPlayer_StartPlayback );
|
|
159 |
|
|
160 |
if( err == KErrNone )
|
|
161 |
{
|
|
162 |
TStartPlaybackReturn* chunk = (TStartPlaybackReturn*)iChunk.Base();
|
|
163 |
iWindowGroupId = chunk->windowGroupId;
|
|
164 |
}
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
iProcess.Kill( KErrCancel );
|
|
169 |
iProcess.Close();
|
|
170 |
}
|
|
171 |
|
|
172 |
}
|
|
173 |
|
|
174 |
return err;
|
|
175 |
}
|
|
176 |
|
|
177 |
// inherited from MPlayerCommands
|
|
178 |
TInt ExecuteOperation( TInt aOperation )
|
|
179 |
{
|
|
180 |
TInt err = KErrNone;
|
|
181 |
|
|
182 |
if( iActive )
|
|
183 |
{
|
|
184 |
TExecuteOperation* chunk = (TExecuteOperation*)iChunk.Base();
|
|
185 |
chunk->operation = aOperation;
|
|
186 |
err = SendMsg( EExternalPlayer_ExecuteOperation );
|
|
187 |
}
|
|
188 |
|
|
189 |
return err;
|
|
190 |
}
|
|
191 |
|
|
192 |
// inherited from MPlayerCommands
|
|
193 |
void MoveWindow( TPoint aNewCenter )
|
|
194 |
{
|
|
195 |
if( iActive )
|
|
196 |
{
|
|
197 |
TMoveWindow* chunk = (TMoveWindow*)iChunk.Base();
|
|
198 |
chunk->centerX = aNewCenter.iX;
|
|
199 |
chunk->centerY = aNewCenter.iY;
|
|
200 |
SendMsg( EExternalPlayer_MoveWindow );
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
void SetOrdinalPosition( TInt /*aPosition*/ )
|
|
205 |
{
|
|
206 |
if( iActive )
|
|
207 |
{
|
|
208 |
// TODO: DEBUG THIS. HOW DOES WINDOW GROUP ORDINAL POSITION RELATE TO WINDOW ORDINAL POSITION?
|
|
209 |
// iWs.SetWindowGroupOrdinalPosition( iWindowGroupId, aPosition );
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
void Terminate()
|
|
214 |
{
|
|
215 |
if( iActive )
|
|
216 |
{
|
|
217 |
SendMsg( EExternalPlayer_Shutdown );
|
|
218 |
|
|
219 |
iProcess.Close();
|
|
220 |
iMsgQueue.Close();
|
|
221 |
|
|
222 |
iActive = false;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
private:
|
|
227 |
|
|
228 |
RWsSession& iWs;
|
|
229 |
RProcess iProcess;
|
|
230 |
bool iActive;
|
|
231 |
RMsgQueue<TExternalPlayerCommands> iMsgQueue;
|
|
232 |
RChunk iChunk;
|
|
233 |
TInt iWindowGroupId;
|
|
234 |
|
|
235 |
};
|
|
236 |
|
|
237 |
#endif
|
|
238 |
|