Category Archives: programming

Getting started with Objective-C?

If you want to get started with Objective-C, and you have some background in C/C++, read this neat post I randomly stumbled upon: “Why Objective-C is cool“. It’s a pretty nice description and hopefully removes a lot of WTFs from a newbie.

Then, read CocoaLab‘s free e-book “Become an Xcoder“.

Finally, this is the longest route, but the one I went with: watch all 18 hours + extras of CS193P iPhone Application Development 2009 (and then go watch some of the 2010 lessons, too). It takes a long time to watch, but it’s worth it.

Google's built-in page previews — reason for releasing Chrome?

After all the years we’ve had Firefox plugins to insert page previews into search results, Google finally added their own. They dubbed it “Instant previews”. These previews are vertically larger than what any of the plugins did before, they include enlarged select portions of text relevant to your query, and they appear only when you click on a search result text (not on the link). After that, you can just hover the mouse above search results.

So what I wonder is: could it be that Google embarked on a journey to build a hyperfast browsing experience in order to provide a better search experience? Or was Chrome really just a part of a larger scheme to collect customer data and statistically analyze it, as was thought previously? I’m not sure; probably it was “let’s build a browser first” and then “what can we use the browser for?” — but the idea that Chrome might be the developed in order to alleviate performance issues that using some other browsers might create running on Google’s servers does not strike me as impossible. This way, they can generate previews without creating a horrible, horrible impact that using some other browser might create.

I just wonder when we’ll be able to see the codebase they use for creating the previews, and will they even release it, considering that WebKit’s LGPL (derived from KHTML’s LGPL) does not require source code release unless the binaries are released; even then, if libs are dynamically linked, source code release is required only for modified library binaries. Still, having a free, usable off-screen rendered WebKit would be very useful. But oh — there is already such a thing, for example Origyn Web Browser (site seems down, here’s a wikipedia link)

Is there a growing interest in GLDM?

Google Analytics says I’ve recently been getting some hits from Google with keywords “gldm login”. GLDM is my login manager which I left in a half-finished state last year; it’s free/libre/opensource software and can be picked up at http://sf.net/projects/gldm/. If you’d like to help, talk to me at gldm+blogpost@vucica.net.

What is GLDM?

Idea behind GLDM was to provide a solid backend for authentication with a well-designed API for dropping in custom-developed graphical themes. That is, the idea was that GLDM would be the backend (with some nice themes/theming engines coming with it), but that people would easily be able to develop their own theming engines. It’s supposed to be an alternative to XDM, GDM and KDM — that is, it’s a login screen for Linux.

Its target is a home user; thus, GLDM does not care for and does not suppot stuff like XDMCP. It’s also probably a little bit less secure, until someone security-conscious comes around and fixes that.

Acronym stands for Graphical Liberty Display Manager, to say that one is able to create the GUI with whatever technique that person wants, as long as it’s somewhat pluggable into the C++ code. It’s also a play on OpenGL Display Manager, but since I didn’t code a single theme that uses OpenGL, it would be a bit of a misnomer, especially since it was intended that you really don’t need to have anything to do with OpenGL.

At the same time, you could; one might design a beautiful 3D island, with ocean having reflection, refraction and other cool shader-based effects. Then, on top of that, adding flying letters or user icons during login, which are reflected in the water below.

In essence, GLDM should be a “Compiz for the login screen”!

Almost all “common home users” would love that; it might help convert people to GNU/Linux, or other UNIX based systems. Who knows — perhaps even Canonical would take GLDM as the default login manager. (Oh, human dream…)

So what if you are getting hits? What do we care?

It surprises me that this unfinished piece of software is getting my poor little blog some hits. It surprises me that it’s getting hits straight from Google. It surprises me that this is happening despite absolutely no chatter on the interwebs about this software. It surprises me that I’ve received no inquiries about it.

It confuses me about what I should do next: should I go back to developing GLDM a little bit (a bit troublesome since I’m a Mac user now)? Will interest go up? Is this perhaps just a Google having a glitch, a cough, giving me hope where there is none?

I’m really not sure. Well, I think it GLDM might still be resumed; there still isn’t a “Compiz for the login screen”, and the barrier to entry for potential theme developers might still be significant. GLDM could be the solution by offering simple, simple API for authentication, while allowing the developer to just plug in their existing code into GLDM to get authentication services.

Adventures in driverland, pt. 1

I’m trying to figure out how to write a virtual HID (human interface device) driver for Windows. By virtual, I mean a device that I’ll be able to control from userspace; for example, by feeding it packets received from network. Since I’m rather slowish in this endeavor, and there’s very little sensible documentation on the internet on how to do this, I’ll document my exploration of the WDK (Windows Driver Kit).  This will hopefully help me understand things better.

Don’t use this as a documentation, and perhaps not even as an explanation of WDK; I’m just typing down what I currently believe about the subject.

So first of all, there are many suggestions to take a look at the sample “hidusbfx2”. This is located in /src/hid/hidusbfx2. This is a driver for a generic USB-teaching device. This device does not present itself as a HID-class USB device, or else Windows’ built in drivers would take place.

HID-class devices are mouses, keyboards, et cetera. I believe that when docs speak of “HID-class Device Driver” , they mean a generic driver for handling any sort of mouse, keyboard, et cetera. These drivers, I believe, don’t actually know how to speak with the hardware. In case of USB-based HID-class devices, the most common kind, Windows do that automatically. They use their own “HID minidriver”.

So what we need to do is implement a HID minidriver. HIDUSBFX2 is, I’m sure, a pretty good example in case you want to write a driver for something that actually connects to a USB port. I don’t have the cash to afford the board used, and I don’t want to develop a driver for an actual device, anyway. As a beginner, I don’t really know how to separate the hardware layer from the software layer. Hence, this is not such a good example for my purposes.

