Generating JNI with a python script

The PyCeda python package comes with a python script called generate_jni.py which is used to generate the .java and .cpp JNI files for a given CEDA based library.

ceda-samples has a python script named generate_pizza_jni_wrappers.py which uses generate_jni.py for the projects Time, Shapes and Pizza under MyCompany:


import os
import pyceda
import pypizza
from pyceda.generate_jni import *

prefix = '../CedaAndroidExample/app/src/main'

# Location for where to write the java files
javaFolderPath = prefix + '/java'

# Location for where to write the cpp files
cppFolderPath = prefix + '/cpp'

# includes paths which are inserted into every cpp file
projectIncludes = [
    '../Utils.h',
    'MyCompany/Pizza/PizzaDeliveries.h'
]

# Mapping from C++ namespace to Java package name
cppNamespaceToJavaPackageMap = {
    'ceda' : 'com.cedanet.ceda',
    'dt' : 'com.MyCompany.dt',
    'shapes' : 'com.MyCompany.shapes',
    'pizza' : 'com.MyCompany.pizza' 
}

# The set of C++ namespaces to be processed
cppNamespacesToProcess = [
    #'ceda',
    'dt',
    'shapes',
    'pizza'
]

def makeDir(dirPath):
    if not os.path.exists(dirPath):
        os.makedirs(dirPath)

#makeDir(javaFolderPath + '/com/cedanet/ceda')
makeDir(javaFolderPath + '/com/MyCompany/dt')
makeDir(javaFolderPath + '/com/MyCompany/shapes')
makeDir(javaFolderPath + '/com/MyCompany/pizza')

#makeDir(cppFolderPath + '/ceda')
makeDir(cppFolderPath + '/dt')
makeDir(cppFolderPath + '/shapes')
makeDir(cppFolderPath + '/pizza')

for cppNamespace in cppNamespacesToProcess:
    processNamespace(cppNamespaceToJavaPackageMap, cppNamespace, javaFolderPath, cppFolderPath, projectIncludes)

The relevant C++ projects are located as follows:

  (root)
    └── MyCompany
        ├── Pizza
        ├── Shapes
        └── Time