core: Add core module for shared code

This commit also makes log4cxx dependency required
diff --git a/core/chronoshare-common.hpp b/core/chronoshare-common.hpp
new file mode 100644
index 0000000..44b5873
--- /dev/null
+++ b/core/chronoshare-common.hpp
@@ -0,0 +1,52 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#ifndef CHRONOSHARE_CORE_COMMON_HPP
+#define CHRONOSHARE_CORE_COMMON_HPP
+
+#include "core/chronoshare-config.hpp"
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <functional>
+#include <limits>
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <type_traits>
+#include <unistd.h>
+
+#include <boost/assert.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/exception/all.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/throw_exception.hpp>
+
+namespace ndn {
+namespace chronoshare {
+
+using std::shared_ptr;
+using std::make_shared;
+
+} // chronoshare
+} // ndn
+
+#endif // CHRONOSHARE_CORE_COMMON_HPP
diff --git a/core/interval-generator.hpp b/core/interval-generator.hpp
new file mode 100644
index 0000000..6e617cf
--- /dev/null
+++ b/core/interval-generator.hpp
@@ -0,0 +1,47 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#ifndef CHRONOSHARE_CORE_INTERVAL_GENERATOR_HPP
+#define CHRONOSHARE_CORE_INTERVAL_GENERATOR_HPP
+
+#include "chronoshare-common.hpp"
+
+namespace ndn {
+namespace chronoshare {
+
+class IntervalGenerator;
+typedef shared_ptr<IntervalGenerator> IntervalGeneratorPtr;
+
+class IntervalGenerator
+{
+public:
+  virtual
+  ~IntervalGenerator()
+  {
+  }
+
+  virtual double
+  nextInterval() = 0;
+};
+
+} // chronoshare
+} // ndn
+
+#endif // CHRONOSHARE_CORE_INTERVAL_GENERATOR_HPP
diff --git a/src/logging.cpp b/core/logging.cpp
similarity index 96%
rename from src/logging.cpp
rename to core/logging.cpp
index b92f83a..08030c9 100644
--- a/src/logging.cpp
+++ b/core/logging.cpp
@@ -20,8 +20,6 @@
 
 #include "logging.hpp"
 
-#ifdef HAVE_LOG4CXX
-
 #include <log4cxx/basicconfigurator.h>
 #include <log4cxx/consoleappender.h>
 #include <log4cxx/defaultconfigurator.h>
@@ -30,11 +28,15 @@
 #include <log4cxx/logger.h>
 #include <log4cxx/patternlayout.h>
 #include <log4cxx/propertyconfigurator.h>
-using namespace log4cxx;
-using namespace log4cxx::helpers;
 
 #include <unistd.h>
 
+namespace ndn {
+namespace chronoshare {
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
 void
 INIT_LOGGERS()
 {
@@ -56,4 +58,5 @@
   configured = true;
 }
 
-#endif
+} // chronoshare
+} // ndn
diff --git a/src/logging.hpp b/core/logging.hpp
similarity index 71%
rename from src/logging.hpp
rename to core/logging.hpp
index 211601f..86e1bf0 100644
--- a/src/logging.hpp
+++ b/core/logging.hpp
@@ -18,15 +18,16 @@
  * See AUTHORS.md for complete list of ChronoShare authors and contributors.
  */
 
-#ifndef LOGGING_H
-#define LOGGING_H
+#ifndef CHRONOSHARE_CORE_LOGGING_HPP
+#define CHRONOSHARE_CORE_LOGGING_HPP
 
 #include "core/chronoshare-config.hpp"
 
-#ifdef HAVE_LOG4CXX
-
 #include <log4cxx/logger.h>
 
+namespace ndn {
+namespace chronoshare {
+
 #define MEMBER_LOGGER static log4cxx::LoggerPtr staticModuleLogger;
 
 #define INIT_MEMBER_LOGGER(className, name) \
@@ -58,34 +59,7 @@
 void
 INIT_LOGGERS();
 
-#else // else HAVE_LOG4CXX
+} // chronoshare
+} // ndn
 
