BAF's Ramblings » #programming

Wooters Android App

October 14, 2010

In addition to working on BAFIRC, I’ve also been contemplating what needs to be done on the Android client for Wooters.us.

The short todo list:

  • Proper notifications - sound/vibrate/etc, all configurable
  • Add polling configuration options and enable poll support (aimed for battery saving)
  • Get proper app icon, release update to Market

Beyond that, I have also been doing a little bit of reading up on Google’s Cloud to Device Messaging (C2DM) framework. This is, for example, what ChromeToPhone uses for pushing messages to the phone.

I have been granted trial/development access to further explore and develop on C2DM for the Wooters app, so I guess all that’s left now is to actually code make it work. One concern is that Google sets strict quotas on the number of messages we can send, so reducing and optimizing for resource usage will be of utmost concern. I will work on the Wooters app, and begin exploring C2DM during the next Wooters.us Hackathon (which may happen as early as this coming Sunday)!

Keep your eyes peeled for any updates on this.

BAFIRC

October 13, 2010bafirc

Yeah, it has been a few days since I have made much progress with BAFIRC. I am hoping to be able to implement something useful for it tonight. I still am not totally sure on how I want to lay out my plugin system, so I may just work on fleshing out the DCC code a little more. Either that, or spend some time considering 005 i-support or a different, seemingly more up to date CTCP spec that Sevalecan linked me to.

Anyway, that’s about it. I just felt like writing a blog post, so I did so from my phone.

BAFIRC: DCC Layer

October 10, 2010bafirc

So, I spent some more time working on BAFIRC. I ended up beginning the DCC layer, as it doesn’t seem to be too much of a jump over the CTCP layer. So far, I only have a similar infrastructure as CTCP has, receiving/sending and parsing the requests. I wrote some quick hacked up code for connecting to a DCC CHAT, however I still need to write more robust classes that will handle the connection layer and handle transferring files. This will mostly be a bunch of brain-numbing, boring code to write, so I may put it off, not sure yet. I am also debating on whether or not to implement an ident server. I’d like to run the core on a Linux box at some point, under Mono, but right now, Mono doesn’t have a stable release supporting .NET 4, so it will be Windows-only until that happens (unless you’re feeling adventurous, I hear that the current SVN head of Mono has full .NET 4 support). Obviously, on Linux, it an internal ident server won’t be used (for a couple of reasons I won’t get into here). I still think it will be beneficial to create, so I may whip one of those up - but again, that falls along the same lines as far as being mind-numbingly boring code to write.

Moving on to more interesting topics, I really need to plan out my plugin system. As I’ve said before, plugins will do just about everything, so it will be important to design this correctly. I’m going to use MEF composition (new to .NET 4) - so I just need to figure out the best way to expose the plugins. One way of doing it is to create an interface, or an abstract base class, with methods for all of the various events that may be called, and then just call them on all the plugins. Another option is to have metadata telling the plugin manager what to call and when/why to call it. However, neither of these approaches lines up with the whole Observable pattern I’ve been playing with and growing fond of. It seems like, in order to utilize that, I will simply require some sort of initialization function in each plugin that can then attach and subscribe to the various Observables it’s interest in (or ones that it derives from the base ones). My only concern with this approach is that it doesn’t seem too OOP-y. I think I can make it work though. One other thing I may support is some sort of permissions/security system for plugins - those of you who have installed extensions in Chrome or have installed applications on Android know what I’m talking about - the screen that shows you what permissions the extension/application requires before it’s installed/activated/whatever. You shouldn’t be loading potentially untrusted plugins into BAFIRC anyway, but I figure it will be a nice touch to show what sorts of messages the plugin hooks in to, and then restrict the plugin to using only those. I’m thinking of a manifest-like metadata attribute on the plugin, and then on plugin initialization, it sends this manifest to the plugin manager, which then can check that it’s been granted all permissions it’s asked for (or prompt/warn user if not), and then return an interface to only those event observables. This is still a fairly early and under-developed idea, but it’s a start (and it’s more than I had when I began writing this post)!

Anyhow, I’ve built another wall of text, so it’s probably time to sign off for now.

BAFIRC: CTCP Layer Refactoring

