Răsfoiți Sursa

Update to use Libraries and fix include order

JDierkse 5 ani în urmă
părinte
comite
157b1ceb51

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "Makefiles"]
+	path = Makefiles
+	url = https://gogs.dierkse.nl/JDierkse/Makefiles.git

+ 20 - 20
Application/PresenceDetection.cc

@@ -1,34 +1,34 @@
+#include "Bluetooth/Device.h"
+#include "UniFi/Device.h"
+#include "Util/Device.h"
+#include "Util/INIh.h"
+#include <clipp.h>
+#include <Logging.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <iostream>
 #include <string>
 #include <signal.h>
 #include <syslog.h>
-#include <unistd.h>
 #include <vector>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "Util/clipp.h"
-#include "Util/Device.h"
-#include "Util/INIh.h"
-#include "Util/Logger.h"
-#include "UniFi/Device.h"
-#include "Bluetooth/Device.h"
 
 
 int main(int argc, char** argv)
 {
 	try
 	{
-		setlogmask(LOG_UPTO(LOG_DEBUG));
-		openlog("PresenceDetection", LOG_NDELAY | LOG_PID, LOG_USER);
+		Logging::OpenLog();
+		Logging::SetLogMask(Logging::Severity::Debug);
 
 		bool daemon = false;
-		PresenceDetection::Util::clipp::group cli {
-			PresenceDetection::Util::clipp::option("-d", "--daemon").set(daemon).doc("Run the process as Daemon")
+		clipp::group cli {
+			clipp::option("-d", "--daemon").set(daemon).doc("Run the process as Daemon")
 		};
 
-		if (!PresenceDetection::Util::clipp::parse(argc, argv, cli))
+		if (!clipp::parse(argc, argv, cli))
 		{
-			std::cout << PresenceDetection::Util::clipp::make_man_page(cli, argv[0]) << std::endl;
+			std::cout << clipp::make_man_page(cli, argv[0]) << std::endl;
 			return 1;
 		}
 
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
 
 		if (daemon)
 		{
-			PresenceDetection::Util::Logger::Log(PresenceDetection::Util::Logger::Severity::Info, "Starting Daemon");
+			Logging::Log(Logging::Severity::Info, "Starting Daemon");
 			pid_t pid, sid;
 			pid = fork();
 
@@ -164,7 +164,7 @@ int main(int argc, char** argv)
 		int sig;
 		sigwait(&wset,&sig);
 
-		PresenceDetection::Util::Logger::Log(PresenceDetection::Util::Logger::Severity::Info, "Stopping...");
+		Logging::Log(Logging::Severity::Info, "Stopping...");
 
 		if (pUniFiDevice)
 			pUniFiDevice->Stop();
@@ -178,7 +178,7 @@ int main(int argc, char** argv)
 		if (pBluetoothDevice)
 			pBluetoothDevice->Wait();
 
-		closelog();
+		Logging::CloseLog();
 	}
 	catch (const std::exception& e)
 	{
@@ -186,9 +186,9 @@ int main(int argc, char** argv)
 		ss << "ERROR: " << e.what() << std::endl;
 
 		std::cerr << ss.str() << std::endl;
-		PresenceDetection::Util::Logger::Log(PresenceDetection::Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 
-		closelog();
+		Logging::CloseLog();
 
 		return -1;
 	}

+ 9 - 12
Application/Test.cc

@@ -1,14 +1,12 @@
-#include <iostream>
-#include <string>
-
-#include <memory>
-#include <algorithm>
+#include "Util/INIh.h"
+#include <Timer.h>
 #include <unistd.h>
+#include <algorithm>
 #include <chrono>
 #include <deque>
-
-#include "Util/Timer.h"
-#include "Util/INIh.h"
+#include <iostream>
+#include <memory>
+#include <string>
 
 
 void print()
@@ -18,7 +16,7 @@ void print()
 
 void TestTimerAbort()
 {
-	PresenceDetection::Util::Timer timer;
+	Timer::Timer timer;
 	std::function<void()> f_print = print;
 
 	std::cout << "---" << std::endl;
@@ -51,7 +49,7 @@ void TestTimerAbort()
 	std::cout << "---" << std::endl << std::endl;
 }
 
-typedef std::unique_ptr<PresenceDetection::Util::Timer> Pointer;
+typedef std::unique_ptr<Timer::Timer> Pointer;
 
 template<typename T, typename... Args>
 std::unique_ptr<T> make_unique(Args&&... args) {
@@ -70,7 +68,7 @@ void StartNewTimer(std::deque<Pointer>& timers)
 	int id(10);
 
 	// Protect!
-	auto timer = make_unique<PresenceDetection::Util::Timer>();
+	auto timer = make_unique<Timer::Timer>();
 	timer->StartSingle(delay, static_cast<std::function<void(const std::string&, int)>>(std::bind(&OnTimerEnd, std::placeholders::_1, std::placeholders::_2)), identifier, id);
 	timers.push_back(std::move(timer));
 }
@@ -123,4 +121,3 @@ int main(int /*argc*/, char** /*argv[]*/)
 
 	return 0;
 }
-

+ 12 - 12
Bluetooth/Device.cpp

@@ -1,9 +1,9 @@
+#include "Device.h"
+#include "Functions.h"
+#include "Util/JSON.h"
+#include <Logging.h>
 #include <algorithm>
 #include <sstream>
-#include "Util/JSON.h"
-#include "Util/Logger.h"
-#include "Functions.h"
-#include "Device.h"
 
 
 namespace PresenceDetection {
@@ -62,7 +62,7 @@ void Device::ClearDevices()
 		{
 			std::stringstream ss;
 			ss << "Bluetooth::Device::ClearDevices() - Error: " << e.what() << std::endl;
-			Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+			Logging::Log(Logging::Severity::Error, ss.str());
 		}
 	}
 
@@ -78,7 +78,7 @@ void Device::ClearDevices()
 			{
 				std::stringstream ss;
 				ss << "Bluetooth::Device::ClearDevices() - Error: " << e.what() << std::endl;
-				Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+				Logging::Log(Logging::Severity::Error, ss.str());
 			}
 		}
 	}
@@ -104,7 +104,7 @@ void Device::UpdateDevicesFromInventory()
 	{
 		std::stringstream ss;
 		ss << "Bluetooth::Device::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
-		Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 	}
 }
 
