1 #ifndef DALI_INTEGRATION_APPLICATION_LAUNCHER_H
2 #define DALI_INTEGRATION_APPLICATION_LAUNCHER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/adaptor-framework/application-devel.h>
26 // Wraps DALi application instance for DaliView JNI interface
27 struct ApplicationLauncher
29 static RefObject* applicationObject;
30 ApplicationLauncher( Application& application )
32 applicationObject = application.GetObjectPtr();
36 // Static DALi application instance for DaliView
37 RefObject* ApplicationLauncher::applicationObject;
42 // JNI native "nativeOnCreate" callback when DaliView is created
43 jlong OnCreate(JNIEnv *jenv, jobject obj)
45 // Extra reference to prevent finalize clearing the app
46 ApplicationLauncher::applicationObject->Reference();
48 // not blocking, does nothing except for the setting of the running flag
49 DevelApplication::DownCast( ApplicationLauncher::applicationObject ).MainLoop();
51 return reinterpret_cast<jlong>( ApplicationLauncher::applicationObject );
56 // JNI daliview library on load entry function. Registers nativeOnCreate callback for DaliView Java class.
57 JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
59 JNIEnv* env = nullptr;
60 if( vm->GetEnv( reinterpret_cast<void **>( &env ), JNI_VERSION_1_6) != JNI_OK )
65 // Find DaliView Java class. JNI_OnLoad is called from the correct class loader context for this to work.
66 jclass clazz = env->FindClass( "com/sec/daliview/DaliView" );
67 if( clazz == nullptr )
72 // Register your class' native methods.
73 static const JNINativeMethod methods[] =
75 { "nativeOnCreate", "()J", (void *)&OnCreate },
78 int rc = env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(JNINativeMethod));
82 return JNI_VERSION_1_6;
85 // This macro facilitates creation of DALi application and launch when DaliView is created.
86 // The DALi application controller is passed to the application created by DaliView JNI library.
87 #define RUN(Controller) Application application = Application::New(); \
88 Controller controller( application ); \
89 ApplicationLauncher launcher( application ); \
91 #endif // DALI_INTEGRATION_APPLICATION_LAUNCHER_H