October 9, 2010bafirc

So, I’ve refactored the CTCP interaction in the core IRC connections - mostly to just neaten things up and do them in a way I feel is much more cleanly done. This didn’t change functionality at all.

I also added some helper methods to get IObservables for the main IRC events, which just wrap the existing event handlers. This is purely added functionality, allowing .NET RX to be used much more easily, rather than having to manually calculate the observables from the events yourself. There are also some extra methods that allow filtering on command type (so with one function call, you get an observable for only one type of message (e.g., privmsg) that you can then subscribe to, or filter further).

To go along with this, I did end up creating another CTCP layer that sits on top of the IRC layer. The core layer still differentiates between regular privmsg/notice and ctcp/ntctp, and the CTCP layer just extends the functionality by making the data easier to access, reply to, and work with. Also featured in this layer are some extension methods that allow you to get CTCP events - notably CTCP received and CTCP sent, along with some extra filtering options (mimicking those in the irc layer).

These changes are mostly minor, but they do enable you to do more powerful event filtering easier and with less boilerplate code. For example, before these additions, in order to reply to a CTCP PING, you would have to write the following code:

// given IrcConnection conn;
conn.MessageReceived += (s, e) =>
{
    if (e.Message.Command == IrcCommand.Ctcp && e.Message.Parameters[1].Equals("ping", StringComparison.OrdinalIgnoreCase))
        conn.SendMessage(IrcMessage.NCtcp(e.Message.From.Nick, "PING", e.Message.Parameters[2]));
};

With these additions, responding to a CTCP ping is simple:

var pingRequest = conn.GetCtcpMessageReceived(CtcpMessageType.Request).Where(request => request.Command.Equals("ping", StringComparison.OrdinalIgnoreCase));
pingRequest.Subscribe(ping => conn.SendMessage(ping.CreateReply(ping.Data)));

The main strength, at least from what I’ve seen so far, is that you gain the ability to filter and join events using LINQ. So in this case, we filter down a CTCP Request (and, the GetCtcpMessageReceived() function just filters the more generic MessageReceived event from the irc layer, using LINQ) down to a PING request, and then subscribe to that specific event, and handle it by sending an appropriate ping reply.

I will definitely be exposing all events to the plugins like this. Depending on what turns out to be easier, I may keep the same event model for firing events, but the Observable wrappers over these events are very powerful and make the code much more concise (just like LINQ does).

Note that the LINQ code is, as most LINQ code usually ends up being, much more dense. I usually tend to split things up over lines to ease in readability, and help keep individual lines short (I usually create a new line at each part of the chain). There’s also the LINQ syntax, which looks more like SQL than C#, which is just turned into these chained function calls by the compiler anyway. The LINQ-ified code can be harder to read, especially when you’re not familiar with LINQ, but I find it tends to be more result-oriented. Rather than looking at a bunch of if statements and crap, you’re being much more declarative in what you want. Rather than saying “give me everything, and if some condition holds, do this,” you’re saying “I don’t care how you do it, but give me things for a certain condition, and then do this.” The example I gave above was trivial, but I’ve seen some much more complex examples involving sequencing that make the LINQ code much easier to write and less messy - such as this.

I got way off on a non-BAFIRC related tangent, but LINQ is awesome. It’s one of those things that seems questionable or even useless, but once you start using it and thinking in terms of ‘how can I do this with LINQ’ it becomes much more useful. I find that it encourages you to think in abstract steps, rather than focus on how to actually implement what you’re doing, and then you can stay at those abstract steps and let LINQ figure the rest out.

BAFIRC Progress

October 9, 2010bafirc

I was lazy today and didn’t do any work on BAFIRC. I did start looking at the new .NET 4 features, on a tangent, while I was refreshing myself on MEF (I’ve used MEF before, and now it’s integrated in .NET 4).

One new feature I stumbled upon is the new event system, with IObserver/IObservable and the fact that these can be push or pull events. It’s described as being LINQ for events. I’m considering refactoring my IRC layer to use the new event model, though I need to do some more research. It seems really powerful and neat, with one line of code, the consumer can subscribe to only private message events, for example. This should cut down on boilerplate code in event handlers to pick and choose what to respond to.