Changes

Jump to: navigation, search

D-Bus and other Linux desktop integration improvements

3,063 bytes added, 22:05, 8 November 2011
m
Reverted edits by Saoagent (Talk) to last revision by Mattar1
There is currently a project called DBuzzilla which has done a good job implementing a module which allows Mozilla to communicate between applications or the system. The author has mentioned he had some personal issues, and has not touched the project since the summer of 2006. He said he will continue to maintain his project. There might be an interest working with this project. However, it seems the author is not willing to work in a manner that is consistent with open development. It is maintained by one person, with some or none users. It is not complete, but is a good start. If this project is to be continued and maintained by Seneca students, it is probably a good idea to start a new project that is updated to the latest version of D-Bus and is developed in an open development manner.
===This ProjectObjective and Features===
The goal of this project is to create a module that will expose the D-Bus technology to Mozilla technologies. This will work by coding a set of libraries and processes in XPCOM and D-Bus. The learning curve in this project is long (assuming you do not know XPCOM). You should also be or become familiar with Linux.
Documentation doesn't always exist for the technologies being used. When learning D-Bus, you may have to play with a function to understand its behaviour.
Read the mailing list discussion we started. A good description of problems we will encounteris in a few of them.
==Important Links==
[[User:David.humphrey|Dave]] - Has given us direction and ideas to start the project.
[[User:Andrew|Andrew Smith]] - Setup SVN for us, but helped fix our environment with Anjuta. == Project == The following is our code, and some tutorials on XPCOM and D-Bus. === Project Code === This is our current basic class files and tutorials. Download it [http://matrix.senecac.on.ca/~mckwan3/dbus/dbus_tutorials.tar.gz here]. We were converting the C dbus examples into C++ objects. We used Anjuta (an IDE), but you can just go into the src dir and type 'make' (in the command line). This is the [http://matrix.senecac.on.ca/~mckwan3/dbus/dbuzilla.tar.gz DBuzilla project file] which will be valuable later. Currently the author has taken down the code or the server just is down for some reason.
=== XPCOM Tutorial and info ===
XPCOM (Cross Platform Component Object Model) is a cross platform component model from Mozilla. It is similar to CORBA or Microsoft COM. It has multiple language bindings and Interface Description Language let the XPCOM components be used and implemented in JavaScript, Java, and Python in addition to C++. Interfaces in XPCOM are defined in a dialect of IDL called XPIDL. XPCOM itself provides a set of core components and classes, e.g. file and memory management, threads, basic data structures (strings, arrays, variants), etc. The majority of XPCOM components is not part of this core set and is provided by other parts of the platform (e.g. Gecko or Necko) or by an application or even by an extension.
It is similar to CORBA or Microsoft COM. It has multiple language bindings and Interface Description Language let the XPCOM components be used and implemented in JavaScript, Java, and Python in addition to C++.  Interfaces in XPCOM are defined in a dialect of IDL called XPIDL.  XPCOM itself provides a set of core components and classes, e.g. file and memory management, threads, basic data structures (strings, arrays, variants), etc.  The majority of XPCOM components is not part of this core set and is provided by other parts of the platform (e.g. Gecko or Necko) or by an application or even by an extension. For D-Bus to work in Mozilla environment we need to create C++ XPCOM components to access the methods with in the D-Bus framework.  To create a C++ XPCOM component we need to create the implementation file and component modules for the required methods.  Once the components are done we can create interface definition file to connect with the XPCOM components.  Follow the steps how to create C++ XPCOM component are listed below.
====Packages needed:====
====Create the Component====
1. Download the Gecko SDK.
  a. * You can find it at ftp://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.13  b. * You can choose a different Mozilla release if you like.  c. * Extract the SDK to a local directory.
2. Create a GUID for the main interface.
  a. * You can use the uuidgen utility to generate the unique 128 bit number. Or  b. * You can use one of the special “bots” on IRC at the irc.mozilla.org server (irc://irc.mozilla.org/#mozilla).
3. Create the interface definition file – ImyComponent.idl
  a. * Use the following template add methods and attributes to the interface.  b. * Fill in the GUID you have generated.
#include “nsISupports.idl”
};
4. Generate the interface header and typelib files out of the interface definition file.
  a. * Use the xpidl utility that comes with Gecko SDK. b. * Substitute the “_DIR_” in the following commands with the full path to the xpcom/idl directory found under the Gecko SDK main directory.  c. * xpidl -m hearer -I_DIR_ IMyComponent.idl will created the IMyComponent.h hearder file.  d. * xpidl -m typelib -I_DIR_ IMyComponent.idl will create the IMyComponent.xpt typelib file.
5. The interface header file IMyComponent.h contains templates for building the component header and implementation files. You can copy and paste the templates to create these files, changing only the component name.
6. Create the component header file “MyComponent.h”.
  a. * Start by inserting double includsion protection code (#ifndef _My_COMPONENT_H_ ….).  b. * Add #include “IMyComponent.h” to include the interface definition.  c. * Create a GUID for the component.  d. * Add the following lines, which define the component name, contract ID, and GUID:
#define MY_COMPONENT_CONTRACTID “@mydomain.com/XPCOMSample/MyComponent;1”
#define MY_COMPONENT_CID _YOU_COMPONENT_GUID_
e. * Copy the header template from IMyComponent.h (starting with /*Header file */) into the MyComponent.h file.  f. * Replace all the instances of _MYCLASS_ with the name of the component.
7. Create the component implementation file “MyComponent.cpp”.
  a. * Add #include “MyComponent.h” to include the component definitions.  b. * Copy the implementation template from IMyComponent.h (starting with /*Implementation file */) into the MyComponent.cpp file.  c. * Replace all the instances of _MYCLASS_ with the name of the component.  d. * Add method implementation code.
8. Create the module definitions file “MyComponentModule.cpp”
a. * Add #include “nsIGenericFactory.h” to include Mozilla GenericFactory definitions.  b. * Add #include “MyComponent.h” to include the component definitions.  c. * Add NS_GENERIC_FACTORY_CONSTRUCTIOR(MyComponent) to define the constructor for the component.  d. * Add
static nsModuleComponentInfo components[] =
{
to define the class name, contract ID and GUID of the component.
e. * Add NS_IMPL_NSGETMODULE(“MyComponentsMoudle”, components) to export the above information to Mozilla.
9. Create a custom makefiles.
1. Build the component.
a. * Navigate to the src directory.  b. * Issues the make command. MyComponent.so file is created.
2. Register the new component with Mozilla.
a. *Copy MyComponent.so and IMyComponent.xpt file to the Mozilla components directory.  b. * This directory is typically located at ~/firefox/components (or ~/mozilla/components).  c. * Run the regxpcom -x COMPONENTS_DIR command supplied with the Gecko SDK to register the new component where COMPONENT_DIR is the component directory.  d. * Delete the xpti.dat and compreg.dat file form the Mozilla profile directory. These files will be automatically rebuilt by Mozilla the next time it is restarted.  e. * The profile directory is typically located at:~/mozilla/firefox/default.????
3. Test the new component.
=== DBUS Tutorial and info ===
This is our current basic class files and tutorials. Download it [http://matrix.senecac.on.ca/~mckwan3/dbus/dbus_tutorials.tar.gz here]. We were converting the C dbus examples into C++ objects. We used Anjuta (I'll walk through a simple example of sending a signal to give you an IDE), but you can just go into the src dir and type 'make' (in the command line)example of what its like.
This is the [http://matrix.senecac.on.ca/~mckwan3/dbus/dbuzilla.tar.gz DBuzilla project file] which will It would be valuable latergood if you know how to connect to databases. Currently the author has taken down the code or the server just is down for some reason. I'll walk through The concepts are similar, but rather than connecting to a simple example of sending database you connect to a signal to give you an example of what its likebus.
First, you either need to use an IDE like Anjuta or learn how Make and its syntax.
#include <dbus/dbus.h>
#endif
 
You need the define DBUS_API... if you not using the dbus version 1.0+.
You need a connection to the DBus server running, and an error object for the error message.
DBusMessageIter args;
const char* sigvalue = "Hello World";
You do the following to make teh Message object a signal. The internals adds the flags it a signal. There are other functions that make a message into a methodcall, method response, or errors.  printf("Attempting to create a new Signal.\n"); msg = dbus_message_new_signal("/com/halcyoncomplex/test", // object name of the signal "com.halcyoncomplex.test", // interface name of the signal "test"); // name of the signal if (NULL == msg) { fprintf(stderr, "Message Null\n"); exit(1); } else printf("Signal Created.\n"); Adding arguments. Type string for our Hello World.  printf("Attempting to add arguments to signal.\n"); dbus_message_iter_init_append(msg, &args); if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue)) { fprintf(stderr, "Out Of Memory!\n"); exit(1); } else printf("Added argument of type(String) with value(Hello World)\n"); Now we send the signal.  printf("Attempting to send signal.\n"); // send the message and flush the connection if (!dbus_connection_send(conn, msg, &serial)) { fprintf(stderr, "Out Of Memory!\n"); exit(1); } else printf("Signal Sent. =)\n"); Clean up.  printf("Serial value for my signal is: %u\n",&serial); //printf("Flushing connection.\n"); dbus_connection_flush(conn); printf("Unreferencing message object.\n"); // free the message dbus_message_unref(msg); //////////////////////////////////////////////////////////////////////////// printf("Closing connection.\n"); dbus_connection_close(conn); The concepts aren't hard, getting things working is a little bit. If you've taken Mehmet's JDBC Connectivity or Jordan's Web Services you might be able to relate some concepts and patterns. I don't think Seneca has taught any RPC in their BTP series classes, but reviewing BTP600 patterns will help. D-Bus is a RPC-like technology and when making your code run in threads or asynchorous you'll need to understand proxies (along with more patterns) very well. == Experiences == === Mohamed Attar === The first problem I had was trying to understand where D-Bus is suppose to fit into Mozilla. It wasn't very clear to me who to talk to in Mozilla, so we looked elsewhere and got some great feedback from the Freedesktop.org community. I got some information from the author of DBuzilla, but nothing I didn't know already from his blog. Once the project objectives was in perspective, getting started was more motivating. Man and I realized working together on D-Bus wasn't working out too well, so we split the work where I would stick with D-Bus and he would work on Mozilla technologies and try to meet somewhere in the middle. We had more trouble getting Mozilla stuff to work. It needs a few long hours to get through the tutorials and get a running example, but we only had bits of time here and there so we got stuck there. Tom helped us figure a few things out, but it was pretty late in the project to capitalize. Either way it was a worth while struggle. We learned more than we developed. If we get marked on deliverables rather than what we learned then I am fearful. lol Maybe with the time off I can get back into it. I enjoyed this project probably more than most others, except for the feeling of failure and being overwhelmed all the time. What would I recommend to the next group of students interested in this project. Work in small steps. Don't think of how the framework should be designed and what the best ways in coding something until you are comfortable in both or all technologies. Just enough experience to develop and debug your code. Divide the work based on technologies. Even if you want to learn it all, if each of you can make something work with each technology only then can you work with each other and use each others experience to make something useful. You'll have to learn the other side anyways, its just easier to struggle in one technology rather than both. Split the pain, then share it.
== Suggestions & Ideas ==
We have some C code running using D-Bus. Working on the phase 1 classes.
 
Code is still very immature.
We need to get XPCOM tutorials running, and try exposing some basic classes and functions.
Code is still very immature. After we have a running dbus object(s) with XPCOM, try using DBuzilla.
Man and Mohamed are still interested in continuing over the break.

Navigation menu