Wednesday 24 February 2010

Detection of architecture violations in C/C++ applications

In a small project, I am experimenting with a cleaner and in this case layered architecture for certain parts of PoDoFo. I think it is a quite usual problem, to have an architecture and a grown application and you would like to check whether the sources adhere to the previously defined architecture. Therefore, it is important to have tools to check for architecture violations. These can be used to validate the architecture at certain points of time or even after each commit to the source repository on a continuous integration server.

I did not know any tool which can easily do this kind of validations for C/C++ source code, so I came up with a small bash script that does exactly this. The only configuration needed are some rules that define the architecture. Architecture is in this case a layered architecture where certain modules are only allowed to include certain other modules. See image 1 for a small UML diagram of the architecture.



These rules can be edited at the top of the script:

RULES="content->structure \
content->datatype \
content->io \
content->util \
structure->datatype \
structure->io \
structure->util \
datatype->io \
datatype->util \
io->util \
content->fontconfig \
content->Carbon \
util->\.\. \
src->.* \
.*->tr1 \
.*->sys"

As you can see, it is also possible to use regular expressions. Also, I had to add some rules for includes like fontconfig (external libraries) that are not available in the UML diagram above.

The script produces quite a lot of output, but grepping for "violation" shows only the important results:


If you are interested you can get the bash script from here: check_architecture.sh The script should be self-explaining and pretty easy to adapt to your needs.

Sunday 14 February 2010

Building KRename trunk from SVN

I just noticed that there is no up to date documentation on how to build KRename trunk from SVN on our website. Well, everyone who is interested in getting the latest version of KRename and does not want to wait for the next release - these are the steps to get KRename trunk from SVN and build it.


svn co https://krename.svn.sourceforge.net/svnroot/krename/trunk krename
cd krename
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR ../
make
sudo make install


This assumes that $KDEDIR is an environment variable pointing to your KDE installation. You can set $KDEDIR using the following bash command:

export KDEDIR=/usr


Most other KDE applications can be built the same way.

Saturday 6 February 2010

Generic web-service queries on your desktop using Plasma

Some days ago, I applied for a new passport. In Munich, where I currently live, you apply for the passport at the city hall and usually can pick the passport up there 3 weeks later. I was surprised to see that they have a new service: You get an ID number with which you can check the status of your passport via a web-service. So, if you check regularly, the web-service will tell you when your
passport is ready to pick it up.

What is the usual you do in cases like that? Of course, you write a Plasmoid that checks the web-service periodically and informs you when your passport is ready. This plasmoid - PersonalKwery - can be seen in screenshot 1.


Thinking further about this quick hack, I came to the conclusion that with only a little bit of work, I could create a generic plasmoid that can query webservices and display the result on your desktop. I managed to create a plasmoid that takes the following configuration:

  • Base URL of the web-service

  • Attributes to the URL (like the ID number of my passport, or arguments to a Google query)

  • An optional XSLT to transform the results

  • An interval, how often the query should be performed



With this little configuration you can easily query many web-services. Of course, most users won't be in the mood to create their own XSLT transformations! Therefore it is possible to store the configurations as XML and share them - for example over "get hot new stuff". In this case, users can
download predefined web-service queries and only have to enter a few necessary attribute values. The screenshot below shows the configuration dialog for a query:


Another small example is a simple query, that get's your current internet IP address.


Of course, the tool is not perfect yet and can be made more user friendly. If you are interested, you can get the tarball here: personalkwery-0.1.tar.gz.