-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCCPomelo.h
115 lines (83 loc) · 2.65 KB
/
CCPomelo.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
//
// Created by xudexin on 13-4-17.
//
//
#ifndef __CCPomelo__
#define __CCPomelo__
#include "cocos2d.h"
#include "jansson.h"
#include "pomelo.h"
#include<queue>
using namespace cocos2d;
class CCPomeloContent_;
class CCPomeloReponse_;
class CCPomeloEvent_ ;
class CCPomeloNotify_;
class CCPomeloConnect_;
class CCPomeloReponse:public cocos2d::CCObject{
public:
CCPomeloReponse(){}
~CCPomeloReponse(){}
const char* rout;
int status;
json_t *docs;
};
class CCPomelo :public cocos2d::CCObject{
public:
static CCPomelo *getInstance();
static void destroyInstance();
int connect(const char* addr,int port);
void asyncConnect(const char* addr,int port,CCObject* pTarget, SEL_CallFuncND pSelector);
void stop();
int request(const char*route,json_t *msg,CCObject* pTarget, SEL_CallFuncND pSelector);
int notify(const char*route,json_t *msg,CCObject* pTarget, SEL_CallFuncND pSelector);
int addListener(const char* event,CCObject* pTarget, SEL_CallFuncND pSelector);
void removeListener(const char* event);
public:
CCPomelo();
virtual ~CCPomelo();
void cleanup();
void cleanupEventContent();
void cleanupNotifyContent();
void cleanupRequestContent();
void dispatchCallbacks(float delta);
void lockReponsQeueue();
void unlockReponsQeueue();
void lockEventQeueue();
void unlockEventQeueue();
void lockNotifyQeueue();
void unlockNotifyQeueue();
void lockConnectContent();
void unlockConnectContent();
void pushReponse(CCPomeloReponse_*resp);
void pushEvent(CCPomeloEvent_*ev);
void pushNotiyf(CCPomeloNotify_*ntf);
void connectCallBack(int status);
private:
void incTaskCount();
void desTaskCount();
CCPomeloReponse_*popReponse();
CCPomeloEvent_*popEvent();
CCPomeloNotify_*popNotify();
std::map<pc_notify_t*,CCPomeloContent_*> notify_content;
pthread_mutex_t notify_queue_mutex;
std::queue<CCPomeloNotify_*> notify_queue;
std::map<std::string,CCPomeloContent_*> event_content;
pthread_mutex_t event_queue_mutex;
std::queue<CCPomeloEvent_*> event_queue;
std::map<pc_request_t *,CCPomeloContent_*> request_content;
pthread_mutex_t reponse_queue_mutex;
std::queue<CCPomeloReponse_*> reponse_queue;
pthread_mutex_t connect_mutex;
CCPomeloConnect_* connect_content;
pthread_mutex_t task_count_mutex;
void dispatchRequest();
void dispatchEvent();
void dispatchNotify();
void connectCallBack();
pc_client_t *client;
int task_count;
int connect_status;
};
#endif /* defined(__CCPomelo__) */