PHP on the D-BUS. Welcome!



Similar documents
D-Bus Language Bindings for oorexx

Visual Basic Programming. An Introduction

CORBA, DCOP and DBUS. A performance comparison.

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

dbusoorexx Bringing the Power of D-Bus to Your Fingertips

How To Write A Freesmartphone.Org For Mobile Devices

Using the VMRC Plug-In: Startup, Invoking Methods, and Shutdown on page 4

PHP Integration Kit. Version User Guide

ARC: appmosphere RDF Classes for PHP Developers

SUSE Linux Enterprise Desktop

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Facebook Twitter YouTube Google Plus Website

DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Spring Design ScreenShare Service SDK Instructions

AP Computer Science Java Subset

Contents. 2 Alfresco API Version 1.0

Certified PHP/MySQL Web Developer Course

Crash Course in Java

Manage cloud infrastructures using Zend Framework

Using AllJoyn with Apache Cordova, Python & Node

Technical documentation

Sample CSE8A midterm Multiple Choice (circle one)

Monday, April 8, 13. Creating Successful Magento ERP Integrations

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Logging and SNMP Trap Notification Of Events. Isonas Access Control System. Release 12 June 2007

PIC 10A. Lecture 7: Graphics II and intro to the if statement

JAVAMAIL API - SMTP SERVERS

CANnes PC CAN Interface Manual

Sources: On the Web: Slides will be available on:

IoT-Ticket.com. Your Ticket to the Internet of Things and beyond. IoT API

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Government Girls Polytechnic, Bilaspur

RCS - Overview. Rich Communication Suite

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Virtuozzo Virtualization SDK

IVR Studio 3.0 Guide. May Knowlarity Product Team

AdFalcon Mobile Web API Integration Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

pyownet Documentation

Online signature API. Terms used in this document. The API in brief. Version 0.20,

PHP Tutorial From beginner to master

J a v a Quiz (Unit 3, Test 0 Practice)

Working with forms in PHP

Types of Cloud Computing

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

EcgSoft. Software Developer s Guide to EcgViewer. Innovative ECG Software info@ecg-soft.com


Replugging the Modern Desktop

Lehrstuhl für Informatik 4 Kommunikation und verteilte Systeme. Middleware. Chapter 8: Middleware

PHP Magic Tricks: Type Juggling. PHP Magic Tricks: Type Juggling

Iotivity Programmer s Guide Soft Sensor Manager for Android

Introduction to Java

Celly FAQ. inbox cells people help. celly help. Common Support Questions. celly company. General. school. policies. About Cells.

USING MAGENTO TRANSLATION TOOLS

OpenStreetMap for the Web

Getting Started Guide for Developing tibbr Apps

Lecture 17: Mobile Computing Platforms: Android. Mythili Vutukuru CS 653 Spring 2014 March 24, Monday

System Calls and Standard I/O

C++FA 5.1 PRACTICE MID-TERM EXAM

Managed File Transfer with Universal File Mover

Understanding Android s Security Framework

The Service Availability Forum Specification for High Availability Middleware

Cleo Communications. CUEScript Training

PHP Authentication Schemes

MS Active Sync: Sync with External Memory Files

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Online Meeting Instructions for Join.me

The Answer to the 14 Most Frequently Asked Modbus Questions

Data Management Applications with Drupal as Your Framework

ECE 358: Computer Networks. Homework #3. Chapter 5 and 6 Review Questions 1

CS1010 Programming Methodology A beginning in problem solving in Computer Science. Aaron Tan 20 July 2015

AllJoyn Framework System Overview

Webair CDN Secure URLs

Data Intensive Computing Handout 5 Hadoop

Integrating Video Conferencing into Everyday Applications. Olivier Crête

latest Release 0.2.6

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

THE CHALLENGE OF ADMINISTERING WEBSITES OR APPLICATIONS THAT REQUIRE 24/7 ACCESSIBILITY

Introduction to Python

Middleware Lou Somers

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

How To Write Portable Programs In C

Java Interview Questions and Answers

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Building Conferencing Applications Using Intel NetStructure Host Media Processing Software

Chapter 2: Remote Procedure Call (RPC)

Application Power Management for Mobility

WORKING WITH WEB SERVICES. Rob Richards