@@ -147,7 +147,7 @@ void Device::UpdatePresentDevices(bool updateOnlineDevices)
 		{
 			std::stringstream ss;
 			ss << "Bluetooth::Device::UpdatePresentDevices() - Error: " << e.what() << std::endl;
-			Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+			Logging::Log(Logging::Severity::Error, ss.str());
 		}
 	}
 
@@ -177,7 +177,7 @@ void Device::UpdatePresentDevices(bool updateOnlineDevices)
 			{
 				std::stringstream ss;
 				ss << "Bluetooth::Device::UpdatePresentDevices() - Error: " << e.what() << std::endl;
-				Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+				Logging::Log(Logging::Severity::Error, ss.str());
 			}
 		}
 	}
@@ -204,7 +204,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 
 	std::stringstream ss;
 	ss << "Bluetooth: " << sign << " " << macAddress;
-	Util::Logger::Log(Util::Logger::Severity::Info, ss.str());
+	Logging::Log(Logging::Severity::Info, ss.str());
 
 	if (!m_target.empty())
 	{
@@ -219,7 +219,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 		{
 			std::stringstream ss;
 			ss << "Bluetooth::Device::SendStateChange() - Error: " << e.what() << std::endl;
-			Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+			Logging::Log(Logging::Severity::Error, ss.str());
 		}
 	}
 
@@ -256,7 +256,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 				{
 					std::stringstream ss;
 					ss << "Bluetooth::Device::SendStateChange() - Error: " << e.what() << std::endl;
-					Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+					Logging::Log(Logging::Severity::Error, ss.str());
 				}
 			}
 		}

+ 7 - 7
Bluetooth/Device.h

@@ -1,11 +1,11 @@
 #ifndef BLUETOOTH_DEVICE_H
 #define BLUETOOTH_DEVICE_H
 
+#include "Util/Device.h"
+#include <HttpClient.h>
+#include <Timer.h>
 #include <string>
 #include <vector>
