26
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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: This class is used to post events to the java.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <jdebug.h>
|
|
21 |
|
|
22 |
#include "cmmasnapshotevent.h"
|
|
23 |
|
|
24 |
CMMASnapshotEvent::CMMASnapshotEvent(jobject aNotifyObject,
|
|
25 |
jmethodID aHandleEventMethod,
|
|
26 |
TInt aError,
|
|
27 |
HBufC8* aImageBuffer,
|
|
28 |
TDisposability aDisposable):
|
|
29 |
CMMAEvent(aNotifyObject,
|
|
30 |
aHandleEventMethod,
|
|
31 |
aDisposable)
|
|
32 |
{
|
|
33 |
iEventData = aError;
|
|
34 |
iImageBuffer = aImageBuffer;
|
|
35 |
}
|
|
36 |
|
|
37 |
CMMASnapshotEvent::~CMMASnapshotEvent()
|
|
38 |
{
|
|
39 |
// image buffer need to be deleted if
|
|
40 |
// event server hasn't sent this event before
|
|
41 |
// middlet is destroyed
|
|
42 |
delete iImageBuffer;
|
|
43 |
|
|
44 |
}
|
|
45 |
|
|
46 |
void CMMASnapshotEvent::Dispatch(JNIEnv& aJni)
|
|
47 |
{
|
|
48 |
DEBUG("MMA::CMMASnapshotEvent::Dispatch");
|
|
49 |
|
|
50 |
// create java byte array
|
|
51 |
|
|
52 |
jbyteArray byteArray;
|
|
53 |
|
|
54 |
if (iImageBuffer)
|
|
55 |
|
|
56 |
{
|
|
57 |
byteArray = aJni.NewByteArray(iImageBuffer->Size());
|
|
58 |
if (byteArray)
|
|
59 |
{
|
|
60 |
ArrayUtils::CopyToJava(aJni,
|
|
61 |
*iImageBuffer,
|
|
62 |
byteArray,
|
|
63 |
0,
|
|
64 |
iImageBuffer->Size());
|
|
65 |
}
|
|
66 |
}
|
|
67 |
else
|
|
68 |
{
|
|
69 |
byteArray = aJni.NewByteArray(0);
|
|
70 |
}
|
|
71 |
|
|
72 |
if (!byteArray)
|
|
73 |
{
|
|
74 |
delete iImageBuffer;
|
|
75 |
iImageBuffer = NULL; // otherwise double delete in destructor
|
|
76 |
DEBUG("MMA::CMMASnapshotEvent::Dispatch - Failed to create ByteArray");
|
|
77 |
return;
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
aJni.CallVoidMethod(iListenerObject,
|
|
82 |
iHandleEventMethod,
|
|
83 |
iEventData,
|
|
84 |
byteArray);
|
|
85 |
|
|
86 |
delete iImageBuffer;
|
|
87 |
iImageBuffer = NULL; // otherwise double delete in destructor
|
|
88 |
|
|
89 |
aJni.DeleteLocalRef(byteArray);
|
|
90 |
|
|
91 |
}
|
|
92 |
|
|
93 |
// END OF FILE
|