From 5bd2f0ea7477fa2ce0d9d98382e8fe197fcf121f Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 9 Apr 2014 15:58:29 +0400 Subject: [PATCH] Out of line methods - Node<> --- libuavcan/include/uavcan/node/node.hpp | 120 ++++++++++++++----------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index cdb174da2c..f63b4fdd11 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -49,19 +49,7 @@ class UAVCAN_EXPORT Node : public INode bool started_; - int initNetwork(NodeInitializationResult& node_init_result) - { - int res = NodeInitializer::publishGlobalDiscoveryRequest(*this); - if (res < 0) - { - return res; - } - NodeInitializer initializer(*this); - StaticAssert<(sizeof(initializer) < 1200)>::check(); - res = initializer.execute(); - node_init_result = initializer.getResult(); - return res; - } + int initNetwork(NodeInitializationResult& node_init_result); protected: virtual void registerInternalFailure(const char* msg) @@ -109,47 +97,7 @@ public: bool isStarted() const { return started_; } - int start(NodeInitializationResult& node_init_result) - { - if (started_) - { - return 0; - } - GlobalDataTypeRegistry::instance().freeze(); - - int res = 0; - res = proto_dtp_.start(); - if (res < 0) - { - goto fail; - } - res = proto_logger_.init(); - if (res < 0) - { - goto fail; - } - res = proto_nsp_.startAndPublish(); - if (res < 0) - { - goto fail; - } - res = proto_rrs_.start(); - if (res < 0) - { - goto fail; - } - res = proto_tsp_.start(); - if (res < 0) - { - goto fail; - } - res = initNetwork(node_init_result); - started_ = (res >= 0) && node_init_result.isOk(); - return res; - fail: - assert(res < 0); - return res; - } + int start(NodeInitializationResult& node_init_result); /* * Initialization methods @@ -219,4 +167,68 @@ public: Logger& getLogger() { return proto_logger_; } }; +// ---------------------------------------------------------------------------- + +template +int Node:: +initNetwork(NodeInitializationResult& node_init_result) +{ + int res = NodeInitializer::publishGlobalDiscoveryRequest(*this); + if (res < 0) + { + return res; + } + NodeInitializer initializer(*this); + StaticAssert<(sizeof(initializer) < 1200)>::check(); + res = initializer.execute(); + node_init_result = initializer.getResult(); + return res; +} + +template +int Node:: +start(NodeInitializationResult& node_init_result) +{ + if (started_) + { + return 0; + } + GlobalDataTypeRegistry::instance().freeze(); + + int res = 0; + res = proto_dtp_.start(); + if (res < 0) + { + goto fail; + } + res = proto_logger_.init(); + if (res < 0) + { + goto fail; + } + res = proto_nsp_.startAndPublish(); + if (res < 0) + { + goto fail; + } + res = proto_rrs_.start(); + if (res < 0) + { + goto fail; + } + res = proto_tsp_.start(); + if (res < 0) + { + goto fail; + } + res = initNetwork(node_init_result); + started_ = (res >= 0) && node_init_result.isOk(); + return res; +fail: + assert(res < 0); + return res; +} + }