Luckily, one of the rarest gems I ever dug out from the Internet is vmulti by Daniel Newton. This is a virtual HID driver just like one I’m trying to write, but this one is specialized for  implementing multitouch on Windows 7. By its folder structure, it is so obviously derived from HIDUSBFX2 that comparing these two might even yield some results. I didn’t yet do this, however.

I have immediately attempted to build and install vmulti. Unfortunately, its documentation is quite scarce, and there isn’t an explanation on how to build it and install it, and not even a documentation on how to use it. There is a test program however; that’s something I’ll have to take a look later on.

vmulti is a KMDF driver (a kernel-mode driver, but higher-level compared to the old WDM model). Windows, due to architecture of  WDF (Windows Driver Foundation) do not support HID class drivers on KMDF level. That’s why Microsoft wrote a “HID mapper”; a thin layer written in WDM to allow KMDF HID-class minidrivers. This is called “hidkmdf”; for Windows 7, you don’t even need to compile it and ship it with your driver since it comes under name “mshidkmdf”. This is what WDM actually thinks the driver is; but, in reality, it’s just a stub, and we write our “filter driver” (HID minidriver) which contains the actual driver code.

So I went and tried to build vmulti, all of its components: Microsoft-provided hidmapper/ folder (containing hidkmdf), vmulti’s sys/ (containing vmulti) and vmulti’s test/ (containing a test tool). I cd’ed into its folder, and I ran command “BLD”, as recommended by Microsoft.

This is where I’m stuck: Windows XP’s Add New Hardware claims there is no information about my hardware when I go to the folder where I put vmulti.inf, and both vmulti.sys and hidkmdf.sys. The alternative I dug out is called “devcon”; it ships with WDK in /tools/devcon/devcon.exe.

Last I’ve tried is a modification of Microsoft’s example how to use devcon/ that came with “echo” example:devcon install vmulti.inf "root\vmulti"

This is where I’m stuck:

Device node created. Install is complete when drivers are installed...
Updating drivers for root\vmulti from C:\projects\vmulti\sys\objfre_wxp_x86\i386
\vmulti.inf.
devcon failed.

Tomorrow is another day! I want to figure this out, and Microsoft did not make it easy, that’s for sure. I’m in a documentation hell; they wrote so much of it, but so little of it is useful.

What sort of software do I need libre/open-source?

After thinking a bit about what I need open-source, and what I’m capable of implementing but too time constrained, here’s a short list. If I had enough cash and if I didn’t have to study, I’d go now and work on some of these.

Open source Steam

And I don’t mean just a game browser and installer. I mean the full deal: friends, shop CMS, patching, DRM, DLC, ingame overlay. Friends could work with XMPP, and when I think about it, so could everything else. How about login with OpenID, Facebook Connect, XMPP?

Better, modular X11 login manager

I want a login manager where I can easily write a GUI in OpenGL or whatever I want, and just plug it in with the backend code that’ll handle the login itself.

I started writing that, but then I got a Mac.

In-game XMPP overlay

I’m sort of obsessed with in-game overlays, right? But that’s what I want to have: a way to talk to my google-talking buddies from in-game. Steam’s in-game browser is NOT a solution. I’ve tried looking around for something like this; I found some open source code for in-game overlays (Mumble VOIP has one), but nothing simple enough for me to fork and add XMPP code and a simple GUI (perhaps using my GLICT or my company’s AprilUI) to be able to have a proper in-game IM experience.

Well commented and structured code

This is not something I can fix even with a lot of time. I try to structure my code well, but that’s about it.

I’ve been through too much OSS code lately that wasn’t commented well. In fact, I know of one instance where I was studying implementation of in-game overlays, and the already-confusing code didn’t have a single useful comment in it. I’ll do an evil namedrop and mention this was, again, Mumble. I want to make it clear: it’s an excellent project, with lots and lots of cool ideas, well implemented tricks such as positioning audio according to the position in the game the speaker and listener are playing, et cetera. But, simply put, when I looked at the code they had in SVN, I found something I couldn’t put my head around.

Functions and classes were oddly named, not to mention files. Platform-specific code was all mixed up and was not separated; while there were attempts to be modular, separation of platform-specific stuff (and when it’s about in-game overlays, you know it’s VERY platform-specific) was done very clumsily. I couldn’t find where the code initializes system-wide monitoring for the launch of a game, and where the overlay is initialized. I gave up.

But this is what defeats the purpose of open source. Why bother releasing it as FLOSS if people can’t learn anything from it? I wrote a lot of code over the years, but if it isn’t instructional or useful, why would I release it as FLOSS? One goal may be to get it into Debian which has a social contract to ship only free software, but if that’s the entire point, then say so.

Don’t insert assembler blobs without commenting them (oh yes, that too).

What about you?

What do YOU want from open-source community that you can’t find? Or, can you imagine a financing model for developing the above? Tell me your thoughts!

Testing for presence of Apple platform in C/C++/ObjC code

Are we running on an Apple platform?
#ifdef __APPLE__
#endif
Prerequisite for other tests
#ifdef __APPLE__
// let Apple define 
// various TARGET_OS_ 
// constants
#include  
#else
// not on Apple platform
TARGET_OS_MAC 0
TARGET_OS_IPHONE 0
#endif
Are we running on Mac OS X?
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
….
#endif
Are we running on an iOS device?
#if TARGET_OS_IPHONE
….
#endif
// updated on Oct13 2010, previous method was flawed. sorry everyone!