• Uncategorized

    A C++ Smart Pointer wrapper for use with JNI

    Introduction In this article, I'll propose a solution for managing native C++ resources from JNI using smart pointers. While Smart Pointers can't be useful from Java, because of the limits of the Java memory management, it may be required by the native library to maintain allocated resources through shared_ptr or unique_ptr, for example because classes derive from std::enable_from_this. Since there is a fixed pattern to maintain native objects in Java classes, a utility C++ class is proposed. The problem of memory management when integrating Java and C++ code Recently, I had to port a library I wrote for Linux to Android. For instance, the library is aimed at implementing an…

  • Linux,  vmware,  Windows

    Vmware Player is slow under Ubuntu 16 host, Part 2.

    So it seems the issue I talked about some week ago, wasn't fixed. Windows is still slow, the hard disk always working at 100% load. Not so slow, because the fix explained in my previous post seems to mitigate the problem, but still slow. Since I was using many Virtual Machines on that box without any problem since longtime, well before my upgrade to Ubuntu 16.04, I guessed the problem was the kernel. So I rolled back to 3.16. And… tada! now the machine works flawlessly. Seems incredible, because I looked around to see if anyone had similar issues, without any luck. So, if you're running kernel 4.4 and VmWare…

  • Linux,  vmware,  Windows

    Vmware Player is slow under Ubuntu 16 host

    So you just upgraded your Ubuntu box and found that all your VmWare Windows Boxes are extremely slow? The symptom is your Windows task manager showning 100% usage of your disk, and the WIndows Instrumentation showing very long lags, says, up to 2.5seconds (yes, seconds) to respond to a disk request. This makes the box practically unusable. Perhaps your vmware logs are shoing a lot of lines like scsi0:0: Command READ(10) took 2.748 seconds (ok) scsi0:0: Command WRITE(10) took 3.224 seconds (ok) and so on… Well, this is a well known issue. A quick search with google will point you to the vblank_mode=0 fix.  Indeed I already fixed that on my…

  • 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…

  • Linux,  vmware

    Fixing problems with Ubuntu 13.04 and VmWare Tools

    Installing Ubuntu on my VmWare fusion box has never been so difficult as it was last weeks, when I needed to have it ready as soon as possible. Though 12.04 LTS has been proved to be a great choice when you need a solid rock linux box, latest Ubuntu boxes are preferable, on my opinion, for development purpose. This way, switching to the latest, bleeding edge kernel hasn’t gone well for the people at VmWare. There are two very big problems with the default installation. I usually choose the default installation because you only need the ubuntu ISO image and few minutes, and a new, shining linux box is ready…

  • 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…

  • AllWinner,  Windows

    Flashing an AllWinner device via LiveSuit from Windows 8

    Flashing an AllWinner device using the LiveSuit tool from Windows 8 isn’t as obvious as it seems. First, as usual with a new operating system, not all drivers works and you must find the “right” version. Second, as the previous issue wasn’t enough, with Windows 8 isn’t possible without some trick to install an “unsigned” driver. “unsigned” driver means a device driver that isn’t approved by Microsoft; on previous Windows versions, when installing an unsigned driver Windows asked for approval to the user. Today, Windows 8 doesn’t ask for approval and sometime refuses the installation without telling anything, it silently exits the driver installation window. So, first you need to…

  • Windows

    Annoying crapware on Java Updates (a.k.a. Ask.com toolbar)

    Tired of this annoying ask.com toolbar being installed every time Java gets updated? Here’s the solution: Open a notepad, copy-and-paste this code and save it on a file called “disable_java_sponsors.reg”.   Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft] "SPONSORS"="DISABLE" [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft] "SPONSORS"="DISABLE"   Then double-click on the new file, answer “yes” to the question about merging the registry and say bye to these annoying crapware. Next time you update Java, the ask.com bar (and eventually all other sponsored tools) should be disabled and not installed. Click here to download disable_java_sponsors.reg. Thanks to Danilko Roascio for his solution on superuser.com.