1 #ifndef DALI_INTEGRATION_APPLICATION_LAUNCHER_H
2 #define DALI_INTEGRATION_APPLICATION_LAUNCHER_H
5 * Copyright (c) 2020 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.
21 #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;
41 // JNI native "nativeOnCreate" callback when DaliView is created
42 jlong OnCreate(JNIEnv* jenv, jobject obj)
44 // Extra reference to prevent finalize clearing the app
45 ApplicationLauncher::applicationObject->Reference();
47 // not blocking, does nothing except for the setting of the running flag
48 DevelApplication::DownCast(ApplicationLauncher::applicationObject).MainLoop();
50 return reinterpret_cast<jlong>(ApplicationLauncher::applicationObject);
55 // JNI daliview library on load entry function. Registers nativeOnCreate callback for DaliView Java class.
56 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
58 JNIEnv* env = nullptr;
59 if(vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
64 // Find DaliView Java class. JNI_OnLoad is called from the correct class loader context for this to work.
65 jclass clazz = env->FindClass("com/sec/daliview/DaliView");
71 // Register your class' native methods.
72 static const JNINativeMethod methods[] =
74 {"nativeOnCreate", "()J", (void*)&OnCreate},
77 int rc = env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(JNINativeMethod));
81 return JNI_VERSION_1_6;
84 // This macro facilitates creation of DALi application and launch when DaliView is created.
85 // The DALi application controller is passed to the application created by DaliView JNI library.
86 #define RUN(Controller) \
87 Application application = Application::New(); \
88 Controller controller(application); \
89 ApplicationLauncher launcher(application);
91 #endif // DALI_INTEGRATION_APPLICATION_LAUNCHER_H