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