-#include "Util/Device.h"
-#include "Util/Timer.h"
-#include "Util/HttpClient.h"
 
 
 namespace PresenceDetection {
@@ -30,10 +30,10 @@ private:
 	void SendStateChange(bool present, const std::string& macAddress);
 
 private:
-	Util::Timer m_onlineDeviceTimer;
-	Util::Timer m_offlineDeviceTimer;
-	Util::Timer m_inventoryTimer;
-	Util::HttpClient m_httpClient;
+	Timer::Timer m_onlineDeviceTimer;
+	Timer::Timer m_offlineDeviceTimer;
+	Timer::Timer m_inventoryTimer;
+	Http::HttpClient m_httpClient;
 
 	std::vector<std::string> m_devices;
 

+ 7 - 8
Bluetooth/Functions.cpp

@@ -1,15 +1,14 @@
-#include <sstream>
-#include <vector>
-#include <stdexcept>
+#include "Functions.h"
+#include "Socket.h"
+#include <fcntl.h>
+#include <unistd.h>
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
 #include <bluetooth/l2cap.h>
-
-#include <fcntl.h>
-#include <unistd.h>
 #include <sys/poll.h>
-#include "Socket.h"
-#include "Functions.h"
+#include <sstream>
+#include <stdexcept>
+#include <vector>
 
 
 namespace PresenceDetection {

+ 2 - 3
Bluetooth/Socket.cpp

@@ -1,8 +1,8 @@
-#include <stdexcept>
+#include "Socket.h"
 #include <unistd.h>
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
-#include "Socket.h"
+#include <stdexcept>
 
 
 namespace PresenceDetection {
@@ -27,4 +27,3 @@ int Socket::Descriptor() const
 
 } // namespace Bluetooth
 } // namespace PresenceDetection
-

+ 1 - 0
Libraries/Http

@@ -0,0 +1 @@
+../../Libraries/Http

+ 1 - 0
Libraries/Logging

@@ -0,0 +1 @@
+../../Libraries/Logging

+ 1 - 0
Libraries/Timer

@@ -0,0 +1 @@
+../../Libraries/Timer

+ 1 - 0
Libraries/Utilities

@@ -0,0 +1 @@
+../../Libraries/Utilities

+ 0 - 234
Makefile

@@ -1,234 +0,0 @@
-#
-# Makefile
-#
-
-ROOTPATH     := /opt/build/PresenceDetection
-COMMANDLINE  := $(shell ps -o args= $$PPID)
-
-ARCHS        := $(shell ls $(ROOTPATH)/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g')
-ARCHS        += any
-ARCH         := $(filter $(ARCHS),$(MAKECMDGOALS))
-MAKECMDGOALS := $(filter-out $(ARCH),$(MAKECMDGOALS))
-ARCHS        := $(filter-out any,$(ARCHS))
-
-ifeq ($(ARCH),)
-ARCH         := x86-64
-endif
-
-ifeq (,$(findstring -S,$(COMMANDLINE)))
-ifneq ($(ARCH),)
-$(info ARCH: $(ARCH))
-endif
-endif
-
--include $(ROOTPATH)/Makefile.conf.$(ARCH)
--include $(ROOTPATH)/Makefile.conf.base
-
-PID          := $(shell echo $$$$)
-PREFIX        = nice -n 19 /usr/bin/time --format='%E (%U)' -o /dev/shm/t-$(PID)
-POSTFIX       = && cat /dev/shm/t-$(PID) | xargs -I "%" echo -en '\033[1A\033[100D\033[60C' "%\n" && rm -f /dev/shm/t-$(PID)
-
-ARNAME        = $(notdir $(CURDIR)).a.$(ARCH)
-
-SUBDIRS      := $(wildcard */.)
-SUBDIRS      := $(foreach dir,$(SUBDIRS),$(subst /.,,$(dir)))
-FILTER        = crash%
-SUBDIRS      := $(filter-out $(FILTER),$(SUBDIRS))
-FILTER        = doc%
-SUBDIRS      := $(filter-out $(FILTER),$(SUBDIRS))
-FILTER        = Libraries%
-SUBDIRS      := $(filter-out $(FILTER),$(SUBDIRS))
-SUBDIRARS     = $(foreach dir,$(SUBDIRS),$(dir)/$(dir).a)
-
-LOCALSOURCES  = $(wildcard *.cpp *.cc)
-LOCALOBJECTS := $(LOCALSOURCES:.cpp=.o.$(ARCH))
-LOCALOBJECTS := $(LOCALOBJECTS:.cc=.o.$(ARCH))
-LOCALDEPENDS  = $(LOCALOBJECTS:.o.$(ARCH)=.d.$(ARCH))
-SOURCES       = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
-OBJECTS       = $(SOURCES:.cpp=.o.$(ARCH))
-DEPENDS       = $(OBJECTS:.o.$(ARCH)=.d.$(ARCH))
-TARGETS       =
-
-define build_target_arch
-	$(eval $@_DATETIME := $(DATETIME))
-	@echo -n " [LD] $(1)\n"
-	@$(PREFIX) $(CC) -o $(1) $(2) $(LFLAGS) $(CFLAGS) $(POSTFIX)
-	@$(OBJCOPY) --only-keep-debug $(1) $(DEBUGDIR)/$(1)-$($@_DATETIME).debug
-	@$(STRIP) $(SFLAGS) $(1)
-	@$(OBJCOPY) --add-gnu-debuglink="$(DEBUGDIR)/$(1)-$($@_DATETIME).debug" $(1)
-	@chmod -x $(DEBUGDIR)/$(1)-$($@_DATETIME).debug
-endef
-
-define build_target
-	@if [ "$(ARCH)" = "any" ]; then \
-		for arch in $(ARCHS); do \
-			echo "ARCH: $$arch"; \
-			$(MAKE) -s -S $(1) $$arch; \
-		done; \
-		true; \
-	else \
-		$(MAKE) -s -S $(1).$(ARCH) $(ARCH); \
-	fi
-endef
-
-$(LOCALOBJECTS): | $(SUBDIRS)
-$(OBJECTS): | $(SUBDIRS)
-
-artifacts: $(LOCALOBJECTS)
-
-.DEFAULT_GOAL := artifacts
-
--include Makefile.target
-
-ifneq ($(MAKECMDGOALS),clean)
--include $(LOCALDEPENDS)
-endif
-
-%.d.$(ARCH): %.cpp
-	@if [ "$(ARCH)" != "any" ]; then \
-		depth=$(MAKELEVEL); \
-		while [ $${depth} -gt 0 ] ; do \
-			echo -n " "; \
-			depth=`expr $$depth - 1`; \
-		done; \
-		true; \
-		echo -n " [MM] $@\n"; \
-		$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX); \
-	fi
-
-%.o.$(ARCH): %.cpp
-	@depth=$(MAKELEVEL); \
-	while [ $${depth} -gt 0 ] ; do \
-		echo -n " "; \
-		depth=`expr $$depth - 1`; \
-	done; \
-	true
-	@echo -n " [CC] $@\n"
-	@$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX)
-
-%.d.$(ARCH): %.cc
-	@if [ "$(ARCH)" != "any" ]; then \
-		depth=$(MAKELEVEL); \
-		while [ $${depth} -gt 0 ] ; do \
-			echo -n " "; \
-			depth=`expr $$depth - 1`; \
-		done; \
-		true; \
-		echo -n " [MM] $@\n"; \
-		$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX); \
-	fi
-
-%.o.$(ARCH): %.cc
-	@depth=$(MAKELEVEL); \
-	while [ $${depth} -gt 0 ] ; do \
-		echo -n " "; \
-		depth=`expr $$depth - 1`; \
-	done; \
-	true
-	@echo -n " [CC] $@\n"
-	@$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX)
-
-$(ARNAME): $(SUBDIRS) $(LOCALOBJECTS)
-	@depth=$(MAKELEVEL); \
-	while [ $${depth} -gt 0 ] ; do \
-		echo -n " "; \
-		depth=`expr $$depth - 1`; \
-	done; \
-	true
-	@echo -n " [AR] $@\n"
-	@$(PREFIX) $(AR) rcuT $@ $(LOCALOBJECTS) $(SUBDIRARS) $(POSTFIX)
-
-.PHONY: $(SUBDIRS)
-$(SUBDIRS):
-	@depth=$(MAKELEVEL); \
-	while [ $${depth} -gt 0 ] ; do \
-		echo -n " "; \
-		depth=`expr $$depth - 1`; \
-	done; \
-	true
-	@echo " <$@>"
-	@$(MAKE) -s -S -C $@ artifacts $(ARCH)
-	@depth=$(MAKELEVEL); \
-	while [ $${depth} -gt 0 ] ; do \
-		echo -n " "; \
-		depth=`expr $$depth - 1`; \
-	done; \
-	true
-	@echo " </$@>"
-
-.PHONY: all
-all: $(TARGETS)
-
-.PHONY: clean
-clean:
-	@if [ "$(ARCH)" = "any" ]; then \
-		for arch in $(ARCHS); do \
-			echo "ARCH: $$arch"; \
-			$(MAKE) -s -S $(MAKECMDGOALS) $$arch; \
-		done; \
-		true; \
-	else \
-		for dir in $(SUBDIRS); do \
-			depth=$(MAKELEVEL); \
-			while [ $${depth} -gt 0 ] ; do \
-				echo -n " "; \
-				depth=`expr $$depth - 1`; \
-			done; \
-			echo " <$$dir>"; \
-			$(MAKE) -s -S -C $$dir $@ $(ARCH); \
-			while [ $${depth} -gt 0 ] ; do \
-				echo -n " "; \
-				depth=`expr $$depth - 1`; \
-			done; \
-			echo " </$$dir>"; \
-		done; \
-		for target in $(TARGETS); do \
-			rm -f $$target.$(ARCH); \
-		done; \
-		true; \
-	fi
-	@rm -f $(LOCALOBJECTS) $(LOCALDEPENDS) $(ARNAME) || true
-
-.PHONY: cleandeps
-cleandeps:
-	@if [ "$(ARCH)" = "any" ]; then \
-		for arch in $(ARCHS); do \
-			echo "ARCH: $$arch"; \
-			$(MAKE) -s -S $(MAKECMDGOALS) $$arch; \
-		done; \
-		true; \
-	else \
-		for dir in $(SUBDIRS); do \
-			depth=$(MAKELEVEL); \
-			while [ $${depth} -gt 0 ] ; do \
-				echo -n " "; \
-				depth=`expr $$depth - 1`; \
-			done; \
-			echo " <$$dir>"; \
-			$(MAKE) -s -S -C $$dir $@ $(ARCH); \
-			while [ $${depth} -gt 0 ] ; do \
-				echo -n " "; \
-				depth=`expr $$depth - 1`; \
-			done; \
-			echo " </$$dir>"; \
-		done; \
-		for target in $(TARGETS); do \
-			rm -f $$target.$(ARCH); \
-		done; \
-		true; \
-	fi
-	@rm -f $(LOCALDEPENDS) || true
-
-.PHONY: $(ARCH)
-$(ARCH):
-	@if [ "$(words $(MAKECMDGOALS))" = "0" ]; then \
-		if [ "$(ARCH)" = "any" ]; then \
-			for arch in $(ARCHS); do \
-				echo "ARCH: $$arch"; \
-				$(MAKE) -s -S $(.DEFAULT_GOAL) $$arch; \
-			done; \
-			true; \
-		else \
-			$(MAKE) -s -S $(.DEFAULT_GOAL) $(ARCH); \
-		fi \
-	fi

