     _makeServicePath: (serviceType) ->
         __dirname + '/services/' + serviceType + '.xml'
 
-exports.createServer = (device) -> new httpServer(device)
+exports.createServer = (device) -> new HttpServer(device)


helpers = require './helpers'

class httpServer
    constructor: (@device) ->
        @server = http.createServer(@listener)

    listener: (req, res) =>
        helpers.debug "#{req.url} served to #{req.client.remoteAddress}"

        @handler req.url, (err, data) ->
            if err?
                res.writeHead data, 'Content-Type': 'text/plain'
                res.write "#{data} - #{err.message}"
            else
                res.writeHead 200,
                    'Content-Type': 'text/xml'
                    'Content-Length': Buffer.byteLength(data)
                res.write data
            res.end()

    handler: (path, callback) ->
        [foo, category, action, type] = path.split('/')
        console.log path
        switch category
            when 'device'
                if action isnt 'description'

                        fs.readFile @_makeServicePath(type), 'utf8', (err, file) ->
                            return callback err, 500 if err
                            callback null, file
            else
                callback new Error('File not found'), 404

