Feed on Posts or Comments

Category ArchiveC



C & Hacking & Linux & ProFUSION Gustavo Sverzut Barbieri on 20 May 2008

One myth less

I do write C code on a daily basis since 2001 and I don’t know why I always believed that free(NULL) would crash, so I always used the painful construction:

        if (p)
                free(p);

Until yesterday! While talking to Lennart Poettering and we bet about that. Damn, I was so sure about it, but I’d really want to believe I was wrong, since I could avoid such stupid “if”. Well, after we got David Zeuthen’s phone we checked the free(3) man page and I was proved wrong!

Thanks Lennart, I owe you some bucks ;-)

C & Free Software & Hacking & Linux & ProFUSION & Python Gustavo Sverzut Barbieri on 13 May 2008

Evas, Smart Objects and Edje

I’m often introducing new developers to Evas, part of the Enlightenment Foundation Libraries (EFL), and one common problem is to understand how Evas, Smart Objects and Edje integrates. Yesterday, while teaching some guys here at ProFUSION I came to the following picture, that describes it well:

figure:evas, smart objects and edje

Evas exposes just a handful object types, like solid color rectangle, gradient rectangles, images, text, text block, polygon, line and smart object.

Smart Object is the only special type because it’s extensible and developers should implement its virtual methods to have it to behave like regular objects with calls like evas_object_color_set() or evas_object_resize(). Smart Objects do not have any visual representation, they can contain other objects that may have it, like images or rectangles, that’s why they’re represented like a box in the figure above. Their children are handled as if they were in a special layer: outside objects cannot interleave smart object children. It’s recommended as good practice to not expose children to outside, instead provide methods to manipulate these children.

A regular mistake is to forget that just creating objects from inside smart object methods don’t make them children! You must assign a parent to a child with evas_object_smart_member_add(child, parent). You can “unparent” them with evas_object_smart_member_del(child). As children can not have more than one parent, adding a new parent to the child will first remove its parent before adding the new one.

Edje is a smart object that loads a group of parts from a description file often called “EDJ” (or edje file). These files contains a collection of groups, each with a set of parts (evas objects), each part with various states. When a group is assigned to some Edje object with edje_object_file_set(object, file_name, group_name) the parts are created in order (first will go first, thus will stay at the bottom) using the "default" 0.0 state. If some part have relative positioning to the whole available space (Edje object geometry), when the edje object is changed, all the dependent parts are recalculated and have their geometry set. If some part is relative to other parts, then when one of these changes, the dependent part is recalculated and reset as well. One can manipulate edje by changing the state of the parts, this should be done by means of programs, which will act based on signals. Edje will dispatch some signals like "resize", "mouse,move" and "show", but users are encouraged to create their own application signals that can be emitted with edje_object_signal_emit(object, "signal", "source").

The most common mistake using Edje is to touch its children. Never, ever, change the object that you get with edje_object_part_object_get(). That call is for inspection purposes only. You’re just allowed to change Edje by emitting signals from your application, EDJ should have programs to catch that signal and trigger some state change on some parts. Let’s remember that it’s recommended to never changed smart object children, Edje is strict, making this a rule. What can you expect if you break this rule? Before, I said that Edje would recalculate dependent parts when the dependency changes, but I lied: for simplicity purposes, when something change, Edje recalculates the whole thing, and it does so using the state information from EDJ, not the current value of the object. If you change the color of some rectangle from white to black, recalculation will enforce the rectangle to be white. Same for images, if you set the image file to be something else, it will be restored to the image specified in the EDJ.

One variation of this mistake is dealing with SWALLOW parts. These parts enable user to add an external object to be managed by Edje with the edje_object_part_swallow(object, "part_name", external_object). As said, Edje will manage this external object: it will become the object’s parent, it will set clippers, colors, visibility and geometry. After that call, user don’t own the object anymore, he is only allowed to change other, non managed properties, ie: images can have their file set because SWALLOW parts don’t have any image property (unlike IMAGE parts!)

It’s very important to understand these concepts. Real applications are a mix of smart objects and edje, one inside the other, which might led to great confusion if management ownership is not clear.

In the figure above we can see the management ownership to avoid these problems. User manages both the smart object and the background. In order to change the edje he should call some API defined in the smart object. To change the “star” image, user should call smart object that would call edje.

 

You can also download the printable version of the figure.

C & Free Software & Hacking & Linux & Maemo & ProFUSION Gustavo Sverzut Barbieri on 02 Apr 2008

Enlightenment DR17 starting to release: EET

The Enlightenment Project DR17, the project known by non releasing any official packages, has now released their first library as “alpha”: EET.

README says:

Eet is a tiny library designed to write an arbitary set of chunks of
data to a file and optionally compress each chunk (very much like a
zip file) and allow fast random-access reading of the file later
on. It does not do zip as a zip itself has more complexity than is
needed, and it was much simpler to implement this once here.

It also can encode and decode data structures in memory, as well as
image data for saving to eet files or sending across the network to
other machines, or just writing to arbitary files on the system. All
data is encoded in a platform independant way and can be written and
read by any architecture.

This library is very stable already, with almost no change in the last years, the last addition was the “inlined strings” that are kept in their own read-only section, so you get them mmap()ed on load.

It’s the core of E17, being used to handle configuration data and Edje themes (includes images, scripts and regular data). What I find great about it is the easy- to use struct serializer/parser that you can use to save and load structured data, including lists and hash tables. And it is almost dependency-free, just: libc, libz, libm and libjpeg.