+ 1 - 0
Makefile

@@ -0,0 +1 @@
+Makefiles/Makefile

+ 25 - 0
Makefile.conf

@@ -0,0 +1,25 @@
+#
+# Makefile.conf
+#
+
+LFLAGS += -lHttp
+LFLAGS += -L$(ROOTPATH)/Libraries/Http/lib/$(ARCH)
+CFLAGS += -I$(ROOTPATH)/Libraries/Http/include
+
+LFLAGS += -lTimer
+LFLAGS += -L$(ROOTPATH)/Libraries/Timer/lib/$(ARCH)
+CFLAGS += -I$(ROOTPATH)/Libraries/Timer/include
+
+LFLAGS += -lLogging
+LFLAGS += -L$(ROOTPATH)/Libraries/Logging/lib/$(ARCH)
+CFLAGS += -I$(ROOTPATH)/Libraries/Logging/include
+
+LFLAGS += -lUtilities
+LFLAGS += -L$(ROOTPATH)/Libraries/Utilities/lib/$(ARCH)
+CFLAGS += -I$(ROOTPATH)/Libraries/Utilities/include
+
+CFLAGS += -I$(ROOTPATH)/Libraries/clipp
+
+LFLAGS += -lpthread -lm -lssl -lcrypto -lcurl -lz -ldl -lbluetooth
+CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/Libraries -I$(ROOTPATH)/Libraries/JSON
+DEBUGDIR := .debug

+ 0 - 14
Makefile.conf.armv6

@@ -1,14 +0,0 @@
-#
-# Makefile.conf.armv6
-#
-
-ARCH := armv6
-CFLAGS := -marm -march=armv6
-
-AR := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar
-CC := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
-STRIP := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip
-OBJCOPY := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-objcopy
-
-CFLAGS += -I/opt/build/rpi-armv6/include
-LFLAGS += -L/opt/build/rpi-armv6/lib --sysroot /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot -Wl,-rpath,/opt/build/rpi-armv6/lib

+ 0 - 14
Makefile.conf.armv8

@@ -1,14 +0,0 @@
-#
-# Makefile.conf.armv8
-#
-
-ARCH := armv8
-CFLAGS := -marm -march=armv8-a
-
-AR := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar
-CC := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
-STRIP := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip
-OBJCOPY := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-objcopy
-
-CFLAGS += -I/opt/build/rpi-armv8/include
-LFLAGS += -L/opt/build/rpi-armv8/lib --sysroot /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot -Wl,-rpath,/opt/build/rpi-armv8/lib

+ 0 - 18
Makefile.conf.base

@@ -1,18 +0,0 @@
-#
-# Makefile.conf.base
-#
-
-CFLAGS += -g3 -O3 -fPIC -std=c++11
-CFLAGS += -Wall -Wextra -Wstrict-aliasing -fmax-errors=5 -Werror -Wunreachable-code -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option
-# CFLAGS += -Wold-style-cast -pedantic -Wcast-qual -Wundef -Wshadow -Wctor-dtor-privacy -Wredundant-decls -Wstrict-overflow=5 -Wcast-align
-LFLAGS += -lpthread -lm -lssl -lcrypto -lcurl -lz -ldl -lbluetooth
-
-CFLAGS += -fpermissive
-CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/Libraries/JSON
-
-CFLAGS += -ffunction-sections -fdata-sections
-LFLAGS += -Wl,--gc-sections
-SFLAGS := -s -R .comment -R .gnu.version --strip-unneeded
-
-DEBUGDIR := .debug
-DATETIME := `date +'%y%m%d-%H%M'`

+ 0 - 10
Makefile.conf.x86-64

@@ -1,10 +0,0 @@
-#
-# Makefile.conf.x86-64
-#
-
-ARCH := x86-64
-
-AR := ar
-CC := g++
-STRIP := strip
-OBJCOPY := objcopy

+ 1 - 0
Makefiles

@@ -0,0 +1 @@
+Subproject commit 61894c4588eb2b85e342a6f923eeb7ac97c3fe64

+ 16 - 13
UniFi/Device.cpp

@@ -1,8 +1,8 @@
+#include "Device.h"
+#include "Util/JSON.h"
+#include <Logging.h>
 #include <algorithm>
 #include <sstream>
-#include "Util/JSON.h"
-#include "Util/Logger.h"
-#include "Device.h"
 
 
 namespace PresenceDetection {
@@ -63,8 +63,11 @@ bool Device::Login()
 
 	try
 	{
+		std::vector<std::string> headers;
+		headers.push_back("Content-Type: application/json");
+
 		std::stringstream output;
-		output << m_httpClient.GetUrlPostContents(url.str(), m_cookieFile, json.dump(), "application/json");
+		output << m_httpClient.GetUrlPostContents(url.str(), headers, m_cookieFile, json.dump());
 
 		Util::JSON outputJSON = Util::JSON::parse(output);
 
@@ -79,7 +82,7 @@ bool Device::Login()
 	{
 		std::stringstream ss;
 		ss << "UniFi::Device::Login() - Error: " << e.what() << std::endl;
-		Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 		std::lock_guard<std::mutex> lock(m_mutex);
 		m_loggedIn = false;
 		return m_loggedIn;
@@ -106,7 +109,7 @@ void Device::Logout()
 	{
 		std::stringstream ss;
 		ss << "UniFi::Device::Logout() - Error: " << e.what() << std::endl;
-		Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 	}
 }
 
@@ -122,7 +125,7 @@ void Device::ClearDevices()
 		{
 			std::stringstream ss;
 			ss << "UniFi::Device::ClearDevices() - Error: " << e.what() << std::endl;
-			Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+			Logging::Log(Logging::Severity::Error, ss.str());
 		}
 	}
 
@@ -138,7 +141,7 @@ void Device::ClearDevices()
 			{
 				std::stringstream ss;
 				ss << "UniFi::Device::ClearDevices() - Error: " << e.what() << std::endl;
-				Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+				Logging::Log(Logging::Severity::Error, ss.str());
 			}
 		}
 	}
