Changes

Jump to: navigation, search

D-Bus and other Linux desktop integration improvements

15,600 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.
***'''NSPR'''
***'''Glib'''
**'''Proxy ''' classes**'''Mozilla ''' process***'''Client ''' (handles requests from internal sources, other XPCOM modules)***'''Server ''' (handles requests from external sources)***'''Monitor ''' (listens to system and applications events to kill internal dependencies, ex. an XPCOM module waiting for a response from an external source which was just killed, dbus sent us a signal telling us this source went offline)***'''Dispatcher ''' (notifies the system and applications Mozilla events, ex. Firefox closing)*'''Phase 3''' - Advanced Features**'''Introspect'''**'''Complete D-Bus spec''' - there are some features in the D-Bus spec for future development, such as D-Bus via Sockets The project design is not fixed and it is very open to suggestions.
===Considerations===
D-Bus has recently frozen the API for version 1.0.
It is unclear if the DBuzilla project has had any updates with this new version or if of the design will be affected.
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 encounter is in a few of them. ==Important Links======Mailing Lists====*[http://lists.freedesktop.org/archives/dbus/2006-November/006387.html Our Post to Freedesktop Dbus mailing list - Need some help and direction]*[http://lists.freedesktop.org/archives/dbus/2006-November/006388.html Havoc Response - Direction we should go]*[http://lists.freedesktop.org/archives/dbus/2006-November/006389.html Gary Response - Problems we will encounter]*[http://lists.freedesktop.org/archives/dbus/2006-November/006394.html Havoc's Response to Gary]*[http://lists.freedesktop.org/archives/dbus/2006-November/006404.html Discussion Continues]*[http://lists.freedesktop.org/archives/dbus/2006-November/006420.html Discussion Continues]*[http://lists.freedesktop.org/archives/dbus/2006-November/006396.html Discussion Continues]
===Important Links=Articles====
*http://www.linuxjournal.com/article/7744.
*[http://enwww.wikipediaredhat.orgcom/wikimagazine/003jan05/features/dbus/ Get on D-BUS] ====Tutorials & Specification====
*http://www.freedesktop.org/wiki/Software/dbus
*http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
*http://en.wikipedia.org/wiki/D-BUS
*[http://www.matthew.ath.cx/misc/dbus Using the D-Bus C API]
*[http://www.redhat.com/magazine/003jan05/features/dbus/ Get on D-BUS]
*[http://www-128.ibm.com/developerworks/linux/library/l-dbus.html Connect desktop apps using D-BUS]
 
====DBuzilla====
*[http://code.google.com/soc/mofo/appinfo.html?csaid=13DDE9DE6AF50C64 DBuzilla - Google summer of code]
*[http://zenit.senecac.on.ca/wiki/index.php/Dbuzilla_report DBuzilla Report]
 
====Patches====
*[https://bugzilla.mozilla.org/show_bug.cgi?id=312793 Support DBUS and listen to NetworkManager events]
 
====Mozilla====
*[http://books.mozdev.org/html/mozilla-chp-8.html Creating Applications with Mozilla]
*[http://www.mozilla.org/projects/xpcom/book/cxc/ Creating XPCOM Components]
*IBM developerWorks - XPCOM Overview [http://www-128.ibm.com/developerworks/webservices/library/co-xpcom.html part 1] [http://www-128.ibm.com/developerworks/webservices/library/co-xpcom2.html part 2] [http://www-128.ibm.com/developerworks/webservices/library/co-xpcom3.html part 3] [http://www-128.ibm.com/developerworks/webservices/library/co-xpcom4/index.html part 4] [http://www-128.ibm.com/developerworks/webservices/library/co-xpcom5.html part 5]
*[http://www.mozilla.org/scriptable/xpidl/idl-authors-guide/index.html IDL Author's Guide]
*[http://developer.mozilla.org/en/docs/XPIDL:xpidl XPIDL]
 
====Linux Desktop====
*[http://developer.gnome.org/ Gnome Developers]
*[http://en.wikipedia.org/wiki/DCOP KDE DCOP]
*[http://books.mozdev.org/html/mozilla-chp-8.html Creating Applications with Mozilla]
== Project Leader(s) ==
[[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 Details == 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. 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:==== * C++ Compiler* egcs* gcc* GNU make* GTK/GLib* Perl 5* tar ====Create the Component====1. Download the Gecko SDK.* You can find it at ftp://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.13* You can choose a different Mozilla release if you like.* Extract the SDK to a local directory. 2. Create a GUID for the main interface.* You can use the uuidgen utility to generate the unique 128 bit number. Or* 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* Use the following template add methods and attributes to the interface.* Fill in the GUID you have generated.  #include “nsISupports.idl” [scriptable, uuid(YOUR_INTERFACE_GUID)] interface IMyComponent:nsISuports { int MyMethod(in int a, in int b); };4. Generate the interface header and typelib files out of the interface definition file.* Use the xpidl utility that comes with Gecko SDK.* Substitute the “_DIR_” in the following commands with the full path to the xpcom/idl directory found under the Gecko SDK main directory.* xpidl -m hearer -I_DIR_ IMyComponent.idl will created the IMyComponent.h hearder file.* 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”.* Start by inserting double includsion protection code (#ifndef _My_COMPONENT_H_ ….).* Add #include “IMyComponent.h” to include the interface definition.* Create a GUID for the component.* 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_CLASSNAME “A Simple XPCOM Sample” #define MY_COMPONENT_CID _YOU_COMPONENT_GUID_ * Copy the header template from IMyComponent.h (starting with /*Header file */) into the MyComponent.h file.* Replace all the instances of _MYCLASS_ with the name of the component. 7. Create the component implementation file “MyComponent.cpp”.* Add #include “MyComponent.h” to include the component definitions.* Copy the implementation template from IMyComponent.h (starting with /*Implementation file */) into the MyComponent.cpp file.* Replace all the instances of _MYCLASS_ with the name of the component.* Add method implementation code. 8. Create the module definitions file “MyComponentModule.cpp” * Add #include “nsIGenericFactory.h” to include Mozilla GenericFactory definitions.* Add #include “MyComponent.h” to include the component definitions.* Add NS_GENERIC_FACTORY_CONSTRUCTIOR(MyComponent) to define the constructor for the component.* Add static nsModuleComponentInfo components[] = { { MY_COMPONENT_CLASSNAME, MY_COMPONENT_CID, MY_COMPONENT_CONTRACTID, MyComponentConstructor, } };  to define the class name, contract ID and GUID of the component. * Add NS_IMPL_NSGETMODULE(“MyComponentsMoudle”, components) to export the above information to Mozilla. 9. Create a custom makefiles. ====Building the Component==== 1. Build the component. * Navigate to the src directory.* Issues the make command. MyComponent.so file is created. 2. Register the new component with Mozilla. *Copy MyComponent.so and IMyComponent.xpt file to the Mozilla components directory.* This directory is typically located at ~/firefox/components (or ~/mozilla/components).* Run the regxpcom -x COMPONENTS_DIR command supplied with the Gecko SDK to register the new component where COMPONENT_DIR is the component directory.* 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.* The profile directory is typically located at:~/mozilla/firefox/default.???? 3. Test the new component. === DBUS Tutorial and info === I'll walk through a simple example of sending a signal to give you an example of what its like. It would be good if you know how to connect to databases. The concepts are similar, but rather than connecting to a database you connect to a bus. First, you either need to use an IDE like Anjuta or learn how Make and its syntax. Make sure you linux distro has Dbus installed.  Quick and dirty way of checking is typing dbus-viewer in teh command line or locate dbus. =P You will need to include the libdbus libraries in your project or make files. They are not in the default path. The first header files you will need:  #include <stdio.h> #include "glib.h" #ifndef DBUS_API_SUBJECT_TO_CHANGE #define DBUS_API_SUBJECT_TO_CHANGE #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. In C, you the function return is the state usually 0 for null then you check the error object for the message.  int main() { DBusConnection *conn; DBusError error; dbus_error_init(&error); Use the dbus native functions to connect to the System bus. You can also connect to teh session bus which is usually meant for application to application communication. System is meant for events, but you can use either one. There is also a starter bus, but not meant to be used by us.  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error); if(conn == NULL) { fprintf(stderr, "Failed to open connection to bus: %s\n",error.message); dbus_error_free(&error); exit(1); } else printf("Connected to System Bus\n"); If you succeed at that point, you will have to create you signal. This involves creating a DBusMessage (represents the signal) and DBusMessageIter (which used to store arguments). You need a unique number to associate replies with requests. Will be used to manage communication later. Signal value is a string.  dbus_uint32_t serial = 0; DBusMessage* msg; 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); }
* Shaver passed 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 this link with more patterns) very well. == Experiences == === Mohamed Attar === The first problem I had was trying to understand where D-Bus is suppose to [http://tracfit into Mozilla.csquad 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/wiki/AboutDBuzilla#CurrentStatus community. I got some information from the author of DBuzilla], which 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 good designed and what the best ways in coding something until you are comfortable in both or all technologies. Just enough experience to investigatedevelop 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 ==
 
* Shaver passed along this link to [http://trac.csquad.org/wiki/AboutDBuzilla#CurrentStatus DBuzilla], which would be good to investigate.
== Project News ==
===Status===
<u>As of December 15th:</u>
 
Our project objectives and vision is defined.
 
We got responses from the community about problems we will run into, and got some status news from the author of DBuzilla.
 
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.
 
After we have a running dbus object(s) with XPCOM, try using DBuzilla.
 
Man and Mohamed are still interested in continuing over the break.
 
===News Posts===
 
<u>December 15th, 2006</u>
 
Sorry we haven't updated for a while.
 
Tom, Man, and I (Mohamed) had a discussion trying to understand how to use Mozilla technologies with D-Bus. Tom has helped us find some important information.
 
We're just updating the wiki now and documenting our work for a lower entry barrier for other students.
 
<u>November 28th, 2006</u>
 
I found an email from the author of DBuzilla in my spam folder. Basically telling us he hasn't work on it for a few months due to some personal issues, but he is planning to maintain it again.
<u>November 13, 2006</u>
<u>November 9th, 2006</u>
Presented project to class.[http://zenit.senecac.on.ca/wiki/index.php/DBus_status_reprt DBus Status Report]
<u>November 7th, 2006</u>
Today [[User:mckwan|Man Choi Kwan]] and [[User:mattar1|Mohamed Attar]] joined this project. We're just getting introduced to this topic and will be doing some research over the weekend.
<u>==To Do:</u>==*Code some XPCOM tutorial (not successful yet)*Code some base classes of Phase 1 (work in progress)*Get help with XPCOM (started, work in progress)*Code some examples of D-Bus (done)*Contact other communities that might help us the project idea, goal to contact Freedesktop (done)*Ensure all group members have a machine they can run linux on with X11.(done)*Research on D-Bus. Get some code and research to share with the group.(done, work in progress)*Find some Mozilla/Linux Gurus to bother. =P(not successful)

Navigation menu