Using AllJoyn with Apache Cordova, Python & Node

32
13 October 2015 AllSeen Alliance 1 Using AllJoyn with Apache Cordova, Python & Node Ivan R. Judson, PhD October 2014, Microsoft

Transcript of Using AllJoyn with Apache Cordova, Python & Node

Page 1: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 1

Using AllJoyn with Apache Cordova,Python & NodeIvan R. Judson, PhDOctober 2014, Microsoft

Page 2: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 22

1. Background

2. Cordova Plugin

3. Language Bindings– Python Bindings– Node Bindings

Agenda

Page 3: Using AllJoyn with Apache Cordova, Python & Node

3

Background

Page 4: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 4

• 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

The Goal

Page 5: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 5

• 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

Our Strategy

Page 6: Using AllJoyn with Apache Cordova, Python & Node

6

AllJoyn: Standard vs Thin

StandardApplication Layer

StandardApplication Layer

App LayerAllJoynStandardService

Frameworks

AllJoynStandard Core

Libs

Physical Layer (Wi-Fi, PLC, Ethernet, Bluetooth)

Standard Core LibrariesMultiple bindings, runson HLOS

C bindings, runs onRTOSThin Apps using ThinCore requires anAllJoyn Routerin the network

Thin CoreLibraries

HLOS RTOS

App LayerAllJoyn ThinService

Frameworks

AllJoyn ThinCore Libs

Standard Apps Thin AppsStandard App LayerApp dev or OEMwrites this

Thin App Layer

OEM writes this

AllJoyn RouterAllJoyn Router

AllJoyn Router can bebundled with a StandardApp or run standalone

Page 7: Using AllJoyn with Apache Cordova, Python & Node

7

Apache Cordova Plugin

Page 8: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 8

•Cross Platform Application development•Primary Focus: Mobile•Native Plugin Support:

– Geolocation, Accelerometer, Camera, Compass, …

What is Apache Cordova?

Page 9: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 9

• Write once, run everywhere…Java?• HTML/JS Skills Required• Native Skills Scarce• Deep investment by Microsoft

Why Apache Cordova?

Page 10: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 10

• 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

Apache Cordova AllJoyn

Page 11: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 11

Cordova AllJoyn Activity

Page 12: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 12

• Using the Apache Cordova Plugin we provide• Apache Cordova AllJoyn Light App

– Luminaire Reference App Compatible

• Apache Cordova TV App– Works with LG TV

Apache Cordova Example Applications

Page 13: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 13

> 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

Apache Cordova AllJoyn Plugin: Example

Page 14: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 14

•Published as open source on Github•We continue to fix bugs and use it•Works with our new Cordova Support in Visual Studio 2015

Apache Cordova AllJoyn Plugin: Ongoing

Page 15: Using AllJoyn with Apache Cordova, Python & Node

15

Language Bindings

Page 16: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 16

Why Bind AJTL To Other Languages?

Page 17: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 17

Why Bind AJTL To Other Languages?

Page 18: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 18

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 –helpTarget Language Options

-allegrocl - Generate ALLEGROCL wrappers -chicken - Generate CHICKEN wrappers -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 wrappers -lua - Generate Lua wrappers -modula3 - Generate Modula 3 wrappers -mzscheme - Generate Mzscheme wrappers -ocaml - Generate Ocaml wrappers -octave - Generate Octave wrappers -perl - Generate Perl wrappers -php - Generate PHP wrappers -pike - Generate Pike wrappers -python - Generate Python wrappers -r - Generate R (aka GNU S) wrappers -ruby - Generate Ruby wrappers -sexp - Generate Lisp S-Expressions wrappers -tcl - Generate Tcl wrappers -uffi - Generate Common Lisp / UFFI wrappers -xml - Generate XML wrappers

Page 19: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 19

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”

Page 20: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 20

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.pymarshal_client.py alljoyn.py intmarshal_service.py alljoyn.pyc int.cmarshal_test.py basic_client.pymarshal.i

Page 21: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 21

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

Page 22: Using AllJoyn with Apache Cordova, Python & Node

22

Python Bindings

Page 23: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 23

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}

Page 24: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 24

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 */

Page 25: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 25

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;

…}

Page 26: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 26

Example: Basic Service

Switch to editor

Page 27: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 27

Example: Basic Client

Switch to editor

Page 28: Using AllJoyn with Apache Cordova, Python & Node

28

Node Bindings

Page 29: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 29

Example: Basic Service

Switch to editor

Page 30: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 30

Example: Basic Client

Switch to editor

Page 31: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 3131

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.

In closing…

Page 32: Using AllJoyn with Apache Cordova, Python & Node

13 October 2015 AllSeen Alliance 32

Thank youFollow us on

For more information on AllSeen Alliance, visit us at: allseenalliance.org & allseenalliance.org/news/blogs