33
Start to Finish: Porting to BlackBerry 10 Native Aaron Ardiri Senior Technical Evangelist [email protected] twitter: @ardiri

Start to Finish: Porting to BlackBerry 10

  • Upload
    ardiri

  • View
    393

  • Download
    4

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Start to Finish: Porting to BlackBerry 10

Start to Finish:Porting to BlackBerry 10 NativeAaron Ardiri

Senior Technical Evangelist

[email protected]

twitter: @ardiri

Page 2: Start to Finish: Porting to BlackBerry 10

Getting Started

BlackBerry Dev Zone: You’ll find everything you need

developer.blackberry.com

2

Page 3: Start to Finish: Porting to BlackBerry 10

Getting Started

3

Page 4: Start to Finish: Porting to BlackBerry 10

4

Getting Started

Page 5: Start to Finish: Porting to BlackBerry 10

5

Getting Started

Page 6: Start to Finish: Porting to BlackBerry 10

Getting Started5 Easy Steps!

Download the Native SDK

6

Create your application and deploy it to your device

Run the getting started wizard Window -> Preferences -> BlackBerry

Sets up your environment, keys, debug token

Register for Signing Keys

developer.blackberry.com/native

Publish to AppWorld™ - make money!

Page 7: Start to Finish: Porting to BlackBerry 10

Source

7

Page 8: Start to Finish: Porting to BlackBerry 10

So; how was it done?

Porting 101 – the textbook guide

application anatomy (mainline, event loop et al) identify a way to debug/handle logging of the application play nice with the navigator/user experience of the platform create a framebuffer object for graphics create a PCM audio callback system for music and sound effects create a handler for input events like touch and keyboard create a resource manager for preferences, game assets create bindings to system resources (memory, time, files, networking)

8

Page 9: Start to Finish: Porting to BlackBerry 10

:: application anatomy

#include <stdio.h>#include <stdlib.h>

int main(int argc, char **argv){ fprintf(stdout, “Hello World!\n”); return EXIT_SUCCESS;}

9

Page 10: Start to Finish: Porting to BlackBerry 10

:: application anatomy - BPS

10

The BlackBerry Platform Services (BPS) library provides an application with a single consistent interface to a number of different services.

event loop input/output (sensors, audio, LED, screen, multimedia) device information payment services network status and geo-location

Page 11: Start to Finish: Porting to BlackBerry 10

:: application anatomy - a real “main()”

int main(int argc, char **argv){ if (application_initialize()) { application_eventloop(); application_terminate(); } return EXIT_SUCCESS;}

11

Page 12: Start to Finish: Porting to BlackBerry 10

:: application anatomy – event handling

event_bps = NULL;bps_get_event(&event_bps, timeout); // -1, foreverif (event_bps != NULL){ event_domain = bps_event_get_domain(event_bps); if (event_domain == navigator_get_domain()) { // request the event id in the navigator domain e_id = bps_event_get_code(event_bps); }}

12

Page 13: Start to Finish: Porting to BlackBerry 10

:: debugging/logging

13

The BlackBerry 10 Platform logs all stdout messages to the application sandbox

fprintf(stdout, “[INFO] my log line\n”);fflush(stdout);

to view the contents of the log – SSH into the device/simulator:

$ cd /accounts/1000/appdata/com.xxx.yyy/logs$ cat log

Page 14: Start to Finish: Porting to BlackBerry 10

:: play nice with navigator/UX

14

The BlackBerry Platform Services (BPS) library issues navigator events applications should handle:

navigator_request_events(0); // request events

NAVIGATOR_EXITNAVIGATOR_SWIPE_DOWNNAVIGATOR_ORIENTATION_CHECKNAVIGATOR_WINDOW_STATE

- fullscreen, thumbnail, invisible

Page 15: Start to Finish: Porting to BlackBerry 10

:: play nice with navigator/UX

15

event_domain :: navigator_get_domain()

