Btk
Btk.hpp
1 #if !defined(_BTK_HPP_)
2 #define _BTK_HPP_
3 #include <exception>
4 #include <cstdint>
5 #include <cstdlib>
6 #include <memory>
7 #include <tuple>
8 #include "defs.hpp"
9 #include "impl/invoker.hpp"
10 #include "window.hpp"
11 namespace Btk{
12 
13  typedef bool(*ExceptionHandler)(std::exception*);
14  BTKAPI ExceptionHandler SetExceptionHandler(ExceptionHandler);
20  BTKAPI void Exit(int code = EXIT_SUCCESS);
21  BTKAPI void Init();
28  BTKAPI void AtExit(void(* fn)(void*),void *data);
29  BTKAPI void AtExit(void(* fn)());
30 
31  template<class Callable,class ...Args>
32  void AtExit(Callable &&callable,Args ...args){
33  auto *invoker = new Impl::Invoker<Callable,Args...>{
34  {std::forward<Args>(args)...},
35  std::forward<Callable>(callable)
36  };
37  void *data = invoker;
38  void (*fn)(void*) = Impl::Invoker<Callable,Args...>::Run;
39  AtExit(fn,data);
40  }
47  BTKAPI void DeferCall(void(* fn)(void*),void *data);
48  BTKAPI void DeferCall(void(* fn)());
49 
50  template<class Callable,class ...Args>
51  void DeferCall(Callable &&callable,Args ...args){
52  auto *invoker = new Impl::Invoker<Callable,Args...>{
53  {std::forward<Args>(args)...},
54  std::forward<Callable>(callable)
55  };
56  void *data = invoker;
57  void (*fn)(void*) = Impl::Invoker<Callable,Args...>::Run;
58  DeferCall(fn,data);
59  }
65  BTKAPI bool IsMainThread();
72  BTKAPI bool CouldBlock();
78  BTKAPI int run();
79 };
80 
81 #endif // _BTK_HPP_
BTKAPI bool CouldBlock()
Check is not the main thread or Main EventLoop is not running.
Definition: core.cpp:436
This header include many useful containers.
Definition: async.hpp:7
BTKAPI void DeferCall(void(*fn)(void *), void *data)
This function will be called in main EventLoop.
Definition: core.cpp:421
BTKAPI void Exit(int code=EXIT_SUCCESS)
End the event loop.
Definition: core.cpp:402
BTKAPI bool IsMainThread()
Check is main thread(which call Btk::run)
Definition: core.cpp:433
BTKAPI void AtExit(void(*fn)(void *), void *data)
Regitser atexit callback.
Definition: core.cpp:413
BTKAPI int run()
Enter the EventLoop.
Definition: core.cpp:58