// Copyright 2014, Renasar Technologies Inc.
/* jshint: node:true */

'use strict';

var di = require('di');

module.exports = eventsProtocolFactory;

di.annotate(eventsProtocolFactory, new di.Provide('Protocol.Events'));
di.annotate(eventsProtocolFactory,
    new di.Inject(
        'Services.Messenger',
        'Assert'
    )
);

function eventsProtocolFactory (messenger, assert) {
    function EventsProtocol () {
    }

    EventsProtocol.prototype.publishTftpSuccess = function (nodeId, data) {
        assert.ok(nodeId);
        assert.object(data);

        messenger.publish(
            this.exchange,
            'tftp.success' + '.' + nodeId,
            data
        );
    };

    EventsProtocol.prototype.publishTftpFailure = function (nodeId, data) {
        assert.ok(nodeId);
        assert.object(data);

        messenger.publish(
            this.exchange,
            'tftp.failure' + '.' + nodeId,
            data
        );
    };

    EventsProtocol.prototype.publishHttpResponse = function (nodeId, data) {
        assert.ok(nodeId);
        assert.object(data);

        messenger.publish(
            this.exchange,
            'http.response' + '.' + nodeId,
            data
        );
    };

    return new EventsProtocol();
}

@@ -299,16 +299,53 @@
 enger',%0A
+        'Protocol.Exchanges.Events',%0A
         
@@ -405,16 +405,32 @@
 ssenger,
+ eventsExchange,
  assert)
@@ -636,36 +636,46 @@
 sh(%0A            
-this
+eventsExchange
 .exchange,%0A     
@@ -912,36 +912,46 @@
 sh(%0A            
-this
+eventsExchange
 .exchange,%0A     
@@ -1201,12 +1201,22 @@
     
-this
+eventsExchange
 .exc

Fix events protocol to reference exchange