switch (e_id) { case NAVIGATOR_EXIT:

// user has requested we exit the application running = 0; break;

Page 16: Start to Finish: Porting to BlackBerry 10

:: play nice with navigator/UX

16

event_domain :: navigator_get_domain()

switch (e_id) { case NAVIGATOR_WINDOW_STATE: switch (navigator_event_get_window_state(event_bps)) { case NAVIGATOR_WINDOW_FULLSCREEN: case NAVIGATOR_WINDOW_THUMBNAIL: case NAVIGATOR_WINDOW_INVISIBLE: break;

Page 17: Start to Finish: Porting to BlackBerry 10

:: create a framebuffer (gfx)

17

The BlackBerry 10 platform provides a composited windowing API (low level) – which allows the creation of a pixmap (framebuffer) for graphics.

screen_create_context(..);screen_create_window(..);screen_set_window_property_iv(..)screen_create_window_buffers(..);

Page 18: Start to Finish: Porting to BlackBerry 10

:: create a pcm audio callback

18

The BlackBerry 10 platform provides an ALSA compliant audio library for capturing and playback of digital audio stream handling

snd_pcm_open_preferred(..);snd_pcm_plugin_params(..);snd_pcm_plugin_prepare(..);snd_pcm_plugin_write(..);

Page 19: Start to Finish: Porting to BlackBerry 10

:: create a handler for touch, key

19

screen_request_events(..);

then capture the appropriate screen related events (pointer, touch, key)

SCREEN_EVENT_POINTERSCREEN_EVENT_MTOUCH_TOUCHSCREEN_EVENT_MTOUCH_MOVESCREEN_EVENT_MTOUCH_RELEASESCREEN_EVENT_KEYBOARD

Page 20: Start to Finish: Porting to BlackBerry 10

:: create a handler for touch, key

20

event_domain :: screen_get_domain()

// obtain the screen event from the abstract bps event event_scr = screen_event_get_event(event_bps);

// obtain the event id in the screen domain screen_get_event_property_iv(event_scr, SCREEN_PROPERTY_TYPE, &e_id);

Page 21: Start to Finish: Porting to BlackBerry 10

:: create a handler for touch, key

21

event_domain :: screen_get_domain()

switch (e_id) { case SCREEN_EVENT_POINTER: // obtain the position and mouse button state screen_get_event_property_iv(event_scr, SCREEN_PROPERTY_SOURCE_POSITION, pos); screen_get_event_property_iv(event_scr, SCREEN_PROPERTY_BUTTONS, &state);

Page 22: Start to Finish: Porting to BlackBerry 10

:: create a handler for touch, key

22

event_domain :: screen_get_domain()

switch (e_id) { case SCREEN_EVENT_MTOUCH_TOUCH: // get the information about the touch event screen_get_mtouch_event(event_scr, &event_mt, 0);

id = event_touch.contact_id; x = event_touch.x; y = event_touch.y; // obtain the (x,y) position

Page 23: Start to Finish: Porting to BlackBerry 10

:: create a handler for touch, key

23

event_domain :: screen_get_domain()

switch (e_id) { case SCREEN_EVENT_KEYBOARD: // get the information about the keyboard event screen_get_event_property_iv(event_scr, SCREEN_PROPERTY_KEY_FLAGS, &state); if ((state & (KEY_DOWN || KEY_REPEAT)) != 0) screen_get_event_property_iv(event_scr, SCREEN_PROPERTY_KEY_SYM, &key);

Page 24: Start to Finish: Porting to BlackBerry 10

:: resource manager for assets

Each app is confined to it’s own sandbox Only your app has read/write access to it’s sandbox

24

R/W$(SANDBOX)/

$(SANDBOX)/app $(SANDBOX)/data$(SANDBOX)/temp $(SANDBOX)/logs$(SANDBOX)/shared

Page 25: Start to Finish: Porting to BlackBerry 10

:: resource manager for assets

25

#define MAX_PATH_LENGTH 256

{ char sandbox[MAX_PATH_LENGTH]; char path[MAX_PATH_LENGTH];

getcwd(sandbox, MAX_PATH_LENGTH); sprintf(path, "%s/data/preferences.dat", sandbox);}

Then use POSIX file functions to read/write the contents of the file.

Page 26: Start to Finish: Porting to BlackBerry 10

:: generate bindings to system

26

The BlackBerry 10 platform provides a vast number of POSIX compliant C libraries that can be used as-is when the appropriate BlackBerry Platform Services API doesn’t exist.

pthread, strings, math, timers, memory, file io etc

A number of open-source libraries are also available for use

openAL, openSSL, SQLite, zlib, libxml2, freetype

Page 27: Start to Finish: Porting to BlackBerry 10

:: building the basics – main.c

27

DEMO… tv static (with white noise) …

edit - compile – deploy – debug – run

(command line tools)

Page 28: Start to Finish: Porting to BlackBerry 10

:: migration to SHARK

28

DEMO… cronk / caveman HD …edit - compile – deploy – debug – run

(command line tools)

Page 29: Start to Finish: Porting to BlackBerry 10

Destination

29

Page 30: Start to Finish: Porting to BlackBerry 10

:: next steps - extend

30

Page 31: Start to Finish: Porting to BlackBerry 10

:: next steps – open source

31

blackberry.github.org

Page 32: Start to Finish: Porting to BlackBerry 10

QUESTIONS

contact me for the “tv static” application sources

Page 33: Start to Finish: Porting to BlackBerry 10

THANK YOU

Aaron Ardiri

Senior Technical Evangelist

[email protected]