From 7f6d6ccebd0b469817710db21c45cf803223ec69 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 10 Oct 2012 11:08:40 +0200 Subject: [PATCH] Remove declaration of static functions from header file. Also exchange the order of the functions in c file, and avoid a forward declaration. --- examples/msg/kademlia/kademlia.c | 84 ++++++++++++++++---------------- examples/msg/kademlia/kademlia.h | 4 +- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/examples/msg/kademlia/kademlia.c b/examples/msg/kademlia/kademlia.c index 10c30ce0e9..0173515a8d 100644 --- a/examples/msg/kademlia/kademlia.c +++ b/examples/msg/kademlia/kademlia.c @@ -19,51 +19,10 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia, extern long unsigned int smx_total_comms; -/** - * \brief Node function - * Arguments : - * - my node ID - * - the ID of the person I know in the system (or not) - * - Time before I leave the system because I'm bored - */ -int node(int argc, char *argv[]) -{ - unsigned int join_sucess = 1; - double deadline; - xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments"); - /* Node initialization */ - unsigned int id = strtoul(argv[1], NULL, 0); - node_t node = node_init(id); - - if (argc == 4) { - XBT_INFO("Hi, I'm going to join the network with id %s", node->mailbox); - unsigned int id_known = strtoul(argv[2], NULL, 0); - join_sucess = join(node, id_known); - deadline = strtod(argv[3], NULL); - } else { - deadline = strtod(argv[2], NULL); - XBT_INFO("Hi, I'm going to create the network with id %s", node->mailbox); - node_routing_table_update(node, node->id); - } - if (join_sucess) { - XBT_VERB("Ok, I'm joining the network with id %s", node->mailbox); - //We start the main loop - main_loop(node, deadline); - } else { - XBT_INFO("I couldn't join the network :("); - } - XBT_DEBUG("I'm leaving the network"); - XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success, - node->find_node_success + node->find_node_failed); - node_free(node); - - return 0; -} - /** * Main loop for the process */ -void main_loop(node_t node, double deadline) +static void main_loop(node_t node, double deadline) { double next_lookup_time = MSG_get_clock() + random_lookup_interval; XBT_VERB("Main loop start"); @@ -114,6 +73,47 @@ void main_loop(node_t node, double deadline) } } +/** + * \brief Node function + * Arguments : + * - my node ID + * - the ID of the person I know in the system (or not) + * - Time before I leave the system because I'm bored + */ +static int node(int argc, char *argv[]) +{ + unsigned int join_sucess = 1; + double deadline; + xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments"); + /* Node initialization */ + unsigned int id = strtoul(argv[1], NULL, 0); + node_t node = node_init(id); + + if (argc == 4) { + XBT_INFO("Hi, I'm going to join the network with id %s", node->mailbox); + unsigned int id_known = strtoul(argv[2], NULL, 0); + join_sucess = join(node, id_known); + deadline = strtod(argv[3], NULL); + } else { + deadline = strtod(argv[2], NULL); + XBT_INFO("Hi, I'm going to create the network with id %s", node->mailbox); + node_routing_table_update(node, node->id); + } + if (join_sucess) { + XBT_VERB("Ok, I'm joining the network with id %s", node->mailbox); + //We start the main loop + main_loop(node, deadline); + } else { + XBT_INFO("I couldn't join the network :("); + } + XBT_DEBUG("I'm leaving the network"); + XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success, + node->find_node_success + node->find_node_failed); + node_free(node); + + return 0; +} + /** * Tries to join the network * @param node node data diff --git a/examples/msg/kademlia/kademlia.h b/examples/msg/kademlia/kademlia.h index dc9101192f..142a7c03b8 100644 --- a/examples/msg/kademlia/kademlia.h +++ b/examples/msg/kademlia/kademlia.h @@ -8,9 +8,7 @@ #define _MSG_EXAMPLES_KADEMLIA_H #include "node.h" #include "task.h" -//process functions -static int node(int argc, char *argv[]); -static void main_loop(node_t node, double deadline); + //core kademlia functions unsigned int join(node_t node, unsigned int id_known); unsigned int find_node(node_t node, unsigned int id_to_find, -- 2.20.1