DocStore: Document Database for MySQL at Facebook. Peng Tian, Tian Xia 04/14/2015

Introduction to Highly Available NFS Server on scale out storage systems based on GlusterFS

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Transcription:

Welcome! PHP on the D-BUS International PHP Conference - Berlin, Germany Derick Rethans - derick@php.net - twitter: @derickr http://derickrethans.nl/talks.html

About Me Derick Rethans Dutchman living in London PHP development Author of the mcrypt, input_filter, dbus, translit and date/time extensions Author of Xdebug Freelancer doing PHP (internals) development

What is DBUS? Part of the freedesktop.org project It is meant to replace Corba (GNOME) and DCOP (KDE) A message bus system, a simple way for applications to talk to one another It consists of a daemon, a library and a protocol It is both meant for system level and session level communication

What is DBUS used for? On the (GNOME) desktop: Avahi, CUPS, GConf, Nautilus, Network Manager, Power Manager, Screen Saver, Volume Manager System level elements: HAL, Network manager Gnome applications: Pidgin, Empathy/Telepathy, Liferea, Rhythmbox Other applications: skype But also on the Openmoko platform (freesmartphone.org)

Architecture

Message Types Method calls From one application to another Method returns Upon succesfull method execution Method error returns Upon a failure while executing the method Signals Broadcast from one application to all others

DBus Parts Bus: Communication pathways that clients can transport messages over Proxy: A client-level representation of an object on the bus.

