simplemqttserverthread.h 1.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * simplemqttserverthread.h
 *
 *  Created on: May 3, 2013
 *      Author: Axel Auweter
 */

#ifndef SIMPLEMQTTSERVERTHREAD_H_
#define SIMPLEMQTTSERVERTHREAD_H_

class SimpleMQTTServerThread
{
protected:
  pthread_t t;
  bool terminate;

17
18
  boost::mutex cleanupMtx;

19
  static void* launch(void* thisPtr);
20
  static void yield();
21
22
23
24
25
26
27
28
29
30
31
32
33
  virtual void run() = 0;

public:
  SimpleMQTTServerThread();
  virtual
  ~SimpleMQTTServerThread();
};

class SimpleMQTTServerMessageThread : SimpleMQTTServerThread
{
protected:
  int numConnections;
  struct pollfd fds[SimpleMQTTConnectionsPerThread];
34
  SimpleMQTTMessage* msg[SimpleMQTTConnectionsPerThread];
35
  boost::mutex fdsMtx;
36
  SimpleMQTTMessageCallback messageCallback;
37
38
39
40
41
42
43

  void run();

public:
  void assignConnection(int newsock);
  void releaseConnection(int connectionId);
  bool hasCapacity();
44
  void setMessageCallback(SimpleMQTTMessageCallback callback);
45

46
  SimpleMQTTServerMessageThread(SimpleMQTTMessageCallback callback);
47
48
49
50
51
52
53
54
55
  virtual
  ~SimpleMQTTServerMessageThread();
};

class SimpleMQTTServerAcceptThread : SimpleMQTTServerThread
{
protected:
  int socket;
  boost::ptr_list<SimpleMQTTServerMessageThread> messageThreads;
56
57
58
  SimpleMQTTMessageCallback messageCallback;

  void run();
59
60

public:
61
62
63
  void setMessageCallback(SimpleMQTTMessageCallback callback);

  SimpleMQTTServerAcceptThread(int listenSock, SimpleMQTTMessageCallback callback);
64
65
66
67
68
  virtual
  ~SimpleMQTTServerAcceptThread();
};

#endif /* SIMPLEMQTTSERVERTHREAD_H_ */