If you are a packager of some distro, or you know some, please package it. If you find out any problems, let them know, but it should be very straightforward, with Ebuild, RPM and DEB packages already available from some sites.

Funny fact: enlightenment is the project ID “2″ at sourceforge.net, the sourceforge.net project itself is the number “1″ :-)

C & Free Software & Hacking & Life & Linux & Maemo & Python Gustavo Sverzut Barbieri on 25 Mar 2008

GSoC: Enlightenment and BlueZ

So it’s that time of the year again, almost summer in North, winter here in South and Google helping free software projects with its Summer of Code. I’m glad some projects I’m involved were accepted, including: Enlightenment and BlueZ.

I’ll be a mentor for Enlightenment and we have great ideas, if you’re interested in them, mail me or go to #edevelop @ irc.freenode.net so we can discuss your ideas, experiences… It’s a great way to get involved in computer graphics and a platform that is growing everyday on mobile systems, with adopters like Canola2 and now OpenMoko!

As for BlueZ, I’m not mentoring, but some friends are, they also have great ideas, things that will benefit every GNU/Linux bluetooth user, from mobile to desktops to laptops, some are really interesting like better audio support. It’s a way to get into kernel and low-level user space world, and get paid for it ;-)

C & Free Software & Hacking & INdT & Life & Linux & Maemo & Python Gustavo Sverzut Barbieri on 21 Mar 2008

BossaConference ‘08: excellent!

So BossaConference ‘08 is over, what a great conference! Lots of great people, some are still around, doing some hacking with us at INdT office, it’s really great to have some time to discuss new ideas, drink some beers and play jokes ;-)

Let’s hope next year we can keep it to the level! Congrats to all the organization members.

C & Free Software & Hacking & INdT & Life & Linux & Maemo & Python Gustavo Sverzut Barbieri on 01 Mar 2008

Old website is now dead

My old website http://www.gustavobarbieri.com.br/ is now dead and points to this blog. It was ugly and hard to keep updated, using wordpress blog is much easier than hand editing HTML and provide lots of useful features, like rss feeds.

If you need some of the files hosted there, please use http://www.gustavobarbieri.com.br/old-website, although I did keep the links to most useful folders, like http://www.gustavobarbieri.com.br/eagle, http://www.gustavobarbieri.com.br/jogos and http://www.gustavobarbieri.com.br/python

C & Free Software & Hacking & INdT & Maemo & Python Gustavo Sverzut Barbieri on 23 Jan 2008

Ruby bindings and bugfixes for LightMediaScanner

Thanks to Levi Bard we now have ruby-lightmediascanner, with even API docs!

On the bug fixes front, after Canola2 was released and it was tested with multitude of media I could fix lots of bugs with parsers, mainly on jpeg and id3lib.

Last but not least, thanks to Renato Chencarek we now have ogg support, and I also added png and audio-dummy to register known media files we still have no specific parsers (real, wma, …)

It’s already stable, when I have time I’ll add a non-dual process version of process and check, so people with “correct” media files can use this and benefit from a much faster version (however this will rely on developers adding support to choose both implementations).

C & Free Software & Hacking & INdT & Life & Linux & Maemo & Python Gustavo Sverzut Barbieri on 21 Jan 2008

Bossa Conference 2008

And so the time has come, almost 1 year since the first Bossa Conference 2007. That was an amazing conference, with exuberant place near the beach, great speakers and lots of time to enjoy both. Since the scope is well defined: Linux and other Free Software in mobile devices, the speakers are really well selected, we could manage to have free time to talk to each other, without going from one side to another, running like crazy and if you have attended conferences before you know what I mean: these casual chats are the best way to know about new features and plans (maybe unofficial or secret ;-)), elaborate new ideas, etc.

That conference was so great that INdT is now promoting another, actually much improved:

Bossa Conference 2008

Come and enjoy a innovative conference on Open Source Software for Mobile Embedded Platforms. Located in Porto de Galinhas, one of the tropical paradises of Brazil, the Bossa Conference will happen during 16th to 19th of March at Summerville Beach Resort. The perfect combination of developers, pleasant environment and good ideas.

Let’s go! We’re waiting for you.

Information and registration: www.bossaconference.org.

C & Free Software & Hacking & INdT & Maemo & Python Gustavo Sverzut Barbieri on 13 Dec 2007

LightMediaScanner 0.1 released!

INdT released today under LGPL the public release of LightMediaScanner (LMS), a lightweight media scanner that will be used by Canola 2.0 and, we hope, many other multimedia software!

Lightweight media scanner meant to be used in not-so-powerful devices,
like embedded systems or old machines.

Provides an optimized way to recursively scan directories, handling
the parser in a child process, avoiding breaks of the main process
when parsers break (quite common with such bad libs and tags).

Parsers are plugins in the form of shared objects, so it’s easy to add
new without having to recompiling the scanner.

The scanner will use SQLite3 to store file-mtime association, avoiding
parsing files that are already up-to-date. This SQLite connection and
the file id within the master table ‘files’ are handled to plugins for
relationship with other tables.

Check out the code, it’s really simple to use and write new parser plugins:

C & Free Software & Hacking & INdT & Maemo & Python Gustavo Sverzut Barbieri on 23 Jun 2007

Edje demo on N800: application launcher mockup

This is a demo I wrote today to demonstrate Edje running via a 60 line python script. The edje file itself is about 190 lines and kind of simple, yet complete in features.

Code can be found at http://www.enlightenment.org/viewvc/e17/proto/python-efl/python-edje/examples/evas-demo/

Next Page »