I gave a presentation at work about Boost.Asio, and it came out reasonably well, so I figured I would post the slides here. Its a brief introduction to Asio and what one might use it for. Also has some basic concepts and patterns one might use while programming with Asio. Aimed for a technical audience, but nothing too detailed though.
Archive for 2009
Boost.Asio Tech Talk Slides
Tuesday, November 24th, 2009Free disk/sector editor from Microsoft
Sunday, October 11th, 2009This is just a random note that I’ve actually known for quite awhile, but I figured I would post it online somewhere where others could find it. Apparently Microsoft made a disk editor thing called ‘Disk Probe’, which came in the NT Resource Kit. I had found it available to download standalone a really long time ago, but it doesn’t appear to be available anymore. However, you can find it in the Windows XP Service Pack 2 Support Tools available from Microsoft’s download website.
Its a bit weird (at least, the NT version was), but its pretty useful if you ever find yourself playing with raw disks and you need to access them from inside windows in a pinch.
Ubuntu Karmic: definitely a good upgrade
Tuesday, October 6th, 2009Ubuntu just released the Beta for Karmic a few days ago, so I figured that I would give it a whirl on my desktop now that I’ve switched to using Linux on my desktop fulltime. So far, I’m very happy about this upgrade, hopefully they don’t screw it up before release. :p
My first impression so far as been that its a vast improvement — and I’ve got rather old hardware, so I think thats a really positive thing. Maybe its just firefox, but it seems like to me that everything works a lot better and is more responsive. The file browser in GNOME too — it used to lag quite a bit while browsing through my drive — now it seems to work exactly as I might expect. I know they’ve been touting a really quick boot time, and it feels a little bit faster, but I’m not quite sure about that. I haven’t bothered timing it or anything though.
There were two annoying things about the upgrade. First, X didn’t work at first and just kept blinking in a loop — but that was totally my fault, since I’m using the latest NVidia drivers, and forgot to reinstall before I rebooted. However, a quick boot into a command prompt and reinstalling the drivers got it all working again. The second thing that is a bit weird is they must have changed the font or the way its anti-aliased now, since everything looks a bit more.. blurry. Or something, I can’t quite put my finger on it. I’m starting to get used to it, but its too bad the fonts aren’t a bit crisper.
FWIW: Keep in mind that I’m using rather old hardware on my desktop, but XP always worked well on it! I’m using an Athlon 3000+ with a triple-monitor setup on two NVidia 6600 cards (one PCI, one AGP). 2GB RAM, and some various SATA and IDE disks.
XSMELL: C++ XML creation library
Wednesday, September 30th, 2009I’m taking a workshop at work taught by David Abrahams, and he briefly mentioned this thing called XSMELL, which apparently allows you to write XML-like things in pure C++ code. From the README:
Congratulations! You have in your hands the MOST BRILLIANTEST C++ XML CREATION LIBRARY EVER CREATED. ... And you no longer have to worry about generating malformed XML! After spending hours fighting obscure C++ compiler errors, you’ll be 100% certain that your XML is correct.
Definitely amusing. 🙂
Middle button in X
Thursday, August 20th, 2009I’ve always been a fan of PuTTY, the Windows terminal emulator. Its extremely simple to use and is one of the main reasons I like using windows to maintain linux systems. One of the biggest things I like about PuTTY is that it allows you to copy on highlight, and paste into the window by right clicking. It saves so much time and is really easy to use.
So when I moved my desktop to Ubuntu this summer and got rid of XP, this has really been one thing that I really miss. However, I just found a blog post that explains copy/paste in X, and that a similar system actually exists system-wide, except it uses the ‘middle’ mouse button instead.
Seriously, this is an awesome feature that I did not know about, and definitely am going to take advantage of. Now I just need to remap one of the extra buttons on my mouse to be the middle one so its more convenient to use…
WebDMA demo video
Saturday, April 25th, 2009If you read my previous post, I was talking about this new open source library I’ve created that allows you to embed a web server in your C++ application so that you could modify variables inside of it. I had created it for our FIRST Robotics team so that we could use it to tune things on our robot (and its been extremely useful for that) and use it for simple data acquisition. Of course, driving a robot is nothing more than changing variables… so I thought it would be a neat demo to set it up so that it could be driven by the web interface. 🙂
Here’s a video of our robot being controlled via the WebDMA interface:
And theres a (non-working) HTML version of the interface (though, its no longer the exact one that is on the robot, but its close) at http://www.virtualroadside.com/botface/index.html
Changing variables using a web interface and embedded HTTP server
Tuesday, April 21st, 2009When walking around during the Boston Regional, I had been talking to some people about code, and they mentioned that LabView was great because they could tune their PID controllers on the fly while the robot was operating. So I thought to myself, “why can’t I do this with C++?”. And… so I did. WebDMA was created to allow our FIRST Robotics team to tune our robot in an easy to use and intuitive way via any modern web browser.
Using C++ operator overloading, WebDMA provides proxy objects that your application can use as normal variables which can be manipulated or displayed by your application via a configurable jQuery/javascript powered Web 2.0 interface hosted by an lightweight embedded web server.
Despite that WebDMA was specifically created for use in FIRST Robotics on the NI-cRio/vxWorks platform, it uses the Boost ASIO portable networking library and Boost Thread portable threads library and is usable on any platform supported by these Boost libraries (tested on Boost 1.38, requires a patch for vxWorks).
A non-functional (but very shiny) demo of the interface is available at http://www.virtualroadside.com/botface/index.html
Visit the Google Code project site for WebDMA
Update: Go here for a video: http://www.virtualroadside.com/blog/index.php/2009/04/25/webdma-demo-video/
Boost Asio and Boost Thread patches for vxWorks
Saturday, April 18th, 2009The FIRST Robotics Competition is using the National Instruments cRio platform for the robot controller this year, and the operating system on it is vxWorks 6.3. After we participated in the competition, I had gotten a great idea involving putting a webserver on the robot so that it would be easier to tune various parameters on the robot (which I will be releasing soon).
I decided to use Boost::Asio for the networking layer since I had been meaning to write something using it for awhile anyways, and since its portable I could do the initial development on my home computer and then easily (at least, ideally) transfer it to another platform. I also decided to use Boost::Thread for the same reason. If you haven’t used Boost before, I highly recommend it — it has a lot of well-written and useful C++ header-only libraries.
Unfortunately, vxWorks is a bit different than ‘standard’ POSIX/*nix systems, so there are a number of patches one needs to make to Boost 1.38.0 in order to compile. I’ve submitted the patches to boost, so hopefully by the time 1.39.0 rolls around you won’t need this. 🙂
You can download the full patchset needed from my FRC resources page. Download it.
I’ve also posted bugs on the Boost Trac site: #2917, #2953, #2955, #2956, #2957, #2958, and #2959
Screw cygwin, I’m using GNUWin32
Wednesday, April 15th, 2009For years I’ve hated cygwin (not for any particular reason, I just don’t like it) and have generally avoided using it because of that — but I’ve finally found a good alternative if you want useful *nix tools on Windows. Its called GNUWin32 and its a bunch of GNU utilities that have been ported to windows, and they’re quite lightweight also.
Its pretty sweet, I’ve actually had grep installed on my computer for quite awhile now, and just recently started installing more of these packages as my needs have evolved. I’d highly recommend it. The key thing to do is to add the bin directory to your path, so that way its accessible from cmd by default without having to screw around with typing out the full path name or anything.
Another solution to the Singleton pattern in C++
Tuesday, March 24th, 2009So, while working on the Kwarqs robotics code, I found a useful solution to implementing the singleton pattern in c++ that I believe avoids the static initialization fiasco (with a small restriction) *and* doesn’t leak memory.
What I’ve created is a template class that takes a pointer to a pointer at construction, and deletes the pointer as it is getting destructed. While you cannot guarantee when the class is created due to static initialization issues, from what I can see the C++ standard does guarantee that all intrinsics are initialized before other items are constructed. By using a pointer to a pointer, we can guarantee that the location of the object will be the same (and thus destruction will happen correctly), and provided we initialize the static variable to NULL we can also guarantee that initialization will happen correctly.
Warning: A key assumption made by this class is that the static object is only accessed during the normal scope of the program — ie, the object that this class contains a pointer to a pointer to should not be accessed by anything that could be called after main() is complete. For some code bases, this can be very tricky to enforce.
Usage of the class is quite trivial:
SomeType * SomeType::m_instance = NULL; StaticDeletersomeTypeDeleter(&m_instance); // example singleton initialization SomeType * SomeType::GetInstance() { if (SomeType::m_instance == NULL) SomeType::m_instance = new SomeType(); return SomeType::m_instance; }
And the implementation of the static deleter is also quite trivial (but I’ve provided a downloadable version as well), check it out:
// (C) 2009 Dustin Spicuzza, released under modified BSD license templateclass StaticDeleter { public: StaticDeleter(TypeToDelete ** ptr2ptr) : m_ptr2ptr(ptr2ptr) {} ~StaticDeleter() { if (*m_ptr2ptr) delete *m_ptr2ptr; } private: TypeToDelete ** m_ptr2ptr; };