Data-types Basic types byte boolean (0 = false, 1 = true) integer (int16, uint16, int32, uint32, int64 and uint64) double (IEEE 754 double) string (UTF-8 string) Compound types array (contains elements of the same type) struct (contains one or more complete types) dictionary entry (contains a key (basic type) and a value, must be part of an array) variant (contains a type and a value) object path (a string representation of a DBUS

PHP DBUS extension DBUS bindings using the low-level C library (libdbus) Provides proxy objects Implements automatic-marshalling of data Provides specific classes for full control Support for method invocation, method calls, sending and receiving signals (Basic) support for introspection

Talking to a DBUS object from PHP Activating the screensaver screensaver.php: <?php $d = new Dbus; $n = $d->createproxy( "org.gnome.screensaver", "/org/gnome/screensaver", "org.gnome.screensaver" ); var_dump($n->getactive()); $n->setactive( true ); var_dump($n->getactive()); sleep(5); $n->setactive( false );?>

Data-type mapping From PHP to DBUS boolean -> boolean integer -> int32 double -> double string -> string array -> array (only basic types as values are supported) DbusByte, DbusBool, DbusInt16, DbusUInt16, DbusInt32, DbusUInt32, DbusInt64, DbusUInt64, DbusDouble DbusArray( int $type, array $elements [, string $signature] ) DbusDict( int $type, array $elements ) DbusVariant( mixed $data ) DbusStruct( string $signature, array $elements )

Data-type mapping From DBUS to PHP Basic types boolean -> boolean byte, int16, uint16, int32, uint32, int64, uint64 -> integer double -> double string -> string Compound types array -> DbusArray or DbusDict (depending on whether there is a dict-entry embedded) dict-entry -> variable (could be anything) variant -> DbusVariant struct -> DbusStruct object-path -> DbusObjectPath

Talking to a DBUS object from PHP Using explicit integer types notify.php: <?php $d = new Dbus( Dbus::BUS_SESSION ); $n = $d->createproxy( "org.freedesktop.notifications", // connection name "/org/freedesktop/notifications", // object "org.freedesktop.notifications" // interface ); $id = $n->notify( 'Testapp', new DBusUInt32( 0 ), // app_name, replaces_id 'iceweasel', 'Testing http://ez.no', 'Test Notification', // app_icon, summary, body new DBusArray( DBus::STRING, array() ), // actions new DBusDict( // hints DBus::VARIANT, array( 'x' => new DBusVariant( 500 ), // x position on screen 'y' => new DBusVariant( 500 ), // y position on screen 'desktop-entry' => new DBusVariant( 'rhythmbox' ) ) ), 1000 // expire timeout in msec ); echo $id[0], "\n";?>

Introspection Most services provide information about their methods' arguments through org.freedesktop.dbus.introspectable. The DBUS extension currently switches between i and u only. <!DOCTYPE node PUBLIC "-//freedesktop//dtd D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> <node> <interface name="org.freedesktop.notifications"> <method name="notify"> <arg name="app_name" type="s" direction="in"/> <arg name="id" type="u" direction="in"/> <arg name="icon" type="s" direction="in"/> <arg name="summary" type="s" direction="in"/> <arg name="body" type="s" direction="in"/> <arg name="actions" type="as" direction="in"/> <arg name="hints" type="a{sv}" direction="in"/> <arg name="timeout" type="i" direction="in"/> <arg name="return_id" type="u" direction="out"/> </method> <method name="getserverinformation"> <arg name="return_name" type="s" direction="out"/>

Talking to a DBUS object from PHP Using introspection to select the correct integer type notify-introspect.php: <?php $d = new Dbus( Dbus::BUS_SESSION, true ); $n = $d->createproxy( "org.freedesktop.notifications", // connection name "/org/freedesktop/notifications", // object "org.freedesktop.notifications" // interface ); $id = $n->notify( 'Testapp', 0, // app_name, replaces_id 'iceweasel', 'Testing http://ez.no', 'Test Notification', // app_icon, summary, body new DBusArray( DBus::STRING, array() ), // actions new DBusDict( // hints DBus::VARIANT, array( 'x' => new DBusVariant( 500 ), // x position on screen 'y' => new DBusVariant( 500 ), // y position on screen 'desktop-entry' => new DBusVariant( 'rhythmbox' ) ) ), 1000 // expire timeout in msec ); echo $id[0], "\n";?>

Providing DBUS services through PHP Request a connection name Register a class that provides methods Introspection is not yet supported <?php $d = new Dbus( Dbus::BUS_SESSION, true ); $d->requestname( 'nl.derickrethans.test' ); $d->registerobject( '/nl/derickrethans/test', 'nl.derickrethans.test', 'testclass' ); class testclass { static function echoone( $a ) { return $a; } static function echotwo( $a, $b ) { return new DbusSet( $a, $b ); } } do { $s = $d->waitloop( 1000 ); } while ( true );?>

Watching signals <?php $d = new Dbus( Dbus::BUS_SYSTEM ); $d->addwatch( 'org.freedesktop.hal.device' ); $d->addwatch( 'nl.derickrethans.interface' ); $b = 0; do { $s = $d->waitloop( 1000 ); if (!$s ) continue; if ( $s->matches( 'org.freedesktop.hal.device', 'Condition' ) ) { $b = $s->getdata()->getdata(); if ( in_array( 'brightness-up', $b ) in_array( 'brightness-down', $b ) ) { echo "Brightness changed\n"; } } else if ( $s->matches( 'nl.derickrethans.interface', 'TestSignal' ) ) { var_dump( $s->getdata() ); } } while ( true );?>

Sending signals <?php $d = new Dbus( Dbus::BUS_SESSION, true ); $d->requestname( 'nl.derickrethans.test' ); $s = new DbusSignal( $d, '/nl/derickrethans/signalobject', 'nl.derickrethans.interface', 'TestSignal' ); $s->send( "ze data", new DBusArray( Dbus::STRING, array( 'one', 'two' ) ) );?>

Skype Implements (on Linux) a DBUS API for communications Documented at https://developer.skype.com/docs/apidoc/src (sparsely)

Skype Objects USER object PROFILE object CALL object MESSAGE object CHAT object CHATMEMBER object CHATMESSAGE object VOICEMAIL object SMS object APPLICATION object GROUP object FILETRANSFER object

Skype Odd DBUS API Everything in and out happens with a weird string protocol It does not make use of objects at all It doesn't send signals, but you have to provide a callback

Skype in polling mode while ( true ) { $r = $n->invoke( "GET CHAT $id RECENTCHATMESSAGES" ); list( $ignore, $dummy, $dummy, $messageids ) = explode( ' ', $r, 4 ); foreach( explode( ", ", $messageids ) as $messageid ) { $data = $n->invoke( "GET CHATMESSAGE $messageid FROM_HANDLE" ); list( $a, $b, $c, $name ) = explode( ' ', $data, 4 ); $data = $n->invoke( "GET CHATMESSAGE $messageid BODY" ); list( $a, $b, $c, $body ) = explode( ' ', $data, 4 ); echo $name, ": ", $body, "\n"; $n->invoke( "SET CHATMESSAGE $messageid SEEN" ); } sleep( 30 ); }?> <?php $d = new Dbus( Dbus::BUS_SESSION, true ); $n = $d->createproxy( "com.skype.api", "/com/skype", "com.skype.api"); $n->invoke( "NAME PHP" ); $n->invoke( "PROTOCOL 7" ); $chatid = $n->invoke( "CHAT CREATE {$argv[1]}" ); list( $ignore, $id, $stuff, $stuff2 ) = explode( " ", $chatid ); $n->invoke( "OPEN CHAT $id" );

$d->registerobject( Skype with callback Instead they should have used signals... <?php $d = new Dbus( Dbus::BUS_SESSION, true ); $n = $d->createproxy( "com.skype.api", "/com/skype", "com.skype.api"); $n->invoke( "NAME PHP" ); $n->invoke( "PROTOCOL 7" ); $chatid = $n->invoke( "CHAT CREATE {$argv[1]}" ); list( $ignore, $id, $stuff, $stuff2 ) = explode( " ", $chatid ); $n->invoke( "OPEN CHAT $id" ); class testclass { static function notify($a) { global $n; @list( $a, $b, $c, $d ) = explode( ' ', $a, 4 ); if ( $a === "CHATMESSAGE" && in_array( $d, array( 'READ', 'SENT' ) ) ) { $data = $n->invoke( "GET CHATMESSAGE $b BODY" ); list( $a, $b, $c, $body ) = explode( ' ', $data, 4 ); echo $body, "\n"; } } }

What's the real goal? Running apps on the OpenMoko With PHP-GTK

Phone Services Playing Sounds <?php $d = new Dbus( Dbus::BUS_SYSTEM ); $sounddbus = $d->createproxy( 'org.freesmartphone.odeviced', '/org/freesmartphone/device/audio', 'org.freesmartphone.device.audio' ); $sounddbus->playsound( '/usr/share/sounds/notify_message.wav', 0, 0 );?>

Phone Services Making a call <?php $d = new DBus( DBus::BUS_SYSTEM ); $callinterface = $d->createproxy( 'org.freesmartphone.ogsmd', '/org/freesmartphone/gsm/device', 'org.freesmartphone.gsm.call' ); $callinterface->initiate( $nr, 'voice' );?>

if ( strlen( $text ) <= 160 ) { $smsinterface->sendmessage( $nr, $text, new DBusDict( Dbus::VARIANT,array() ) ); echo "Sending: $text\n"; } else { $textparts = chunk_split( $text, 140, "\n" ); $textparts = explode( "\n", trim( $textparts ) ); $id = mt_rand( 0, 255 ); $cnt = count( $textparts ); $c = 1; foreach( $textparts as $textpart ) { $smsinterface->sendmessage( $nr, Phone Services Sending SMS <?php $d = new DBus( DBus::BUS_SYSTEM ); $smsinterface = $d->createproxy( 'org.freesmartphone.ogsmd', '/org/freesmartphone/gsm/device', 'org.freesmartphone.gsm.sms' );

Phone Services Getting GPS coordinates <?php $d = new Dbus( Dbus::BUS_SYSTEM ); $gpspos = $d->createproxy( 'org.freedesktop.gypsy', '/org/freedesktop/gypsy', 'org.freedesktop.gypsy.position' ); $gpsdevice = $d->createproxy( 'org.freedesktop.gypsy', '/org/freedesktop/gypsy', 'org.freedesktop.gypsy.device' ); $coords = $gpspos->getposition()->getdata(); $fix = $gpsdevice->getfixstatus(); switch ( $fix ) { case 0: $txt = 'Invalid fix'; break; case 1: $txt = 'No fix'; break; case 2: $txt = '2D fix'; break; case 3: $txt = '3D fix'; break; } printf( "%s Location: %.2f, %.2f %s", date_create()->format( 'H:i:s' ), $coords[2], $coords[3], $txt );?>

Questions?

Thanks! Derick Rethans - derick@php.net - twitter: @derickr http://derickrethans.nl/talks.html