Cross Compiling
Technology Behind
Client API 2.0
Copyright (c) 2015 Glympse, Inc.
Creative Commons Attribution 4.0 International License
Egor Pushkin
egor@glympse.com
Platform Architect
Glympse, Inc.
Introduction
"Language shapes the way we think,
and determines what we can think about."
Benjamin Lee Whorf
Copyright (c) 2015 Glympse, Inc.
Platform
mobile OS
Language
paradigm
Possibilities
flexibility
Defines
Defines
Define
1 Based on market state in Q2 2015
2 Only mobile platforms are considered
3 With focus on native application development
Topical mobile
operating systems
- Android
- iOS
- BlackBerry
- Windows Phone
- Tizen
1
Predominant programming
languages
- Java
- ObjectiveC
- Swift
- C++
- C#
2, 3
Cross-platform
development techniques
- Browser-based frameworks
- Scripting / VM approach
- Portable code (mostly C++)
3
Goals
● Minimize the efforts towards the development of
cross-platform SDK (for mobile and desktop platforms)
● Provide consistent public API across all platforms
Common documentation
● Maintain portable, stable and performant code base
Native, line to line identical code across all platforms (languages)
Efficient debugging / troubleshooting
Low cost adoption of new platforms
● Shared infrastructure tools
Unit tests
Simulators
Copyright (c) 2015 Glympse, Inc.
Requirements
● Support of the following programming languages
C++ / Java / C#
● No sacrifices in performance!
● Code must be readable/debuggable across all platforms
● Native code should be executed on each platform
This includes public interface, which is of prime importance
from the standpoint of integration into 3rd party applications
● The following components must be shared
Business logic
Object model
Backend interaction (protocol, flow)
Persistence (local databases, configuration)
Resource handling (images)
Copyright (c) 2015 Glympse, Inc.
Fundamentals
● Code translation is used as a part of porting process
Shared code is written in C++ and is translated to Java and C#
● Lowest common denominator approach
With regards to language features
● Platform-specific features are hidden behind
OS Abstraction Layer
Be smart on where to draw the line (shared code vs platform-specific)
Library should remain functional,
if some features are not supported by the OS
● Component-oriented architecture
● Focus on OOP and design patterns
With elements of generic programming
Copyright (c) 2015 Glympse, Inc.
Library Structure
Object Model
Foundation
Core
Memory
Management
Common
Interfaces
Strings /
Containers
API
Domain-specific public interfaces
Business
Logic
Lib
Object
Model
Backend
Interaction
External
Services
Persistence
Image
Cache
JSON /
WebSocket
Battery
Manager
Job Queue
Engine
Network
Manager
OSAL Public
Public interfaces of OS-dependent module
Concurrency
OSAL
Core GPS
Contacts /
Calendar
Storage
Debug PUSHBattery
Networking
Images
Copyright (c) 2015 Glympse, Inc.
Translation Process
Core
API
Lib
OSAL Public
OSAL
Portable
Code
Platform
Specific
LIbrary
(C++ code)
Translator
Java
code
jar archive
C#
code dll library
.a library
Android AL
WinPhone AL
iOS AL BB AL
.a library
WinAPI AL
.lib library
The majority of code belongs to
this layer
Tizen
.a library
Copyright (c) 2015 Glympse, Inc.
Code Analysis
#ifdef ...
#define
namespace ...
{
class Class : public IInterface
{
private: Member _member;
public: virtual void method()
{
methodCall();
for ( ... ; ... ; ... )
{
}
}
};
}
#endif ...
package ...;
import ...;
import ...;
class Class implements IInterface
{
private Member _member;
public void method()
{
methodCall();
for ( ... ; ... ; ... )
{
}
}
}
header
footer
class statement
class member
class method
for statement
JavaC++
Copyright (c) 2015 Glympse, Inc.
● JSON Parser
Powers JSON serialization
● Job Queue
Provides background execution support
● Resource Manager
Abstracts content extraction and caching
● WebSocket Implementation
RFC 6455 compliant
● Unit Testing Engine
Portable tests
Examples of reusable components implemented in common code
Portable Components
Copyright (c) 2015 Glympse, Inc.
JSON Parser
● SAX support
Nested handlers
Partial DOM extraction
● DOM support
Implemented on top of SAX
Partial DOM extraction
● Flexible cancellation support
● Advanced performance optimization techniques
Intermediate strings are not created
Values are only parsed on demand
● Error handling (with recovery)
1
JSON Parser
IJSONParser
IJSONHandler
Handler X
JSON Tokener
JSON Token
IJSONHandlerStack
JSONSerializer
DOM
SAX
* 1 *
IPrimitive
Primitive
Copyright (c) 2015 Glympse, Inc.
● Configurable pool of worker threads
● Flexible completion notifications
● Cancellation support
● Retry mechanism with configurable backoff policy
● HTTP(s) support
Job
Job Queue
1 *
Worker Thread
IJob
Http JobIHttpConnectionHttp Connection
IRunnable
IThreadThread
11
1*
IHandlerHandler
1
1
1
1
Job Queue
Copyright (c) 2015 Glympse, Inc.
Drawable
Job Queue
Job
Image
0,1
1
1
*
Image Cache
Memory Cache
Disk Cache
Load Image Job
Content Resolver
Content Provider
1
Web Image Provider
Person Avatar Provider Contacts Provider
11
1
1
1
*
*
*
1
OS Bitmap
0,1
1
Content Resolver
Contacts Manager
● Customizable content extraction
Based on URIs and external providers
● Advanced image handling and caching
Resource Manager
Copyright (c) 2015 Glympse, Inc.
Libraries and tools built with the use of cross compiling technology
● Glympse Client SDK
Glympse flagship platform shares 80k lines of common code across 5 topical mobile operating systems
(iOS, Android, Windows Phone, BlackBerry and Tizen).
● RPC component
Transport layer built on top of Glympse Client SDK enabling interprocess communication capabilities
heavily utilized in wearables and automotive applications.
● Glympse Map control
Library powering Glympse viewing experience in native applications. Map control supports variety of
rendering backends (including Apple MapKit, Google Map SDK, HERE Map SDK, WinPhone Map SDK,
Mapquest SDK) and shares business logic across all platforms.
● Dispatch library
Component is designed to power B2C applications (aka Glympse EnRoute) built on top of Glympse Core.
● Remote Debugger component
Debugging tool enabling remote monitoring of application object model.
Glympse Products
Copyright (c) 2015 Glympse, Inc.
Codebase Stats
Copyright (c) 2015 Glympse, Inc.
● 87% of codebase for specific OS is shared with other OSes
● Multiple levels of code validation, verification
The code can be analyzed using variety of compilers and utilities
● Code coverage grows exponentially
Porting the same code to OSes causes different patterns of adoption
● Free of charge automation
.Net platforms natively supports scripting
● Beyond the library itself
Cross-platform tools (bots / simulators / explorers)
Cross-platform unit testing
● Beyond the mobile
Ability to share library code with desktop applications
Ability to share business logic and specific components with
server side applications (JSON parser)
Conclusion
Copyright (c) 2015 Glympse, Inc.
● Multi directional translation
Involves fully-functional lexical analysis
Dramatically extends flexibility and minimizes limitations
● Support language-specific features
Modern C++ features, anonymous classes, etc.
● Support scripting languages (JavaScript, Python)
Allows code sharing between native and Web (HTML5) platforms
Technology Evolution (Next Steps)
Copyright (c) 2015 Glympse, Inc.
● Translator source code
https://github.com/Glympse/CrossCompiling
● Translator online demo
https://github.com/Glympse/CrossCompilingConsole
References
Copyright (c) 2015 Glympse, Inc.

