forked from fnc12/Mitsoko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDispatch.hpp
59 lines (45 loc) · 1.36 KB
/
Dispatch.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Dispatch.hpp
// Jako
//
// Created by John Zakharov on 20.03.16.
// Copyright © 2016 Outlaw Studio. All rights reserved.
//
#ifndef __VIPER_DISPATCH_H
#define __VIPER_DISPATCH_H
#ifdef __APPLE__
#include <dispatch/dispatch.h>
#else
#include "AndroidUtil/AndroidUtil.hpp"
#endif
#include <functional>
#include <map>
#include <mutex>
#include <vector>
namespace Mitsoko{
struct Dispatch{
#ifdef __ANDROID__
protected:
typedef std::map<int,std::function<void()>> Callbacks;
static Callbacks callbacks;
static std::mutex callbacksMutex;
static std::mutex mainThreadHandlersMutex;
static int callbackId;
static android::os::Handler mainThreadHandler;
public:
static void postCallback(int callbackId,bool isMainThread);
/**
* Creates android.os.Handler object. Should be called once
* and from main thread only before any 'onMainThread' call.
*/
static void initMainThreadHandler();
#endif
public:
static void onBackground(std::function<void()> functionPointer);
static void onMainThread(std::function<void()> functionPointer);
};
// syntax sugar..
void operator--(std::function<void()> f);
void operator++(std::function<void()> f);
}
#endif /* __VIPER_DISPATCH_H */