2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file test_watched-thread.h
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
27 #include <boost/test/test_tools.hpp>
28 #include <dpl/exception.h>
29 #include <noncopyable.h>
31 // Error handling in threads
32 DECLARE_EXCEPTION_TYPE(CKM::Exception, ThreadErrorMessage)
34 template <typename F, typename... Args>
37 // can't use rreferences for Args because std::thread needs to copy all arguments
38 explicit WatchedThread(F&& function, const Args&... args) :
39 m_function(std::move(function)),
40 m_thread(&WatchedThread::Wrapper, this, args...)
49 NONCOPYABLE(WatchedThread);
51 WatchedThread(WatchedThread&&) = default;
52 WatchedThread& operator=(WatchedThread&&) = default;
56 void Wrapper(const Args&... args) {
59 } catch (const ThreadErrorMessage& e) {
60 m_error = e.DumpToString();
69 template <typename F, typename... Args>
70 WatchedThread<F, Args...> CreateWatchedThread(F&& function, const Args&... args)
72 return WatchedThread<F, Args...>(std::move(function), args...);
75 #define THREAD_REQUIRE_MESSAGE(expr, message) \
78 ThrowMsg( ThreadErrorMessage, message); \