-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyflx.h
93 lines (83 loc) · 2.45 KB
/
pyflx.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
// pyflx.h
#if !defined(__PYFLX_H)
#define __PYFLX_H
#include "Python.h"
//Boost Header files
#include <boost/python.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/python/overloads.hpp>
#include <boost/python/call_method.hpp>
#include <iostream>
#include <locale.h>
#include <set>
#include "CSymProxy.h"
#include "CSymData.h"
#include "CCommand.h"
#include "SymConnection.h"
#include "SymListener.h"
class CSymProxy;
class CSymConnection;
class CSymListener;
class Symproxy : public CSymProxy {
public:
Symproxy();
virtual ~Symproxy();
bool initialize(int nBindPort);
int getFd();
int select();
bool checkSocket();
bool closeClient();
bool dispatch();
virtual bool OnLogon(const char *szUserName, const char *szPassword);
virtual void OnSubscribe(const char* szTopic);
virtual void OnUnsubscribe(const char* szTopic);
void onLogon(PyObject *callable);
void onSubscribe(PyObject *callable);
void onUnsubscribe(PyObject *callable);
void publish(const char* szTopic, boost::python::dict data);
private:
int nFd;
int nCount;
int nPort;
fd_set readF;
struct timeval tmInit;
struct timeval tm;
PyObject *onLogonCallback;
PyObject *onSubscribeCallback;
PyObject *onUnsubscribeCallback;
};
class Symlistener : public CSymListener {
public:
Symlistener();
virtual ~Symlistener();
virtual bool connect(const char *host, int port, const char *username, const char *password);
void dispatchEvents();
bool subscribeAll();
bool unsubscribeAll();
bool subscribe(const char *szTopic);
bool unsubscribe(const char *szTopic);
void loop();
virtual void OnData(const char *szTopic, const CSymData *pData);
void onData(PyObject *callable);
void disconnect();
private:
CSymConnection *pConn;
PyObject *onDataCallback;
int m_nVal;
double m_dblVal;
GrowingStr m_sVal;
char m_cVal;
boost::python::dict m_Dict;
};
class py_error {
public:
py_error(const std::string str) {_str = str;}
~py_error() {}
std::string what() const {return _str;}
private:
std::string _str;
};
#endif // __PYFLX_H