Glympse API Cross Compiling

  • 1.
    Cross Compiling Technology Behind ClientAPI 2.0 Copyright (c) 2015 Glympse, Inc. Creative Commons Attribution 4.0 International License Egor Pushkin egor@glympse.com Platform Architect Glympse, Inc.
  • 2.
    Introduction "Language shapes theway we think, and determines what we can think about." Benjamin Lee Whorf Copyright (c) 2015 Glympse, Inc. Platform mobile OS Language paradigm Possibilities flexibility Defines Defines Define 1 Based on market state in Q2 2015 2 Only mobile platforms are considered 3 With focus on native application development Topical mobile operating systems - Android - iOS - BlackBerry - Windows Phone - Tizen 1 Predominant programming languages - Java - ObjectiveC - Swift - C++ - C# 2, 3 Cross-platform development techniques - Browser-based frameworks - Scripting / VM approach - Portable code (mostly C++) 3
  • 3.
    Goals ● Minimize theefforts towards the development of cross-platform SDK (for mobile and desktop platforms) ● Provide consistent public API across all platforms Common documentation ● Maintain portable, stable and performant code base Native, line to line identical code across all platforms (languages) Efficient debugging / troubleshooting Low cost adoption of new platforms ● Shared infrastructure tools Unit tests Simulators Copyright (c) 2015 Glympse, Inc.
  • 4.
    Requirements ● Support ofthe following programming languages C++ / Java / C# ● No sacrifices in performance! ● Code must be readable/debuggable across all platforms ● Native code should be executed on each platform This includes public interface, which is of prime importance from the standpoint of integration into 3rd party applications ● The following components must be shared Business logic Object model Backend interaction (protocol, flow) Persistence (local databases, configuration) Resource handling (images) Copyright (c) 2015 Glympse, Inc.
  • 5.
    Fundamentals ● Code translationis used as a part of porting process Shared code is written in C++ and is translated to Java and C# ● Lowest common denominator approach With regards to language features ● Platform-specific features are hidden behind OS Abstraction Layer Be smart on where to draw the line (shared code vs platform-specific) Library should remain functional, if some features are not supported by the OS ● Component-oriented architecture ● Focus on OOP and design patterns With elements of generic programming Copyright (c) 2015 Glympse, Inc.
  • 6.
    Library Structure Object Model Foundation Core Memory Management Common Interfaces Strings/ Containers API Domain-specific public interfaces Business Logic Lib Object Model Backend Interaction External Services Persistence Image Cache JSON / WebSocket Battery Manager Job Queue Engine Network Manager OSAL Public Public interfaces of OS-dependent module Concurrency OSAL Core GPS Contacts / Calendar Storage Debug PUSHBattery Networking Images Copyright (c) 2015 Glympse, Inc.
  • 7.
    Translation Process Core API Lib OSAL Public OSAL Portable Code Platform Specific LIbrary (C++code) Translator Java code jar archive C# code dll library .a library Android AL WinPhone AL iOS AL BB AL .a library WinAPI AL .lib library The majority of code belongs to this layer Tizen .a library Copyright (c) 2015 Glympse, Inc.
  • 8.
    Code Analysis #ifdef ... #define namespace... { class Class : public IInterface { private: Member _member; public: virtual void method() { methodCall(); for ( ... ; ... ; ... ) { } } }; } #endif ... package ...; import ...; import ...; class Class implements IInterface { private Member _member; public void method() { methodCall(); for ( ... ; ... ; ... ) { } } } header footer class statement class member class method for statement JavaC++ Copyright (c) 2015 Glympse, Inc.
  • 9.
    ● JSON Parser PowersJSON serialization ● Job Queue Provides background execution support ● Resource Manager Abstracts content extraction and caching ● WebSocket Implementation RFC 6455 compliant ● Unit Testing Engine Portable tests Examples of reusable components implemented in common code Portable Components Copyright (c) 2015 Glympse, Inc.
  • 10.
    JSON Parser ● SAXsupport Nested handlers Partial DOM extraction ● DOM support Implemented on top of SAX Partial DOM extraction ● Flexible cancellation support ● Advanced performance optimization techniques Intermediate strings are not created Values are only parsed on demand ● Error handling (with recovery) 1 JSON Parser IJSONParser IJSONHandler Handler X JSON Tokener JSON Token IJSONHandlerStack JSONSerializer DOM SAX * 1 * IPrimitive Primitive Copyright (c) 2015 Glympse, Inc.
  • 11.
    ● Configurable poolof worker threads ● Flexible completion notifications ● Cancellation support ● Retry mechanism with configurable backoff policy ● HTTP(s) support Job Job Queue 1 * Worker Thread IJob Http JobIHttpConnectionHttp Connection IRunnable IThreadThread 11 1* IHandlerHandler 1 1 1 1 Job Queue Copyright (c) 2015 Glympse, Inc.
  • 12.
    Drawable Job Queue Job Image 0,1 1 1 * Image Cache MemoryCache Disk Cache Load Image Job Content Resolver Content Provider 1 Web Image Provider Person Avatar Provider Contacts Provider 11 1 1 1 * * * 1 OS Bitmap 0,1 1 Content Resolver Contacts Manager ● Customizable content extraction Based on URIs and external providers ● Advanced image handling and caching Resource Manager Copyright (c) 2015 Glympse, Inc.
  • 13.
    Libraries and toolsbuilt with the use of cross compiling technology ● Glympse Client SDK Glympse flagship platform shares 80k lines of common code across 5 topical mobile operating systems (iOS, Android, Windows Phone, BlackBerry and Tizen). ● RPC component Transport layer built on top of Glympse Client SDK enabling interprocess communication capabilities heavily utilized in wearables and automotive applications. ● Glympse Map control Library powering Glympse viewing experience in native applications. Map control supports variety of rendering backends (including Apple MapKit, Google Map SDK, HERE Map SDK, WinPhone Map SDK, Mapquest SDK) and shares business logic across all platforms. ● Dispatch library Component is designed to power B2C applications (aka Glympse EnRoute) built on top of Glympse Core. ● Remote Debugger component Debugging tool enabling remote monitoring of application object model. Glympse Products Copyright (c) 2015 Glympse, Inc.
  • 14.
    Codebase Stats Copyright (c)2015 Glympse, Inc.
  • 15.
    ● 87% ofcodebase for specific OS is shared with other OSes ● Multiple levels of code validation, verification The code can be analyzed using variety of compilers and utilities ● Code coverage grows exponentially Porting the same code to OSes causes different patterns of adoption ● Free of charge automation .Net platforms natively supports scripting ● Beyond the library itself Cross-platform tools (bots / simulators / explorers) Cross-platform unit testing ● Beyond the mobile Ability to share library code with desktop applications Ability to share business logic and specific components with server side applications (JSON parser) Conclusion Copyright (c) 2015 Glympse, Inc.
  • 16.
    ● Multi directionaltranslation Involves fully-functional lexical analysis Dramatically extends flexibility and minimizes limitations ● Support language-specific features Modern C++ features, anonymous classes, etc. ● Support scripting languages (JavaScript, Python) Allows code sharing between native and Web (HTML5) platforms Technology Evolution (Next Steps) Copyright (c) 2015 Glympse, Inc.
  • 17.
    ● Translator sourcecode https://github.com/Glympse/CrossCompiling ● Translator online demo https://github.com/Glympse/CrossCompilingConsole References Copyright (c) 2015 Glympse, Inc.