Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.279.316 Times

Net::DBus::Tutorial::ExportingObjects 0.33.4

  Date Added: April 01, 2010  |  Visits: 1.440

Net::DBus::Tutorial::ExportingObjects

Report Broken Link
Printer Friendly Version


Product Homepage
Download (95 downloads)



Net::DBus::Tutorial::ExportingObjects is a Perl module that contains tutorials on providing a DBus service. This document provides a tutorial on providing a DBus service using the Perl Net::DBus application bindings. This examples in this document will be based on the code from the Music::Player distribution, which is a simple DBus service providing a music track player. CREATING AN OBJECT The first step in creating an object is to create a new package which inherits from Net::DBus::Object. The Music::Player::Manager object provides an API for managing the collection of music player backends for different track types. To start with, lets create the skeleton of the package & its constructor. The constructor of the super type, Net::DBus::Object expects to be given to parameters, a handle to the Net::DBus::Service owning the object, and a path under which the object shall be exported. Since the manager class is intended to be a singleton object, we can hard code the path to it within the constructor: package Music::Player::Manager; use base qw(Net::DBus); sub new { my $class = shift; my $service = shift; my $self = $class->SUPER::new($service, "/music/player/manager"); bless $self, $class; return $self; } 1; Now, as mentioned, the manager with handle a number of different player backends. So we need to provide methods for registering new backends, and querying for backends capable of playing a particular file type. So modifying the above code we add a hash table in the constructor, to store the backends: sub new { my $class = shift; my $service = shift; my $self = $class->SUPER::new($service, "/music/player/manager"); $self->{backends} = {}; bless $self, $class; return $self; } And now a method to register a new backend. This takes a Perl module name and uses it to instantiate a backend. Since the backends are also going to be DBus objects, we need to pass in a reference to the service we are attached to, along with a path under which to register the backend. We use the get_service method to retreieve a reference to the service the manager is attached to, and attach the player backend to this same service: When a method on DBus object is invoked, the first parameter is the object reference ($self), and the remainder are the parameters provided to the method call. Thus writing a method implementation on a DBUs is really no different to normal object oriented Perl (cf perltoot): sub register_backend { my $self = shift; my $name = shift; my $module = shift; eval "use $module"; if ($@) { die "cannot load backend $module: $@" ; } $self->{backends} = $module->new($self->get_service, "/music/player/backend/$name"); } Looking at this one might wonder what happens if the die method is triggered. In such a scenario, rather than terminating the service process, the error will be caught and propagated back to the remote caller to deal with. The player backends provide a method get_track_types which returns an array reference of the music track types they support. We can use this method to provide an API to allow easy retrieval of a backend for a particular track type. This method will return a path with which the backend object can be accessed sub find_backend { my $self = shift; my $extension = shift; foreach my $name (keys %{$self->{backends}}) { my $backend = $self->{backends}->{$name}; foreach my $type (@{$backend->get_track_types}) { if ($type eq $extension) { return $backend->get_object_path; } } } die "no backend for type $extension"; } Lets take a quick moment to consider how this method would be used to play a music track. If youve not already done so, refresh your memory from Net::DBus::Tutorial::UsingObjects. Now, we have an MP3 file which we wish to play, so we search for the path to a backend, then retrieve the object for it, and play the track: ...get the music player service... # Ask for a path to a player for mp3 files my $path = $service->find_backend("mp3"); # $path now contains /music/player/backend/mpg123 # and we can get the backend object my $backend = $service->get_object($path); # and finally play the track $backend->play("/vol/music/beck/guero/09-scarecrow.mp3");. libvirt, virtualization, virtualization API

Requirements: No special requirements
Platforms: Linux
Keyword: Backend Backends Dbus Exportingobjects Libraries Method Netdbustutorialexportingobjects Object Path Perl Module Programming Service
Users rating: 0/10

License: Freeware Size: 94.21 KB
USER REVIEWS
More Reviews or Write Review


NET::DBUS::TUTORIAL::EXPORTINGOBJECTS RELATED
Libraries  -  Locale::Object::Language 0.75
Locale::Object::Language Perl module contains language information objects. Locale::Object::Language allows you to create objects containing information about languages such as their ISO codes, the countries theyre used in and so on. SYNOPSIS...
47.1 KB  
Libraries  -  Class::Method::hash 2.08
Class::Method::hash is a Perl module that helps you create methods for handling a hash value. SYNOPSIS use Class::MethodMaker [ hash => [qw/ x /] ]; $instance->x; # empty $instance->x(a => 1, b => 2, c => 3); $instance->x_count == 3; #...
89.09 KB  
Libraries  -  Method::Declarative 0.03
Method::Declarative is a Perl module to create methods with declarative syntax. SYNOPSIS use Method::Declarative ( --defaults => { precheck => [ [ qw(precheck1 arg1 arg2) ], # ... ], postcheck => [ [ qw(postcheck1 arg3 arg4) ], #...
8.19 KB  
Libraries  -  ASNMTAP::Asnmtap::Applications 3.000.009
ASNMTAP::Asnmtap::Applications is a Perl module that provides a nice object oriented interface for ASNMTAP Applications. ASNMTAP::Asnmtap::Applications Subclass of ASNMTAP::Asnmtap This version is still the old ASNMTAP Applications v3.000.001...
1.6 MB  
Libraries  -  Net::DBus::Error 0.33.4
Net::DBus::Error is a Perl module with error details for remote method invocation. SYNOPSIS package Music::Player::UnknownFormat; use base qw(Net::DBus::Error); # Define an error type for unknown track encoding type # for a music player...
94.21 KB  
Libraries  -  Object::Realize::Later 0.16
Object::Realize::Later is a Perl module with delayed creation of objects. SYNOPSIS package MyLazyObject; use Object::Realize::Later becomes => MyRealObject, realize => load; The Object::Realize::Later class helps with implementing...
10.24 KB  
Libraries  -  Object::Trampoline 1.25
Object::Trampoline is a Perl module for delay object construction, and optionally using the class module, until a method is actually dispatched, simplifies runtime definition of handler classes. SYNOPSIS # adding "use_class" will perform an...
9.22 KB  
Libraries  -  Object::LocalVars 0.16
Object::LocalVars is a Perl module with outside-in objects with local aliasing of $self and object variables. SYNOPSIS package My::Object; use strict; use Object::LocalVars; give_methods our $self; # this exact line is required our...
40.96 KB  
Libraries  -  Games::Object 0.11
Games::Object is a Perl module to provide a base class for game objects. SYNOPSIS package MyGameObject; use Games::Object; use vars qw(@ISA); @ISA = qw(Games::Object); sub new { # Create object my $proto = shift; my $class =...
84.99 KB  
Libraries  -  Object::Declare 0.13
Object::Declare is a Perl module for declarative object constructor. SYNOPSIS use Object::Declare [MyApp::Column, MyApp::Param]; my %objects = declare { param foo => !is global, is immutable, valid_values are qw( more values ); column...
27.65 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB