Syndicate content

Type-safe publish/subscribe in C++ (part 1)

In the next few posts, I'll be describing a type-safe implementation of the publish/subscribe pattern in C++ that has proven quite useful to me. I've used this code for everything from handling input events to implementing message passing across a network. It's main advantages are:

  • No modifications to a subscriber's interface are necessary (ie: doesn't need to define a specific method or implement any specific interface)
  • Abstracts the manner in which messages are published to subscribers behind a common interface (ie: publish messages immediately, queue them up for delivery from a single thread, etc.)
  • Easily allows subscribing for specific messages or entire groups of messages (ie: subscribing for the escape key versus subscribing for all keyboard messages)
  • Type safety (subscribers will only receive messages of the C++ type they specified at subscription time)
  • Doesn't rely on singletons or any other type of global state (more concurrency-friendly and allows localized subscriptions for better performance)

This first post will concentrate on the system's primary interfaces and won't delve into implementation very much. Subsequent posts will then go under the hood as well as describe some of the non-essential, but useful pieces of code. This post assumes some familiarity with templates as well as common Boost components such as Bind, Function, and Shared Pointer.

CMP Android app is available for purchase

I've been working on an Android version of the CMP iPhone app and it was officially released to the Android Market yesterday. It was my first foray into Android development, so it's pretty cool to see people buying it. It was released under an exclusive license from the Civilian Marksmanship Program and a portion of every sale goes directly to the CMP. If you have an Android phone and want to try it out, just go to the "Market" app on your phone, search for "CMP", and download it!

Signed books from Philadelphia

I had a couple books signed recently at Wizard World in Philadelphia. The first one was a gift for my girlfriend who's a big Patrick Stewart and Next Generation fan. The second I just had signed on a whim after seeing it in a 50 cent box near John de Lancie's table. I'll probably add Michael Dorn and Marina Sirtis to it.

My other expensive hobby

Besides comics, I'm also a pretty avid shooter. Moving to Pittsburgh from Texas has only amplified my firearm enthusiasm. I know that seems backwards with Texas' gun-happy stigma, but that couldn't be further from the truth. When you compare each state's laws and the facilities available, Pennsylvania is a much better place to be a gun owner than Texas. I found a shooter's paradise within 20 minutes of Pittsburgh where a $60 per year membership allows me to participate in nearly any shooting sport I want any time I want. I've started to dabble in IPSC pistol and CMP high-power rifle, along with a weekly dosage of skeet.

Last week, I brought a coworker out for skeet who's also a talented photographer, and he snapped a few pictures. As you can see, I have a pretty unorthodox skeet gun, but I still consistently score 19 or 20 with it:

Dan Aykroyd SS book is back

I got the book I had signed by Dan Aykroyd back from CGC:

Psycho II wings at Jigger's

So some friends who know I like eating insanely hot wings have been telling me to try the wing challenge at this place called Jigger's east of Pittsburgh. You basically have 40 minutes to eat either 12 of their "Psycho" wings or 12 of their "Psycho II" wings (twice as hot). Now, these are the whole wing. So 12 of these wings are the same as 24 of what most places call a "wing". I'd been told that only an idiot would attempt the Psycho II challenge. I guess I'm an idiot. It took me a mere eight and a half minutes of the 40 allowed to take them down:

Triple-Atomic wings at Quaker Steak and Lube

So after totally embarrassing the Blazin' Challenge at Buffalo Wild Wings several months ago, I decided to take on the Atomic Challenge at Quaker Steak and Lube in Pittsburgh. It sounded simple compared to the Blazin' Challenge. You only have to eat six wings, with no time limit or drink restrictions (not that I would need a drink anyways). When I showed up, I was surprised to find that they had a new hottest sauce; the Triple-Atomic. Made with the world's current hottest pepper, these wings supposedly reach 500,000 on the Scoville Scale. I'm not one to back down from a challenge, however unexpected. So, I signed the waiver and ordered up six of the new wings. While they were hotter than the Blazin' wings, I had no trouble devouring them all in a mere minute and a half:

(sorry about the video was a bit too dark inside for the crappy phone camera)

Dan Aykroyd comic signing

So I was browsing the CGC message boards at work the Friday before my girlfriend and I were due to fly out to Las Vegas, and I saw a post by Kris (thecollector) announcing a rare Dan Aykroyd Signature Series opportunity. He had seven spots available and all had already been spoken for by the time I came along. I was about to throw a fit when I noticed that the signing was taking place in Las Vegas on our last day there. After a few frantic messages, I got in touch with CGC witness Chandler who was going to be doing the actual witnessing at the signing, and he said it would be no problem for me to bring my own book and get it signed in-person. I immediately knew what book I wanted signed. The only problem was that my copy was beat to hell and had water damage. I ran over to Eide's on my lunch break, but they didn't have a copy. Calls to other local shops came up empty as well. I was about to give up when I remembered a friend in Texas who had a complete Marvel bronze age collection. A few short hours later, he was packing his high-grade copy and preparing to overnight it to my hotel! So, a few days later, we woke up at our hotel, had breakfast, and prepared to catch a cab to the signing. The only problem? The book hadn't arrived yet! After several frantic calls to various USPS numbers, I got them to change the carrier's route and go to our hotel first. The book was finally in my hands a mere two hours before we needed to be in line at the signing...a little too close for comfort.

Vacation in Las Vegas

Despite Delta Airlines' best efforts, my girlfriend and I just got back from a fabulous five days and four nights in Vegas. We flew in Friday night and boarded a shuttle full of guys who sounded like Niko from GTA IV. After being dropped off at the Rio, we checked in and bought Penn & Teller tickets on the way up to our huge and luxurious room:

Arcade project is (really) finished!

So it only took me three years to get around to having the custom control panel overlay printed up for my arcade machine. I've had the image file sitting on my computer the whole time, but I just recently sent it to Scott at Mame Marquees for printing. It came out great. Here's a before and after: