javauis/mmapi_akn/baseline/src/videocontrol.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 has JNI wrappers for CMMAVideoControl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <jutils.h>
       
    20 #include <lcdui.h>
       
    21 #include "com_nokia_microedition_media_control_VideoControl.h"
       
    22 #include "cmmaeventsource.h"
       
    23 #include "cmmavideocontrol.h"
       
    24 #include "CMIDToolkit.h"
       
    25 #include "cmmadeleterefevent.h"
       
    26 #include <jdebug.h>
       
    27 #include <JniEnvWrapper.h>
       
    28 
       
    29 #include <mswtclient.h>
       
    30 #include <swtcliententry.h>
       
    31 
       
    32 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1construct
       
    33 (JNIEnv* aJni, jobject aControlObject, jint aControlHandle,
       
    34  jint aEventSourceHandle, jint aToolkitHandle)
       
    35 {
       
    36     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1construct + ");
       
    37     CMMAVideoControl* videoControl =
       
    38         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
    39 
       
    40     CMMAEventSource* eventSource =
       
    41         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
    42 
       
    43 
       
    44     __ASSERT_DEBUG(videoControl,
       
    45                    User::Panic(_L("videocontrol::control is null"),
       
    46                                KErrArgument));
       
    47     __ASSERT_DEBUG(eventSource,
       
    48                    User::Panic(_L("videocontrol::eventsource is null"),
       
    49                                KErrArgument));
       
    50 
       
    51     // reference must be done, that events can sent to java side
       
    52     jobject controlObject = aJni->NewWeakGlobalRef(aControlObject);
       
    53 
       
    54     CMIDToolkit* ptoolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
       
    55 
       
    56     //MACRO (JniEnvWrapper.h): In case of J9, this macro gets a pointer to VM
       
    57     //and nastly casts it to JNIEnv.
       
    58     JNIENV_TO_VM(aJni);
       
    59     TInt error = eventSource->ExecuteTrap(&CMMAVideoControl::ConstructL,
       
    60                                           videoControl,
       
    61                                           controlObject,
       
    62                                           JNI_PARAM, //Passes JavaVM*, not JNIEnv*.
       
    63                                           (MMMAEventPoster*)eventSource,
       
    64                                           ptoolkit);
       
    65     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1construct - ");
       
    66     return error;
       
    67 }
       
    68 
       
    69 
       
    70 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1setDisplayProperty
       
    71 (JNIEnv*, jobject, jint aControlHandle, jint aEventSourceHandle,
       
    72  jint aPropertyA, jint aPropertyB, jint aPropertyType)
       
    73 {
       
    74     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1setDisplayProperty");
       
    75 
       
    76     CMMAVideoControl* videoControl =
       
    77         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
    78 
       
    79     CMMAEventSource* eventSource =
       
    80         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
    81 
       
    82     __ASSERT_DEBUG(videoControl,
       
    83                    User::Panic(_L("videocontrol::control is null"),
       
    84                                KErrArgument));
       
    85     __ASSERT_DEBUG(eventSource,
       
    86                    User::Panic(_L("videocontrol::eventsource is null"),
       
    87                                KErrArgument));
       
    88 
       
    89     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticSetPropertyL,
       
    90                                         videoControl,
       
    91                                         aPropertyType,
       
    92                                         aPropertyA,
       
    93                                         aPropertyB));
       
    94     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1setDisplayProperty -");
       
    95     return error;
       
    96 }
       
    97 
       
    98 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty
       
    99 (JNIEnv*, jobject, jint aControlHandle, jint aEventSourceHandle,
       
   100  jint aPropertyType)
       
   101 {
       
   102     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty");
       
   103 
       
   104     CMMAVideoControl* videoControl =
       
   105         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
   106 
       
   107     CMMAEventSource* eventSource =
       
   108         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   109 
       
   110     __ASSERT_DEBUG(videoControl,
       
   111                    User::Panic(_L("videocontrol::control is null"),
       
   112                                KErrArgument));
       
   113     __ASSERT_DEBUG(eventSource,
       
   114                    User::Panic(_L("videocontrol::evetnsource is null"),
       
   115                                KErrArgument));
       
   116     TInt returnValue(KErrNone);
       
   117 
       
   118     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticGetPropertyL,
       
   119                                         videoControl,
       
   120                                         aPropertyType,
       
   121                                         &returnValue));
       
   122     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty - ");
       
   123     if (error == KErrNone)
       
   124     {
       
   125         return returnValue;
       
   126     }
       
   127     return error;
       
   128 }
       
   129 
       
   130 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot
       
   131 (JNIEnv* aJni, jobject, jint aControlHandle, jint aEventSourceHandle,
       
   132  jstring aProperties)
       
   133 {
       
   134     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot + ");
       
   135 
       
   136     CMMAVideoControl* videoControl =
       
   137         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
   138 
       
   139     CMMAEventSource* eventSource =
       
   140         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   141 
       
   142     __ASSERT_DEBUG(videoControl,
       
   143                    User::Panic(_L("videocontrol::control is null"),
       
   144                                KErrArgument));
       
   145     __ASSERT_DEBUG(eventSource,
       
   146                    User::Panic(_L("videocontrol::evetnsource is null"),
       
   147                                KErrArgument));
       
   148 
       
   149     RJString properties(*aJni, aProperties);
       
   150     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::TakeSnapShotL,
       
   151                                         videoControl,
       
   152                                         (const TDesC*)&properties));
       
   153     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot - ");
       
   154     return error;
       
   155 }
       
   156 
       
   157 /**
       
   158  * Initializes dynamic display mode
       
   159  * @return handle to MMMADirectContent or error code
       
   160  */
       
   161 LOCAL_C jint InitDynamicMode(CMMAEventSource* aEventSource,
       
   162                              CMMAVideoControl* aVideoControl,
       
   163                              jobject aGUIObject,
       
   164                              CMMAEvent* aDeleteRefEvent)
       
   165 {
       
   166     TInt contentHandle = 0;
       
   167     TInt error = aEventSource->ExecuteTrap(
       
   168                      &CMMAVideoControl::StaticInitDynamicModeL,
       
   169                      aVideoControl,
       
   170                      &contentHandle,
       
   171                      aEventSource,
       
   172                      aGUIObject,
       
   173                      aDeleteRefEvent);
       
   174 
       
   175     // if init failed return error code
       
   176     if (error != KErrNone)
       
   177     {
       
   178         contentHandle = error;
       
   179     }
       
   180     return contentHandle;
       
   181 }
       
   182 
       
   183 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode
       
   184 (JNIEnv* aJni, jobject, jint aControlHandle, jint aEventSourceHandle,
       
   185  jint aComponentHandle, jobject aComponent)
       
   186 {
       
   187     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode +");
       
   188 
       
   189     DEBUG_INT("aControlHandle = %d", aControlHandle);
       
   190     DEBUG_INT("aEventSourceHandle = %d", aEventSourceHandle);
       
   191     DEBUG_INT("aComponentHandle = %d", aComponentHandle);
       
   192 
       
   193     CMMAVideoControl* videoControl =
       
   194         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
   195 
       
   196     CMMAEventSource* eventSource =
       
   197         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   198 
       
   199     // Reference need to created to the component that component won't be deleted
       
   200     // before display associated to it.
       
   201     jobject componentRef = aJni->NewGlobalRef(aComponent);
       
   202     if (componentRef == NULL)
       
   203     {
       
   204         return KErrNoMemory;
       
   205     }
       
   206     // Component reference need to be deleted in controls destructor. Created here to
       
   207     // be sure that reference can be deleted. .
       
   208     CMMAEvent* deleteRefEvent = new CMMADeleteRefEvent(componentRef);
       
   209     // Cleanup stack is not needed, because static init takes the ownership and
       
   210     // cannot leave before that.
       
   211     if (!deleteRefEvent)
       
   212     {
       
   213         aJni->DeleteGlobalRef(componentRef);
       
   214         return KErrNoMemory;
       
   215     }
       
   216 
       
   217     // other modes has component
       
   218     if (aComponentHandle == 0)
       
   219     {
       
   220         return InitDynamicMode(eventSource,
       
   221                                videoControl,
       
   222                                componentRef,
       
   223                                deleteRefEvent);
       
   224     }
       
   225 
       
   226     MMIDComponent* component = JavaUnhand< MMIDComponent >(aComponentHandle);
       
   227 
       
   228 
       
   229     __ASSERT_DEBUG(videoControl,
       
   230                    User::Panic(_L("videocontrol::control is null"),
       
   231                                KErrArgument));
       
   232     __ASSERT_DEBUG(component,
       
   233                    User::Panic(_L("videocontrol::component is null"),
       
   234                                KErrArgument));
       
   235     __ASSERT_DEBUG(eventSource,
       
   236                    User::Panic(_L("videocontrol::eventsource is null"),
       
   237                                KErrArgument));
       
   238     TInt handle(0);
       
   239     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticInitL,
       
   240                                         videoControl,
       
   241                                         component,
       
   242                                         &handle,
       
   243                                         deleteRefEvent));
       
   244     DEBUG("Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode - ");
       
   245     if (error == KErrNone)
       
   246     {
       
   247         return handle;
       
   248     }
       
   249     return error;
       
   250 }
       
   251 
       
   252 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1setForeground
       
   253 (JNIEnv* /*aJni*/, jobject, jint aControlHandle, jint aEventSourceHandle, jint aIsForeground)
       
   254 {
       
   255     DEBUG_INT("_1setForeground + FOREGROUND = %d",aIsForeground);
       
   256     CMMAVideoControl* videoControl =
       
   257         JavaUnhand< CMMAVideoControl >(aControlHandle);
       
   258 
       
   259     CMMAEventSource* eventSource =
       
   260         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   261 
       
   262     TInt handle(0);
       
   263     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticSetForegroundL,
       
   264                                         videoControl,
       
   265                                         aIsForeground));
       
   266     if (error == KErrNone)
       
   267     {
       
   268         DEBUG("_1setForeground -");
       
   269         return handle;
       
   270     }
       
   271 
       
   272     DEBUG("_1setForeground -");
       
   273     return error;
       
   274 }
       
   275 JNIEXPORT jboolean JNICALL Java_com_nokia_microedition_media_control_VideoControl__1isESWT
       
   276 (JNIEnv *, jobject)
       
   277 {
       
   278     MSwtClient* client = NULL;
       
   279     TRAP_IGNORE(client = SWT::CreateClientL());
       
   280 
       
   281     if (!client)
       
   282     {
       
   283         return false; // LCDUI midlet running
       
   284     }
       
   285     else
       
   286     {
       
   287         delete client;
       
   288         client = NULL;
       
   289         return true;  // eSWT midlet running
       
   290     }
       
   291 
       
   292     // enable above code once you have support for eswt in 3.2.3, it is already enable for 5.0
       
   293 
       
   294 }
       
   295 //  END OF FILE