Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
C/C++ WebAssembly
/ @llamerada_jp
2019/04/19 Emscripten & WebAssembly night !! #7
•
• ; SE
• , Java, Cloud, VMWare
• ;
• C/C++, go, WebAssembly, WebRTC, WebSocket
• PROCESS WARP
• twitter ; @llamerada_jp
...
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
@SlideShare
https://www.slideshare.net/llamerada-jp/webassembly-75175349
https://www.slideshare.net/llamerada-jp/cmu29
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
C/C++( )
WebAssembly(emscripten) web export
•
•
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
C/C++
• C++ name mangling extern "C" export
• EMSCRIPTEN_KEEPALIVE 



-s 'EXPORTED_FUNCTIONS=["_<C >", …]'

( )
extern "C...
Build
•
$ emcc …
-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall", “cwrap"]'
JavaScript
• ccall, cwrap ; emscripten 

(.wasm WebAssembly.Instance.exports)
let r = ccall(
'c_func', // C
'number', // n...
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
JavaScript
• C/C++ export JavaScript API
<api >
mergeInto(LibraryManager.library, {
js_func: function(p1, p2) {
//
…
},
…
...
Build
•
$ emcc … --js-library <api >
C/C++
• C/C++
extern "C" {
extern void js_func(int p1, void* p2);
}
•
js_func(100, &val);
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
JavaScript
• JavaScript C
• addFunction ; JavaScript emscripten
• ccall C/C++
• C/C++


let f_ptr = addFunction(
js_func.b...
Build
•
$ emcc … -s 'RESERVED_FUNCTION_POINTERS=< >'
•
• JavaScript on Callback
• Promise (※ )
connect(url, token) {
const promise = new Promise((resolve, reject) => {
// resolve/reject
let onSuccess = ...
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
C++ class
• ID JavaScript
• JavaScript C++
ID
• C ID C++
('A`)
get/set
<C/C++>
extern "C" {
EMSCRIPTEN_KEEPALIVE int64_t get_int(PTR_T value_ptr);
EMSCRIPTEN_KEEPALIVE void set_int(PTR_...
• get/set
•
•
•
• ( )
• Module.HEAPU8
•
• JavaScript get/set
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
• ,
• new, delete
• alloc, free
• ,
• open, close
• JavaScript
• WebAssembly JavaScript GC
(2019/04 )
•
•
JavaScript API
connect(url, token) {
const promise = new Promise((resolve, reject) => {
let onSuccess = addFunction((veinPtr) => { resolv...
disconnect() {
//
if (this._timerInvoke) {
clearTimeout(this._timerInvoke);
this._timerInvoke = false;
}
// C++
ccall('js_...
• WebAssembly
•
• JavaScript C/C++ API
• C/C++ JavaScript API
• CallBack
•
•
•
•
libvein
•
• KVS, 2 PubSub
• C/C++, Python, web
(
)
oinari
• https://www.oinari.app
• https://github.com/llamerada-jp/
oinari
•
• libvein
Seed/Server

(WebRTC )
Application
API
Application
API
Application
API
Node

( )
Application
API
Node Node Node
Routing 

...
Core(C++)
Application(JavaScript)
API(JavaScript)
I/F(C/C++)
I/F(C/C++, JavaScript)


WebSocket


WebRTC
Core(C++)
Applica...
C/C++とWebAssemblyを利用したライブラリ開発
C/C++とWebAssemblyを利用したライブラリ開発
Upcoming SlideShare
Loading in …5
×

of

C/C++とWebAssemblyを利用したライブラリ開発 Slide 1 C/C++とWebAssemblyを利用したライブラリ開発 Slide 2 C/C++とWebAssemblyを利用したライブラリ開発 Slide 3 C/C++とWebAssemblyを利用したライブラリ開発 Slide 4 C/C++とWebAssemblyを利用したライブラリ開発 Slide 5 C/C++とWebAssemblyを利用したライブラリ開発 Slide 6 C/C++とWebAssemblyを利用したライブラリ開発 Slide 7 C/C++とWebAssemblyを利用したライブラリ開発 Slide 8 C/C++とWebAssemblyを利用したライブラリ開発 Slide 9 C/C++とWebAssemblyを利用したライブラリ開発 Slide 10 C/C++とWebAssemblyを利用したライブラリ開発 Slide 11 C/C++とWebAssemblyを利用したライブラリ開発 Slide 12 C/C++とWebAssemblyを利用したライブラリ開発 Slide 13 C/C++とWebAssemblyを利用したライブラリ開発 Slide 14 C/C++とWebAssemblyを利用したライブラリ開発 Slide 15 C/C++とWebAssemblyを利用したライブラリ開発 Slide 16 C/C++とWebAssemblyを利用したライブラリ開発 Slide 17 C/C++とWebAssemblyを利用したライブラリ開発 Slide 18 C/C++とWebAssemblyを利用したライブラリ開発 Slide 19 C/C++とWebAssemblyを利用したライブラリ開発 Slide 20 C/C++とWebAssemblyを利用したライブラリ開発 Slide 21 C/C++とWebAssemblyを利用したライブラリ開発 Slide 22 C/C++とWebAssemblyを利用したライブラリ開発 Slide 23 C/C++とWebAssemblyを利用したライブラリ開発 Slide 24 C/C++とWebAssemblyを利用したライブラリ開発 Slide 25 C/C++とWebAssemblyを利用したライブラリ開発 Slide 26 C/C++とWebAssemblyを利用したライブラリ開発 Slide 27 C/C++とWebAssemblyを利用したライブラリ開発 Slide 28 C/C++とWebAssemblyを利用したライブラリ開発 Slide 29 C/C++とWebAssemblyを利用したライブラリ開発 Slide 30 C/C++とWebAssemblyを利用したライブラリ開発 Slide 31 C/C++とWebAssemblyを利用したライブラリ開発 Slide 32 C/C++とWebAssemblyを利用したライブラリ開発 Slide 33 C/C++とWebAssemblyを利用したライブラリ開発 Slide 34
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

1 Like

Share

Download to read offline

C/C++とWebAssemblyを利用したライブラリ開発

Download to read offline

Emscripten & WebAssembly night !! #7での発表資料です

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

C/C++とWebAssemblyを利用したライブラリ開発

  1. 1. C/C++ WebAssembly / @llamerada_jp 2019/04/19 Emscripten & WebAssembly night !! #7
  2. 2. • • ; SE • , Java, Cloud, VMWare • ; • C/C++, go, WebAssembly, WebRTC, WebSocket • PROCESS WARP • twitter ; @llamerada_jp • facebook ; https://www.facebook.com/ito.yuuji • github ; https://github.com/llamerada-jp
  3. 3. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  4. 4. @SlideShare https://www.slideshare.net/llamerada-jp/webassembly-75175349 https://www.slideshare.net/llamerada-jp/cmu29
  5. 5. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  6. 6. C/C++( ) WebAssembly(emscripten) web export • •
  7. 7. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  8. 8. C/C++ • C++ name mangling extern "C" export • EMSCRIPTEN_KEEPALIVE 
 
 -s 'EXPORTED_FUNCTIONS=["_<C >", …]'
 ( ) extern "C" { EMSCRIPTEN_KEEPALIVE int c_func(int p_int, void* p_ptr); }
  9. 9. Build • $ emcc … -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall", “cwrap"]'
  10. 10. JavaScript • ccall, cwrap ; emscripten 
 (.wasm WebAssembly.Instance.exports) let r = ccall( 'c_func', // C 'number', // number(pointer ), array, string, boolean ['number', 'number'], // [< >, < >] // ); let f = cwrap('c_func', 'number', ['number', 'number']); f(< >, < >);
  11. 11. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  12. 12. JavaScript • C/C++ export JavaScript API <api > mergeInto(LibraryManager.library, { js_func: function(p1, p2) { // … }, … });
  13. 13. Build • $ emcc … --js-library <api >
  14. 14. C/C++ • C/C++ extern "C" { extern void js_func(int p1, void* p2); } • js_func(100, &val);
  15. 15. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  16. 16. JavaScript • JavaScript C • addFunction ; JavaScript emscripten • ccall C/C++ • C/C++ 
 let f_ptr = addFunction( js_func.bind(this), // bind 'vi' // (1 ), (2 ) // v:void, i:int32, j:int64, f:float, d:double );
  17. 17. Build • $ emcc … -s 'RESERVED_FUNCTION_POINTERS=< >' • • JavaScript on Callback
  18. 18. • Promise (※ ) connect(url, token) { const promise = new Promise((resolve, reject) => { // resolve/reject let onSuccess = addFunction((veinPtr) => { resolve(); }, 'vi'); let onFailure = addFunction((veinPtr) => { reject(); }, 'vi'); let [urlPtr] = allocPtrString(url); let [tokenPtr] = allocPtrString(token); // C/C++ Callback ccall('js_connect', 'null', ['number', 'number', 'number', 'number'], [this._veinPtr, urlPtr, tokenPtr, onSuccess, onFailure]); freePtr(url); freePtr(token); }); return promise; }
  19. 19. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  20. 20. C++ class • ID JavaScript • JavaScript C++ ID • C ID C++ ('A`)
  21. 21. get/set <C/C++> extern "C" { EMSCRIPTEN_KEEPALIVE int64_t get_int(PTR_T value_ptr); EMSCRIPTEN_KEEPALIVE void set_int(PTR_T value_ptr, int64_t v); } <JavaScript> get() { return ccall('get_int', 'number', ['number'], [this._valuePtr]); } set(v) { ccall('set_int', 'void', ['number', 'number'], [this._valuePtr, v]); }
  22. 22. • get/set • • • • ( ) • Module.HEAPU8 • • JavaScript get/set
  23. 23. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  24. 24. • , • new, delete • alloc, free • , • open, close
  25. 25. • JavaScript • WebAssembly JavaScript GC (2019/04 ) • • JavaScript API
  26. 26. connect(url, token) { const promise = new Promise((resolve, reject) => { let onSuccess = addFunction((veinPtr) => { resolve(); }, 'vi'); let onFailure = addFunction((veinPtr) => { reject(); }, 'vi'); // JavaScript C/C++ let [urlPtr] = allocPtrString(url); let [tokenPtr] = allocPtrString(token); // ccall('js_connect', 'null', ['number', 'number', 'number', 'number'], // !C/C++ [this._veinPtr, urlPtr, tokenPtr, onSuccess, onFailure]); // freePtr(url); freePtr(token); }); return promise; }
  27. 27. disconnect() { // if (this._timerInvoke) { clearTimeout(this._timerInvoke); this._timerInvoke = false; } // C++ ccall('js_disconnect', 'null', ['number'], [this._veinPtr]); // JS delete this._instanceCache; }
  28. 28. • WebAssembly • • JavaScript C/C++ API • C/C++ JavaScript API • CallBack • • • •
  29. 29. libvein • • KVS, 2 PubSub • C/C++, Python, web ( )
  30. 30. oinari • https://www.oinari.app • https://github.com/llamerada-jp/ oinari • • libvein
  31. 31. Seed/Server (WebRTC ) Application API Application API Application API Node ( ) Application API Node Node Node Routing KVS, 2 PubSub WebSocket WebRTC
  32. 32. Core(C++) Application(JavaScript) API(JavaScript) I/F(C/C++) I/F(C/C++, JavaScript) WebSocket WebRTC Core(C++) Application(Native) API(C++) I/F(C++) WebRTC WebSocket API(C) Seed/Server(golang) WebAssembly (emscripten) =
  • ssuser85fcd2

    Aug. 28, 2021

Emscripten & WebAssembly night !! #7での発表資料です

Views

Total views

2,315

On Slideshare

0

From embeds

0

Number of embeds

186

Actions

Downloads

13

Shares

0

Comments

0

Likes

1

×