@@ -164,7 +167,7 @@ void Device::UpdateDevicesFromInventory()
 	{
 		std::stringstream ss;
 		ss << "UniFi::Device::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
-		Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 	}
 }
 
@@ -236,7 +239,7 @@ void Device::UpdatePresentDevices()
 	{
 		std::stringstream ss;
 		ss << "UniFi::Device::IsDevicePresent() - Error: " << e.what() << std::endl;
-		Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+		Logging::Log(Logging::Severity::Error, ss.str());
 		Logout();
 		return;
 	}
@@ -264,7 +267,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 
 	std::stringstream ss;
 	ss << "UniFi: " << sign << " " << macAddress;
-	Util::Logger::Log(Util::Logger::Severity::Info, ss.str());
+	Logging::Log(Logging::Severity::Info, ss.str());
 
 	if (!m_target.empty())
 	{
@@ -279,7 +282,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 		{
 			std::stringstream ss;
 			ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
-			Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+			Logging::Log(Logging::Severity::Error, ss.str());
 		}
 	}
 
@@ -316,7 +319,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
 				{
 					std::stringstream ss;
 					ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
-					Util::Logger::Log(Util::Logger::Severity::Error, ss.str());
+					Logging::Log(Logging::Severity::Error, ss.str());
 				}
 			}
 		}

+ 6 - 6
UniFi/Device.h

@@ -1,12 +1,12 @@
 #ifndef UNIFI_DEVICE_H
 #define UNIFI_DEVICE_H
 
+#include "Util/Device.h"
+#include <HttpClient.h>
+#include <Timer.h>
 #include <mutex>
 #include <string>
 #include <vector>
