SlideShare a Scribd company logo
Djinni
Java/Objective-C and C++ bridging
Agenda
1. Multiplatform app
2. App architecture
3. C++11
4. Djinni
5. Demo
6. Pros & cons
Me
• over 10 years in IT
• over 4 years as C++ software engineer
• some Java experience
• no Objective-C experience
• last half of year of free time (boring guy) spent on
Android/iOS mobile app development, Swift learning, etc.
• want to share idea of broad usage of C++ in mobile app
development world
Multiplatform app
• multiplatform app is…
mobile / web / “traditional”,

Android / iOS / MacOS / Linux / Windows, etc.
• native look & feel
• performance
Potential issues
• Each of app platform version in native language
(Java, Objective-C, C# etc.)
• Duplicated code
• More code - harder maintenance
• Slow development
App architecture
platform-specific (Java, Objective-C/Swift; UI)platform-specific (Java, Objective-C/Swift; UI)
platform-agnostic (C/C++/C++11; business logic)
platform-specific (Java, Objective-C/Swift; UI)
—————————————————————————
cross-language bridge
—————————————————————————
platform-agnostic (C/C++/C++11; business logic)
C++11 (modern C++)
“C++ feels like a new language. That is, I can
express my ideas more clearly, more simply, and
more directly in C++11 than I could in C++98.
Furthermore, the resulting programs are better
checked by the compiler and run faster.”
Bjarne Stroustrup,

The C++ programming language
C++11 (modern C++)
• auto
• foreach
• lambdas
• smart pointers
• move semantics
• constexpr
• many libraries
• a lot more…
Cross-language bridge
• Java Native Interface (JNI): C++ <-> Java
• Objective-C++: C++ <-> Objective-C
• Consistent interface across languages
• Data types that are the same in all languages
• Object’s lifetime
• Error handling
JNI code example
JNIEnv* env;
if (m_javaVM->AttachCurrentThread(&env, nullptr) < 0) {
return;
}
jclass applicationClass = env->GetObjectClass(cameraSupportClassPointer);
if (applicationClass) {
jmethodID getFrameID = env->GetMethodID(applicationClass, "getFrame", "()[B");
jobject frameObject = env->CallObjectMethod(cameraSupportClassPointer, getFrameID);
if (frameObject) {
jbyteArray *frameByteArray = reinterpret_cast<jbyteArray*>(&frameObject);
jsize frameByteArrayLength = env->GetArrayLength(*frameByteArray);
env->GetByteArrayRegion(*frameByteArray, 0, frameByteArrayLength,
reinterpret_cast<jbyte*>(yuv));
jbyte *frameBytePointer = env->GetByteArrayElements(*frameByteArray, nullptr);
env->ReleaseByteArrayElements(*frameByteArray, frameBytePointer, 0);
}
}
m_javaVM->DetachCurrentThread();
JNIEnv* env;
if (m_javaVM->AttachCurrentThread(&env, nullptr) < 0) {
return;
}
jclass applicationClass = env->GetObjectClass(cameraSupportClassPointer);
if (applicationClass) {
jmethodID getFrameID = env->GetMethodID(applicationClass, "getFrame", "()[B");
jobject frameObject = env->CallObjectMethod(cameraSupportClassPointer, getFrameID);
if (frameObject) {
jbyteArray *frameByteArray = reinterpret_cast<jbyteArray*>(&frameObject);
jsize frameByteArrayLength = env->GetArrayLength(*frameByteArray);
env->GetByteArrayRegion(*frameByteArray, 0, frameByteArrayLength,
reinterpret_cast<jbyte*>(yuv));
jbyte *frameBytePointer = env->GetByteArrayElements(*frameByteArray, nullptr);
env->ReleaseByteArrayElements(*frameByteArray, frameBytePointer, 0);
}
}
m_javaVM->DetachCurrentThread();
Djinni
• Dropbox’s Carousel and Mailbox
• Bridge between C++ and Java/Objective-C
• Bridge between C++ and Python (experimental)
• Open source
• Facebook’s Moments
Djinni’s Interface Definition
Language (IDL)
• Enums
• Records
• Interfaces
• Implementation languages
C++11: auto
std::vector<std::string> vec;
std::vector<std::string>::iterator iter = vec.begin();
vintage C++
C++11: auto
std::vector<std::string> vec;
std::vector<std::string>::iterator iter = vec.begin();
std::vector<std::string> vec;
auto iter = vec.begin();
modern C++
vintage C++
C++11: smart pointers
auto d = new Dynamic;
do_sth(d); // may throw
vintage C++
C++11: smart pointers
auto d = new Dynamic;
do_sth(d); // may throw
delete d;
vintage C++
C++11: smart pointers
auto d = new Dynamic;
try {
do_sth(d); // may throw
}
catch (...) {
delete d;
throw; // rethrow
}
delete d;
vintage C++
C++11: smart pointers
auto d = new Dynamic;
try {
do_sth(d); // may throw
}
catch (...) {
delete d;
throw; // rethrow
}
delete d;
auto d = std::make_shared<Dynamic>();
do_sth(d); // may throw
modern C++
vintage C++
C++11: std::move
Huge h;
do_sth(h);
Huge h;
do_sth(std::move(h));
modern C++
vintage C++
Demo
Pros
• Less code
• Easier maintenance
• More consistency between app platform versions
• Faster development
• Better performance
• Easy switch from single- to multi-platform
Cons
• Reasonable use of bridges
• Djinni’s limitations (lack of interface inheritance)
• Compilers issues (AndroidNDK vs CrystaxNDK)
• Size of Android app increases (architectures)
• No single IDE
Links
• github.com/dropbox/djinni
• github.com/michal-kowalczyk/

trambambule-helper
• mobilecpptutorials.com
• code.facebook.com/posts/498597036962415/
under-the-hood-building-moments
Thanks
mkk.ekk.pl

More Related Content

PPTX
4Developers2016: Introduction to Xamarin.Platform
PDF
4Developers2016: Łukasz Szydło- Continuous Deployment - alternatywa dla żmudn...
PDF
[4developers2016] The ultimate mobile DX using JS as a primary language (Fato...
PPTX
Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016
PPTX
Mobile C++
PPTX
Introduction of Android Camera1
PPT
Android cameraoverview
PDF
Building a Native Camera Access Library - Part I - Transcript.pdf
4Developers2016: Introduction to Xamarin.Platform
4Developers2016: Łukasz Szydło- Continuous Deployment - alternatywa dla żmudn...
[4developers2016] The ultimate mobile DX using JS as a primary language (Fato...
Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016
Mobile C++
Introduction of Android Camera1
Android cameraoverview
Building a Native Camera Access Library - Part I - Transcript.pdf

Similar to 4Developers2016: Michał Kowalczyk- Djinni - bridge pomiędzy Java, Objective-C, Swift i C++ (20)

PDF
Android and cpp
PPTX
Cross Platform App Development with C++
KEY
Cross Platform Development with Xamarin
PPTX
Cross Platform Mobile Development with Visual Studio 2015 and C++
PDF
Building a Native Camera Access Library - Part V.pdf
PPT
C++ programming with jni
PPTX
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
PDF
Building a Native Camera Access Library - Part I.pdf
PDF
Lviv MD Day 2015 Ігор Кантор "Розробка додатків зі спільним C++ кодом для iOS...
PPTX
Developing a mobile cross-platform library
PDF
Mobile Application Development with JUCE and Native API’s
PDF
Building a Native Camera Access Library - Part III - Transcript.pdf
PPTX
Eco system apps
ODP
Funambol C++ API
PDF
Android media framework overview
PDF
Glympse API Cross Compiling
PDF
HDF-EOS Java Application Programming Interfaces
PDF
Patrick broman mo sync
PDF
Android Developer Days: Increasing performance of big arrays processing on An...
PDF
The Future of Cross-Platform is Native
Android and cpp
Cross Platform App Development with C++
Cross Platform Development with Xamarin
Cross Platform Mobile Development with Visual Studio 2015 and C++
Building a Native Camera Access Library - Part V.pdf
C++ programming with jni
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
Building a Native Camera Access Library - Part I.pdf
Lviv MD Day 2015 Ігор Кантор "Розробка додатків зі спільним C++ кодом для iOS...
Developing a mobile cross-platform library
Mobile Application Development with JUCE and Native API’s
Building a Native Camera Access Library - Part III - Transcript.pdf
Eco system apps
Funambol C++ API
Android media framework overview
Glympse API Cross Compiling
HDF-EOS Java Application Programming Interfaces
Patrick broman mo sync
Android Developer Days: Increasing performance of big arrays processing on An...
The Future of Cross-Platform is Native
Ad

Recently uploaded (20)

PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
A Presentation on Touch Screen Technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
August Patch Tuesday
PPTX
TLE Review Electricity (Electricity).pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
WOOl fibre morphology and structure.pdf for textiles
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Getting Started with Data Integration: FME Form 101
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
cloud_computing_Infrastucture_as_cloud_p
A Presentation on Touch Screen Technology
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Building Integrated photovoltaic BIPV_UPV.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Encapsulation_ Review paper, used for researhc scholars
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
MIND Revenue Release Quarter 2 2025 Press Release
August Patch Tuesday
TLE Review Electricity (Electricity).pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
OMC Textile Division Presentation 2021.pptx
A comparative analysis of optical character recognition models for extracting...
WOOl fibre morphology and structure.pdf for textiles
Ad

4Developers2016: Michał Kowalczyk- Djinni - bridge pomiędzy Java, Objective-C, Swift i C++

  • 2. Agenda 1. Multiplatform app 2. App architecture 3. C++11 4. Djinni 5. Demo 6. Pros & cons
  • 3. Me • over 10 years in IT • over 4 years as C++ software engineer • some Java experience • no Objective-C experience • last half of year of free time (boring guy) spent on Android/iOS mobile app development, Swift learning, etc. • want to share idea of broad usage of C++ in mobile app development world
  • 4. Multiplatform app • multiplatform app is… mobile / web / “traditional”,
 Android / iOS / MacOS / Linux / Windows, etc. • native look & feel • performance
  • 5. Potential issues • Each of app platform version in native language (Java, Objective-C, C# etc.) • Duplicated code • More code - harder maintenance • Slow development
  • 6. App architecture platform-specific (Java, Objective-C/Swift; UI)platform-specific (Java, Objective-C/Swift; UI) platform-agnostic (C/C++/C++11; business logic) platform-specific (Java, Objective-C/Swift; UI) ————————————————————————— cross-language bridge ————————————————————————— platform-agnostic (C/C++/C++11; business logic)
  • 7. C++11 (modern C++) “C++ feels like a new language. That is, I can express my ideas more clearly, more simply, and more directly in C++11 than I could in C++98. Furthermore, the resulting programs are better checked by the compiler and run faster.” Bjarne Stroustrup,
 The C++ programming language
  • 8. C++11 (modern C++) • auto • foreach • lambdas • smart pointers • move semantics • constexpr • many libraries • a lot more…
  • 9. Cross-language bridge • Java Native Interface (JNI): C++ <-> Java • Objective-C++: C++ <-> Objective-C • Consistent interface across languages • Data types that are the same in all languages • Object’s lifetime • Error handling
  • 10. JNI code example JNIEnv* env; if (m_javaVM->AttachCurrentThread(&env, nullptr) < 0) { return; } jclass applicationClass = env->GetObjectClass(cameraSupportClassPointer); if (applicationClass) { jmethodID getFrameID = env->GetMethodID(applicationClass, "getFrame", "()[B"); jobject frameObject = env->CallObjectMethod(cameraSupportClassPointer, getFrameID); if (frameObject) { jbyteArray *frameByteArray = reinterpret_cast<jbyteArray*>(&frameObject); jsize frameByteArrayLength = env->GetArrayLength(*frameByteArray); env->GetByteArrayRegion(*frameByteArray, 0, frameByteArrayLength, reinterpret_cast<jbyte*>(yuv)); jbyte *frameBytePointer = env->GetByteArrayElements(*frameByteArray, nullptr); env->ReleaseByteArrayElements(*frameByteArray, frameBytePointer, 0); } } m_javaVM->DetachCurrentThread(); JNIEnv* env; if (m_javaVM->AttachCurrentThread(&env, nullptr) < 0) { return; } jclass applicationClass = env->GetObjectClass(cameraSupportClassPointer); if (applicationClass) { jmethodID getFrameID = env->GetMethodID(applicationClass, "getFrame", "()[B"); jobject frameObject = env->CallObjectMethod(cameraSupportClassPointer, getFrameID); if (frameObject) { jbyteArray *frameByteArray = reinterpret_cast<jbyteArray*>(&frameObject); jsize frameByteArrayLength = env->GetArrayLength(*frameByteArray); env->GetByteArrayRegion(*frameByteArray, 0, frameByteArrayLength, reinterpret_cast<jbyte*>(yuv)); jbyte *frameBytePointer = env->GetByteArrayElements(*frameByteArray, nullptr); env->ReleaseByteArrayElements(*frameByteArray, frameBytePointer, 0); } } m_javaVM->DetachCurrentThread();
  • 11. Djinni • Dropbox’s Carousel and Mailbox • Bridge between C++ and Java/Objective-C • Bridge between C++ and Python (experimental) • Open source • Facebook’s Moments
  • 12. Djinni’s Interface Definition Language (IDL) • Enums • Records • Interfaces • Implementation languages
  • 14. C++11: auto std::vector<std::string> vec; std::vector<std::string>::iterator iter = vec.begin(); std::vector<std::string> vec; auto iter = vec.begin(); modern C++ vintage C++
  • 15. C++11: smart pointers auto d = new Dynamic; do_sth(d); // may throw vintage C++
  • 16. C++11: smart pointers auto d = new Dynamic; do_sth(d); // may throw delete d; vintage C++
  • 17. C++11: smart pointers auto d = new Dynamic; try { do_sth(d); // may throw } catch (...) { delete d; throw; // rethrow } delete d; vintage C++
  • 18. C++11: smart pointers auto d = new Dynamic; try { do_sth(d); // may throw } catch (...) { delete d; throw; // rethrow } delete d; auto d = std::make_shared<Dynamic>(); do_sth(d); // may throw modern C++ vintage C++
  • 19. C++11: std::move Huge h; do_sth(h); Huge h; do_sth(std::move(h)); modern C++ vintage C++
  • 20. Demo
  • 21. Pros • Less code • Easier maintenance • More consistency between app platform versions • Faster development • Better performance • Easy switch from single- to multi-platform
  • 22. Cons • Reasonable use of bridges • Djinni’s limitations (lack of interface inheritance) • Compilers issues (AndroidNDK vs CrystaxNDK) • Size of Android app increases (architectures) • No single IDE
  • 23. Links • github.com/dropbox/djinni • github.com/michal-kowalczyk/
 trambambule-helper • mobilecpptutorials.com • code.facebook.com/posts/498597036962415/ under-the-hood-building-moments