summaryrefslogtreecommitdiff
path: root/frameworks/middleware/handout_middleware.tex
diff options
context:
space:
mode:
Diffstat (limited to 'frameworks/middleware/handout_middleware.tex')
-rw-r--r--frameworks/middleware/handout_middleware.tex528
1 files changed, 264 insertions, 264 deletions
diff --git a/frameworks/middleware/handout_middleware.tex b/frameworks/middleware/handout_middleware.tex
index 44c75f7..7e227fa 100644
--- a/frameworks/middleware/handout_middleware.tex
+++ b/frameworks/middleware/handout_middleware.tex
@@ -10,7 +10,7 @@ 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
+ 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
@@ -91,27 +91,27 @@ possible one of these libraries should be used:
\subparagraph{Terminology}
\begin{description}
\item[bus address] is the name of ther underlying unix socket, e.g.
- \cmd{/tmp/dbus\_lx.socket}
+ \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}.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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}
@@ -186,7 +186,7 @@ calculated values.
\label{img:rtorb}
\end{figure}
-As shown in figure \ref{img:rtorb}, a real-time capable ORB extends a standard
+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.
@@ -230,13 +230,13 @@ 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);
- };
+ interface Ping{
+ oneway void send(in string payload);
+ };
};
\end{lstlisting}
-Then a IDL compiler is used to generater headers and wrappers for client and
+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}
@@ -280,10 +280,10 @@ 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";
+ // 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}
@@ -300,70 +300,70 @@ implementation:
#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;
- }
+ 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}
@@ -385,69 +385,69 @@ 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;
+ 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}
@@ -456,19 +456,19 @@ 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
- }
+ requires += exceptions
+ Source_Files {
+ ping_I.cpp
+ Receiver.cpp
+ }
}
project(*Supplier): rt_client, naming {
- requires += exceptions
- Source_Files {
- pingC.cpp
- Supplier.cpp
- }
+ requires += exceptions
+ Source_Files {
+ pingC.cpp
+ Supplier.cpp
+ }
}
\end{lstlisting}
@@ -501,71 +501,71 @@ First \cmd{ping-server.c} will be created to host the ping object:
#include <time.h>
static DBusHandlerResult signal_filter
- (DBusConnection *connection, DBusMessage *message, void *user_data);
+ (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;
+ 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)
+ (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;
+ /* 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}
@@ -586,59 +586,59 @@ 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;
+ 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;
+ 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}