Skip to content

Celix Wrapper (Android Library)

Daan Veldhof edited this page Jan 28, 2016 · 1 revision

The library is located here
There's also a small example how to use this library.

Celix.java

The Celix object class. This class implements the singleton pattern. The object can be retrieved by calling Celix.getInstance(); This class has methods to communicate with the jni_part.c, which can communicate with the Celix framework. The jni_part also has callbacks to this Celix instance to tell it has changed. The Celix class implements the observable pattern, when being observed it notifies observers when the log has changed, Celix status has been changed or bundles are changed/installed. When bundles are changed it returns a OsgiBundle object which represents the bundle that was changed.

Config.java

The Config class is used for generating, reading and writing the config.properties used by Apache Celix. There should be only one instance of this object. In this application this object is made inside the Model class which is implementing the singleton pattern. It's not necessary to use this class for configuration, but it's easy to use and easily extendable by extending it. If you don't want to use this class then you have to generate the config.properties file yourself and use the path to this file to the celix.startCelix method.

OsgiBundle.java

This is a class describing an OSGi bundle. It has the location, id, status and symbolic name. There's also a method to retrieve the filename, which is the last part of the location.

Update

This is a enum which are send to observers when something has changed. Contains values like LOG_CHANGED and CELIX_CHANGED.

Jni folder

Armeabi & Armeabi-v7a folder

Contains the prebuilt shared libraries used (celix utils, celix framework, celix dfi and curl) The application automatically chooses the build abi (armeabi or armeabi v7a) which the phone uses. The correct folder will be used for the build abi. Both directories contain the same files, armeabi-v7a is optimized for v7a architecture. (in Android.mk is specified that it uses the (TARGET_ARCH_ABI)/foo.so library)

Include

The include files needed for the .so files in the armeabi and armeabi-v7a folders.

Android.mk

Prepares prebuilt libraries for jni, points to the .so and include files.
Also specifies the parameters how to build the jni part and which prebuilt shared / prebuilt static libraries are needed for it. The $(TARGET_ARCH_ABI) is a wildcard used for pointing to the build abi directory. Android decides which build abi is supported and which one it should use. Then the wildcard will be filled in by this chosen abi on runtime.
Official Android documentation

Application.mk

APP_ABI tells the application for which ABI's to build it.
Official Android documentation

jni_part.c

This is C code which has functions that do something with the Celix framework and callbacks to java code (Celix.java)

The functions that look like this JNIEXPORT jint JNICALL <java_android_package_name>_<classname>_<methodname>(JNIEnv* je, jobject obj) are functions that can be called from the Java class, in this case Celix.java. In this class there are methods that look like this: public native int <methodname>(). These are the methods that correspond with the methods in jni_part.c. So if you call the method <methodname>() you actually call JNIEXPORT jint JNICALL <java_android_package_name>_<classname>_<methodname>(JNIEnv* je, jobject obj)

There is also a logger started in the onload which redirects stdio to logcat and callback in Celix.java. This code is mainly used to communicate with Apache celix to start/stop and install/delete/run/stop bundles.
The confirm*(*) methods in this file will attach to the java environment and execute the callback methods. This is also the part where native communication with the framework is being done. There is a bundle listener attached when starting with a callback method to Celix.java. This takes care of syncing the framework with the Celix.java