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