javauis/mmapi_akn/baseline/src/cmmaplayerevent.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 "cmmaplayerevent.h"
       
    23 
       
    24 CMMAPlayerEvent::CMMAPlayerEvent(jobject aNotifyObject,
       
    25                                  jmethodID aHandleEventMethod,
       
    26                                  TDisposability aDisposable):
       
    27         CMMAEvent(aNotifyObject, aHandleEventMethod, aDisposable)
       
    28 {
       
    29 }
       
    30 
       
    31 CMMAPlayerEvent::~CMMAPlayerEvent()
       
    32 {
       
    33     delete iStringEventType;
       
    34     delete iStringEventData;
       
    35 }
       
    36 
       
    37 void CMMAPlayerEvent::SetObjectEventL(TEventType aEventType,
       
    38                                       const jobject aEventData)
       
    39 {
       
    40     iEventType = aEventType;
       
    41     iObjectEventData = aEventData;
       
    42     iEventParams = EObject;
       
    43 }
       
    44 
       
    45 void CMMAPlayerEvent::SetLongEvent(TEventType aEventType,
       
    46                                    const TInt64& aEventData)
       
    47 {
       
    48     iEventType = aEventType;
       
    49     iLongEventData = aEventData;
       
    50     iEventParams = ELong;
       
    51 }
       
    52 
       
    53 void CMMAPlayerEvent::SetStringEventL(TEventType aEventType,
       
    54                                       const TDesC& aEventData)
       
    55 {
       
    56     __ASSERT_DEBUG(iStringEventData == NULL, User::Invariant());
       
    57     iEventType = aEventType;
       
    58     iStringEventData = aEventData.AllocL();
       
    59     iEventParams = EString;
       
    60 }
       
    61 
       
    62 void CMMAPlayerEvent::Dispatch(JNIEnv& aJni)
       
    63 {
       
    64     DEBUG_INT("MMA::CMMAPlayerEvent::Dispatch type=%d", iEventType);
       
    65     if (aJni.IsSameObject(iListenerObject, 0))
       
    66     {
       
    67         DEBUG_INT("MMA::CMMAPlayerEvent::Dispatch EVENT_NOT_VALID type=%d", iEventType);
       
    68         return;
       
    69     }
       
    70     switch (iEventParams)
       
    71     {
       
    72     case ENormal:
       
    73     {
       
    74         jstring javaString = CreateJavaString(aJni, *iStringEventType);
       
    75         aJni.CallVoidMethod(iListenerObject,
       
    76                             iHandleEventMethod,
       
    77                             javaString,
       
    78                             iObjectEventData);
       
    79         break;
       
    80     }
       
    81     case ELong:
       
    82     {
       
    83         aJni.CallVoidMethod(iListenerObject,
       
    84                             iHandleEventMethod,
       
    85                             iEventType,
       
    86                             iLongEventData);
       
    87         break;
       
    88     }
       
    89     case EString:
       
    90     {
       
    91         jstring javaString = CreateJavaString(aJni, *iStringEventData);
       
    92         aJni.CallVoidMethod(iListenerObject,
       
    93                             iHandleEventMethod,
       
    94                             iEventType,
       
    95                             javaString);
       
    96         break;
       
    97     }
       
    98     case EObject:
       
    99     {
       
   100         aJni.CallVoidMethod(iListenerObject,
       
   101                             iHandleEventMethod,
       
   102                             iEventType,
       
   103                             iObjectEventData);
       
   104         break;
       
   105     }
       
   106     default:
       
   107     {
       
   108         // cannot occur
       
   109         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   110     }
       
   111     }
       
   112 
       
   113 }
       
   114 
       
   115 //  END OF FILE