• c++,  Code

    Strong Typing PODs

    Identifiying object by a numerical integer is an almost trivial task. In DISPLACE, a very complex simulator I am involved with, there are many of different categories of objects that model different categoris of agents in the simulator, like vessels, marine locations, ships, ports, and so on. Each object has an Id, and it was very natural, at the start of the project, to implement it using an int. Problems started when we decided, for optimization purpose, to shrink the memory footprint, to use smaller int instead. Indeed, there could be at most 65535 nodes, and at most 256 node types, and each was modeled with an int. The mess started when we…

  • c++,  Metaprogramming

    A compact CSV parser using C++ TMP

    How many times have you implemented a CSV parser to fill a list of stucts from a text file? Personally, it happens to me about every time I have new project. Though it is a simple task that requires no more than half an hour to build and debug, it is boring, error prone and repetitive. The algorithm is quite trivial, read each line, split it in a vector of string using some separator (about always a comma, hence the "Comma Separated" name), use something to convert each field in a PoD (int, double, whatever) and fill a struct.  Here's a general solution that makes use of Metaprogramming to implement a parser…

  • c++,  Code,  Linux,  Uncategorized

    The dbus-cpp Library, introduction

    While working on a bluetooth based embedded device, I needed to deal with the somehow infamous dbus. DBus and Bluez5 have a very steep learning curve, and if you are don't have access to either Qt framework or glib framework, you have indeed a problem. Glib are very complex C libraries that mimick some of the built-in feature of the C++ language, while on the other hand, Qt are very vast and sometime a big overkill. The stunning news is that it seems there aren't many options if you need a C++ only lightweight solution. It is not true, indeed. Somehow well hidden in the creases of the web, I…

  • Code,  Embedded

    Pairing Bluetooth with no pin on Intel Edison

    It may seems strange for an IoT enabled device, but there's no obvious way to pair an Intel Edison through Bluetooth without accessing the shell. I spent different hours to do something that with Bluez4 took at most 4 minutes, including the research on Google. Here's what I did. Edison provides Bluez5 that reworks most of the tools using DBUS, so to make two quite frequent actions, like pairing a device without providing user intervention on the device, and registering a new bluetooth RFCOMM service, you need to interface with it, that isn't so obvious from C or C++. The second action can be done if bluetoothd is started with…

  • Android,  Code

    TouchWiz and the onOffsetChanged missing call

    I am currently working on a Live Wallpaper project for a customer. Interestingly, I found that though my app works perfectly on different devices – I have a Nexus7, Nexus10, a Galaxy Tab p1010, different chinese allWinner devices, and a Note II phone – my wallpaper can’t scroll when the screen is swiped on some Samsung Device. Usually to detect the swiping on a Live Wallpaper, you use the WallpaperService.Engine.onOffsetChanged, i.e. overriding this method on your engine class. Unfortunately, the Samsung launcher app, TouchWiz, seems to have a bug, or maybe it’s an undocumented/not compliant feature: the onOffsetChanged method is never reached, because simply they don’t call it (or maybe…