-#include "Util/Device.h"
-#include "Util/Timer.h"
-#include "Util/HttpClient.h"
 
 
 namespace PresenceDetection {
@@ -32,9 +32,9 @@ private:
 	void SendStateChange(bool present, const std::string& macAddress);
 
 private:
-	Util::Timer m_deviceTimer;
-	Util::Timer m_inventoryTimer;
-	Util::HttpClient m_httpClient;
+	Timer::Timer m_deviceTimer;
+	Timer::Timer m_inventoryTimer;
+	Http::HttpClient m_httpClient;
 
 	std::mutex m_mutex;
 	bool m_loggedIn;

+ 1 - 1
Util/Device.cpp

@@ -1,5 +1,5 @@
-#include <algorithm>
 #include "Device.h"
+#include <algorithm>
 
 
 namespace PresenceDetection {

+ 0 - 36
Util/Helpers.h

@@ -1,36 +0,0 @@
-#ifndef UTIL_HELPERS_H
-#define UTIL_HELPERS_H
-
-#include <functional>
-
-
-namespace PresenceDetection {
-namespace Util {
-namespace Helpers {
-
-template <int... Is>
-struct index {};
-
-template <int N, int... Is>
-struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
-
-template <int... Is>
-struct gen_seq<0, Is...> : index<Is...> {};
-
-template <typename ...FunctionArguments, typename ...Arguments, int... Is>
-void execute(std::function<void(FunctionArguments...)> const & function, std::tuple<Arguments...>& tuple, index<Is...>)
-{
-	function(std::get<Is>(tuple)...);
-}
-
-template <typename ...FunctionArguments, typename ...Arguments>
-void execute(std::function<void(FunctionArguments...)> const & function, std::tuple<Arguments...>& tuple)
-{
-	execute(function, tuple, gen_seq<sizeof...(Arguments)>{});
-}
-
-} // namespace Helpers
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_HELPERS_H

+ 0 - 630
Util/HttpClient.cpp

@@ -1,630 +0,0 @@
-#include <fstream>
-#include <sstream>
-#include <boost/algorithm/string.hpp>
-#include <curl/curl.h>
-#include <openssl/crypto.h>
-#include "HttpClientHelpers.h"
-#include "HttpClient.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-
-HttpClient::HttpClient()
-{
-	curl_global_init(CURL_GLOBAL_ALL);
-
-	m_userAgents.push_back("Opera/9.80 (X11; Linux i686; U; en) Presto/2.7.62 Version/11.00");
-
-	InitializeLocks();
-}
-
-HttpClient::~HttpClient()
-{
-	FreeLocks();
-	curl_global_cleanup();
-}
-
-std::string HttpClient::GetUrlContents(const std::string& url) const
-{
-	std::string buffer;
-
-	CURL* curl = curl_easy_init();
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlSilent(const std::string& url) const
-{
-	CURL* curl = curl_easy_init();
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-std::string HttpClient::GetUrlContents(const std::string& url, const std::string& cookieFile) const
-{
-	std::string buffer;
-
-	CURL* curl = curl_easy_init();
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlSilent(const std::string& url, const std::string& cookieFile) const
-{
-	CURL* curl = curl_easy_init();
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-std::string HttpClient::GetUrlPostContents(const std::string& url, const std::string& postData, const std::string& contentType) const
-{
-	std::string buffer;
-
-	CURL* curl = curl_easy_init();
-
-	std::stringstream contentTypeString;
-	contentTypeString << "Content-Type: " << contentType;
-
-	struct curl_slist *list = NULL;
-	list = curl_slist_append(list, contentTypeString.str().c_str());
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postData.size());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlPostSilent(const std::string& url, const std::string& postData, const std::string& contentType) const
-{
-	CURL* curl = curl_easy_init();
-
-	std::stringstream contentTypeString;
-	contentTypeString << "Content-Type: " << contentType;
-
-	struct curl_slist *list = NULL;
-	list = curl_slist_append(list, contentTypeString.str().c_str());
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postData.size());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-std::string HttpClient::GetUrlPostContents(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& contentType) const
-{
-	std::string buffer;
-
-	CURL* curl = curl_easy_init();
-
-	std::stringstream contentTypeString;
-	contentTypeString << "Content-Type: " << contentType;
-
-	struct curl_slist *list = NULL;
-	list = curl_slist_append(list, contentTypeString.str().c_str());
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postData.size());
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlPostSilent(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& contentType) const
-{
-	CURL* curl = curl_easy_init();
-
-	std::stringstream contentTypeString;
-	contentTypeString << "Content-Type: " << contentType;
-
-	struct curl_slist *list = NULL;
-	list = curl_slist_append(list, contentTypeString.str().c_str());
-
-	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, m_userAgents[rand() % m_userAgents.size()].c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postData.size());
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-std::string HttpClient::GetUrlPostAttachmentContents(const std::string& url, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const
-{
-	std::string buffer;
-	std::string contents;
-	std::ifstream fileStream(filename, std::ios::in | std::ios::binary);
-
-	if (fileStream)
-	{
-		fileStream.seekg(0, std::ios::end);
-		contents.resize(fileStream.tellg());
-		fileStream.seekg(0, std::ios::beg);
-		fileStream.read(&contents[0], contents.size());
-		fileStream.close();
-	}
-
-	CURL* curl = curl_easy_init();
-	CURLcode result;
-
-	struct curl_httppost *formpost = nullptr;
-	struct curl_httppost *lastptr = nullptr;
-	struct curl_slist *headerlist = nullptr;
-	static const char headerBuffer[] =  "Expect:";
-
-	curl_global_init(CURL_GLOBAL_ALL);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "cache-control:",
-		CURLFORM_COPYCONTENTS, "no-cache",
-		CURLFORM_END);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "content-type:",
-		CURLFORM_COPYCONTENTS, "multipart/form-data",
-		CURLFORM_END);
-
-	std::vector<std::string> postTokens;
-	boost::split(postTokens, postData, boost::is_any_of("&"));
-
-	for (std::vector<std::string>::iterator it = postTokens.begin(); it != postTokens.end(); ++it)
-	{
-		std::vector<std::string> tokens;
-		boost::split(tokens, *it, boost::is_any_of("="));
-
-		curl_formadd(&formpost, &lastptr,
-			CURLFORM_COPYNAME, tokens[0].c_str(),
-			CURLFORM_COPYCONTENTS, tokens[1].c_str(),
-			CURLFORM_END);
-	}
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, fileFieldname.c_str(),
-		CURLFORM_BUFFER, "data",
-		CURLFORM_BUFFERPTR, contents.data(),
-		CURLFORM_BUFFERLENGTH, contents.size(),
-		CURLFORM_END);
-
-	headerlist = curl_slist_append(headerlist, headerBuffer);
-
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-	curl_formfree(formpost);
-	curl_slist_free_all(headerlist);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlPostAttachmentSilent(const std::string& url, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const
-{
-	std::string contents;
-	std::ifstream fileStream(filename, std::ios::in | std::ios::binary);
-
-	if (fileStream)
-	{
-		fileStream.seekg(0, std::ios::end);
-		contents.resize(fileStream.tellg());
-		fileStream.seekg(0, std::ios::beg);
-		fileStream.read(&contents[0], contents.size());
-		fileStream.close();
-	}
-
-	CURL* curl = curl_easy_init();
-	CURLcode result;
-
-	struct curl_httppost *formpost = nullptr;
-	struct curl_httppost *lastptr = nullptr;
-	struct curl_slist *headerlist = nullptr;
-	static const char headerBuffer[] =  "Expect:";
-
-	curl_global_init(CURL_GLOBAL_ALL);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "cache-control:",
-		CURLFORM_COPYCONTENTS, "no-cache",
-		CURLFORM_END);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "content-type:",
-		CURLFORM_COPYCONTENTS, "multipart/form-data",
-		CURLFORM_END);
-
-	std::vector<std::string> postTokens;
-	boost::split(postTokens, postData, boost::is_any_of("&"));
-
-	for (std::vector<std::string>::iterator it = postTokens.begin(); it != postTokens.end(); ++it)
-	{
-		std::vector<std::string> tokens;
-		boost::split(tokens, *it, boost::is_any_of("="));
-
-		curl_formadd(&formpost, &lastptr,
-			CURLFORM_COPYNAME, tokens[0].c_str(),
-			CURLFORM_COPYCONTENTS, tokens[1].c_str(),
-			CURLFORM_END);
-	}
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, fileFieldname.c_str(),
-		CURLFORM_BUFFER, "data",
-		CURLFORM_BUFFERPTR, contents.data(),
-		CURLFORM_BUFFERLENGTH, contents.size(),
-		CURLFORM_END);
-
-	headerlist = curl_slist_append(headerlist, headerBuffer);
-
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-	curl_formfree(formpost);
-	curl_slist_free_all(headerlist);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-std::string HttpClient::GetUrlPostAttachmentContents(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const
-{
-	std::string buffer;
-	std::string contents;
-	std::ifstream fileStream(filename, std::ios::in | std::ios::binary);
-
-	if (fileStream)
-	{
-		fileStream.seekg(0, std::ios::end);
-		contents.resize(fileStream.tellg());
-		fileStream.seekg(0, std::ios::beg);
-		fileStream.read(&contents[0], contents.size());
-		fileStream.close();
-	}
-
-	CURL* curl = curl_easy_init();
-	CURLcode result;
-
-	struct curl_httppost *formpost = nullptr;
-	struct curl_httppost *lastptr = nullptr;
-	struct curl_slist *headerlist = nullptr;
-	static const char headerBuffer[] =  "Expect:";
-
-	curl_global_init(CURL_GLOBAL_ALL);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "cache-control:",
-		CURLFORM_COPYCONTENTS, "no-cache",
-		CURLFORM_END);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "content-type:",
-		CURLFORM_COPYCONTENTS, "multipart/form-data",
-		CURLFORM_END);
-
-	std::vector<std::string> postTokens;
-	boost::split(postTokens, postData, boost::is_any_of("&"));
-
-	for (std::vector<std::string>::iterator it = postTokens.begin(); it != postTokens.end(); ++it)
-	{
-		std::vector<std::string> tokens;
-		boost::split(tokens, *it, boost::is_any_of("="));
-
-		curl_formadd(&formpost, &lastptr,
-			CURLFORM_COPYNAME, tokens[0].c_str(),
-			CURLFORM_COPYCONTENTS, tokens[1].c_str(),
-			CURLFORM_END);
-	}
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, fileFieldname.c_str(),
-		CURLFORM_BUFFER, "data",
-		CURLFORM_BUFFERPTR, contents.data(),
-		CURLFORM_BUFFERLENGTH, contents.size(),
-		CURLFORM_END);
-
-	headerlist = curl_slist_append(headerlist, headerBuffer);
-
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-	curl_formfree(formpost);
-	curl_slist_free_all(headerlist);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		error << "Data: " << buffer;
-		throw std::runtime_error(error.str());
-	}
-
-	return buffer;
-}
-
-void HttpClient::GetUrlPostAttachmentSilent(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const
-{
-	std::string contents;
-	std::ifstream fileStream(filename, std::ios::in | std::ios::binary);
-
-	if (fileStream)
-	{
-		fileStream.seekg(0, std::ios::end);
-		contents.resize(fileStream.tellg());
-		fileStream.seekg(0, std::ios::beg);
-		fileStream.read(&contents[0], contents.size());
-		fileStream.close();
-	}
-
-	CURL* curl = curl_easy_init();
-	CURLcode result;
-
-	struct curl_httppost *formpost = nullptr;
-	struct curl_httppost *lastptr = nullptr;
-	struct curl_slist *headerlist = nullptr;
-	static const char headerBuffer[] =  "Expect:";
-
-	curl_global_init(CURL_GLOBAL_ALL);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "cache-control:",
-		CURLFORM_COPYCONTENTS, "no-cache",
-		CURLFORM_END);
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, "content-type:",
-		CURLFORM_COPYCONTENTS, "multipart/form-data",
-		CURLFORM_END);
-
-	std::vector<std::string> postTokens;
-	boost::split(postTokens, postData, boost::is_any_of("&"));
-
-	for (std::vector<std::string>::iterator it = postTokens.begin(); it != postTokens.end(); ++it)
-	{
-		std::vector<std::string> tokens;
-		boost::split(tokens, *it, boost::is_any_of("="));
-
-		curl_formadd(&formpost, &lastptr,
-			CURLFORM_COPYNAME, tokens[0].c_str(),
-			CURLFORM_COPYCONTENTS, tokens[1].c_str(),
-			CURLFORM_END);
-	}
-
-	curl_formadd(&formpost, &lastptr,
-		CURLFORM_COPYNAME, fileFieldname.c_str(),
-		CURLFORM_BUFFER, "data",
-		CURLFORM_BUFFERPTR, contents.data(),
-		CURLFORM_BUFFERLENGTH, contents.size(),
-		CURLFORM_END);
-
-	headerlist = curl_slist_append(headerlist, headerBuffer);
-
-	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-	curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
-	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFile.c_str());
-	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieFile.c_str());
-
-	int code = 0;
-	curl_easy_perform(curl);
-	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
-	curl_easy_cleanup(curl);
-	curl_formfree(formpost);
-	curl_slist_free_all(headerlist);
-
-	if (code != 200)
-	{
-		std::stringstream error;
-		error << "Error (" << code << ") encountered while retrieving " << url << "\n";
-		throw std::runtime_error(error.str());
-	}
-}
-
-size_t HttpClient::WriteCallback(char* data, size_t size, size_t nmemb, std::string* writerData)
-{
-	if (writerData == nullptr)
-		return size * nmemb;
-
-	writerData->append(data, size * nmemb);
-	return size * nmemb;
-}
-
-} // namespace Util
-} // namespace PresenceDetection

