From e658892793c42b2d058eed0937025ef2ddaaa372 Mon Sep 17 00:00:00 2001 From: jin-eld Date: Sun, 4 Aug 2013 15:10:37 +0300 Subject: [PATCH] Rename core directory because of autoconf name clash While doing the checks configure might generate "core" files and will then try to remove them. Having a "core" directory generates an error while runing the configure script. There's no workaround but to rename the core directory. --- CMakeLists.txt | 2 +- auto_tests/crypto_test.c | 2 +- auto_tests/friends_test.c | 4 +- auto_tests/messenger_test.c | 3 +- other/DHT_bootstrap.c | 4 +- .../DHT_bootstrap_daemon.c | 4 +- other/unused/timer.c | 290 ------------------ other/unused/timer.h | 104 ------- testing/DHT_test.c | 4 +- testing/Lossless_UDP_testclient.c | 4 +- testing/Lossless_UDP_testserver.c | 4 +- testing/Messenger_test.c | 2 +- testing/crypto_speed_test.c | 2 +- testing/nTox.h | 2 +- {core => toxcore}/CMakeLists.txt | 0 {core => toxcore}/DHT.c | 0 {core => toxcore}/DHT.h | 0 {core => toxcore}/LAN_discovery.c | 0 {core => toxcore}/LAN_discovery.h | 0 {core => toxcore}/Lossless_UDP.c | 0 {core => toxcore}/Lossless_UDP.h | 0 {core => toxcore}/Messenger.c | 0 {core => toxcore}/Messenger.h | 0 {core => toxcore}/friend_requests.c | 0 {core => toxcore}/friend_requests.h | 0 {core => toxcore}/net_crypto.c | 0 {core => toxcore}/net_crypto.h | 0 {core => toxcore}/network.c | 0 {core => toxcore}/network.h | 0 {core => toxcore}/packets.h | 0 {core => toxcore}/ping.c | 0 {core => toxcore}/ping.h | 0 {core => toxcore}/tox.c | 0 {core => toxcore}/tox.h | 0 {core => toxcore}/util.c | 0 {core => toxcore}/util.h | 0 36 files changed, 19 insertions(+), 412 deletions(-) delete mode 100644 other/unused/timer.c delete mode 100644 other/unused/timer.h rename {core => toxcore}/CMakeLists.txt (100%) rename {core => toxcore}/DHT.c (100%) rename {core => toxcore}/DHT.h (100%) rename {core => toxcore}/LAN_discovery.c (100%) rename {core => toxcore}/LAN_discovery.h (100%) rename {core => toxcore}/Lossless_UDP.c (100%) rename {core => toxcore}/Lossless_UDP.h (100%) rename {core => toxcore}/Messenger.c (100%) rename {core => toxcore}/Messenger.h (100%) rename {core => toxcore}/friend_requests.c (100%) rename {core => toxcore}/friend_requests.h (100%) rename {core => toxcore}/net_crypto.c (100%) rename {core => toxcore}/net_crypto.h (100%) rename {core => toxcore}/network.c (100%) rename {core => toxcore}/network.h (100%) rename {core => toxcore}/packets.h (100%) rename {core => toxcore}/ping.c (100%) rename {core => toxcore}/ping.h (100%) rename {core => toxcore}/tox.c (100%) rename {core => toxcore}/tox.h (100%) rename {core => toxcore}/util.c (100%) rename {core => toxcore}/util.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cba0013c..73e89171 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ endmacro() cmake_policy(SET CMP0011 NEW) -add_subdirectory(core) +add_subdirectory(toxcore) add_subdirectory(testing) add_subdirectory(other) add_subdirectory(docs) diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 01c545c8..b3ce6259 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -1,4 +1,4 @@ -#include "../core/net_crypto.h" +#include "../toxcore/net_crypto.h" #include #include #include diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c index b6223489..0426c18d 100644 --- a/auto_tests/friends_test.c +++ b/auto_tests/friends_test.c @@ -18,8 +18,8 @@ * times. This is used both to ensure that we don't loop forever on a broken build, * and that we don't get too slow with messaging. The current time is 15 seconds. */ -#include "../core/friend_requests.h" -#include "../core/Messenger.h" +#include "../toxcore/friend_requests.h" +#include "../toxcore/Messenger.h" #include #include #include diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 9de69409..deac749b 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -10,7 +10,8 @@ * checking that status changes are received, messages can be sent, etc. * All of that is done in a separate test, with two local clients running. */ -#include "../core/Messenger.h" +#include "../toxcore/Messenger.h" +#include "../toxcore/Lossless_UDP.h" #include #include #include diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index c0d4fcc6..0bf71312 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -27,8 +27,8 @@ * */ -#include "../core/DHT.h" -#include "../core/friend_requests.h" +#include "../toxcore/DHT.h" +#include "../toxcore/friend_requests.h" #include "../testing/misc_tools.h" //Sleep function (x = milliseconds) diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c index 46409b76..eec4e39f 100644 --- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c @@ -32,8 +32,8 @@ #include /* htons() */ #include /* strcpy() */ -#include "../../core/DHT.h" -#include "../../core/friend_requests.h" +#include "../../toxcore/DHT.h" +#include "../../toxcore/friend_requests.h" #define DEFAULT_PORT 33445 #define DEFAULT_PID_FILE "bootstrap_server.pid" diff --git a/other/unused/timer.c b/other/unused/timer.c deleted file mode 100644 index 29190921..00000000 --- a/other/unused/timer.c +++ /dev/null @@ -1,290 +0,0 @@ -#define __STDC_FORMAT_MACROS -#include - -#include "timer.h" -#include "network.h" - -/* -A nested linked list increases efficiency of insertions. -Depending on the number of timers we have, we might need to have nested linked lists -in order to improve insertion efficiency. -The code below is preperation for that end, should it be necessary. - -typedef struct { - struct timer_package* _next; - union { - timer_packet* _inner; - timer* queue; - }; - uint64_t pkgtime; -} timer_package; - -timer_package* timer_package_pool; - -static timer_package* new_package() -{ - timer_package* ret; - if (timer_package_pool) { - ret = timer_package_pool; - timer_package_pool = timer_package_pool->_next; - } else { - ret = calloc(1, sizeof(struct timer_package)); - } - return ret; -} - -static void delete_package(timer_package* p) -{ - p->_next = timer_package_pool; - timer_package_pool = p; -} -*/ - -enum timer_state { - STATE_INACTIVE = 0, - STATE_ACTIVE, - STATE_CALLBACK -}; - -struct timer { - enum timer_state state; - timer *_prev; - timer *_next; - timer_callback cb; - void *userdata; - uint64_t deadline; -}; - -static timer *timer_main_queue; -static timer *timer_us_queue; /* hi-speed queue */ - -inline static void timer_dequeue(timer *t, timer **queue) -{ - if (t->state == STATE_INACTIVE) return; /* not in a queue */ - - if (t->_prev) { - t->_prev->_next = t->_next; - } else { - *queue = t->_next; - } - - if (t->_next) t->_next->_prev = t->_prev; - - t->state = STATE_INACTIVE; -} - -static void timer_enqueue(timer *t, timer **queue, timer *prev) -{ - t->state = STATE_ACTIVE; - - while (true) { - if (!*queue) { - t->_next = 0; - t->_prev = prev; - *queue = t; - return; - } - - if ((*queue)->deadline > t->deadline) { - (*queue)->_prev = t; - t->_next = *queue; - t->_prev = prev; - *queue = t; - return; - } - - prev = *queue; - queue = &((*queue)->_next); - } -} - -/*** interface ***/ - -void timer_init() -{ - /* Nothing needs to be done... yet. */ -} - -/* Do not depend on fields being zeroed */ -static timer *timer_pool; /* timer_pool is SINGLY LINKED!! */ - -timer *new_timer(void) -{ - timer *ret; - - if (timer_pool) { - ret = timer_pool; - timer_pool = timer_pool->_next; - } else { - ret = calloc(1, sizeof(struct timer)); - } - - ret->state = STATE_INACTIVE; - return ret; -} - -void delete_timer(timer *t) -{ - timer_dequeue(t, &timer_main_queue); - t->_next = timer_pool; - t->state = STATE_INACTIVE; - timer_pool = t; -} - -void timer_setup(timer *t, timer_callback cb, void *userarg) -{ - t->cb = cb; - t->userdata = userarg; -} - -void *timer_get_userdata(timer *t) -{ - return t->userdata; -} - -static void timer_delay_us(timer *t, int us) -{ - t->deadline += us; - timer **queue = t->_prev ? &(t->_prev->_next) : &timer_main_queue; - timer_dequeue(t, &timer_main_queue); - timer_enqueue(t, queue, t->_prev); -} - -/* Starts the timer so that it's called in sec seconds in the future. - * A non-positive value of sec results in the callback being called immediately. - * This function may be called again after a timer has been started to adjust - * the expiry time. */ -void timer_start(timer *t, int sec) -{ - uint64_t newdeadline = current_time() + sec * US_PER_SECOND; - - if (timer_is_active(t)) { - if (t->deadline < newdeadline) { - timer_delay_us(t, newdeadline - t->deadline); - return; - } - - timer_dequeue(t, &timer_main_queue); - } - - t->deadline = newdeadline; - timer_enqueue(t, &timer_main_queue, 0); -} - -/* Stops the timer. Returns -1 if the timer was not active. */ -int timer_stop(timer *t) -{ - int ret = timer_is_active(t) ? -1 : 0; - timer_dequeue(t, &timer_main_queue); - return ret; -} - -/* Adds additionalsec seconds to the timer. - * Returns -1 and does nothing if the timer was not active. */ -int timer_delay(timer *t, int additonalsec) -{ - if (!timer_is_active(t)) return -1; - - timer_delay_us(t, additonalsec * US_PER_SECOND); - return 0; -} - -static uint64_t timer_diff(timer *t, uint64_t time) -{ - if (t->deadline <= time) return 0; - - return time - t->deadline; -} - -/* Returns the time remaining on a timer in seconds. - * Returns -1 if the timer is not active. - * Returns 0 if the timer has expired and will be called upon the next call to timer_poll. */ -int timer_time_remaining(timer *t) -{ - if (!timer_is_active(t)) return -1; - - return timer_diff(t, current_time()) / US_PER_SECOND; -} - -bool timer_is_active(timer *t) -{ - return t->state != STATE_INACTIVE; -} - -/* Single-use timer. - * Creates a new timer, preforms setup and starts it. */ -void timer_single(timer_callback cb, void *userarg, int sec) -{ - timer *t = new_timer(); - timer_setup(t, cb, userarg); - timer_start(t, sec); -} - -/* Single-use microsecond timer. */ -void timer_us(timer_callback cb, void *userarg, int us) -{ - timer *t = new_timer(); - timer_setup(t, cb, userarg); - t->deadline = current_time() + us; - t->state = STATE_ACTIVE; - timer_enqueue(t, &timer_us_queue, 0); -} - -uint64_t prevtime = 0; -void timer_poll(void) -{ - uint64_t time = current_time(); - - /* Handle millisecond timers */ - while (timer_us_queue) { - if (timer_diff(timer_us_queue, time) != 0) break; - - timer *t = timer_us_queue; - timer_dequeue(t, &timer_us_queue); - t->cb(0, t->userdata); - delete_timer(t); - } - - if (time - prevtime > US_PER_SECOND || prevtime == 0 || prevtime > time) { - /* time moving backwards is just a sanity check */ - prevtime = time; - - while (timer_main_queue) { - if (timer_diff(timer_main_queue, time) != 0) break; - - timer *t = timer_main_queue; - t->state = STATE_CALLBACK; - int rv = t->cb(t, t->userdata); - - if (rv != 0) { - timer_dequeue(t, &timer_main_queue); - delete_timer(t); - continue; - } - - if (t->state != STATE_ACTIVE) { - timer_dequeue(t, &timer_main_queue); - } - } - } -} - -/*** Internal Testing ***/ - -/* I do not want to expose internals to the public, - * which is why internals testing is done this way. */ -void timer_internal_tests(bool (*assert)(bool, char *)) -{ - -} - -void timer_debug_print() -{ - timer *t = timer_main_queue; - printf("Queue:\n"); - - while (t) { - printf("%" PRIu64 " (%" PRIu64 ") : %s\n", t->deadline, t->deadline / US_PER_SECOND, (char *)t->userdata); - t = t->_next; - } -} diff --git a/other/unused/timer.h b/other/unused/timer.h deleted file mode 100644 index 15491326..00000000 --- a/other/unused/timer.h +++ /dev/null @@ -1,104 +0,0 @@ -/* timer.h - * - * Timing subsystem. Provides deadline timers. - * All times are aliased to a second for efficiency. - * - * Timer Guarantees: - * - The callback will not be called before the timer expires. - * - The callback will be called sometime after the timer expires, - * on a best effort basis. - * - If timer_poll is called at least once a second, the callback - * will be called at most one second after it expires. - * - * Copyright (C) 2013 Tox project All Rights Reserved. - * - * This file is part of Tox. - * - * Tox is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tox is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tox. If not, see . - * - */ - -#ifndef TIMER_H -#define TIMER_H - -#include -#include - -#define US_PER_SECOND 1000000 /* 1 s = 10^6 us */ - -struct timer; -typedef struct timer timer; - -/* If time_callback returns a non-zero value, timer t is deleted. - * You may call any of the timer functions within the callback: - * For example, you may call timer_start to restart the timer from - * within a callback. */ -typedef int (*timer_callback)(timer *t, void *userarg); - -/* Initisalise timer subsystem */ -void timer_init(void); - -/* Poll. (I will eventually replace all polling in Tox with an async system.) */ -void timer_poll(void); - -/* Creates a new timer. Does not enqueue/start it. */ -timer *new_timer(void); - -/* Destroys a timer instance. */ -void delete_timer(timer *t); - -/* Sets up the timer callback. */ -void timer_setup(timer *t, timer_callback cb, void *userarg); - -/* Accessor Function. */ -void *timer_get_userdata(timer *t); - -/* Starts the timer so that it's called in sec seconds in the future from now. - * A non-positive value of sec results in the callback being called immediately. - * This function may be called again after a timer has been started to adjust - * the expiry time. */ -void timer_start(timer *t, int sec); - -/* Stops the timer. Returns -1 if the timer was not active. */ -int timer_stop(timer *t); - -/* Adds additionalsec seconds to the timer. - * Returns -1 and does nothing if the timer was not active. */ -int timer_delay(timer *t, int additonalsec); - -/* Returns the time remaining on a timer in seconds. - * Returns -1 if the timer is not active. - * Returns 0 if the timer has expired and the callback hasn't been called yet. */ -int timer_time_remaining(timer *t); - -/* Determines if timer is active. Returns TRUE if it is active */ -bool timer_is_active(timer *t); - -/* Single-use timer. - * Creates a new timer, preforms setup and starts it. - * Callback must return a non-zero value to prevent memory leak. */ -void timer_single(timer_callback cb, void *userarg, int sec); - -/* Single-use microsecond timer. - * Creates a new timer, preforms setup and starts it. - * Please do not use this when accuracy is not absolutely required. - * Use when one needs to time a period < 1 s. - * Use the more coarse timers above for periods > 5 s. - * WARNING: the callback will be called with NULL as the first argument */ -void timer_us(timer_callback cb, void *userarg, int us); - -/* Internal Testing */ -void timer_internal_tests(bool( *)(bool, char *)); - -#endif diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 53369794..d14f9781 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -28,8 +28,8 @@ */ //#include "../core/network.h" -#include "../core/DHT.h" -#include "../core/friend_requests.h" +#include "../toxcore/DHT.h" +#include "../toxcore/friend_requests.h" #include "misc_tools.h" #include diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 09e9e0a3..af349863 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c @@ -28,8 +28,8 @@ * */ -#include "../core/network.h" -#include "../core/Lossless_UDP.h" +#include "../toxcore/network.h" +#include "../toxcore/Lossless_UDP.h" #ifdef WIN32 diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index a82b787a..5c2cabd0 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c @@ -28,8 +28,8 @@ * */ -#include "../core/network.h" -#include "../core/Lossless_UDP.h" +#include "../toxcore/network.h" +#include "../toxcore/Lossless_UDP.h" //Sleep function (x = milliseconds) #ifdef WIN32 diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index c76584d7..19fd9ab7 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -37,7 +37,7 @@ * */ -#include "../core/Messenger.h" +#include "../toxcore/Messenger.h" #include "misc_tools.h" #ifdef WIN32 diff --git a/testing/crypto_speed_test.c b/testing/crypto_speed_test.c index a61b30e8..b06c25e1 100644 --- a/testing/crypto_speed_test.c +++ b/testing/crypto_speed_test.c @@ -28,7 +28,7 @@ double get_time() #endif -#include "../core/net_crypto.h" +#include "../toxcore/net_crypto.h" #include #include diff --git a/testing/nTox.h b/testing/nTox.h index b27a956f..df9d404a 100644 --- a/testing/nTox.h +++ b/testing/nTox.h @@ -35,7 +35,7 @@ #include #include #include -#include "../core/tox.h" +#include "../toxcore/tox.h" #define STRING_LENGTH 256 #define HISTORY 50 diff --git a/core/CMakeLists.txt b/toxcore/CMakeLists.txt similarity index 100% rename from core/CMakeLists.txt rename to toxcore/CMakeLists.txt diff --git a/core/DHT.c b/toxcore/DHT.c similarity index 100% rename from core/DHT.c rename to toxcore/DHT.c diff --git a/core/DHT.h b/toxcore/DHT.h similarity index 100% rename from core/DHT.h rename to toxcore/DHT.h diff --git a/core/LAN_discovery.c b/toxcore/LAN_discovery.c similarity index 100% rename from core/LAN_discovery.c rename to toxcore/LAN_discovery.c diff --git a/core/LAN_discovery.h b/toxcore/LAN_discovery.h similarity index 100% rename from core/LAN_discovery.h rename to toxcore/LAN_discovery.h diff --git a/core/Lossless_UDP.c b/toxcore/Lossless_UDP.c similarity index 100% rename from core/Lossless_UDP.c rename to toxcore/Lossless_UDP.c diff --git a/core/Lossless_UDP.h b/toxcore/Lossless_UDP.h similarity index 100% rename from core/Lossless_UDP.h rename to toxcore/Lossless_UDP.h diff --git a/core/Messenger.c b/toxcore/Messenger.c similarity index 100% rename from core/Messenger.c rename to toxcore/Messenger.c diff --git a/core/Messenger.h b/toxcore/Messenger.h similarity index 100% rename from core/Messenger.h rename to toxcore/Messenger.h diff --git a/core/friend_requests.c b/toxcore/friend_requests.c similarity index 100% rename from core/friend_requests.c rename to toxcore/friend_requests.c diff --git a/core/friend_requests.h b/toxcore/friend_requests.h similarity index 100% rename from core/friend_requests.h rename to toxcore/friend_requests.h diff --git a/core/net_crypto.c b/toxcore/net_crypto.c similarity index 100% rename from core/net_crypto.c rename to toxcore/net_crypto.c diff --git a/core/net_crypto.h b/toxcore/net_crypto.h similarity index 100% rename from core/net_crypto.h rename to toxcore/net_crypto.h diff --git a/core/network.c b/toxcore/network.c similarity index 100% rename from core/network.c rename to toxcore/network.c diff --git a/core/network.h b/toxcore/network.h similarity index 100% rename from core/network.h rename to toxcore/network.h diff --git a/core/packets.h b/toxcore/packets.h similarity index 100% rename from core/packets.h rename to toxcore/packets.h diff --git a/core/ping.c b/toxcore/ping.c similarity index 100% rename from core/ping.c rename to toxcore/ping.c diff --git a/core/ping.h b/toxcore/ping.h similarity index 100% rename from core/ping.h rename to toxcore/ping.h diff --git a/core/tox.c b/toxcore/tox.c similarity index 100% rename from core/tox.c rename to toxcore/tox.c diff --git a/core/tox.h b/toxcore/tox.h similarity index 100% rename from core/tox.h rename to toxcore/tox.h diff --git a/core/util.c b/toxcore/util.c similarity index 100% rename from core/util.c rename to toxcore/util.c diff --git a/core/util.h b/toxcore/util.h similarity index 100% rename from core/util.h rename to toxcore/util.h