Using AllJoyn with Apache Cordova, Python & Node Ivan R. Judson, PhD October 2014, Microsoft 13 October 2015 AllSeen Alliance 1
Agenda 1. Background 2. Cordova Plugin 3. Language Bindings Python Bindings Node Bindings 13 October 2015 AllSeen Alliance 2
Background 3
The Goal Accelerate the growth and adoption of AllJoyn by: Enabling more AllJoyn Development Engage more Development Communities Meet Developers where they are Help create a healthy AllJoyn Ecosystem Lots of participants from hardware and services to clients Provide Windows Expertise to the community Provide Knowledge to the community 13 October 2015 AllSeen Alliance 4
Our Strategy Assume Routers provided Deliver tools and software that fills gaps Harden the software Advocate for developers & engineers Windows 10, OS X, Android, OpenWRT Conclusion: Focus on Thin Library 13 October 2015 AllSeen Alliance 5
AllJoyn: Standard vs Thin Standard App Layer App dev or OEM writes this Standard Apps App Layer AllJoyn Standard Standard Service Application Frameworks Layer Thin Apps App Layer AllJoyn Thin Service Frameworks Standard Application Layer Thin App Layer OEM writes this Standard Core Libraries Multiple bindings, runs on HLOS AllJoyn Router AllJoyn Router can be bundled with a Standard App or run standalone AllJoyn Standard Core Libs AllJoyn Router HLOS AllJoyn Thin Core Libs RTOS Physical Layer (Wi-Fi, PLC, Ethernet, Bluetooth) Thin Core Libraries C bindings, runs on RTOS Thin Apps using Thin Core requires an AllJoyn Router in the network 6
Apache Cordova Plugin 7
What is Apache Cordova? Cross Platform Application development Primary Focus: Mobile Native Plugin Support: Geolocation, Accelerometer, Camera, Compass, 13 October 2015 AllSeen Alliance 8
Why Apache Cordova? Write once, run everywhere Java? HTML/JS Skills Required Native Skills Scarce Deep investment by Microsoft 13 October 2015 AllSeen Alliance 9
Apache Cordova AllJoyn https://github.com/alljoyn-cordova/ Apache Cordova Plugin (cordova-plugin-alljoyn) Android, ios, Windows Phone Example Applications Light (cordova-lighting-alljoyn) TV (cordova-tv-alljoyn) Blog posts Documentation 13 October 2015 AllSeen Alliance 10
Cordova AllJoyn Activity 13 October 2015 AllSeen Alliance 11
Apache Cordova Example Applications Using the Apache Cordova Plugin we provide Apache Cordova AllJoyn Light App Luminaire Reference App Compatible Apache Cordova TV App Works with LG TV 13 October 2015 AllSeen Alliance 12
Apache Cordova AllJoyn Plugin: Example > cordova create AllJoyn-Cordova-Example org.alljoyn.cordovaexample "Cordova AllJoyn Example" > cd AllJoyn-Cordova-Example/ > cordova plugin add org.allseen.alljoyn > cordova platform add android > cordova build > cordova run 13 October 2015 AllSeen Alliance 13
Apache Cordova AllJoyn Plugin: Ongoing Published as open source on Github We continue to fix bugs and use it Works with our new Cordova Support in Visual Studio 2015 13 October 2015 AllSeen Alliance 14
Language Bindings 15
Why Bind AJTL To Other Languages? 13 October 2015 AllSeen Alliance 16
Why Bind AJTL To Other Languages? 13 October 2015 AllSeen Alliance 17
Language Bindings In the AllJoyn Standard Library Core: C++ Plus Bindings: Java, JavaScript, Objective-C Deprecated: C#/Unity Meanwhile, in the AllJoyn Thin Library: Core: C Bindings in progress: Python, Node Any SWIG supported language Brook:~ irjudson$ swig help Target Language Options -allegrocl - Generate ALLEGROCL wrap -chicken - Generate CHICKEN wrappe -clisp - Generate CLISP wrappers -cffi - Generate CFFI wrappers -csharp - Generate C# wrappers -d - Generate D wrappers -go - Generate Go wrappers -guile - Generate Guile wrappers -java - Generate Java wrappers -javascript - Generate Javascript wra -lua - Generate Lua wrappers -modula3 - Generate Modula 3 wrapp -mzscheme - Generate Mzscheme wrapp -ocaml - Generate Ocaml wrappers -octave - Generate Octave wrapper -perl - Generate Perl wrappers -php - Generate PHP wrappers -pike - Generate Pike wrappers -python - Generate Python wrapper -r - Generate R (aka GNU S) -ruby - Generate Ruby wrappers -sexp - Generate Lisp S-Express -tcl - Generate Tcl wrappers -uffi - Generate Common Lisp / -xml - Generate XML wrappers 13 October 2015 AllSeen Alliance 18
My Approach: SWIG SWIG => SoftWare Interface Generator, http://swig.org/ David Beazley, author Driven by an interface file, which can be auto generated in simple cases. %module example %{ /* Includes the header in the wrapper code */ #include "header.h" % } /* Parse the header file to generate wrappers */ %include "header.h 13 October 2015 AllSeen Alliance 19
My Approach: SWIG 11:47 $ scons WS=off LANG=python scons: Reading SConscript files... 11:47 $ cd swig/python/ 11:47 $ ls _alljoyn.so basic_service.py marshal_client.py alljoyn.py int marshal_service.py alljoyn.pyc int.c marshal_test.py basic_client.py marshal.i 13 October 2015 AllSeen Alliance 20
Status: Almost there! Progress is slow, but steady. Working on Python first. Debugging a structure marshaling / unmarshaling issue with the message header (endianess specifically). Finishing the marshaling of basic types for Python Then Node, etc https://jira.allseenalliance.org/browse/asacore-1060 My issue to resolve the outstanding issues with language bindings 13 October 2015 AllSeen Alliance 21
Python Bindings 22
AllJoyn Messages AllJoyn Services and Clients communicate by sending messages Messages generally have the form of headers and payloads The payloads are Marshaled (encoded safely for types) when sent The recipient needs to be able to Unmarshal the messages Here are the signatures of all the messages found in the AJTL: # (ayay) # (ii) # (usay) # (vvvvvv) # au # ay # ays # b # I # ii # o # q # qq # qsq # s # sq # ss # sss # su # u # u(usu(ii)qsq)yyy # uq # us # usu # uu # v # y # ys # yyy # {iv} # {s(us)} # {sv} # {us} # {ys} 13 October 2015 AllSeen Alliance 23
Data Marshaling /* * Message argument types */ #define AJ_ARG_INVALID '\0' /**< AllJoyn invalid type */ #define AJ_ARG_ARRAY 'a' /**< AllJoyn array container type */ #define AJ_ARG_BOOLEAN 'b' /**< AllJoyn boolean basic type */ #define AJ_ARG_DOUBLE 'd' /**< AllJoyn IEEE 754 double basic type */ #define AJ_ARG_SIGNATURE 'g' /**< AllJoyn signature basic type */ #define AJ_ARG_HANDLE 'h' /**< AllJoyn socket handle basic type */ #define AJ_ARG_INT32 'i' /**< AllJoyn 32-bit signed integer basic type */ #define AJ_ARG_INT16 'n' /**< AllJoyn 16-bit signed integer basic type */ #define AJ_ARG_OBJ_PATH 'o' /**< AllJoyn Name of an AllJoyn object instance basic type */ #define AJ_ARG_UINT16 'q' /**< AllJoyn 16-bit unsigned integer basic type */ #define AJ_ARG_STRING 's' /**< AllJoyn UTF-8 NULL terminated string basic type */ #define AJ_ARG_UINT64 't' /**< AllJoyn 64-bit unsigned integer basic type */ #define AJ_ARG_UINT32 'u' /**< AllJoyn 32-bit unsigned integer basic type */ #define AJ_ARG_VARIANT 'v' /**< AllJoyn variant container type */ #define AJ_ARG_INT64 'x' /**< AllJoyn 64-bit signed integer basic type */ #define AJ_ARG_BYTE 'y' /**< AllJoyn 8-bit unsigned integer basic type */ #define AJ_ARG_STRUCT '(' /**< AllJoyn struct container type */ #define AJ_ARG_DICT_ENTRY '{' /**< AllJoyn dictionary or map container type */ 13 October 2015 AllSeen Alliance 24
Data Marshaling Language specific Not all types map uniquely Luckily there aren t that many types switch(signature[i]) { case 'y': printf("got a byte: "); arg.val.v_data = (void *)PyInt_AsLong(o); printf("%d\n", (int)arg.val.v_byte); break; case 'q': printf("got a 16-bit unsigned integer: "); arg.val.v_data = (void *)PyInt_AsLong(o); printf("%d\n", (int)arg.val.v_uint16); break; case 'u': printf("got a 32-bit unsigned integer: "); arg.val.v_data = (void *)PyInt_AsLong(o); printf("%d\n", (int)arg.val.v_uint32); break; case 't': printf("got a 64-bit unsigned integer: "); arg.val.v_data = (void *)PyInt_AsLong(o); printf("%d\n", (int)arg.val.v_uint64); break; } 13 October 2015 AllSeen Alliance 25
Example: Basic Service Switch to editor 13 October 2015 AllSeen Alliance 26
Example: Basic Client Switch to editor 13 October 2015 AllSeen Alliance 27
Node Bindings 28
Example: Basic Service Switch to editor 13 October 2015 AllSeen Alliance 29
Example: Basic Client Switch to editor 13 October 2015 AllSeen Alliance 30
In closing We are here to help We have experience with all the platforms, lots of data, and software. We ll work with you where you are We are platform agnostic. You don t have to learn a new language You can use AllJoyn with C, C++, Objective-C, JavaScript, Python, Node, more every day. 13 October 2015 AllSeen Alliance 31
Thank you Follow us on For more information on AllSeen Alliance, visit us at: allseenalliance.org & allseenalliance.org/news/blogs 13 October 2015 AllSeen Alliance 32