javauis/mmapi_qt/baseline/src/videocontrol.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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, jint aToolkitHandle)
       
    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)
       
    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 
       
    92     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticSetPropertyL,
       
    93                                         videoControl,
       
    94                                         aPropertyType,
       
    95                                         aPropertyA,
       
    96                                         aPropertyB));
       
    97     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1setDisplayProperty -");
       
    98     return error;
       
    99 }
       
   100 
       
   101 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty
       
   102 (JNIEnv*, jobject, jint aControlHandle, jint aEventSourceHandle,
       
   103  jint aPropertyType)
       
   104 {
       
   105     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty");
       
   106 
       
   107     CMMAVideoControl* videoControl =
       
   108         reinterpret_cast< CMMAVideoControl* >(aControlHandle);
       
   109 
       
   110     MMAFunctionServer* eventSource =
       
   111         reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
   112 
       
   113     __ASSERT_DEBUG(videoControl,
       
   114                    User::Panic(_L("videocontrol::control is null"),
       
   115                                KErrArgument));
       
   116     __ASSERT_DEBUG(eventSource,
       
   117                    User::Panic(_L("videocontrol::evetnsource is null"),
       
   118                                KErrArgument));
       
   119     TInt returnValue(KErrNone);
       
   120 
       
   121     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticGetPropertyL,
       
   122                                         videoControl,
       
   123                                         aPropertyType,
       
   124                                         &returnValue));
       
   125     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1getControlProperty - ");
       
   126     if (error == KErrNone)
       
   127     {
       
   128         return returnValue;
       
   129     }
       
   130     return error;
       
   131 }
       
   132 
       
   133 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot
       
   134 (JNIEnv* aJni, jobject, jint aControlHandle, jint aEventSourceHandle,
       
   135  jstring aProperties)
       
   136 {
       
   137     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot + ");
       
   138 
       
   139     CMMAVideoControl* videoControl =
       
   140         reinterpret_cast< CMMAVideoControl* >(aControlHandle);
       
   141 
       
   142     MMAFunctionServer* eventSource =
       
   143         reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
   144 
       
   145     __ASSERT_DEBUG(videoControl,
       
   146                    User::Panic(_L("videocontrol::control is null"),
       
   147                                KErrArgument));
       
   148     __ASSERT_DEBUG(eventSource,
       
   149                    User::Panic(_L("videocontrol::evetnsource is null"),
       
   150                                KErrArgument));
       
   151 
       
   152     JStringUtils properties(*aJni, aProperties);
       
   153     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::TakeSnapShotL,
       
   154                                         videoControl,
       
   155                                         (const TDesC*)&properties));
       
   156     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1getSnapshot - ");
       
   157     return error;
       
   158 }
       
   159 
       
   160 /**
       
   161  * Initializes dynamic display mode
       
   162  * @return handle to MMMADirectContent or error code
       
   163  */
       
   164 LOCAL_C jint InitDynamicMode(MMAFunctionServer* aEventSource,
       
   165                              CMMAVideoControl* aVideoControl,
       
   166                              jobject aGUIObject,
       
   167                              CMMAEvent* aDeleteRefEvent)
       
   168 {
       
   169     TInt contentHandle = 0;
       
   170     TInt error = aEventSource->ExecuteTrap(
       
   171                      &CMMAVideoControl::StaticInitDynamicModeL,
       
   172                      aVideoControl,
       
   173                      &contentHandle,
       
   174                      aEventSource,
       
   175                      aGUIObject,
       
   176                      aDeleteRefEvent);
       
   177 
       
   178     // if init failed return error code
       
   179     if (error != KErrNone)
       
   180     {
       
   181         contentHandle = error;
       
   182     }
       
   183     return contentHandle;
       
   184 }
       
   185 
       
   186 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode
       
   187 (JNIEnv* aJni, jobject aJavaVideoControl, jint aControlHandle, jint aEventSourceHandle,
       
   188  jobject aJavaDisplayObj, jobject aComponent)
       
   189 {
       
   190     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode +");
       
   191     LOG1( EJavaMMAPI, EInfo, "aControlHandle = %d", aControlHandle);
       
   192     LOG1( EJavaMMAPI, EInfo, "aEventSourceHandle = %d", aEventSourceHandle);
       
   193 //    LOG1( EJavaMMAPI, EInfo, "aComponentHandle = %d", aComponentHandle);
       
   194 
       
   195     CMMAVideoControl* videoControl =
       
   196         reinterpret_cast< CMMAVideoControl* >(aControlHandle);
       
   197 
       
   198     MMAFunctionServer* eventSource =
       
   199         reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
   200         
       
   201     jobject javaVideoControlPeer = aJni->NewWeakGlobalRef(aJavaVideoControl);
       
   202 
       
   203     // Reference need to created to the component that component won't be deleted
       
   204     // before display associated to it.
       
   205     jobject componentRef = aJni->NewGlobalRef(aComponent);
       
   206     if (componentRef == NULL)
       
   207     {
       
   208         return KErrNoMemory;
       
   209     }
       
   210     // Component reference need to be deleted in controls destructor. Created here to
       
   211     // be sure that reference can be deleted. .
       
   212     CMMAEvent* deleteRefEvent = new CMMADeleteRefEvent(componentRef);
       
   213     // Cleanup stack is not needed, because static init takes the ownership and
       
   214     // cannot leave before that.
       
   215     if (!deleteRefEvent)
       
   216     {
       
   217         aJni->DeleteGlobalRef(componentRef);
       
   218         return KErrNoMemory;
       
   219     }
       
   220 
       
   221 // for javaside display object  // TODO:  delete this object after its not required in destructor of control
       
   222 
       
   223 	// Reference need to created to the component that component won't be deleted
       
   224     // before display associated to it.
       
   225     jobject javaDisplayRef = aJni->NewGlobalRef(aJavaDisplayObj);
       
   226     if (javaDisplayRef == NULL)
       
   227     {
       
   228         return KErrNoMemory;
       
   229     }
       
   230 
       
   231     /*// other modes has component
       
   232     if (aComponentHandle == 0)
       
   233     {
       
   234         return InitDynamicMode(eventSource,
       
   235                                videoControl,
       
   236                                componentRef,
       
   237                                deleteRefEvent);
       
   238     }
       
   239 	*/
       
   240   //  MMIDComponent* component = JavaUnhand< MMIDComponent >(aComponentHandle);
       
   241 
       
   242 
       
   243     __ASSERT_DEBUG(videoControl,
       
   244                    User::Panic(_L("videocontrol::control is null"),
       
   245                                KErrArgument));
       
   246 //    __ASSERT_DEBUG(component,
       
   247 //                   User::Panic(_L("videocontrol::component is null"),
       
   248 //                               KErrArgument));
       
   249     __ASSERT_DEBUG(eventSource,
       
   250                    User::Panic(_L("videocontrol::eventsource is null"),
       
   251                                KErrArgument));
       
   252     TInt handle(0);
       
   253 
       
   254     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticInitL,
       
   255                                         videoControl,
       
   256                                         javaDisplayRef,
       
   257                                         eventSource,
       
   258                                         &handle,
       
   259                                         deleteRefEvent));
       
   260     LOG( EJavaMMAPI, EInfo, "Java_com_nokia_microedition_media_control_VideoControl__1initDisplayMode - ");
       
   261     if (error == KErrNone)
       
   262     {
       
   263         return handle;
       
   264     }
       
   265     return error;
       
   266 }
       
   267 
       
   268 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_VideoControl__1setForeground
       
   269 (JNIEnv* /*aJni*/, jobject, jint aControlHandle, jint aEventSourceHandle, jint aIsForeground)
       
   270 {
       
   271     LOG1( EJavaMMAPI, EInfo, "_1setForeground + FOREGROUND = %d",aIsForeground);
       
   272     CMMAVideoControl* videoControl =
       
   273         reinterpret_cast< CMMAVideoControl *>(aControlHandle);
       
   274 
       
   275     MMAFunctionServer* eventSource =
       
   276         reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
   277 
       
   278     TInt handle(0);
       
   279     TInt error(eventSource->ExecuteTrap(&CMMAVideoControl::StaticSetForegroundL,
       
   280                                         videoControl,
       
   281                                         aIsForeground));
       
   282     if (error == KErrNone)
       
   283     {
       
   284         LOG( EJavaMMAPI, EInfo, "_1setForeground -");
       
   285         return handle;
       
   286     }
       
   287 
       
   288     LOG( EJavaMMAPI, EInfo, "_1setForeground -");
       
   289     return error;
       
   290 }
       
   291 JNIEXPORT jboolean JNICALL Java_com_nokia_microedition_media_control_VideoControl__1isESWT
       
   292 (JNIEnv *, jobject)
       
   293 {/*
       
   294     MSwtClient* client = NULL;
       
   295     TRAP_IGNORE(client = SWT::CreateClientL());
       
   296 
       
   297     if (!client)
       
   298     {
       
   299         return false; // LCDUI midlet running
       
   300     }
       
   301     else
       
   302     {
       
   303         delete client;
       
   304         client = NULL;
       
   305         return true;  // eSWT midlet running
       
   306     }
       
   307 */
       
   308     // enable above code once you have support for eswt in 3.2.3, it is already enable for 5.0
       
   309 return false;
       
   310 }
       
   311 //  END OF FILE