1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
\input{confighandout}
\subsection{Middleware}
Distributed systems need to communicate with each other. Middleware assists the
developer by delivering a communication framework. The developer doesn't need
to care about protocols, datatype conversion, low level socket handling, \dots
There are different kinds of middleware:
\begin{description}
\item[RPC] Remote Procedure Calls are used to trigger a function in e.g. Task\_A
calls a function of Task\_B
\item[MOM] Message Orientated Middleware is used the send messages between Taks.
(1:n and 1:1)
\item[ORB] An Object Request Broker is used to host complete objects of an
application in the broker. Other applications contact the broker; their object
request is handled by the orb.
\end{description}
Also a middleware can provide different degrees of abstraction:
\begin{itemize}
\item Programming Language
\item Operating System
\item Communication Protocol
\item Datatype conversions
\item Localization of Services
\end{itemize}
\subsubsection{D-Bus / Desktop Bus}
D-Bus is designed for
\begin{itemize}
\item communication between application and operating system (system-bus)
\item communication between desktop applications (session-bus)
\end{itemize}
and used by several Desktop Environments
\begin{itemize}
\item GNOME
\item KDE4
\item Enlightenment E17
\item XFCE4
\item \dots
\end{itemize}
D-Bus is designed for local IPC only. It is a message based Middleware
supporting 1:n publish/subscribe mechanism and 1:1 message passing. D-Bus has
integrated datatype marschalling.
\paragraph{Architecture}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/dbus.png}
\caption{D-Bus Architecture}
\label{img:dbus}
\end{figure}
In the centre of the D-Bus architecture (Figure \ref{img:dbus}) is a
\cmd{dbus-daemon}. Connections to the \cmd{dbus-daemon} are established by the
help of the \cmd{dbus-library}. There are many language bindins for the
\cmd{dbus-library}:
\begin{itemize}
\item C/C++
\item JAVA
\item Python
\item Perl
\item PHP
\item Pascal
\item Ruby
\item Tcl
\item Smalltalk
\end{itemize}
A higher level abstraction is served by integrating D-Bus into frameworks. If
possible one of these libraries should be used:
\begin{itemize}
\item glib
\item QT4 (QT3 backport exists)
\item Mono
\item e\_dbus (Enlightenment E17)
\item .NET
\end{itemize}
\subparagraph{Terminology}
\begin{description}
\item[bus address] is the name of ther underlying unix socket, e.g.
\cmd{/tmp/dbus\_lx.socket}
\item[unique bus name] is generated by the daemon for every connection
\item[well-known bus name] must be set by the user for a connection, multiple
names for one connection are allowed. A well known bus name has a namespace
and is seperated by dots, e.g. \cmd{de.linutronix.Foo}.
\item[Object] Each Endpoint is called Object. An Object offers services on the
bus. A client can create multiple Objects.
\item[Proxies] are used to access Objects. The use of Proxies and Objects are
defined by the language binding, to fit best in the schemantics of the
programming language.
\item[Methods] may require input parameters. Each call returns its output
parameters or an exception if the action couldn't be performed.
\item[Signals] are used for 1:n message passing. An application needs to be
subscribed for a signal. A filter can be provided during subscription, to get
only signals with certain values in its parameters.
\item[AMI] Asynchronus Method Invocation can be used to make non blocking calls
to Methods.
\item[Activation] A config file can provide the information which objects are
hosted by an application. The dbus daemon is able, to activate those
applications on request or by invoking a method of an object in the context
of the clients well-known bus name.
\end{description}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/dbus-hal.png}
\caption{D-Bus Use-Case: NetworkManager}
\label{img:dbus-hal}
\end{figure}
Figure \ref{img:dbus-hal} shows a typical D-Bus use-case. The
HAL\footnote{Hardware Abstraction Layer} daemon is connected with the Linux
kernel by the Device interfaces. Objects and Methods which represent the
hardware of the device running the Linux kernel are hosted on the D-Bus system
message bus by HAL. The NetworkManager user daemon and the NetworkManager daemon
are also connected to the D-Bus system bus. The NM\footnote{NetworkManager}
user daemon is getting the Network Settings from the User via config file or
NM Applet and sends it to the D-Bus system bus. The NM daemon listens for the
messages from the NM user daemon and configures the networking stack via system
calls.
\paragraph{Tools}
\subparagraph{qdbusviewer}
is a tool to browse through the hosted objects and call any method. (Figure
\ref{img:qdbusviewer})
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/qdbusviewer.png}
\caption{qdbusviewer}
\label{img:qdbusviewer}
\end{figure}
\paragraph{Conclusion}
D-Bus is good for accessing System Infos and for IPC of Desktop Applications.
Its small API has bindings for all common languages and frameworks and is easy
to learn.
On the other hand D-Bus is limited on local IPC. Applications hosted on other
machines cannot be reached via D-Bus. Also there are no QoS features integrated,
to guarantee any real-time behaviour. There is even no message ordering. There
is no guarantee which method returns first, if two methods are invoked around
the same time.
\subsubsection{CORBA}
CORBA is a middleware, which allows RPC\footnote{Remote Procedure
Call}-based IPC\footnote{Inter Process Communication} between
different operating systems and different programming languages
(Figure \ref{img:orb}).
The communication interfaces are defined in IDL\footnote{Interface Definition
Language}. The IDL files are compiled into, e.g. c++, java, \dots,
code which does the (de)serialization of the datatypes. The interface
implementations (CORBA objects) are registered with language
specific ORB\footnote{Object Request Broker}s. Each CORBA process owns
one ORB, which handles the function requests and returns the
calculated values.
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/orb.jpg}
\caption{Object Request Broker}
\label{img:orb}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/rtcorbaext.jpg}
\caption{Real-time Object Request Broker (source: [1])}
\label{img:rtorb}
\end{figure}
As shown in figure \ref{img:rtorb}, a real-time capable ORB extends a standard
ORB with the following features: locating objects in constant time,
preallocation of resources, operating system independent priority
handling, priority based scheduling.
ACE is an open-source c++ framework for platform-independent system-
and network-programming. TAO is a Real-time CORBA implementation build
on top of ACE (Figure \ref{img:ace}).
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{images/ace.jpg}
\caption{ACE Framework (source: [2])}
\label{img:ace}
\end{figure}
The ACE/TAO package is available for all important operating
systems. The framework can be trimmed for embedded systems: Each
application described in this paper consumes less than 1 MByte of
RAM. Also the consumed CPU time is suprisingly low.
\paragraph{Conclusion}
CORBA offers a wide variety of middleware communication methods. There is no
limitation for a communication between different operating systems, even the
network protocols can be exchanged. CORBA provides a Real-time extension.
On the other hand, the framework is complex and difficult to learn.
\subsubsection{Exercises}
An application should be created, to send a message to the 'server' with a
variable payload, that the time needed for the call / return of the call can be
measured in the client.
The above described application will be implemented with ACE/TAO RTCORBA and
the D-Bus glib bindings:
\paragraph{ACE/TAO RTCORBA}
First an IDL for the Ping interface will be created (\cmd{ping.idl}:
\begin{lstlisting}
module Linutronix{
interface Ping{
oneway void send(in string payload);
};
};
\end{lstlisting}
Then a IDL compiler is used to generater headers and wrappers for client and
server and a dummy implementation file:
\cmd{tao\_idl -GI ping.idl}
The following files will be generated:
\begin{itemize}
\item pingC.cpp
\item pingC.h
\item pingC.inl
\item pingI.cpp
\item pingI.h
\item pingS.cpp
\item pingS.h
\item pingS.inl
\end{itemize}
Before editing the implementation dummy, we alter its name, to avoid that it is
overwritten by a further \cmd{tao\_idl} call:
\cmd{mv pingI.cpp ping\_I.cpp}
Now we can alter the \cmd{ping\_I.cpp} file, that it looks like this:
\begin{lstlisting}
#include <time.h>
#include <iostream>
#include "pingI.h"
// Implementation skeleton constructor
Linutronix_Ping_i::Linutronix_Ping_i (void)
{
}
// Implementation skeleton destructor
Linutronix_Ping_i::~Linutronix_Ping_i (void)
{
}
void Linutronix_Ping_i::send (
const char * payload)
{
// Add your implementation here
struct timespec time_rx;
clock_gettime(CLOCK_MONOTONIC, &time_rx);
std::cout<<time_rx.tv_sec<<":"<<time_rx.tv_nsec/1000<<": "<<payload<<"\n";
}
\end{lstlisting}
Next step is to create an application \cmd{Receiver.cpp} which hosts the Ping
implementation:
\begin{lstlisting}
#include <iostream>
#include "pingI.h"
#include "orbsvcs/CosNamingC.h"
#include <tao/RTCORBA/RTCORBA.h>
int main(int argc, char* argv[]){
try{
// initialize ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "ServerORB");
std::cout<<"ORB initialized"<<std::endl;
// access RT Extensions
CORBA::Object_var rtorb = orb->resolve_initial_references("RTORB");
RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow(rtorb);
std::cout<<"RT Extensions OK"<<std::endl;
// obtain root_poa
CORBA::Object_var poa = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa.in());
// activate POA Manager
PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
poa_manager->activate();
std::cout<<"root_poa OK"<<std::endl;
// create Policy
CORBA::PolicyList ping_policy(1);
ping_policy.length(1);
ping_policy[0] = rt_orb->create_priority_model_policy(
RTCORBA::CLIENT_PROPAGATED, RTCORBA::maxPriority);
// create ObjectAdapter, assign Policy
PortableServer::POA_var ping_poa =
root_poa->create_POA("ping_poa", poa_manager.in(), ping_policy);
std::cout<<"Policy assigned"<<std::endl;
// create the servant
Linutronix_Ping_i ping_i;
// activate servant
PortableServer::ObjectId_var object_id = ping_poa->activate_object(&ping_i);
CORBA::Object_var ping_obj = ping_poa->id_to_reference(object_id.in());
CORBA::String_var ior = orb->object_to_string(ping_obj.in());
std::cout<<"Servant activated"<<std::endl;
// NameService
CORBA::Object_var naming_obj =
orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var naming_context =
CosNaming::NamingContext::_narrow(naming_obj.in());
CosNaming::Name name(1);
name.length(1);
name[0].id = CORBA::string_dup("Receiver");
naming_context->rebind(name, ping_obj.in());
std::cout<<"Bound Receiver to NameService"<<std::endl;
// start ORB
orb->run();
std::cout<<"ORB ready"<<std::endl;
//destroy
root_poa->destroy(1,1);
orb->destroy();
} catch(CORBA::Exception &any) {
std::cout<<"Exception: "<<any<<std::endl;
}
return 0;
}
\end{lstlisting}
Then we create an application \cmd{Supplier.cpp} which raises calls to the Ping
interface:
\begin{lstlisting}
#include <iostream>
#include <string>
#include <unistd.h>
#include <orbsvcs/CosNamingC.h>
#include <tao/RTCORBA/RTCORBA.h>
#include "pingC.h"
static Linutronix::Ping_var ping;
static std::string str;
int main(int argc, char* argv[])
{
if (argc > 1)
str = argv[1];
else
str = "no argument given";
try{
// initialize ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "ClientORB");
std::cout<<"ORB ok"<<std::endl;
// get RTORB
CORBA::Object_var rtorb = orb->resolve_initial_references("RTORB");
RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow(rtorb.in());
std::cout<<"RTORB ok"<<std::endl;
// NamingService
CORBA::Object_var naming_obj =
orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var naming_context =
CosNaming::NamingContext::_narrow(naming_obj.in());
std::cout<<"NamingService ok"<<std::endl;
CosNaming::Name name(1);
name.length(1);
name[0].id = CORBA::string_dup("Receiver");
// receive Object
CORBA::Object_var ping_obj = naming_context->resolve(name);
ping = Linutronix::Ping::_narrow(ping_obj.in());
std::cout<<"TransferOjekt ok"<<std::endl;
// Private Connection Policy
CORBA::PolicyList pc_policy(1);
pc_policy.length(1);
pc_policy[0] = rt_orb->create_private_connection_policy();
CORBA::Object_var new_tran =
ping->_set_policy_overrides(pc_policy, CORBA::SET_OVERRIDE);
ping = Linutronix::Ping::_narrow(new_tran.in());
std::cout<<"PrivateConnection ok"<<std::endl;
struct timespec time_tx;
struct timespec time_done;
for(unsigned int i = 0; i < 100; i++)
{
clock_gettime(CLOCK_MONOTONIC, &time_tx);
ping->send((const char*)str.c_str());
clock_gettime(CLOCK_MONOTONIC, &time_done);
std::cout<<time_tx.tv_sec<<":"<<time_tx.tv_nsec/1000<<"\n";
std::cout<<time_done.tv_sec<<":"<<time_done.tv_nsec/1000<<"\n\n";
}
// destroy ORB
orb->destroy();
} catch(CORBA::Exception &any) {
std::cout<<"Exception occured: "<<any<<std::endl;
}
return 0;
}
\end{lstlisting}
Typically ACE/TAO projects are build with MPC\footnote{MakeProjectCreator}. An
appropirate config file (\cmd{ping.idl}) looks like this:
\begin{lstlisting}
project(*Receiver): rt_server, naming {
requires += exceptions
Source_Files {
ping_I.cpp
Receiver.cpp
}
}
project(*Supplier): rt_client, naming {
requires += exceptions
Source_Files {
pingC.cpp
Supplier.cpp
}
}
\end{lstlisting}
Debian Users can use the following commands to translate all stuff:
\cmd{export ACE\_ROOT=/usr/share/ace}
\cmd{export TAO\_ROOT=/usr/share/ace/TAO}
\cmd{mpc-ace -type make ping.mpc}
\cmd{make -f Makefile.Ping\_Receiver}
\cmd{make -f Makefile.Ping\_Supplier}
To run the applications, first a NamingService has to be started:
\cmd{Naming\_Service -ORBEndpoint iiop://localhost:55555}
Then the server and client can be started:
\begin{enumerate}
\item \cmd{./server -ORBInitRef NameService=corbaloc:iiop:localhost:55555/NameService}
\item \cmd{./client -ORBInitRef NameService=corbaloc:iiop:localhost:55555/NameService}
\end{enumerate}
\subsubsection*{D-Bus glib bindings}
First \cmd{ping-server.c} will be created to host the ping object:
\begin{lstlisting}
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <time.h>
static DBusHandlerResult signal_filter
(DBusConnection *connection, DBusMessage *message, void *user_data);
int main(int argc, char **argv)
{
GMainLoop *loop;
DBusConnection *bus;
DBusError error;
loop = g_main_loop_new (NULL, FALSE);
dbus_error_init (&error);
bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
if (!bus) {
g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free (&error);
return 1;
}
dbus_connection_setup_with_g_main (bus, NULL);
/* listening to messages from all objects as no path is specified */
dbus_bus_add_match (bus, "type='signal',interface='de.linutronix.Ping'",
&error);
dbus_connection_add_filter (bus, signal_filter, loop, NULL);
g_main_loop_run (loop);
return 0;
}
static DBusHandlerResult signal_filter
(DBusConnection *connection, DBusMessage *message, void *user_data)
{
/* User data is the event loop we are running in */
GMainLoop *loop = user_data;
/* A signal from the bus saying we are about to be disconnected */
if (dbus_message_is_signal(message, "org.freedesktop.Local",
"Disconnected"))
{
/* Tell the main loop to quit */
g_main_loop_quit (loop);
/* We have handled this message, don't pass it on */
return DBUS_HANDLER_RESULT_HANDLED;
}
else if (dbus_message_is_signal (message, "de.linutronix.Ping", "Ping"))
{
DBusError error;
char *s;
dbus_error_init (&error);
if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &s,
DBUS_TYPE_INVALID))
{
struct timespec rx_time;
clock_gettime(CLOCK_MONOTONIC, &rx_time);
g_print("ping received: %s - %d:%d\n", s, rx_time.tv_sec,
rx_time.tv_nsec/1000);
// dbus_free (s);
} else {
g_print("ping received, but error getting message: %s\n", error.message);
dbus_error_free (&error);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
\end{lstlisting}
The server application will be compiled with the following command:
\cmd{gcc -o server `pkg-config --libs --cflags dbus-glib-1` -lrt ping-server.c}
Next a file \cmd{ping-client.c} with the following content is created:
\begin{lstlisting}
#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <time.h>
static gboolean send_ping (DBusConnection *bus);
static const char *v_STRING;
int main (int argc, char **argv)
{
GMainLoop *loop;
DBusConnection *bus;
DBusError error;
if (argc > 1)
v_STRING = argv[1];
else
v_STRING = "no arg given";
/* Create a new event loop to run in */
loop = g_main_loop_new (NULL, FALSE);
/* Get a connection to the session bus */
dbus_error_init (&error);
bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
if (!bus) {
g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free (&error);
return 1;
}
/* Set up this connection to work in a GLib event loop */
dbus_connection_setup_with_g_main (bus, NULL);
/* Every second call send_ping() with the bus as an argument*/
g_timeout_add (1000, (GSourceFunc)send_ping, bus);
/* Start the event loop */
g_main_loop_run (loop);
return 0;
}
static gboolean send_ping (DBusConnection *bus)
{
DBusMessage *message;
struct timespec tx_time;
struct timespec done_time;
message = dbus_message_new_signal ("/de/linutronix/Ping",
"de.linutronix.Ping", "Ping");
/* Append the string to the signal */
dbus_message_append_args (message,
DBUS_TYPE_STRING, &v_STRING,
DBUS_TYPE_INVALID);
clock_gettime(CLOCK_MONOTONIC, &tx_time);
/* Send the signal */
dbus_connection_send (bus, message, NULL);
clock_gettime(CLOCK_MONOTONIC, &done_time);
g_print("%d:%d\n%d:%d\n\n", tx_time.tv_sec, tx_time.tv_nsec/1000,
done_time.tv_sec, done_time.tv_nsec/1000);
/* Free the signal now we have finished with it */
dbus_message_unref (message);
/* Return TRUE to tell the event loop we want to be called again */
return TRUE;
}
\end{lstlisting}
The client application will be compiled with the following command:
\cmd{gcc -o client `pkg-config --libs --cflags dbus-glib-1` -lrt ping-client.c}
To run the applications start them with:
\begin{itemize}
\item \cmd{./client WhatEverYouWantAsPayLoad}
\item \cmd{./server}
\end{itemize}
The order, which application is started first doesn't matter. Take care that
the \cmd{dbus-daemon} is running.
\begin{thebibliography}{9}
\bibitem{paper1},{\it Real-time CORBA Specification},2005, {\sc OMG}
\bibitem{paper2},{\it Overview of ACE},2007\\{\it http://www.cs.wustl.edu/schmidt/ACE-overview.html}
\end{thebibliography}
\input{tailhandout}
|