SlideShare a Scribd company logo
1 of 24
Download to read offline
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

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

PhoneGap_Javakuche0612
PhoneGap_Javakuche0612PhoneGap_Javakuche0612
PhoneGap_Javakuche0612
Yuhei Miyazato
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
Petr Dvorak
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
 

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

以 Kotlin 快速打造 Mobile Backend
以 Kotlin 快速打造 Mobile Backend以 Kotlin 快速打造 Mobile Backend
以 Kotlin 快速打造 Mobile Backend
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)
 
PhoneGap_Javakuche0612
PhoneGap_Javakuche0612PhoneGap_Javakuche0612
PhoneGap_Javakuche0612
 
Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
io 19 extended android flutter&mlkit
io 19 extended android flutter&mlkitio 19 extended android flutter&mlkit
io 19 extended android flutter&mlkit
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
iOS 7 SDK特訓班
iOS 7 SDK特訓班iOS 7 SDK特訓班
iOS 7 SDK特訓班
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
 
Understanding memory management in xamarin forms
Understanding memory management in xamarin formsUnderstanding memory management in xamarin forms
Understanding memory management in xamarin forms
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
multi platform mobile development using titanium
multi platform mobile development using titaniummulti platform mobile development using titanium
multi platform mobile development using titanium
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build System
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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