Subversion Repositories HomeAutomation

Rev

Rev 984 | Rev 1026 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 984 Rev 999
Line 48... Line 48...
48
#include "../Threads/threadsafequeue.h"
48
#include "../Threads/threadsafequeue.h"
49
#include "../Tools/tools.h"
49
#include "../Tools/tools.h"
50
 
50
 
51
#include "socketexception.h"
51
#include "socketexception.h"
52
#include "socketevent.h"
52
#include "socketevent.h"
-
 
53
#include "socketeventcallback.h"
53
 
54
 
54
const int MAXBUFFER = 1024;
55
const int MAXBUFFER = 1024;
55
const int MAXCONNECTIONS = 10;
56
const int MAXCONNECTIONS = 10;
56
 
57
 
57
class AsyncSocket : public Thread<AsyncSocket>
58
class AsyncSocket : public Thread<AsyncSocket>
Line 60... Line 61...
60
    AsyncSocket();
61
    AsyncSocket();
61
    ~AsyncSocket();
62
    ~AsyncSocket();
62
 
63
 
63
    void run();
64
    void run();
64
 
65
 
65
    string getId() { return myId; };
66
    int getId() { return myId; };
66
    bool isConnected() { return mySocket != -1; };
67
    bool isConnected() { return mySocket != -1; };
67
 
68
 
68
    void forceReconnect() { myForceReconnect = true; };
69
    void forceReconnect() { myForceReconnect = true; };
69
    void setReconnectTimeout(unsigned int reconnectTimeout) { myReconnectTimeout = reconnectTimeout; };
70
    void setReconnectTimeout(unsigned int reconnectTimeout) { myReconnectTimeout = reconnectTimeout; };
70
    unsigned int getReconnectTimeout() { return myReconnectTimeout; };
71
    unsigned int getReconnectTimeout() { return myReconnectTimeout; };
Line 87... Line 88...
87
   
88
   
88
    void startListen();
89
    void startListen();
89
    bool accept(AsyncSocket* newSocket);
90
    bool accept(AsyncSocket* newSocket);
90
   
91
   
91
 
92
 
92
   
-
 
-
 
93
    void eventSetCallback(SocketEventCallback *eventCallback);
93
 
94
 
94
protected:
95
protected:
95
    void reconnectLoop();
96
    void reconnectLoop();
96
    void create();
97
    void create();
97
 
98
 
98
    void connect();
99
    void connect();
99
   
100
   
100
    void silentClose();
101
    void silentClose();
101
    void close();
102
    void close();
102
 
103
 
103
 
104
 
104
private:
105
private:
105
    string myId;
106
    int myId;
106
    string myAddress;
107
    string myAddress;
107
    int myPort;
108
    int myPort;
108
    unsigned int myReconnectTimeout;
109
    unsigned int myReconnectTimeout;
109
    int mySocket;
110
    int mySocket;
110
    bool myForceReconnect;
111
    bool myForceReconnect;
111
    sockaddr_in myAddressStruct;
112
    sockaddr_in myAddressStruct;
-
 
113
 
112
 
114
 
113
    Semaphore myEventSemaphore;
115
    Semaphore myEventSemaphore;
114
    ThreadSafeQueue<SocketEvent> myEventQueue;
116
    ThreadSafeQueue<SocketEvent> myEventQueue;
-
 
117
    SocketEventCallback *myEventCallback;
115
    void eventAdd(unsigned int eventType, string eventData);
118
    void eventAdd(unsigned int eventType, string eventData);
116
    void eventAdd(unsigned int eventType);
119
    void eventAdd(unsigned int eventType);
117
 
120
 
118
    bool receiveData();
121
    bool receiveData();
119
};
122
};