thread.cpp
Go to the documentation of this file.
1 
11 #include <opc/common/thread.h>
12 
13 #include <iostream>
14 
15 namespace Common
16 {
17 
18 Thread::Thread(std::function<void()> f, ThreadObserver * observer)
19  : Observer(observer)
20  , Func(f)
21  , Impl(Thread::ThreadProc, this)
22 {
23 }
24 
26 {
27  try
28  {
29  Join();
30  }
31 
32  catch (std::exception &)
33  {
34  }
35 }
36 
38 {
39  Impl.join();
40 }
41 
43 {
44  try
45  {
46  Func();
47 
48  if (Observer)
49  {
51  }
52  }
53 
54  catch (const std::exception & exc)
55  {
56  if (Observer)
57  {
58  Observer->OnError(exc);
59  }
60  }
61 }
62 
63 void Thread::ThreadProc(Thread * thread)
64 {
65  thread->Run();
66 }
67 
68 } // namespace Common
69 
virtual void OnSuccess()=0
thread exited with Success.
Common::ThreadProc Func
Definition: thread.h:66
Addon interface definition GNU LGPL.
Thread(std::function< void()> f, ThreadObserver *observer=0)
Starts f in a separate thread.
Definition: thread.cpp:18
f
void Run()
Calls in the separate thread from ThreadProc.
Definition: thread.cpp:42
std::thread Impl
Definition: thread.h:67
void Join()
Wait until started thread stop.
Definition: thread.cpp:37
static void ThreadProc(Thread *thread)
static member required for std::thread
Definition: thread.cpp:63
std::function< void()> ThreadProc
Definition: thread.h:32
virtual void OnError(const std::exception &exc)=0
Thread exited with error.
ThreadObserver * Observer
Definition: thread.h:65


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08