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...) {}
50 NONCOPYABLE(WatchedThread);
52 WatchedThread(WatchedThread &&) = default;
53 WatchedThread &operator=(WatchedThread &&) = default;
56 void Wrapper(const Args &... args)
60 } catch (const ThreadErrorMessage &e) {
61 m_error = e.DumpToString();
70 template <typename F, typename... Args>
71 WatchedThread<F, Args...> CreateWatchedThread(F &&function,
74 return WatchedThread<F, Args...>(std::move(function), args...);
77 #define THREAD_REQUIRE_MESSAGE(expr, message) \
80 ThrowMsg(ThreadErrorMessage, message); \