-#define INIT_LOGGER(name)
-#define _LOG_FUNCTION(x)
-#define _LOG_FUNCTION_NOARGS
-#define _LOG_TRACE(x)
-#define INIT_LOGGERS(x)
-#define _LOG_ERROR(x)
-#define _LOG_ERROR_COND(cond, x)
-#define _LOG_DEBUG_COND(cond, x)
-
-#define MEMBER_LOGGER
-#define INIT_MEMBER_LOGGER(className, name)
-
-#ifdef _DEBUG
-
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/thread/thread.hpp>
-#include <iostream>
-
-#define _LOG_DEBUG(x)                                                                      \
-  std::clog << boost::get_system_time() << " " << boost::this_thread::get_id() << " " << x \
-            << std::endl;
-
-#else
-#define _LOG_DEBUG(x)
-#endif
-
-#endif // HAVE_LOG4CXX
-
-#endif // LOGGING_H
+#endif // CHRONOSHARE_CORE_LOGGING_HPP
diff --git a/core/random-interval-generator.hpp b/core/random-interval-generator.hpp
new file mode 100644
index 0000000..ceeef60
--- /dev/null
+++ b/core/random-interval-generator.hpp
@@ -0,0 +1,108 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#ifndef CHRONOSHARE_CORE_RANDOM_INTERVAL_GENERATOR_HPP
+#define CHRONOSHARE_CORE_RANDOM_INTERVAL_GENERATOR_HPP
+
+#include "interval-generator.hpp"
+
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/variate_generator.hpp>
+
+namespace ndn {
+namespace chronoshare {
+
+// generates intervals with uniform distribution
+class RandomIntervalGenerator : public IntervalGenerator
+{
+public:
+  enum class Direction {
+    UP = 1,
+    DOWN = 2,
+    EVEN = 3
+  };
+
+public:
+  // percent is random-range/interval; e.g. if interval is 10 and you wish the random-range to be 2
+  // e.g. 9 ~ 11, percent = 0.2
+  // direction shifts the random range; e.g. in the above example, UP would produce a range of
+  // 10 ~ 12, DOWN of 8 ~ 10, and EVEN of 9 ~ 11
+  RandomIntervalGenerator(double interval, double percent, Direction direction = Direction::EVEN)
+    // : m_rng(time(NULL))
+    : m_rng(static_cast<int>(
+        boost::posix_time::microsec_clock::local_time().time_of_day().total_nanoseconds())),
+      m_dist(0.0, fractional(percent)),
+      m_random(m_rng, m_dist),
+      m_direction(direction),
+      m_percent(percent),
+      m_interval(interval)
+  {
+  }
+
+  virtual ~RandomIntervalGenerator()
+  {
+  }
+
+  virtual double
+  nextInterval()
+  {
+    double percent = m_random();
+    double interval = m_interval;
+    switch (m_direction) {
+      case Direction::UP:
+        interval = m_interval * (1.0 + percent);
+        break;
+      case Direction::DOWN:
+        interval = m_interval * (1.0 - percent);
+        break;
+      case Direction::EVEN:
+        interval = m_interval * (1.0 - m_percent / 2.0 + percent);
+        break;
+      default:
+        break;
+    }
+
+    return interval;
+  }
+
+private:
+  inline double
+  fractional(double x)
+  {
+    double dummy;
+    return std::abs<double>(modf(x, &dummy));
+  }
+
+private:
+  typedef boost::mt19937 RNG_TYPE;
+  RNG_TYPE m_rng;
+  boost::uniform_real<> m_dist;
+  boost::variate_generator<RNG_TYPE&, boost::uniform_real<>> m_random;
+  Direction m_direction;
+  double m_percent;
+  double m_interval;
+};
+
+} // chronoshare
+} // ndn
+
+#endif // CHRONOSHARE_CORE_RANDOM_INTERVAL_GENERATOR_HPP
diff --git a/wscript b/wscript
index a0115e7..4049598 100644
--- a/wscript
+++ b/wscript
@@ -8,7 +8,6 @@
     opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
                    help='''Build unit tests''')
     opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
-    opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
 
     opt.add_option('--without-sqlite-locking', action='store_false', default=True,
                    dest='with_sqlite_locking',
@@ -56,9 +55,7 @@
     if Utils.unversioned_sys_platform() == "linux":
         conf.define("TRAY_ICON", "chronoshare-ubuntu.png")
 
-    if conf.options.log4cxx:
-        conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
-        conf.define("HAVE_LOG4CXX", 1)
+    conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
 
     USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
                        'regex', 'program_options', 'thread']
@@ -85,6 +82,14 @@
     conf.write_config_header('core/chronoshare-config.hpp')
 
 def build(bld):
+    bld(name='core-objects',
+        target='core-objects',
+        features=['cxx'],
+        source=bld.path.ant_glob('core/**/*.cpp'),
+        use='LOG4CXX BOOST',
+        includes='.',
+        export_includes='.')
+
     # if Utils.unversioned_sys_platform() == 'darwin':
     #     bld(
     #         target='adhoc',