-
Notifications
You must be signed in to change notification settings - Fork 0
/
AEEAppGen.c
executable file
·335 lines (225 loc) · 9.83 KB
/
AEEAppGen.c
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/* =========================================================================
FILE: AEEAppGen.c
SERVICES: Sample IApplet implementation file
DESCRIPTION
This file contains sample implementation of the IApplet interface
PUBLIC CLASSES:
N/A
INITIALIZATION AND SEQUENCING REQUIREMENTS: N/A
Copyright (c) 1999-2002 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary and Confidential
========================================================================= */
/* =========================================================================
INCLUDES AND VARIABLE DEFINITIONS
========================================================================= */
#include "AEE.h" // Standard AEE definitions
#include "AEEShell.h" // AEE Shell Services
#include "AEEStdLib.h" // AEE stdlib stuff
#include "AEEAppGen.h" // AEEApplet definitions
#include "AEEModGen.h" // AEEMod definitions and utility function
#include "nmdef.h"
/* =========================================================================
PUBLIC DATA DECLARATIONS
========================================================================= */
/*-------------------------------------------------------------------
Type Declarations
-------------------------------------------------------------------*/
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
//Functions belonging to the AEEApplet VTBL
static uint32 AEEApplet_AddRef(IApplet * po);
static uint32 AEEApplet_Release(IApplet * po);
static boolean AEEApplet_HandleEvent(IApplet * po, AEEEvent evt,
uint16 wParam, uint32 dwParam);
/*-------------------------------------------------------------------
Global Constant Definitions
-------------------------------------------------------------------*/
/*-------------------------------------------------------------------
Global Data Definitions
-------------------------------------------------------------------*/
/*-------------------------------------------------------------------
Static variable Definitions
-------------------------------------------------------------------*/
/* =========================================================================
FUNCTION DEFINITIONS
========================================================================= */
/* =========================================================================
Function: AEEApplet_AddRef()
Description:
This function increases the referecne count for the AEEApplet object
Prototype:
uint32 AEEApplet_AddRef(IApplet * po)
Parameters:
po: Pointer to IApplet interface whos reference count is to be incremented
Return Value:
The updated reference count
Comments: None
Side Effects: None
========================================================================= */
static uint32 AEEApplet_AddRef(IApplet * po)
{
return ++(((AEEApplet *)po)->m_nRefs);
}
/* =========================================================================
Function: AEEApplet_Release()
Description:
This function decreases the referecne count for the IApplet object. If
the reference count reaches zero, it does the required cleanup
If the application developer has added data to the AEEApplet structure,
then the corresponding cleanup operations (if any) must be done here for those
data members
Prototype:
uint32 AEEApplet_Release(IApplet * po)
Parameters:
po: Pointer to the IApplet interface whose reference count needs to be
decremented.
Return Value:
The updated reference count
Comments: None
Side Effects: None
========================================================================= */
static uint32 AEEApplet_Release(IApplet * po)
{
IShell * pIShell = NULL;
AEEApplet * pme = (AEEApplet *)po;
if (--pme->m_nRefs)
return(pme->m_nRefs);
// Invoke the APP's FreeAppData function. This gives them a chance to
// free-up any data they may have allocated when the app was created.
if(pme->pFreeAppData)
pme->pFreeAppData(po);
// Release the interfaces created in AEEApplet_New()
if (pme->m_pIDisplay)
IDISPLAY_Release(pme->m_pIDisplay);
IMODULE_Release(pme->m_pIModule);
pIShell = pme->m_pIShell;
// delete this AEEApplet object
FREE_VTBL(pme, IApplet);
FREE(pme);
ISHELL_Release(pIShell); // Release the Shell
return 0;
}
/* ===========================================================================
FUNCTION AEEApplet_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled
in this function. This function passes the event to the HandleEvent()
function that has been registered by the app during AEE_AppNew() function
PROTOTYPE:
boolean AEEApplet_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam,
uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during the
AppCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
boolean AEEApplet_HandleEvent(IApplet * po, AEEEvent evt, uint16 wParam,
uint32 dwParam)
{
return ((AEEApplet *)po)->pAppHandleEvent(po, evt,wParam,dwParam);
}
/* =========================================================================
FUNCTION AEEApplet_New
DESCRIPTION
This function is invoked when the app is being loaded. It creates a new
instance of the AEEApplet structure for this applet. This function is
invoked by the app from within the AEEClsCreateInstance() function
PROTOTYPE:
boolean AEEApplet_New(int16 nSize,
AEECLSID clsID,
IShell * pIShell,
IModule * pIModule,
IApplet **ppobj,
AEEHANDLER pAppHandleEvent,
PFNFREEAPPDATA pFreeAppData)
PARAMETERS:
nSize: [in]: Specifies the size of the structure that needs to be allocated
for the applet. Typically,applets will define their struct (say,
CSocketApp) that contains AEEApplet as the first element. This
structure will then contain app specific data. The size of the
entire struct (CSocketApp) needs to be passed here.
clsID: [in]: Specifies the ClassID of this applet
pIShell: [in]: Contains a valid pointer to the AEE IShell interface
pIModule: [in]: contains a vlaid pointer to the module to which this app
belongs
ppobj: [out]: On return, *ppobj points to a valid AEEApplet structure. This
allocation is done by this function
pAppHandleEvent: [in]: Functipn Pointer to the App's HandleEvent function.
It is used from within AEEAppet_HandleEvent()
pFreeAppdata: [in]: Function pointer to the App's function to free the app
data. This function will be invoked when the reference count
of the app reaches zero. The app must free all its dynamically
allocated data inside this function.
DEPENDENCIES
none
RETURN VALUE
TRUE: If successful
FALSE: If failed
SIDE EFFECTS
none
===========================================================================*/
boolean AEEApplet_New(int16 nIn,
AEECLSID clsID,
IShell * pIShell,
IModule * pIModule,
IApplet **ppobj,
AEEHANDLER pAppHandleEvent,
PFNFREEAPPDATA pFreeAppData)
{
AEEApplet * pme = NULL;
VTBL(IApplet) * appFuncs;
int nSize;
if(nIn < 0)
return(FALSE);
nSize = (int)nIn;
if(!ppobj)
return(FALSE);
*ppobj = NULL;
//Validate parameters
if (!pIShell || !pIModule)
return FALSE;
if(nSize < sizeof(AEEApplet))
nSize += sizeof(AEEApplet);
// Create an Applet object
if (NULL == (pme = (AEEApplet*)MALLOC(nSize + sizeof(IAppletVtbl))))
return FALSE;
appFuncs = (IAppletVtbl *)((byte *)pme + nSize);
//Initialize the individual entries in the VTBL
appFuncs->AddRef = AEEApplet_AddRef;
appFuncs->Release = AEEApplet_Release;
appFuncs->HandleEvent = AEEApplet_HandleEvent;
INIT_VTBL(pme, IApplet, *appFuncs); // Initialize the VTBL
//Initialize the data members
pme->m_nRefs = 1;
pme->m_pIShell = pIShell;
pme->m_pIModule = pIModule;
pme->m_pIDisplay = NULL;
pme->clsID = clsID;
//Store the function pointers to APP's HandleEvent and FreeAppData functions
pme->pAppHandleEvent = pAppHandleEvent;
pme->pFreeAppData = pFreeAppData;
ISHELL_CreateInstance(pIShell, AEECLSID_DISPLAY,
(void **)&pme->m_pIDisplay);
if (!pme->m_pIDisplay) {
//Cleanup
FREE_VTBL(pme, IApplet);
FREE(pme);
return FALSE;
}
ISHELL_AddRef(pIShell);
IMODULE_AddRef(pIModule);
*ppobj = (IApplet*)pme;
return TRUE;
}
/* ============= End of File =============================================== */