Log4Vala – A logging framework for Vala inspired by Log4J

It’s getting pretty easy to see that I should start finishing some entries for this blog if it’s going to be at all relevant or useful, but I’ll take a moment to introduce another “thing”.

This past weekend, while working on a web project in Ambition, I started wishing I could control logging in a better way than what was already provided. Specifically, I wanted to be able to amp up logging in one controller while keeping another one quiet. In a horrific turn of events, I found myself longing for something like log4j/log4perl/log4net so I could use a configuration file to handle that.

A few days go by, and here we are.

Introducing Log4Vala, available on GitHub. Available as a shared library to integrate into your Vala application or library, Log4Vala provides most of the core concepts available in the other logging frameworks, without a lot of overhead. Yes, there are still a few method calls for each logging pass, but it’s quiet a bit tighter than a VM environment. I’m pretty happy with the result.

Patches/documentation/heckling welcome.

Project Audi TT Audio: Head Unit

I always felt that the head unit was the easiest component of most vehicles to replace. Modern vehicles have hugely custom setups, some controlling HVAC and car preferences, which makes it a pain. Luckily, in this case, the only sin is that Audi uses a slightly wider faceplate on their head units. I actually replaced my head unit last fall as the original Concert unit was failing, so there’s going to be some stuff from memory here. I grabbed parts as required for the first installation, however, since I’m bypassing the Bose amplifier now, it’s possible that we can go for a cheaper wiring harness.
  • Metra 70-1787 Radio Wiring Harness for VW/Audi – Bose
  • Metra 40-VW54 Amplified Antenna Adapter

 

Wiring Harness and Power

I had to modify the wiring harness before as the pinouts didn’t match what the TT was bringing out at all. The yellow power lead didn’t connect to anything, and it required me to pull pins out and replace them elsewhere. For this install, I yanked everything else out. So, you’ll only need the black harness, providing power, as everything else is for either audio output or the amp remote wire, which isn’t necessary, as I’m disconnecting the Bose amp. To be clear: You’re getting constant 12V power via the yellow line, and ground via the black line. Switched power has to be tapped.

To tap switched power, I went under the driver’s side again, and ran a wire from the 30X terminal on the far left side of the power bar directly under the steering wheel. It does what it needs to do — it’s on when the key is on, it’s off when the key is off, and it provides 12V. I wouldn’t power anything more intense than a head unit off that line, but it works really well for this purpose.

For FM radio to work, the 40-VW54 adapter is just connected to the separate antenna connector in the TT, and the blue line is connected to either the amp remote or antenna remote of your head unit. The Sony head unit I purchased had two separate leads, so I could connect the amp remote to one, and the antenna remote to my adapter. If the head unit doesn’t have separate leads, connect both the amp remote and the 40-VW54 to the amp remote lead of the head unit. If one were using the original Audi head unit, you could wire it into the amp remote line on the red wiring harness in the above Metra kit.

Audio Line Out

Project Audi TT Audio: Amp Power

I’ve installed amps in vehicles all of twice, and both of those cars were not German. One was a 1997 Dodge Intrepid, and one was a 2001 Mitsubishi Eclipse Spyder. The Intrepid was fairly easy because it was huge and had a lot of open spaces, so finding a place to drill wasn’t terrible. That said, I made someone else do the drilling, as I was 18 and stupid, but not stupid enough to ruin my only car. The Eclipse was easy because the thing was a tin can and you could route wires through any of the wide open, uninsulated spaces in the whole car. I hated that car. Anyway, since the Audi is getting a whole build, I elected to start taking stuff out of the car first, to make the process (theoretically) easier. First, I yanked out the head unit, and then pulled out the seats. Well, first first, I disconnected the battery. Let’s not be ridiculous.
Audi recommends the use of an adapter of sorts when removing the seats from the car, to prevent the airbags from going off. Dr. Google seems to have the opinion that this isn’t required if you’re doing this in a space where static electricity isn’t much of an issue. I ran with that, pulled four bolts from the bottom of each seat with an allen wrench, disconnected the three wire harnesses underneath, and put the seats aside. This gave me plenty of room to work in the car. Note that there isn’t a lot of room under those seats to remove those clips, and they fasten on the top and bottom. I ended up using a flathead screwdriver to lift one clip while wiggling it out. It helps to unbolt first and then rock the seat back to get more room to work.
After that was complete, I pulled out the lower dash panel under the steering wheel. To do that, remove the cover of the fuse box, which you’ll see if you open the driver’s side door, and look on the left side of the dashboard. Those are just push clips, so it’ll pull off if you slide a flathead under and pull outward gently. There are two hex screws on the lower curve, and then one nearly dead center, that is inset somewhat, as it’s bolting in the dash cover and not the outside of the fuse box. Then, underneath the steering wheel, there are two hex screws on the bottom that need to be pulled out. The dash cover can then be pulled straight toward you from the steering wheel, and then downward. You’ll want to pull the wiring from the headlight switch and from down below, and then you can pull the whole thing out, if you want.
Once you’re done, you’re left with this:

I started with the guide on Waks Wide Web, the defacto source of garage how-to for the TT, to run the amp power cable. The guides on that site assume a RHD UK TT, so when he mentions “glove box”, it’s under the driver’s side for the US. I also ignored everything about the remote wire, since this is being controlled by an aftermarket head unit with a dedicated remote lead. I was stumped with what I saw there. First, the box that can “easily be unclipped and moved to the side” is either the thing on the left or on the right. The thing on the left provided no more visibility or ease to me when it was unclipped and moved. The thing on the right wasn’t going to budge for anyone or anything. So, I tried from the inside. He talks about the big loom, so I found that above the dead pedal, taped my 4-gauge power cable to a wire hanger, and tried to push it through.

Nope. Not going anywhere.

So, I’m shining a flashlight behind the engine. I pulled out the airbox entirely (which came in handy later), to see if I could see another hole with more room. I’m shining a flashlight all around under the driver’s side, and I’m starting to get ready to find a place to drill, or try to remove the white covering that is all along the firewall on the inside of the car, thinking maybe something is covered on my car that isn’t covered on others. Then, as usual, it was actually staring at me all along. There’s a dime to nickel size rubber grommet almost directly above the gas pedal. I pushed on it, it came out, and I could see the light from the open hood of the car. Success! I took my taped cable and ran it through that hole until it it something.

It comes out somewhere around that box that Waks Wide Web was talking about. Mine poked through the heat shield behind the engine, but I pushed it back and routed it to the right hand side. In a perfect world, this would run along the wire track that you see on the right, but as I mentioned before, I have no idea how to gain access to it. I successfully unclipped it from the bottom, but without getting to it from the top, that’s useless.
I kept the cable below the airbox, covered the cable, and put the airbox back into the car. I’m not attaching it to anything yet, but now I know my cable length, and I know where it’s going. Insert a new grommet so the metal is not rubbing against the cable, and put some sealant on there so water doesn’t get in the cabin.

Project Audi TT Audio

So, last fall, I picked up a 2002 Audi TT 225 Roadster with a little over 160,000 miles. It’s super high mileage, but drives super well, and I figure it’s a great little car to learn on. Luckily, nothing terrible has happened yet, but I can guarantee you that this car will be featured more than once on this blog in the near future. Once winter came, the convertible was in the garage quite a bit, and I noticed that after a couple of weeks, the car needed a jump start.

Super annoying.

After some considerable trial and error using the fuse box, turns out that it’s the Bose amplifier that is causing a pretty big power drain while the car is off. Not a big deal if it’s driven every few days, but significant enough that it’s dead after about a week and a half. Well, go big or go home, right? Instead of picking up a new amp to provide the same lackluster sound, why not spend a little more and redo all of the audio? I have the Bentley manual, how hard could it be?

I love bad ideas!

