SlideShare a Scribd company logo
1 of 68
Download to read offline
www.italiancpp.org
C++ Day 2017
2 Dicembre, Modena
C++ interoperability
with other languages
Alberto Bignotti
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/
C++ Day 2017 – Un evento dell’Italian C++ Community
TIOBE Programming Community index
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Necessità
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Preparazione della presentazione
◦ Copia / Taglia / Incolla
◦ Semplificare
◦ Cross platform
◦ Librerie facili da compilare
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
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
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
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.
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 …
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
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)
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.
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.
C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
C++ Day 2017 – Un evento dell’Italian C++ Community
TinyExpr
Demo
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
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
“
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");
}
}
C++ Day 2017 – Un evento dell’Italian C++ Community
Java – Create JAR
> jar cf svc01.jar alfredTest*.class
Ottengo: svc01.jar (Java Archive)
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>
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++
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
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++
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"
);
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++
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Java
Ottima documentazione!
C++ Day 2017 – Un evento dell’Italian C++ Community
Java
Demo
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.”
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
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>
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
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);
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");
}
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
};
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#
C++ Day 2017 – Un evento dell’Italian C++ Community
.NET Core – C#
Demo
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)
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
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;
}
C++ Day 2017 – Un evento dell’Italian C++ Community
pybind11 - shutdown
void ThreadStorage::stopPythonEngine() {
delete static_cast<py::scoped_interpreter*>( pythonGuard );
}
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);
}
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);
}
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)
C++ Day 2017 – Un evento dell’Italian C++ Community
Pybind11 Alternative
Boost.Python
C++ Day 2017 – Un evento dell’Italian C++ Community
Demo
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Lua
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
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;
}
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);
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).
“
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");
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Lua
Demo
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. ‘’
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;
}
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");
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
C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript - Alternative
Chrome V8
Mozilla SpiderMonkey
Microsoft ChakraCore
…
C++ Day 2017 – Un evento dell’Italian C++ Community
Javascript
Demo
C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred - ToDo
C++ Day 2017 – Un evento dell’Italian C++ Community
Alfred
C++ Day 2017 – Un evento dell’Italian C++ Community
Prossima puntata
C++ Day 2017 – Un evento dell’Italian C++ Community
Domande
@albertino80
italiancpp.slack.com
@albertino
@albertino80
albertino80@bigno.it

More Related Content

What's hot

Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2Federico Galassi
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationKAI CHU CHUNG
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5firenze-gtug
 
WebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationWebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationJooinK
 
Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Jarek Ratajski
 
DocuOps & Asciidoctor in a JVM World
DocuOps & Asciidoctor in a JVM WorldDocuOps & Asciidoctor in a JVM World
DocuOps & Asciidoctor in a JVM WorldSchalk Cronjé
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonYi-Lung Tsai
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkZachary Blair
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtoolingDouglas Chen
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Johan Thelin
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationPaolo Predonzani
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applicationsaccount inactive
 
DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.JooinK
 
More developers on DevOps with Docker orchestration
More developers on DevOps with Docker orchestrationMore developers on DevOps with Docker orchestration
More developers on DevOps with Docker orchestrationGiulio De Donato
 

What's hot (19)

Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
Qt for beginners
Qt for beginnersQt for beginners
Qt for beginners
 
WebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationWebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computation
 
Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Eta lang Beauty And The Beast
Eta lang Beauty And The Beast
 
Securité des container
Securité des containerSecurité des container
Securité des container
 
DocuOps & Asciidoctor in a JVM World
DocuOps & Asciidoctor in a JVM WorldDocuOps & Asciidoctor in a JVM World
DocuOps & Asciidoctor in a JVM World
 
How to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDKHow to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDK
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application Framework
 
PSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTPPSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTP
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java Application
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
 
DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
More developers on DevOps with Docker orchestration
More developers on DevOps with Docker orchestrationMore developers on DevOps with Docker orchestration
More developers on DevOps with Docker orchestration
 

Similar to how u can learn C/C++

Nodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to heroNodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to heroNicola Del Gobbo
 
DIY- computer vision with GWT
DIY- computer vision with GWTDIY- computer vision with GWT
DIY- computer vision with GWTFrancesca Tosi
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWTArnaud Tournier
 
C++ and UIs: an unorthodox approach
C++ and UIs: an unorthodox approachC++ and UIs: an unorthodox approach
C++ and UIs: an unorthodox approachDaniele Pallastrelli
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalNAVER D2
 
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Codemotion
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 
O futuro do desenvolvimento .NET
O futuro do desenvolvimento .NETO futuro do desenvolvimento .NET
O futuro do desenvolvimento .NETRodrigo Kono
 
Red Hat and kubernetes: awesome stuff coming your way
Red Hat and kubernetes:  awesome stuff coming your wayRed Hat and kubernetes:  awesome stuff coming your way
Red Hat and kubernetes: awesome stuff coming your wayJohannes Brännström
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioGünter Obiltschnig
 
Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewelljwi11iams
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...Edge AI and Vision Alliance
 

Similar to how u can learn C/C++ (20)

Nodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to heroNodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to hero
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
DIY- computer vision with GWT
DIY- computer vision with GWTDIY- computer vision with GWT
DIY- computer vision with GWT
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWT
 
C++ and UIs: an unorthodox approach
C++ and UIs: an unorthodox approachC++ and UIs: an unorthodox approach
C++ and UIs: an unorthodox approach
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
O futuro do desenvolvimento .NET
O futuro do desenvolvimento .NETO futuro do desenvolvimento .NET
O futuro do desenvolvimento .NET
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Red Hat and kubernetes: awesome stuff coming your way
Red Hat and kubernetes:  awesome stuff coming your wayRed Hat and kubernetes:  awesome stuff coming your way
Red Hat and kubernetes: awesome stuff coming your way
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.io
 
Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewell
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Node js
Node jsNode js
Node js
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 

Recently uploaded

RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...ThinkInnovation
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 

Recently uploaded (20)

RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 

how u can learn C/C++

  • 1. www.italiancpp.org C++ Day 2017 2 Dicembre, Modena C++ interoperability with other languages Alberto Bignotti
  • 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