diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-08-31 01:57:30 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-08-31 01:57:30 +0100 | 
| commit | 5d4d818ce49a007ea3c07deaf53f4370baf4e8f1 (patch) | |
| tree | 330076b4b175e3c21571201a443ba2427bb1f3ef | |
| parent | Migrate cache from libmisc and add covering tests, some minor renaming and re... (diff) | |
| download | libadhocutil-5d4d818ce49a007ea3c07deaf53f4370baf4e8f1.tar.bz2 libadhocutil-5d4d818ce49a007ea3c07deaf53f4370baf4e8f1.tar.xz libadhocutil-5d4d818ce49a007ea3c07deaf53f4370baf4e8f1.zip  | |
Tidy up
| -rw-r--r-- | libadhocutil/buffer.h | 4 | ||||
| -rw-r--r-- | libadhocutil/cache.h | 4 | ||||
| -rw-r--r-- | libadhocutil/cache.impl.h | 5 | ||||
| -rw-r--r-- | libadhocutil/curlMultiHandle.cpp | 11 | ||||
| -rw-r--r-- | libadhocutil/curlStream.cpp | 6 | ||||
| -rw-r--r-- | libadhocutil/curlStream.h | 2 | ||||
| -rw-r--r-- | libadhocutil/definedDirs.h | 9 | ||||
| -rw-r--r-- | libadhocutil/intrusivePtrBase.h | 4 | ||||
| -rw-r--r-- | libadhocutil/lazyPointer.h | 4 | ||||
| -rw-r--r-- | libadhocutil/lockHelpers.h | 10 | ||||
| -rw-r--r-- | libadhocutil/nvpParse.h | 6 | ||||
| -rw-r--r-- | libadhocutil/nvpParse.ll | 2 | ||||
| -rw-r--r-- | libadhocutil/runtimeContext.cpp | 20 | ||||
| -rw-r--r-- | libadhocutil/runtimeContext.h | 10 | ||||
| -rw-r--r-- | libadhocutil/scopeExit.h | 4 | ||||
| -rw-r--r-- | libadhocutil/unittests/testContext.cpp | 24 | ||||
| -rw-r--r-- | libadhocutil/unittests/testCurl.cpp | 14 | ||||
| -rw-r--r-- | libadhocutil/unittests/testNvpParse.cpp | 6 | ||||
| -rw-r--r-- | libadhocutil/unittests/testProcessPipes.cpp | 2 | 
19 files changed, 78 insertions, 69 deletions
diff --git a/libadhocutil/buffer.h b/libadhocutil/buffer.h index ff1e250..49e7df8 100644 --- a/libadhocutil/buffer.h +++ b/libadhocutil/buffer.h @@ -1,5 +1,5 @@ -#ifndef ADHOC_BUFFER_H -#define ADHOC_BUFFER_H +#ifndef ADHOCUTIL_BUFFER_H +#define ADHOCUTIL_BUFFER_H  #include "intrusivePtrBase.h"  #include <string> diff --git a/libadhocutil/cache.h b/libadhocutil/cache.h index 8cd7903..b28c6dc 100644 --- a/libadhocutil/cache.h +++ b/libadhocutil/cache.h @@ -1,5 +1,5 @@ -#ifndef NETFS_FUSE_CACHE_H -#define NETFS_FUSE_CACHE_H +#ifndef ADHOCUTIL_CACHE_H +#define ADHOCUTIL_CACHE_H  #include <time.h>  #include <boost/shared_ptr.hpp> diff --git a/libadhocutil/cache.impl.h b/libadhocutil/cache.impl.h index 43fcd1a..c47eabf 100644 --- a/libadhocutil/cache.impl.h +++ b/libadhocutil/cache.impl.h @@ -1,3 +1,6 @@ +#ifndef ADHOCUTIL_CACHE_IMPL_H +#define ADHOCUTIL_CACHE_IMPL_H +  #include "cache.h"  #include <boost/lambda/lambda.hpp>  #include "lockHelpers.h" @@ -125,3 +128,5 @@ Cache<T, K>::prune() const  	}  } +#endif + diff --git a/libadhocutil/curlMultiHandle.cpp b/libadhocutil/curlMultiHandle.cpp index 4d5ca12..433b78c 100644 --- a/libadhocutil/curlMultiHandle.cpp +++ b/libadhocutil/curlMultiHandle.cpp @@ -12,7 +12,7 @@ class RunningCurl : public CurlStreamSource {  		{  		} -		void Callback() override +		void callback() override  		{  			typedef boost::reference_wrapper<RunningCurl> rc_ref;  			boost::iostreams::stream<rc_ref> curlstrm(boost::ref(*this)); @@ -45,7 +45,7 @@ CurlMultiHandle::addRunner(CURLM * curlm, Running & running, CurlMultiHandle::CU  	auto runner = *curls.begin();  	curl_multi_add_handle(curlm, *runner);  	running[*runner] = runner; -	runner->SwapContext(); +	runner->swapContext();  	curls.erase(runner);  } @@ -69,9 +69,10 @@ CurlMultiHandle::performAll()  			while ((msg = curl_multi_info_read(curlm, &msgs))) {  				if (msg->msg == CURLMSG_DONE) {  					curl_multi_remove_handle(curlm, msg->easy_handle); -					running[msg->easy_handle]->res = msg->data.result; -					running[msg->easy_handle]->SwapContext(); -					running.erase(msg->easy_handle); +					auto ri = running.find(msg->easy_handle); +					ri->second->res = msg->data.result; +					ri->second->swapContext(); +					running.erase(ri);  					if (!curls.empty()) {  						addRunner(curlm, running, curls);  						act += 1; diff --git a/libadhocutil/curlStream.cpp b/libadhocutil/curlStream.cpp index 727aa21..1cc0f4b 100644 --- a/libadhocutil/curlStream.cpp +++ b/libadhocutil/curlStream.cpp @@ -14,7 +14,7 @@ std::streamsize  CurlStreamSource::read(char * target, std::streamsize targetSize)  {  	if (!buflen) { -		SwapContext(); +		swapContext();  		checkCurlCode(res);  		if (!buflen) {  			return 0; @@ -28,7 +28,7 @@ CurlStreamSource::read(char * target, std::streamsize targetSize)  }  void -CurlStreamSource::Callback() +CurlStreamSource::callback()  {  	if (curl_headers) {  		curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, curl_headers); @@ -47,7 +47,7 @@ CurlStreamSource::recv(void * data, size_t datalen)  {  	buf = (char *)data;  	buflen = datalen; -	SwapContext(); +	swapContext();  	return datalen;  } diff --git a/libadhocutil/curlStream.h b/libadhocutil/curlStream.h index efe8c4e..74816a0 100644 --- a/libadhocutil/curlStream.h +++ b/libadhocutil/curlStream.h @@ -16,7 +16,7 @@ class DLL_PUBLIC CurlStreamSource : public boost::iostreams::source, public Curl  	private:  		friend class CurlMultiHandle; -		DLL_PRIVATE void Callback() override; +		DLL_PRIVATE void callback() override;  		DLL_PRIVATE static size_t recvWrapper(void * data, size_t sz, size_t nm, void * css);  		DLL_PRIVATE size_t recv(void * data, size_t datalen); diff --git a/libadhocutil/definedDirs.h b/libadhocutil/definedDirs.h index cbed012..b24a1c9 100644 --- a/libadhocutil/definedDirs.h +++ b/libadhocutil/definedDirs.h @@ -1,5 +1,5 @@ -#ifndef P2_UT_DEFINEDDIRS -#define P2_UT_DEFINEDDIRS +#ifndef ADHOCUTIL_DEFINEDDIRS_H +#define ADHOCUTIL_DEFINEDDIRS_H  #include <boost/filesystem/path.hpp>  #include <boost/filesystem/convenience.hpp> @@ -10,8 +10,9 @@  #define XSTR(s) STR(s)  #define STR(s) #s -const auto BinDir = boost::filesystem::canonical("/proc/self/exe").parent_path(); -const boost::filesystem::path RootDir(XSTR(ROOT)); +const auto selfExe = boost::filesystem::canonical("/proc/self/exe"); +const auto binDir = selfExe.parent_path(); +const boost::filesystem::path rootDir(XSTR(ROOT));  #endif diff --git a/libadhocutil/intrusivePtrBase.h b/libadhocutil/intrusivePtrBase.h index e10e2f1..b5fa94e 100644 --- a/libadhocutil/intrusivePtrBase.h +++ b/libadhocutil/intrusivePtrBase.h @@ -1,5 +1,5 @@ -#ifndef ADHOC_INTRUSIVEPTRBASE_H -#define ADHOC_INTRUSIVEPTRBASE_H +#ifndef ADHOCUTIL_INTRUSIVEPTRBASE_H +#define ADHOCUTIL_INTRUSIVEPTRBASE_H  #include <boost/intrusive_ptr.hpp> diff --git a/libadhocutil/lazyPointer.h b/libadhocutil/lazyPointer.h index 23058c7..2aed50e 100644 --- a/libadhocutil/lazyPointer.h +++ b/libadhocutil/lazyPointer.h @@ -1,5 +1,5 @@ -#ifndef LIBADHOC_LAZYPOINTER_H -#define LIBADHOC_LAZYPOINTER_H +#ifndef ADHOCUTIL_LAZYPOINTER_H +#define ADHOCUTIL_LAZYPOINTER_H  #include <boost/function.hpp>  #include <boost/variant.hpp> diff --git a/libadhocutil/lockHelpers.h b/libadhocutil/lockHelpers.h index 85a1b73..c583421 100644 --- a/libadhocutil/lockHelpers.h +++ b/libadhocutil/lockHelpers.h @@ -1,11 +1,11 @@ -#ifndef LIBADHOC_LOCKHELPERS_H -#define LIBADHOC_LOCKHELPERS_H +#ifndef ADHOCUTIL_LOCKHELPERS_H +#define ADHOCUTIL_LOCKHELPERS_H  template <typename locktype> -class _lockLoop { +class _LockLoop {  	public:  		template<typename l> -		_lockLoop(l & _l) : +		_LockLoop(l & _l) :  			lock(_l),  			flag(true)  		{ @@ -23,7 +23,7 @@ class _lockLoop {  #define LIBADHOC_LOCK_CONCAT(a, b) LIBADHOC_LOCK_CONCAT2(a, b)  #define LIBADHOC_LOCK_WITHLINE(a) LIBADHOC_LOCK_CONCAT(a,  __LINE__) -#define BaseScopeLock(l,lt,mt) for (_lockLoop<lt<mt>> LIBADHOC_LOCK_WITHLINE(_lck)(l); LIBADHOC_LOCK_WITHLINE(_lck); !LIBADHOC_LOCK_WITHLINE(_lck)) +#define BaseScopeLock(l,lt,mt) for (_LockLoop<lt<mt>> LIBADHOC_LOCK_WITHLINE(_lck)(l); LIBADHOC_LOCK_WITHLINE(_lck); !LIBADHOC_LOCK_WITHLINE(_lck))  #define BaseLock(l,lt,mt) lt<mt> LIBADHOC_LOCK_WITHLINE(_lck)(l)  #define Lock(l) BaseLock(l, boost::unique_lock, boost::shared_mutex) diff --git a/libadhocutil/nvpParse.h b/libadhocutil/nvpParse.h index bb5afd8..0e3f2ff 100644 --- a/libadhocutil/nvpParse.h +++ b/libadhocutil/nvpParse.h @@ -52,16 +52,16 @@ class NvpParse : public yyFlexLexer {  #define NvpValue(c, m) { #m, boost::shared_ptr<NvpParse::Target<c, decltype(c::m)>>(new NvpParse::Target<c, decltype(c::m)>(&c::m)) }  		template <typename T> -		static void Parse(std::istream & in, const NvpTarget(T) & tm, T & t) +		static void parse(std::istream & in, const NvpTarget(T) & tm, T & t)  		{  			NvpParse::AssignMap am;  			for (const auto & v : tm) {  				am[v.first] = v.second->assign(&t);  			} -			return Parse(in, am); +			return parse(in, am);  		} -		DLL_PUBLIC static void Parse(std::istream & in, const AssignMap & m); +		DLL_PUBLIC static void parse(std::istream & in, const AssignMap & m);  	private:  		NvpParse(std::istream & in, const AssignMap &); diff --git a/libadhocutil/nvpParse.ll b/libadhocutil/nvpParse.ll index b149b92..7e4d0dc 100644 --- a/libadhocutil/nvpParse.ll +++ b/libadhocutil/nvpParse.ll @@ -75,7 +75,7 @@ NvpParse::LexerError(const char * msg)  }  void -NvpParse::Parse(std::istream & in, const AssignMap & m) +NvpParse::parse(std::istream & in, const AssignMap & m)  {  	NvpParse p(in, m);  	p.yylex(); diff --git a/libadhocutil/runtimeContext.cpp b/libadhocutil/runtimeContext.cpp index 731053a..cb938d4 100644 --- a/libadhocutil/runtimeContext.cpp +++ b/libadhocutil/runtimeContext.cpp @@ -5,12 +5,12 @@ RuntimeContext::RuntimeContext(size_t stacksize) :  	swapped(false)  {  	stack = malloc(stacksize); -	if (getcontext(&callback) == -1) +	if (getcontext(&ctxCallback) == -1)  		throw std::runtime_error("Failed to getcontext"); -	callback.uc_stack.ss_sp = stack; -	callback.uc_stack.ss_size = stacksize; -	callback.uc_link = &initial; -	makecontext(&callback, (void (*)())&RuntimeContext::ccallback, 1, this); +	ctxCallback.uc_stack.ss_sp = stack; +	ctxCallback.uc_stack.ss_size = stacksize; +	ctxCallback.uc_link = &ctxInitial; +	makecontext(&ctxCallback, (void (*)())&RuntimeContext::callbackWrapper, 1, this);  }  RuntimeContext::~RuntimeContext() @@ -19,23 +19,23 @@ RuntimeContext::~RuntimeContext()  }  void -RuntimeContext::SwapContext() +RuntimeContext::swapContext()  {  	swapped = !swapped;  	if (swapped) { -		swapcontext(&initial, &callback); +		swapcontext(&ctxInitial, &ctxCallback);  	}  	else {  		if (stack) { -			swapcontext(&callback, &initial); +			swapcontext(&ctxCallback, &ctxInitial);  		}  	}  }  void -RuntimeContext::ccallback(RuntimeContext * rc) +RuntimeContext::callbackWrapper(RuntimeContext * rc)  { -	rc->Callback(); +	rc->callback();  	free(rc->stack);  	rc->stack = nullptr;  } diff --git a/libadhocutil/runtimeContext.h b/libadhocutil/runtimeContext.h index 6fe26f0..aa424d4 100644 --- a/libadhocutil/runtimeContext.h +++ b/libadhocutil/runtimeContext.h @@ -10,17 +10,17 @@ class DLL_PUBLIC RuntimeContext {  		RuntimeContext(size_t stacksize = 16384);  		virtual ~RuntimeContext(); -		void SwapContext(); +		void swapContext();  	protected: -		DLL_PRIVATE virtual void Callback() = 0; +		DLL_PRIVATE virtual void callback() = 0;  	private: -		DLL_PRIVATE static void ccallback(RuntimeContext * rc); +		DLL_PRIVATE static void callbackWrapper(RuntimeContext * rc);  		void * stack; -		ucontext_t initial; -		ucontext_t callback; +		ucontext_t ctxInitial; +		ucontext_t ctxCallback;  		bool swapped;  }; diff --git a/libadhocutil/scopeExit.h b/libadhocutil/scopeExit.h index d9854d5..7534add 100644 --- a/libadhocutil/scopeExit.h +++ b/libadhocutil/scopeExit.h @@ -1,5 +1,5 @@ -#ifndef LIBADHOC_SCOPEEXIT_H -#define LIBADHOC_SCOPEEXIT_H +#ifndef ADHOCUTIL_SCOPEEXIT_H +#define ADHOCUTIL_SCOPEEXIT_H  #include <boost/function.hpp>  #include "visibility.h" diff --git a/libadhocutil/unittests/testContext.cpp b/libadhocutil/unittests/testContext.cpp index 6a291bf..727425e 100644 --- a/libadhocutil/unittests/testContext.cpp +++ b/libadhocutil/unittests/testContext.cpp @@ -3,23 +3,25 @@  #include "runtimeContext.h" -class testRuntimeContext : RuntimeContext { +class TestRuntimeContext : RuntimeContext {  	public: -		void Run() +		void run()  		{  			log += "a"; -			SwapContext(); +			swapContext();  			log += "b"; -			SwapContext(); +			swapContext();  			log += "c"; +			swapContext(); +			log += "d";  		} -		void Callback() override +		void callback() override  		{ -			log += "d"; -			SwapContext();  			log += "e"; -			SwapContext(); +			swapContext(); +			log += "f"; +			swapContext();  		}  		std::string log; @@ -27,8 +29,8 @@ class testRuntimeContext : RuntimeContext {  BOOST_AUTO_TEST_CASE ( basic )  { -	testRuntimeContext trc; -	trc.Run(); -	BOOST_REQUIRE_EQUAL("adbec", trc.log); +	TestRuntimeContext trc; +	trc.run(); +	BOOST_REQUIRE_EQUAL("aebfcd", trc.log);  } diff --git a/libadhocutil/unittests/testCurl.cpp b/libadhocutil/unittests/testCurl.cpp index 1c1f179..a62800d 100644 --- a/libadhocutil/unittests/testCurl.cpp +++ b/libadhocutil/unittests/testCurl.cpp @@ -15,7 +15,7 @@ size_t discard(void *, size_t sz, size_t nm, void *)  BOOST_AUTO_TEST_CASE( fetch_file )  { -	auto url = "file://" + RootDir.string() + "/testCurl.cpp"; +	auto url = "file://" + rootDir.string() + "/testCurl.cpp";  	CurlHandle ch(url);  	ch.setopt(CURLOPT_WRITEFUNCTION, (void*)&discard);  	ch.perform(); @@ -23,14 +23,14 @@ BOOST_AUTO_TEST_CASE( fetch_file )  BOOST_AUTO_TEST_CASE( fetch_missing )  { -	auto url = "file://" + RootDir.string() + "/nothere"; +	auto url = "file://" + rootDir.string() + "/nothere";  	CurlHandle ch(url);  	BOOST_REQUIRE_THROW(ch.perform(), AdHoc::Net::CurlException);  }  BOOST_AUTO_TEST_CASE( fetch_file_stream )  { -	auto url = "file://" + RootDir.string() + "/testCurl.cpp"; +	auto url = "file://" + rootDir.string() + "/testCurl.cpp";  	CurlStreamSource css(url);  	boost::iostreams::stream<css_ref> curlstrm(boost::ref(css));  	std::string tok; @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE( fetch_file_stream )  BOOST_AUTO_TEST_CASE( fetch_missing_stream )  { -	auto url = "file://" + RootDir.string() + "/nothere"; +	auto url = "file://" + rootDir.string() + "/nothere";  	BOOST_REQUIRE_THROW({  		CurlStreamSource css(url);  		boost::iostreams::stream<css_ref> curlstrm(boost::ref(css)); @@ -71,11 +71,11 @@ BOOST_AUTO_TEST_CASE( fetch_multi )  {  	CurlMultiHandle cmh;  	std::map<std::string, std::string> files; -	cmh.addCurl("file://" + RootDir.string() + "/testBuffer.cpp", +	cmh.addCurl("file://" + rootDir.string() + "/testBuffer.cpp",  			boost::bind(&mapFileToName, boost::ref(files), "testBuffer.cpp", _1)); -	cmh.addCurl("file://" + RootDir.string() + "/testCurl.cpp", +	cmh.addCurl("file://" + rootDir.string() + "/testCurl.cpp",  			boost::bind(&mapFileToName, boost::ref(files), "testCurl.cpp", _1)); -	cmh.addCurl("file://" + RootDir.string() + "/testLocks.cpp", +	cmh.addCurl("file://" + rootDir.string() + "/testLocks.cpp",  			boost::bind(&mapFileToName, boost::ref(files), "testLocks.cpp", _1));  	cmh.performAll();  	BOOST_REQUIRE_EQUAL(3, files.size()); diff --git a/libadhocutil/unittests/testNvpParse.cpp b/libadhocutil/unittests/testNvpParse.cpp index 09f3ff4..dd7432f 100644 --- a/libadhocutil/unittests/testNvpParse.cpp +++ b/libadhocutil/unittests/testNvpParse.cpp @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE ( parse )  {  	TestTarget tt;  	std::stringstream i("a = foo;b=bar; c=3;d=3.14"); -	NvpParse::Parse(i, TestTargetMap, tt); +	NvpParse::parse(i, TestTargetMap, tt);  	BOOST_REQUIRE_EQUAL("foo", tt.a);  	BOOST_REQUIRE_EQUAL("bar", tt.b);  	BOOST_REQUIRE_EQUAL(3, tt.c); @@ -42,13 +42,13 @@ BOOST_AUTO_TEST_CASE ( missing )  {  	TestTarget tt;  	std::stringstream i("missing=nothing;"); -	BOOST_REQUIRE_THROW(NvpParse::Parse(i, TestTargetMap, tt), NvpParse::ValueNotFound); +	BOOST_REQUIRE_THROW(NvpParse::parse(i, TestTargetMap, tt), NvpParse::ValueNotFound);  }  BOOST_AUTO_TEST_CASE ( bad )  {  	TestTarget tt;  	std::stringstream i("{bad="); -	BOOST_REQUIRE_THROW(NvpParse::Parse(i, TestTargetMap, tt), std::runtime_error); +	BOOST_REQUIRE_THROW(NvpParse::parse(i, TestTargetMap, tt), std::runtime_error);  } diff --git a/libadhocutil/unittests/testProcessPipes.cpp b/libadhocutil/unittests/testProcessPipes.cpp index 7131e70..c87e074 100644 --- a/libadhocutil/unittests/testProcessPipes.cpp +++ b/libadhocutil/unittests/testProcessPipes.cpp @@ -7,7 +7,7 @@  BOOST_AUTO_TEST_CASE ( readfind )  { -	ProcessPipes pp({"/usr/bin/find", RootDir.string(), "-maxdepth", "1"}, false, true, true); +	ProcessPipes pp({"/usr/bin/find", rootDir.string(), "-maxdepth", "1"}, false, true, true);  	BOOST_REQUIRE_EQUAL(pp.fdIn(), -1);  	BOOST_REQUIRE(pp.fdOut() != -1);  	BOOST_REQUIRE(pp.fdError() != -1);  | 