So far, on the build list:

  • Sony DSX-S310BTX for the head unit
  • Alpine MRP-F300 4-channel amplifier to drive speakers
  • Alpine MRV-T320 2-channel amplifier to drive subwoofer
  • Alpine SPR-60C 6.5″ Component speakers for the doors
  • Infinity Reference 4032cf 4″ 2-way speakers for the rears
  • JL-Audio 8W1v2-4 8″ Subwoofer for the rear
  • A boatload of Dynamat, cabling, and fuses

I’ve already started the project, slowly but surely, as I have an infant and a job, so I’ll be updating with some of the ridiculous crap I’ve dealt with so far, and continuing from there.

Introduction

I keep finding myself in situations where I say, “Yeah, I could totally do that myself.” Honestly, I have no freaking idea what I’m doing, but at least I can share the knowledge after I’ve broken everything.

You may also find instances where my wife and I have both not had any idea what we were doing at At Our Own Risk.

GCouchbase – A reasonable Couchbase library for Vala

I’m pleased to announce that there is a reasonable Couchbase library coming along for Vala, and it is semi-functional at this point. Sure, an announcement seems weird at “semi-functional”, but considering the absence of a library up to this point, I’m calling it good.

Introducing GCouchbase (github/web).

GCouchbase is a combination of a fully functional vapi wrapper around the C libcouchbase library and a pleasant GObject layer on top of it. The libcouchbase functionality is available to the end user via GCouchbase or on its own, but GCouchbase makes the library work more like how one would expect out of a higher level language. The structure is loosely based off of the .NET library, but does not rely on libmemcached or any other proxy layer.

For those who may not be aware of what Couchbase is, it is (in my humble opinion) NoSQL done right. While similar in functionality to other offerings like MongoDB or CouchDB, Couchbase combines a persistence layer with a memory layer to provide fast, scalable JSON blob storage and retrieval that scales evenly with memory and CPU. In other words, you don’t need to have a cache layer, a data layer, and a replication layer, Couchbase handles it for you. The built in view functionality is powerful, but can directly connect to an ElasticSearch instance for advanced queries.

It’s very neat, and blends in nicely with the speed of Vala.

I’m speaking at Twin Cities Code Camp 15!

I will be presenting the Ambition MVC Framework at TCCC15. Twin Cities Code Camp is a free event that occurs twice a year at the University of Minnesota in Minneapolis, MN, and it caters to novice to advanced developers using multiple languages and devices. TCCC15 will be held on October 19th, 2013, starting at 8:00am, and you can register here.

The synopsis of my talk:

There are tons of great MVC web frameworks out in the wild, for most major compiled and dynamic languages. They’re great tools to get projects prototyped and quickly into production. The Ambition MVC framework is a hobby that turned into a reasonable web framework. Written using Vala, the Ambition framework allows a developer or team of developers to create web applications or RESTful services using a static-typed object oriented language without relying on a VM or a garbage collection cycle. Plus, being compiled, it allows cloud deployment to be easy and inexpensive, as memory and CPU requirements can be a fraction of PHP, Ruby, Python, or Perl sites. While it’s not “officially” released, it’s available on GitHub, and being actively developed. Patches, help, and end users are very welcome, and I’d like to show you more.

Welcome Back

After some thought and paging through many years of old, outdated technical advice, I have migrated my blog to a new domain with a bit of a fresh start. Because I never want to let go of what I’ve said in the past, I kept a few entries around for grins, but will start fresh and new from here on forward.

Welcome to my new blog.

The main reason I’m writing here is to share thoughts and elicit some conversation about modern development on the web and in the cloud, using old and tired technology, as well as new and busted technology. With any luck, none of the entries will end with “get off my lawn”.

Adventures in Vala: Ambition Framework

Quite some time ago, I posted about my Adventures in Objective-C, postulating that people would be willing to rapidly develop in a static-typed language if the language was easy to deal with. I created the foundation of a web framework that didn’t do too much, but was functional enough to prove that it was possible. I also gave up shortly after, as I found development on Windows and Linux to be a gigantic pain — too few libraries, not much support.

