The document discusses various technologies for enabling interoperability between C++ and other languages. It describes setting up Java, .NET Core, and C# to call code written in C++ and vice versa. It also provides code samples and links to documentation for Java Native Interface (JNI), loading the Java VM from C++, and registering C++ methods in Java.
Overview of Android NDK (Native Development Toolkit).
Android application development is primarily done with the Android SDK.
Apps are written in Java thus benefitting from the high-level constructs
of the managed environment as well as the wealth of functionality provided
by the Android application platform.
However, sometimes it is necessary to implement certain functionality natively
in C++, e.g. when access to hardware is required or 3rd party stacks have to
be included that are only available as C++ code.
The NDK is a lightweight development toolkit for writing native applications
and libraries that can interwork with Java application code.
Hiveminder - Everything but the Secret SauceJesse Vincent
Ten tools and techniques to help you:
Find bugs faster バグの検出をもっと素早く
Build web apps ウェブアプリの構築
Ship software ソフトのリリース
Get input from users ユーザからの入力を受けつける
Own the Inbox 受信箱を用意する
今日の話
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)PROIDEA
Since the beginnings of C++, classes are the basic building block of any self-respecting application. The combination of data and its relevant functionality heavily impacts the way we modularize the program, design APIs, construct and reuse the code - think of software in general.
In the previous era, C++ was a hammer for every nail, providing secure high-level abstractions without sacrifice of the superior performance. Yet during the past decades, competing technologies dethroned it out of many domains. As the language evolved to prevail its principal advantages, so did the way classes are programmed.
I am pleased to invite you to a speech about code construction and programming techniques used in programs and libraries now and then. Expect a lot of code samples!
Using the Android Native Development Kit (NDK)DroidConTLV
Android NDK is used to integrate C/C++ code into Android applications. Learn when and how to use it ; and what it implies to do so from development, integration within Eclipse and Android Studio, to distribution.
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeKAI CHU CHUNG
Gokit is microservice tookit and use Service/Endpoint/Transport to strict separation of concerns design. This talk to use go-kit develop microservice application integrate with consul, zipkin, prometheus, etc service and deploy on Kubernetes.
Overview of Android NDK (Native Development Toolkit).
Android application development is primarily done with the Android SDK.
Apps are written in Java thus benefitting from the high-level constructs
of the managed environment as well as the wealth of functionality provided
by the Android application platform.
However, sometimes it is necessary to implement certain functionality natively
in C++, e.g. when access to hardware is required or 3rd party stacks have to
be included that are only available as C++ code.
The NDK is a lightweight development toolkit for writing native applications
and libraries that can interwork with Java application code.
Hiveminder - Everything but the Secret SauceJesse Vincent
Ten tools and techniques to help you:
Find bugs faster バグの検出をもっと素早く
Build web apps ウェブアプリの構築
Ship software ソフトのリリース
Get input from users ユーザからの入力を受けつける
Own the Inbox 受信箱を用意する
今日の話
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)PROIDEA
Since the beginnings of C++, classes are the basic building block of any self-respecting application. The combination of data and its relevant functionality heavily impacts the way we modularize the program, design APIs, construct and reuse the code - think of software in general.
In the previous era, C++ was a hammer for every nail, providing secure high-level abstractions without sacrifice of the superior performance. Yet during the past decades, competing technologies dethroned it out of many domains. As the language evolved to prevail its principal advantages, so did the way classes are programmed.
I am pleased to invite you to a speech about code construction and programming techniques used in programs and libraries now and then. Expect a lot of code samples!
Using the Android Native Development Kit (NDK)DroidConTLV
Android NDK is used to integrate C/C++ code into Android applications. Learn when and how to use it ; and what it implies to do so from development, integration within Eclipse and Android Studio, to distribution.
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeKAI CHU CHUNG
Gokit is microservice tookit and use Service/Endpoint/Transport to strict separation of concerns design. This talk to use go-kit develop microservice application integrate with consul, zipkin, prometheus, etc service and deploy on Kubernetes.
Second iteration of my javascript talk.
Presented at PHP Day Italia 2009 on May 15th.
Slides refactored, cut down code examples and added some content about js abstractions and ecmascript 3.1.
See http://federico.galassi.net/2009/05/17/javascript-the-good-parts-talk/
Follow me on Twitter!
https://twitter.com/federicogalassi
Talk donné à la soirée DockerLyon du 30Mai autour de la sécurité de container.
les do's and don'ts accompagné d'exemples d'utilisation de fonctionnalités avancées (Capabilities, AppAmor, SecComp ...)
What is DocuOps. How does Asciidoctor contribute? How to add it to your Maven & Gradle build. Tying all of the tech documentation together in a single project from commit to publish.
This manual is “How to Build” manual for OpenCV with OpenCL for Android.
If you want to “Use OpenCL on OpenCV” ONLY,
Please see
http://github.com/noritsuna/OpenCVwithOpenCL4AndroidNDKSample
Threads and Callbacks for Embedded PythonYi-Lung Tsai
Python is a great choice to be customized plug-ins for existing applications. Extending existing applications with Python program is also practical. For large systems, multi-thread programming is ubiquitous along with asynchronous programming, such as event routing. This presentation focuses on dealing with threads and callbacks while embedding Python in other applications.
Supporting several languages is a key point to increase the audience of an application. We will see what is needed in Qt to enable internationalization and how to ensure all the components can be translated. We will also see the tools available for the translators and how to use them.
Presentation by Benjamin Poulain held during Qt Developer Days 2009.
http://qt.nokia.com/developer/learning/elearning
More developers on DevOps with Docker orchestrationGiulio De Donato
Few things you have to Know in Order to use docker with Orchestration in Production like I did, but not really like i did, because I cried, I really cried hard! Three way devops, pipeline...
This talk is about creating Node.js interfaces for native libraries written in C or C++. It starts with various situations in which you need to build native addons and the common problems in doing that. I'll discuss the reference provided by the new N-API (Node-API) that helps mantainers to support a wide variety of Node.js releases without needing recompilation or abstraction layers. With all these tools and knowledge I'll show you how to build some addons from scratch and how to convert existing addons using the new N-API. The last part is related to future developments about addons.
Second iteration of my javascript talk.
Presented at PHP Day Italia 2009 on May 15th.
Slides refactored, cut down code examples and added some content about js abstractions and ecmascript 3.1.
See http://federico.galassi.net/2009/05/17/javascript-the-good-parts-talk/
Follow me on Twitter!
https://twitter.com/federicogalassi
Talk donné à la soirée DockerLyon du 30Mai autour de la sécurité de container.
les do's and don'ts accompagné d'exemples d'utilisation de fonctionnalités avancées (Capabilities, AppAmor, SecComp ...)
What is DocuOps. How does Asciidoctor contribute? How to add it to your Maven & Gradle build. Tying all of the tech documentation together in a single project from commit to publish.
This manual is “How to Build” manual for OpenCV with OpenCL for Android.
If you want to “Use OpenCL on OpenCV” ONLY,
Please see
http://github.com/noritsuna/OpenCVwithOpenCL4AndroidNDKSample
Threads and Callbacks for Embedded PythonYi-Lung Tsai
Python is a great choice to be customized plug-ins for existing applications. Extending existing applications with Python program is also practical. For large systems, multi-thread programming is ubiquitous along with asynchronous programming, such as event routing. This presentation focuses on dealing with threads and callbacks while embedding Python in other applications.
Supporting several languages is a key point to increase the audience of an application. We will see what is needed in Qt to enable internationalization and how to ensure all the components can be translated. We will also see the tools available for the translators and how to use them.
Presentation by Benjamin Poulain held during Qt Developer Days 2009.
http://qt.nokia.com/developer/learning/elearning
More developers on DevOps with Docker orchestrationGiulio De Donato
Few things you have to Know in Order to use docker with Orchestration in Production like I did, but not really like i did, because I cried, I really cried hard! Three way devops, pipeline...
This talk is about creating Node.js interfaces for native libraries written in C or C++. It starts with various situations in which you need to build native addons and the common problems in doing that. I'll discuss the reference provided by the new N-API (Node-API) that helps mantainers to support a wide variety of Node.js releases without needing recompilation or abstraction layers. With all these tools and knowledge I'll show you how to build some addons from scratch and how to convert existing addons using the new N-API. The last part is related to future developments about addons.
Easing offline web application development with GWTArnaud Tournier
At this current time, HTML5 APIs are mature enough so that the web browser can now be a very good platform for applications that were before only implemented as native applications : offline applications with locally stored data, embedded SQL engines, etc. Although there are many good Javascript frameworks out there, the Java language allows to build, maintain, debug and work with ease on really big applications (> 100,000 LOC).
You'll discover in this presentation all the tools we assembled to make an application available with its data 100% of the time, even without internet!
Slideshow from C++ Day 2017 held in Modena, about the idea to create desktop applications by adding an HTML5 UI to a C++ executable. The solution is lightweight: it exploits the power of websockets and doesn't need web servers.
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Codemotion
This talk is about creating Node.js interfaces for native libraries written in C or C++. It starts with various situations in which you need to build native addons and the common problems in doing that. I'll discuss the reference provided by the new N-API (Node-API) that helps mantainers to support a wide variety of Node.js releases without needing recompilation or abstraction layers. With all these tools and knowledge I'll show you how to build some addons from scratch and how to convert existing addons using the new N-API. The last part is related to future developments about addons.
http://fr.droidcon.com/2014/agenda/
http://fr.droidcon.com/2014/agenda/detail?title=The+Android+Native+Development+Kit
The Android NDK is used to integrate C/C++ code into Android applications and libraries.
Learn how you can use the NDK and NDK-based libraries with Eclipse and Android Studio, and how you can debug and optimize your code.
Discover what changes from the new Android Runtime may break your integration, and how you can target new 64-bit architectures with the upcoming android L-release.
Speaker : Alexander Weggerle, Intel
A Microsoft continua investindo muito e continua ouvindo bastante toda a comunidade técnica afim de para melhorar a tecnologia .NET. Em função disto o código do .NET se tornou aberto junto com uma série de tecnologias que formam a .NET Foundation.
For the full video of this presentation, please visit:
http://www.embedded-vision.com/platinum-members/embedded-vision-alliance/embedded-vision-training/videos/pages/may-2015-embedded-vision-summit-opencv
For more information about embedded vision, please visit:
http://www.embedded-vision.com
Gary Bradski, President and CEO of the OpenCV Foundation, presents the "OpenCV Open Source Computer Vision Library: Latest Developments" tutorial at the May 2015 Embedded Vision Summit.
OpenCV is an enormously popular open source computer vision library, with over 9 million downloads. Originally used mainly for research and prototyping, in recent years OpenCV has increasingly been used in deployed products on a wide range of platforms from cloud to mobile.
The latest version, OpenCV 3.0 is currently in beta, and is a major overhaul, bringing OpenCV up to modern C++ standards and incorporating expanded support for 3D vision. The new release also introduces a modular “contrib” facility that enables independently developed modules to be quickly integrated with OpenCV as needed, providing a flexible mechanism to allow developers to experiment with new techniques before they are officially integrated into the library.
In this talk, Gary Bradski, head of the OpenCV Foundation, provides an insider’s perspective on the new version of OpenCV and how developers can utilize it to maximum advantage for vision research, prototyping, and product development.
As Europe's leading economic powerhouse and the fourth-largest hashtag#economy globally, Germany stands at the forefront of innovation and industrial might. Renowned for its precision engineering and high-tech sectors, Germany's economic structure is heavily supported by a robust service industry, accounting for approximately 68% of its GDP. This economic clout and strategic geopolitical stance position Germany as a focal point in the global cyber threat landscape.
In the face of escalating global tensions, particularly those emanating from geopolitical disputes with nations like hashtag#Russia and hashtag#China, hashtag#Germany has witnessed a significant uptick in targeted cyber operations. Our analysis indicates a marked increase in hashtag#cyberattack sophistication aimed at critical infrastructure and key industrial sectors. These attacks range from ransomware campaigns to hashtag#AdvancedPersistentThreats (hashtag#APTs), threatening national security and business integrity.
🔑 Key findings include:
🔍 Increased frequency and complexity of cyber threats.
🔍 Escalation of state-sponsored and criminally motivated cyber operations.
🔍 Active dark web exchanges of malicious tools and tactics.
Our comprehensive report delves into these challenges, using a blend of open-source and proprietary data collection techniques. By monitoring activity on critical networks and analyzing attack patterns, our team provides a detailed overview of the threats facing German entities.
This report aims to equip stakeholders across public and private sectors with the knowledge to enhance their defensive strategies, reduce exposure to cyber risks, and reinforce Germany's resilience against cyber threats.
Opendatabay - Open Data Marketplace.pptxOpendatabay
Opendatabay.com unlocks the power of data for everyone. Open Data Marketplace fosters a collaborative hub for data enthusiasts to explore, share, and contribute to a vast collection of datasets.
First ever open hub for data enthusiasts to collaborate and innovate. A platform to explore, share, and contribute to a vast collection of datasets. Through robust quality control and innovative technologies like blockchain verification, opendatabay ensures the authenticity and reliability of datasets, empowering users to make data-driven decisions with confidence. Leverage cutting-edge AI technologies to enhance the data exploration, analysis, and discovery experience.
From intelligent search and recommendations to automated data productisation and quotation, Opendatabay AI-driven features streamline the data workflow. Finding the data you need shouldn't be a complex. Opendatabay simplifies the data acquisition process with an intuitive interface and robust search tools. Effortlessly explore, discover, and access the data you need, allowing you to focus on extracting valuable insights. Opendatabay breaks new ground with a dedicated, AI-generated, synthetic datasets.
Leverage these privacy-preserving datasets for training and testing AI models without compromising sensitive information. Opendatabay prioritizes transparency by providing detailed metadata, provenance information, and usage guidelines for each dataset, ensuring users have a comprehensive understanding of the data they're working with. By leveraging a powerful combination of distributed ledger technology and rigorous third-party audits Opendatabay ensures the authenticity and reliability of every dataset. Security is at the core of Opendatabay. Marketplace implements stringent security measures, including encryption, access controls, and regular vulnerability assessments, to safeguard your data and protect your privacy.
Adjusting primitives for graph : SHORT REPORT / NOTESSubhajit Sahu
Graph algorithms, like PageRank Compressed Sparse Row (CSR) is an adjacency-list based graph representation that is
Multiply with different modes (map)
1. Performance of sequential execution based vs OpenMP based vector multiply.
2. Comparing various launch configs for CUDA based vector multiply.
Sum with different storage types (reduce)
1. Performance of vector element sum using float vs bfloat16 as the storage type.
Sum with different modes (reduce)
1. Performance of sequential execution based vs OpenMP based vector element sum.
2. Performance of memcpy vs in-place based CUDA based vector element sum.
3. Comparing various launch configs for CUDA based vector element sum (memcpy).
4. Comparing various launch configs for CUDA based vector element sum (in-place).
Sum with in-place strategies of CUDA mode (reduce)
1. Comparing various launch configs for CUDA based vector element sum (in-place).
Show drafts
volume_up
Empowering the Data Analytics Ecosystem: A Laser Focus on Value
The data analytics ecosystem thrives when every component functions at its peak, unlocking the true potential of data. Here's a laser focus on key areas for an empowered ecosystem:
1. Democratize Access, Not Data:
Granular Access Controls: Provide users with self-service tools tailored to their specific needs, preventing data overload and misuse.
Data Catalogs: Implement robust data catalogs for easy discovery and understanding of available data sources.
2. Foster Collaboration with Clear Roles:
Data Mesh Architecture: Break down data silos by creating a distributed data ownership model with clear ownership and responsibilities.
Collaborative Workspaces: Utilize interactive platforms where data scientists, analysts, and domain experts can work seamlessly together.
3. Leverage Advanced Analytics Strategically:
AI-powered Automation: Automate repetitive tasks like data cleaning and feature engineering, freeing up data talent for higher-level analysis.
Right-Tool Selection: Strategically choose the most effective advanced analytics techniques (e.g., AI, ML) based on specific business problems.
4. Prioritize Data Quality with Automation:
Automated Data Validation: Implement automated data quality checks to identify and rectify errors at the source, minimizing downstream issues.
Data Lineage Tracking: Track the flow of data throughout the ecosystem, ensuring transparency and facilitating root cause analysis for errors.
5. Cultivate a Data-Driven Mindset:
Metrics-Driven Performance Management: Align KPIs and performance metrics with data-driven insights to ensure actionable decision making.
Data Storytelling Workshops: Equip stakeholders with the skills to translate complex data findings into compelling narratives that drive action.
Benefits of a Precise Ecosystem:
Sharpened Focus: Precise access and clear roles ensure everyone works with the most relevant data, maximizing efficiency.
Actionable Insights: Strategic analytics and automated quality checks lead to more reliable and actionable data insights.
Continuous Improvement: Data-driven performance management fosters a culture of learning and continuous improvement.
Sustainable Growth: Empowered by data, organizations can make informed decisions to drive sustainable growth and innovation.
By focusing on these precise actions, organizations can create an empowered data analytics ecosystem that delivers real value by driving data-driven decisions and maximizing the return on their data investment.
StarCompliance is a leading firm specializing in the recovery of stolen cryptocurrency. Our comprehensive services are designed to assist individuals and organizations in navigating the complex process of fraud reporting, investigation, and fund recovery. We combine cutting-edge technology with expert legal support to provide a robust solution for victims of crypto theft.
Our Services Include:
Reporting to Tracking Authorities:
We immediately notify all relevant centralized exchanges (CEX), decentralized exchanges (DEX), and wallet providers about the stolen cryptocurrency. This ensures that the stolen assets are flagged as scam transactions, making it impossible for the thief to use them.
Assistance with Filing Police Reports:
We guide you through the process of filing a valid police report. Our support team provides detailed instructions on which police department to contact and helps you complete the necessary paperwork within the critical 72-hour window.
Launching the Refund Process:
Our team of experienced lawyers can initiate lawsuits on your behalf and represent you in various jurisdictions around the world. They work diligently to recover your stolen funds and ensure that justice is served.
At StarCompliance, we understand the urgency and stress involved in dealing with cryptocurrency theft. Our dedicated team works quickly and efficiently to provide you with the support and expertise needed to recover your assets. Trust us to be your partner in navigating the complexities of the crypto world and safeguarding your investments.
2. C++ Day 2017 – Un evento dell’Italian C++ Community
TIOBE Index for November 2017
The TIOBE Programming Community index is an indicator of
the popularity of programming languages.
https://www.tiobe.com/tiobe-index/
3. C++ Day 2017 – Un evento dell’Italian C++ Community
TIOBE Programming Community index
4. C++ Day 2017 – Un evento dell’Italian C++ Community
Ispirazione
itCppCon17
Costruire un bridge C++ tra NodeJS e
C# (Raffaele Rialdi)
http://italiancpp.org/itcppcon17
5. C++ Day 2017 – Un evento dell’Italian C++ Community
Necessità
6. C++ Day 2017 – Un evento dell’Italian C++ Community
Il mio lavoro
Http Services Framework, Win + Linux
Linguaggi (C++, R, Java, SQL, PL/SQL e PL/pgSQL)
Framework di base
◦ Http
◦ Database and datasources
◦ Logging
◦ Configuration
◦ In memory cache
◦ Event notification
◦ Db interface
◦ Security
◦ Scalability
7. C++ Day 2017 – Un evento dell’Italian C++ Community
Preparazione della presentazione
◦ Copia / Taglia / Incolla
◦ Semplificare
◦ Cross platform
◦ Librerie facili da compilare
8. C++ Day 2017 – Un evento dell’Italian C++ Community
Preparazione della presentazione
La mia C++ toolchain (on windows)
http://www.msys2.org/
MSYS2 is a software distro
and building platform for Windows
pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-gdb
...
https://codelite.org/
A Free, open source, cross platform C,C++,PHP and Node.js IDE
9. C++ Day 2017 – Un evento dell’Italian C++ Community
Librerie di base
http://fmtlib.net
alternative to printf
https://zlib.net/
Compression Library
https://github.com/mity/md4c
C Markdown parser. Fast
https://github.com/gabime/spdlog
Super fast C++ logging library.
https://github.com/civetweb/civetweb
Embedded C/C++ web server
http://www.boost.org
C++ source libraries
https://github.com/skystrife/cpptoml
parsing TOML
https://curl.haxx.se/libcurl/
the multiprotocol file transfer library
https://unqlite.org/
An Embeddable NoSQL Database Engine
10. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred
A C++ multi-threaded http REST server
I servizi possono essere implementati in
Linguaggio matematico
C++
Javascript
Lua
Python
C#
Java
11. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred
FastCGI ?
FastCGI è un protocollo che permette di interfacciare programmi interattivi CGI con
un server web. Lo scopo principale di FastCGI è quello di ottimizzare le risorse
del sistema nell'interfacciamento tra il programma CGI e il server web,
permettendo al server di gestire più richieste di pagina web assieme.
12. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred
http server (civetweb)
C++ framework
Java JVM
Jar file
.Net core
.Net
assembly
Ducktape
Js
Script
Python
Script
LUA
Script
Tinyexpr
Static files
*.md
*.html +
*.cs +
*.js …
13. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred - Civetweb
https://github.com/civetweb/civetweb
“Project mission is to provide easy to use, powerful, C/C++
embeddable web server with optional CGI, SSL and Lua
support. CivetWeb has a MIT license so you can innovate
without restrictions.
CivetWeb can be used by developers as a library, to add web
server functionality to an existing application. It can also be
used by end users as a stand-alone web server. It is available as
single executable, no installation is required.”
CivetWeb has been forked from the last MIT version of
Mongoose. Since 2013
14. C++ Day 2017 – Un evento dell’Italian C++ Community
Requisiti
Da C++ chiamo <lang>
Da <lang> chiamo C++ (callback)
Il framework c++ offre funzioni di esempio:
http.call
Log api
Passo i parametri del servizio http a <lang>
Ottengo in output status e body (json)
15. C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
https://github.com/codeplea/tinyexpr
TinyExpr is a very small recursive descent parser and
evaluation engine for math expressions.
16. C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
https://it.wikipedia.org/wiki/Normalized_Difference_Veget
ation_Index - NDVI
Il Normalized Difference Vegetation Index (NDVI) è un
semplice indicatore grafico per valutare se la zona osservata
contiene della vegetazione viva.
17. C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
18. C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
Demo
19. C++ Day 2017 – Un evento dell’Italian C++ Community
Java - setup
http://www.oracle.com/technetwork/java/javase/downloads/index.html
jdk-9.0.1_windows-x64_bin.exe
-> tools.zip
->-> bin/
->-> conf/
…
Apro come zip file, estraggo il contenuto di tools.zip, ottengo:
.libsjavax64binserverjvm.dll
20. C++ Day 2017 – Un evento dell’Italian C++ Community
Java - setup
https://neugens.wordpress.com/2015/02/26/debugging-the-jdk-with-gdb/
“
Hotspot uses segfaults for a number of interesting things, like deoptimise, NullPointerException etc..
Apparently, this is faster than doing specific checks and jumping around the code. This is a problem for
gdb though, since it will stop every now and then to some random routines you don’t really (usually!) care
about:
Program received signal SIGSEGV, Segmentation fault.
Irritating, since those are all legitimate segfaults.
To avoid that just do the following in the gdb console (or from the IDE in whatever way this is handled
there):
(gdb) handle SIGSEGV nostop noprint pass
Now all the interesting work can be done without interruptions
“
21. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Compile class
TestService.java
> javac TestService.java
Ottengo: TestService.class
public class TestService {
public void doService(HashMap serviceParameters){
// Prints "Hello, World" in the terminal window.
System.out.println("Hello, World");
}
}
22. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Create JAR
> jar cf svc01.jar alfredTest*.class
Ottengo: svc01.jar (Java Archive)
23. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – JNI
La Java Native Interface o JNI è
un framework del linguaggio Java che consente al codice
Java di richiamare (o essere richiamato da) codice
cosiddetto "nativo ".
#include <jni.h>
24. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Jvm startup
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
options[0].optionString = "-Djava.class.path=.";
vm_args.version = JNI_VERSION_1_6; // minimum Java version
vm_args.nOptions = 1; // number of options
vm_args.options = options;
prepare loading of Java
VM
C++
25. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Jvm startup
jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (rc != JNI_OK) {
//error processing...
}
cout << "JVM load succeeded: Version ";
jint ver = env->GetVersion();
cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl;
jvm->DestroyJavaVM();
load and initialize Java
VM and JNI interface
Ready to use JVM
26. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Call Java Method from C++
jclass service_class = jenv->FindClass( "package/classname" );
jmethodID service_constructor = jenv->GetMethodID(service_class, "<init>", "SIGN");
jobject service_obj = jenv->NewObject(service_class, service_constructor,
CTOR_PARAMS);
jmethodID callService = jenv->GetMethodID(service_class, "methodToCall", "SIGN");
jenv->CallObjectMethod(service_obj, callService, METHOD_PARAMS);
if(jenv->ExceptionCheck())
{
jthrowable jt = jenv->ExceptionOccurred();
decodeException(a_error_msg, jt);
jenv->ExceptionClear();
}
jenv->DeleteLocalRef(service_obj);
Construct
object
Call method
Exception
check
Tell GC to clear
C++
27. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Class File Disassembler
Come leggere le firme dei metodi
> javap -s TestService.class
public void doService(java.util.HashMap);
descriptor: (Ljava/util/HashMap;)V
Lo uso così (c++)
jmethodID callService = jenv->GetMethodID(service_class,
"doService",
"(Ljava/util/HashMap;)V"
);
28. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Call C++ Method from Java
static void JNICALL alfLogInfo(JNIEnv *env, jclass clazz, jstring toLog) {
//do something
}
static JNINativeMethod method_table[] =
{
{ (char*)("alfLogInfo"), (char*)("SIGN"), (void*) alfLogInfo },
{ (char*)("alfLogDebug"), (char*)("SIGN"), (void*) alfLogDebug },
{ (char*)("alfLogError"), (char*)("SIGN"), (void*) alfLogError }
};
jclass service_class = jenv->FindClass( “alfredTest /TestService” );
ret = jenv->RegisterNatives(service_class, method_table, method_table_size);
C++
29. C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Call C++ Method from Java
package alfredTest;
public class TestService
{
public static native void alfLogInfo(String toLog);
public static native void alfLogDebug(String toLog);
public static native void alfLogError(String toLog);
public void doService(HashMap serviceParameters){
alfLogInfo("Jave here!");
}
}
Java
30. C++ Day 2017 – Un evento dell’Italian C++ Community
Java
Ottima documentazione!
31. C++ Day 2017 – Un evento dell’Italian C++ Community
Java
Demo
32. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
https://dotnet.github.io/
“The C#, Visual Basic, and F# languages
can be used to write applications
and libraries for .NET Core.”
33. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
https://dotnet.github.io/
.NET Core is a general purpose development platform
maintained by Microsoft and the .NET community
on GitHub. It is cross-platform, supporting Windows,
macOS and Linux, and can be used in device, cloud, and
embedded/IoT scenarios.
https://www.microsoft.com/net/learn/get-
started/windows
34. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
cd C:dev_gccalfred
dotnet new classlib -o manlib
cd manlib
Edit *.cs
dotnet build
Per aggiungere funzioni native ho dovuto mettere nel file .csproj il seguente blocco:
<PropertyGroup>
...
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
...
</PropertyGroup>
35. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
Step 1 - Identify the managed entry point
Step 2 - Find and load CoreCLR.dll
Step 3 - Get an ICLRRuntimeHost2 Instance
Step 4 - Setting startup flags and starting the runtime
Step 5 - Preparing AppDomain settings
Step 6 - Create the AppDomain
Step 7 - Run managed code!
Step 8 - Clean up
36. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
Da C++ invoco metodo C#
typedef int (STDMETHODCALLTYPE * runIt)(const char* p1, int p2);
runIt pfnDelegate;
ICLRRuntimeHost2* runtimeHostPtr = (ICLRRuntimeHost2*)runtimeHost;
HRESULT hr = runtimeHostPtr->CreateDelegate(
domainId,
theAssembly.c_str(), // Target managed assembly
theClass.c_str(), // Target managed type
toCall.c_str(), // Target entry point (static method)
(INT_PTR*)&pfnDelegate
);
(*pfnDelegate)("alfa", 33);
37. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
Da C# invoco metodo C++ (callback)
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
unsafe delegate IntPtr ptr_to_cpp_funz( int p1, string p2 );
static void doService(IntPtr cpp_callback) {
ptr_to_cpp_funz del_to_cpp;
del_to_cpp = Marshal.GetDelegateForFunctionPointer(cpp_callback, typeof(ptr_to_cpp_funz) );
del_to_cpp(1, "Hello world");
}
38. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
Callbacks (da C# chiamo C++) previste
enum NativeFunctions {
curlNew,
curlGetStatus,
curlGetContentType,
curlGetBody,
curlFree,
getParam,
replyService,
logInfo,
logDebug,
logError
};
39. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
void doService(){ //coreclr startup code
(*pfnDelegate)(getNative);
}
enum DNetNativeFunctions {e_logInfo, ...};
void* getNative(int what){
switch(what)
{
case e_logInfo:
return logInfo;
break;
...
}
return 0;
}
void logInfo(const char* toLog){
serverLog->info(toLog);
}
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
unsafe delegate IntPtr ptr_getNative( int what );
unsafe delegate void ptr_logInfo(string toLog);
enum NativeFunctions { logInfo, ...};
static void doService(IntPtr cback_getNative) {
ptr_getNative getNative;
ptr_logInfo del_logInfo;
getNative = Marshal.GetDelegateForFunctionPointer(
cback_getNative, typeof(ptr_getNative) );
del_logInfo = Marshal.GetDelegateForFunctionPointer(
getNative((int)NativeFunctions.logInfo), typeof(ptr_logInfo) );
del_logInfo("Hello world");
}
C++ C#
40. C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
Demo
41. C++ Day 2017 – Un evento dell’Italian C++ Community
https://www.python.it/
https://github.com/pybind/pybind11
“Seamless operability between C++11 and Python”
Python (2.7 or 3.x, or PyPy2.7 >= 5.7)
42. C++ Day 2017 – Un evento dell’Italian C++ Community
Setup
https://www.python.it/
Installo python-3.6.3-amd64.exe
Ottengo C:toolsPython36
https://github.com/pybind/pybind11
Scarico e scompatto
Ottengo C:dev_gccalfredlibspybind11
C++ 11
Header Only
43. C++ Day 2017 – Un evento dell’Italian C++ Community
pybind11 - startup
bool ThreadStorage::startPythonEngine(const std::string& scriptsPath) {
pythonGuard = static_cast<void*>( new py::scoped_interpreter() );
std::string plugInInitCode = fmt::format(
"import sysnimport osnsys.path.insert(0,'{}')",
scriptsPath
);
py::exec(plugInInitCode, py::globals());
return true;
}
44. C++ Day 2017 – Un evento dell’Italian C++ Community
pybind11 - shutdown
void ThreadStorage::stopPythonEngine() {
delete static_cast<py::scoped_interpreter*>( pythonGuard );
}
45. C++ Day 2017 – Un evento dell’Italian C++ Community
Call python method
PythonService pySvc;
try
{
py::module py_module = py::module::import( scriptFileName.c_str() );
if(isModified)
py_module.reload();
py::object serviceMain = py_module.attr("serviceMain");
serviceMain( &pySvc );
}
catch(py::error_already_set& err)
{
std::string errorMsg = err.what();
serverLog->error("Error on {}('{}'): '{}'", __FUNCTION__, scriptFileName, errorMsg);
}
46. C++ Day 2017 – Un evento dell’Italian C++ Community
Call python method
PYBIND11_EMBEDDED_MODULE(AlfCore, m)
{
m.def("logInfo", &logInfo);
m.def("logDebug", &logDebug);
m.def("logError", &logError);
py::class_<PythonService>(m, "AlfService")
.def(py::init<>())
.def("setBody", &PythonService::setBody)
.def("setReturnCode", &PythonService::setReturnCode)
.def("getParam", &PythonService::getParam);
py::class_<PythonHttp>(m, "AlfHttp")
.def(py::init<const std::string &, const std::string &, const std::string &, const std::string &, const std::string &>())
.def("getContentType", &PythonHttp::getContentType)
.def("getBody", &PythonHttp::getBody)
.def("getStatus", &PythonHttp::getStatus);
}
47. C++ Day 2017 – Un evento dell’Italian C++ Community
Call C++ method
import AlfCore
import json
import time
def serviceMain(alfRequest):
AlfCore.logInfo( 'Python HERE! P1={}'.format( alfRequest.getParam( 'P1' ) ) )
httpCall = AlfCore.AlfHttp('', 'https://jsonplaceholder.typicode.com/posts?userId=1', '', '', '')
if httpCall.getStatus() == 200 and httpCall.getContentType().startswith('application/json'):
decoded = json.loads( httpCall.getBody() )
data = { 'user' : decoded[0]['title'], 'price' : 542.23 }
reply = json.dumps( data )
returnCode = 200
alfRequest.setBody( reply )
alfRequest.setReturnCode(returnCode)
48. C++ Day 2017 – Un evento dell’Italian C++ Community
Pybind11 Alternative
Boost.Python
49. C++ Day 2017 – Un evento dell’Italian C++ Community
Demo
50. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua
https://www.lua.org/
Lua is a powerful, efficient, lightweight, embeddable
scripting language. It supports procedural programming,
object-oriented programming, functional programming,
data-driven programming, and data description.
http://luajit.org/
a Just-In-Time Compiler for Lua
51. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua
52. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua - Setup
Scaricare LuaJIT-2.0.5.zip
Scompattarlo
Building with MSVC
cd src
msvcbuild
Building with MinGW
mingw32-make
Include dir: LuaJIT-2.0.5src
Libs dir: LuaJIT-2.0.5src
Additional libraries: lua51dll
Ottengo: liblua51dll.a + lua52.dll
53. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua – Startup code
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
int main()
{
lua_State *state = luaL_newstate();
luaL_openlibs( state ); // Open standard libraries
…
lua_close(state);
return 0;
}
54. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua – Call Lua function
int luaL_dostring (lua_State *L, const char *str);
int ret = luaL_dostring(state, scriptFile->c_str());
if(ret != 0)
{
std::string errM = lua_tostring(state, -1);
}
lua_settop(state, 0);
55. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua – The lua stack
Bottom
1
2
3-1
-2
-3
“
Whenever you want to ask for a value from Lua (such as the value of a global variable),
you call Lua, which pushes the required value on the stack.
Whenever you want to pass a value to Lua, you first push the value on the stack,
and then you call Lua (which will pop the value).
“
56. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua – Call C++ callback
static int getParameters(lua_State* L)
{
lua_newtable(L);
for(std::map<std::string, std::string>::iterator it = curReqLua->queryParams.params.begin();
it != curReqLua->queryParams.params.end();
it++)
{
lua_pushstring(L, it->first.c_str()); // push key
lua_pushstring(L, it->second.c_str()); // push value
lua_settable(L, -3);
}
return 1; // one return value
}
C++
lua_pushcfunction(lua, getParameters);
lua_setglobal(lua, "getParameters");
lua_pushcfunction(lua, curlForLua);
lua_setglobal(lua, "curl");
57. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua – Call C++ callback
params = getParameters()
for key,value in pairs(params) do
logInfo('Param: ' .. key .. '; Value:' .. value)
end
ret = curl("https://xyz.com", “user", “pass")
obj = json.decode(ret["body"]) Lua
58. C++ Day 2017 – Un evento dell’Italian C++ Community
Lua
Demo
59. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript
http://duktape.org/
‘’ Duktape is an embeddable Javascript engine, with a focus on portability and
compact footprint.
Duktape is easy to integrate into a C/C++ project: add duktape.c, duktape.h,
and duk_config.h to your build, and use the Duktape API to call Ecmascript
functions from C code and vice versa. ‘’
60. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript - Startup
#include <stdio.h>
#include "duktape.h"
int main(int argc, char *argv[]) {
duk_context *ctx = duk_create_heap_default();
duk_push_string(ctx, scriptFile->c_str());
if (duk_peval(ctx) != 0) {
printf("Error running: %sn", duk_safe_to_string(ctx, -1));
}
duk_pop(ctx);
duk_destroy_heap(ctx);
return 0;
}
61. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript - Call C++ callback
static duk_ret_t native_get_parameters(duk_context *ctx) {
alfred::ByteBuff jsonParams;
jsonParams.append("[");
for(std::map<std::string, std::string>::iterator it = curReq->queryParams.params.begin();
it != curReq->queryParams.params.end(); it++) {
if( it != curReq->queryParams.params.begin() ) jsonParams.append(",");
jsonParams.append( fmt::format( "{{"{}":"{}"}}", it->first, it->second );
}
jsonParams.append("]");
duk_push_string( ctx, jsonParams.c_str() );
duk_json_decode( ctx, -1 );
return 1; // one return value
}
C++
duk_push_c_function(duk_ctx, native_get_parameters, DUK_VARARGS);
duk_put_global_string(duk_ctx, "getParameters");
62. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript - Call C++ callback
function executeService() {
var params = getParameters();
logInfo( 'P1: ' + params[0].P1 );
}
executeService();
Js
63. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript - Alternative
Chrome V8
Mozilla SpiderMonkey
Microsoft ChakraCore
…
64. C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript
Demo
65. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred - ToDo
66. C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred
67. C++ Day 2017 – Un evento dell’Italian C++ Community
Prossima puntata
68. C++ Day 2017 – Un evento dell’Italian C++ Community
Domande
@albertino80
italiancpp.slack.com
@albertino
@albertino80
albertino80@bigno.it