+ 0 - 42
Util/HttpClient.h

@@ -1,42 +0,0 @@
-#ifndef UTIL_HTTPCLIENT_H
-#define UTIL_HTTPCLIENT_H
-
-#include <string>
-#include <vector>
-
-
-namespace PresenceDetection {
-namespace Util {
-
-class HttpClient
-{
-public:
-	HttpClient();
-	~HttpClient();
-
-	HttpClient(const HttpClient&) = delete;
-
-	std::string GetUrlContents(const std::string& url) const;
-	void GetUrlSilent(const std::string& url) const;
-	std::string GetUrlContents(const std::string& url, const std::string& cookieFile) const;
-	void GetUrlSilent(const std::string& url, const std::string& cookieFile) const;
-	std::string GetUrlPostContents(const std::string& url, const std::string& postData, const std::string& contentType) const;
-	void GetUrlPostSilent(const std::string& url, const std::string& postData, const std::string& contentType) const;
-	std::string GetUrlPostContents(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& contentType) const;
-	void GetUrlPostSilent(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& contentType) const;
-	std::string GetUrlPostAttachmentContents(const std::string& url, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const;
-	void GetUrlPostAttachmentSilent(const std::string& url, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const;
-	std::string GetUrlPostAttachmentContents(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const;
-	void GetUrlPostAttachmentSilent(const std::string& url, const std::string& cookieFile, const std::string& postData, const std::string& filename, const std::string& fileFieldname) const;
-
-private:
-	static size_t WriteCallback(char* data, size_t size, size_t nmemb, std::string* writerData);
-
-private:
-	std::vector<std::string> m_userAgents;
-};
-
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_HTTPCLIENT_H

+ 0 - 46
Util/HttpClientHelpers.h

@@ -1,46 +0,0 @@
-#ifndef UTIL_HTTPCLIENTHELPERS_H
-#define UTIL_HTTPCLIENTHELPERS_H
-
-#include <memory>
-#include <mutex>
-#include <vector>
-#include <openssl/crypto.h>
-
-
-namespace PresenceDetection {
-namespace Util {
-
-static std::vector<std::shared_ptr<std::mutex> > g_mutexes;
-
-static void LockCallback(int mode, int type, const char* /*file*/, int /*line*/)
-{
-	if (mode & CRYPTO_LOCK)
-		g_mutexes[type]->lock();
-	else
-		g_mutexes[type]->unlock();
-}
-
-static unsigned long ThreadId(void)
-{
-	return (unsigned long)pthread_self();
-}
-
-static void InitializeLocks(void)
-{
-	g_mutexes.resize(CRYPTO_num_locks());
-	for (int i = 0; i < CRYPTO_num_locks(); ++i)
-		g_mutexes[i] = std::shared_ptr<std::mutex>(new std::mutex());
-
-	CRYPTO_set_id_callback(ThreadId);
-	CRYPTO_set_locking_callback(LockCallback);
-}
-
-static void FreeLocks(void)
-{
-	CRYPTO_set_locking_callback(NULL);
-}
-
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_HTTPCLIENTHELPERS_H

+ 0 - 20
Util/Logger.cpp

@@ -1,20 +0,0 @@
-#include <iostream>
-#include <syslog.h>
-#include "Logger.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-
-void Logger::Log(Severity::type severity, const std::string& message)
-{
-	if (severity > Severity::Error)
-		std::cout << message << std::endl;
-	else
-		std::cerr << message << std::endl;
-
-	syslog(static_cast<int>(severity), "%s", message.c_str());
-}
-
-} // namespace Util
-} // namespace PresenceDetection

+ 0 - 37
Util/Logger.h

@@ -1,37 +0,0 @@
-#ifndef UTIL_LOGGER_H
-#define UTIL_LOGGER_H
-
-#include <string>
-
-
-namespace PresenceDetection {
-namespace Util {
-
-class Logger
-{
-public:
-	class Severity
-	{
-	public:
-		enum type
-		{
-			Emergency = 0,
-			Alert = 1,
-			Critical = 2,
-			Error = 3,
-			Warning = 4,
-			Notice = 5,
-			Info = 6,
-			Debug = 7
-		};
-	};
-
-
-public:
-	static void Log(Severity::type severity, const std::string& message);
-};
-
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_LOGGER_H

+ 0 - 59
Util/Timer.cpp

@@ -1,59 +0,0 @@
-#include <chrono>
-#include "Util.h"
-#include "Timer.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-
-Timer::Timer() :
-	m_run(false),
-	m_aborted(false),
-	m_identifier(CreateRandomString(10))
-{
-}
-
-Timer::~Timer()
-{
-	Abort();
-	Wait();
-}
-
-bool Timer::operator==(const Timer& other) const
-{
-	return m_identifier == other.Identifier();
-}
-
-std::string Timer::Identifier() const
-{
-	return m_identifier;
-}
-
-void Timer::Stop()
-{
-	m_run.store(false, std::memory_order_release);
-}
-
-void Timer::Abort()
-{
-	m_run.store(false, std::memory_order_release);
-	{
-		std::unique_lock<std::mutex> lock(m_mutex);
-		m_aborted = true;
-	}
-	m_conditionVariable.notify_all();
-}
-
-bool Timer::IsRunning() const noexcept
-{
-	return (m_run.load(std::memory_order_acquire) && m_thread.joinable());
-}
-
-void Timer::Wait()
-{
-	if (m_thread.joinable())
-		m_thread.join();
-}
-
-} // namespace Util
-} // namespace PresenceDetection

+ 0 - 106
Util/Timer.h

@@ -1,106 +0,0 @@
-#ifndef UTIL_TIMER_H
-#define UTIL_TIMER_H
-
-#include <atomic>
-#include <condition_variable>
-#include <functional>
-#include <memory>
-#include <mutex>
-#include <thread>
-#include "Helpers.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-
-class Timer
-{
-public:
-	Timer();
-	~Timer();
-
-	Timer(const Timer&) = delete;
-	Timer& operator= (const Timer&) = delete;
-
-	bool operator==(const Timer& other) const;
-
-public:
-	std::string Identifier() const;
-
-	template <typename ...FunctionArguments, typename ...Arguments>
-	void StartSingle(int milliSeconds, std::function<void(FunctionArguments...)> const & function, Arguments && ...arguments)
-	{
-		Start(TimerType::Single, milliSeconds, function, std::forward<Arguments>(arguments)...);
-	}
-
-	template <typename ...FunctionArguments, typename ...Arguments>
-	void StartContinuous(int milliSeconds, std::function<void(FunctionArguments...)> const & function, Arguments && ...arguments)
-	{
-		Start(TimerType::Continuous, milliSeconds, function, std::forward<Arguments>(arguments)...);
-	}
-
-	void Stop();
-	void Abort();
-	bool IsRunning() const noexcept;
-	void Wait();
-
-private:
-	class TimerType
-	{
-	public:
-		enum type
-		{
-			Unknown,
-			Single,
-			Continuous
-		};
-	};
-
-private:
-	template <typename ...FunctionArguments, typename ...Arguments>
-	void Start(TimerType::type type, int milliSeconds, std::function<void(FunctionArguments...)> const & function, Arguments && ...arguments)
-	{
-		if (type == TimerType::Unknown)
-			return;
-
-		if (m_run.load(std::memory_order_acquire))
-			Stop();
-
-		m_thread = std::thread([this, type, milliSeconds, function, &arguments...]()
-			{
-				auto argumentsCopy = std::make_tuple(std::forward<Arguments>(arguments)...);
-				m_run.store(true, std::memory_order_release);
-				m_aborted = false;
-
-				while (m_run.load(std::memory_order_acquire))
-				{
-					std::unique_lock<std::mutex> lock(m_mutex);
-					if (!m_conditionVariable.wait_for(lock, std::chrono::milliseconds(milliSeconds), [&]{return m_aborted;}))
-					{
-						Helpers::execute(function, argumentsCopy);
-						if (type == TimerType::Single)
-							m_run.store(false, std::memory_order_release);
-					}
-				}
-			});
-
-		while (!IsRunning())
-		{
-		}
-	}
-
-private:
-	std::atomic<bool> m_run;
-	bool m_aborted;
-	std::mutex m_mutex;
-	std::condition_variable m_conditionVariable;
-	std::string m_identifier;
-	std::thread m_thread;
-};
-
-typedef std::unique_ptr<Timer> TimerPointer;
-
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_TIMER_H

+ 0 - 25
Util/Util.cpp

@@ -1,25 +0,0 @@
-#include <algorithm>
-#include "Util.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-
-std::string CreateRandomString(size_t length)
-{
-	auto randchar = []() -> char
-	{
-		const char charset[] =
-			"0123456789"
-			"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-			"abcdefghijklmnopqrstuvwxyz";
-		const size_t max_index = (sizeof(charset) - 1);
-		return charset[ rand() % max_index ];
-	};
-	std::string str(length,0);
-	std::generate_n(str.begin(), length, randchar);
-	return str;
-}
-
-} // namespace Util
-} // namespace PresenceDetection

+ 0 - 15
Util/Util.h

@@ -1,15 +0,0 @@
-#ifndef UTIL_UTIL_H
-#define UTIL_UTIL_H
-
-#include <string>
-
-
-namespace PresenceDetection {
-namespace Util {
-
-std::string CreateRandomString(size_t length);
-
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_UTIL_H

+ 0 - 17
Util/clipp.h

@@ -1,17 +0,0 @@
-#ifndef UTIL_CLIPP_H
-#define UTIL_CLIPP_H
-
-#include "Libraries/clipp/clipp.h"
-
-
-namespace PresenceDetection {
-namespace Util {
-namespace clipp {
-
-using namespace ::clipp;
-
-} // namespace clipp
-} // namespace Util
-} // namespace PresenceDetection
-
-#endif // UTIL_CLIPP_H