Some of the same ideals I was going for in that previous post still hold true. Java still clicks in a weird way for me, even if it’s too verbose and runs in a VM and 90% of the web frameworks for it annoy me to death. Objective-C was cute, but mostly useless for me. I don’t mind the idea of C#, except for the fact that it’s Windows-centric, and I’m still uncomfortable putting my eggs in the Mono basket.

In the meantime, I stumbled across a language called Vala. Vala’s roots are in the GNOME community, where they have a couple of great C libraries: GLib, and included in that, GObject. Using this standard library, C-based GNOME applications have had a lot of the great benefits of object oriented programming while maintaining the speed and support of the C language. Unfortunately, you got everything else that C provides: no memory management, no namespaces, and difficulty in reading it later.

I’m going to get flamed for that.

Nevertheless, other people saw some of those same things. They also saw some Mono applications creeping into the GNOME core, and felt that all the pieces were there to do something better. Vala was born as a true object oriented programming language, with a very similar design to C#. The difference is, it relies on GLib and GObject to accomplish the OO goals, and therefore, compiles into C, which is then compiled by gcc. As a result, you get significantly smaller and faster binaries than VM-hosted languages, with very minimal pain. Furthermore, you don’t need to use GTK or anything like that, it’s still a general purpose language that can be hosted on any platform that can compile GLib. That means I can code on OS X and Linux, and, while I haven’t done it in a while, Windows can join the party as well.

You see where this is going.

In the end, I took my ideas for a reasonable web framework, and started porting them to Vala. Months ago, I had a proof of concept similar to the ObjC example in my previous post. But, I kept working on it. Routing, templates, plugins, configuration, build systems, all managed to find their way in. Then, the nice things. Session, Authorization, and Form frameworks are a part of it. I’ve started on a fairly simple ORM, as well, Almanna. The result is, well, this.

This blog is the first production test of the framework. I ported the blog software from Catalyst to Ambition, launched it here on the existing database, and I’m going to see all the places it fails. It will likely do a lot of failing, but it’s a decent first effort. After a little stress testing, I’ll open this up on GitHub, and see where else it can go.

Detecting scrolls in an Android ScrollView widget

So, Android.

You would think that Google would have an event available for when someone scrolls a ScrollView widget. After all, it’s the basic way to make some view scroll. Even better, there is an event for the AbsListView and other scrollable widgets. Turns out, there is an event that gets fired in a ScrollView, but you have to subclass the widget to get at it. Then, you have to figure out how to get that message back to your controller.

Lame.

So, for those of you who want to see if a scroll changed on a ScrollView, do the following:

1) Create a class, call it whatever you’d like, but subclass ScrollView. You’ll probably need to override the three existing constructors to be able to instantiate from your controller or XML layout.

public class ExampleScrollView extends ScrollView {
    public ExampleScrollView(Context context) {
        super(context);
    }

    public ExampleScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ExampleScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
}

2) Add an interface within our new class to be able to set a listener. We’ll call it something different so we don’t override any existing OnScrollListeners.

public interface OnScrollViewListener {
    void onScrollChanged( ExampleScrollView v, int l, int t, int oldl, int oldt );
}

3) Let’s add a private attribute and a way to set that listener in the class.

private OnScrollViewListener mOnScrollViewListener;

public void setOnScrollViewListener(OnScrollViewListener l) {
    this.mOnScrollViewListener = l;
}

4) Now, set onScrollChanged to fire the event we provide.

protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    mOnScrollViewListener.onScrollChanged( this, l, t, oldl, oldt );
    super.onScrollChanged( l, t, oldl, oldt );
}

You’re done! You can now set up one of these in your XML layout, or built on the fly. Set your new listener like this, provided you have one in your layout with an id of ‘example_scroll_view’:

ExampleScrollView exampleScrollView = (ExampleScrollView) findViewById( R.id.example_scroll_view);
exampleScrollView.setOnScrollViewListener( new OnScrollViewListener() {
    public void onScrollChanged( ExampleScrollView v, int l, int t, int oldl, int oldt ) {
        Log.d( “Scroller”, “I changed!” );
    }
} );