Skip to content

Commit bde19ab

Browse files
committed
turned DMD server into re-usable libraray functionality
1 parent a01e995 commit bde19ab

File tree

5 files changed

+344
-237
lines changed

5 files changed

+344
-237
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ set(DMDUTIL_SOURCES
7676
src/Logger.cpp
7777
src/AlphaNumeric.cpp
7878
src/SceneGenerator.cpp
79+
src/DMDServer.cpp
7980
)
8081

8182
if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux")
@@ -144,7 +145,7 @@ if(BUILD_SHARED)
144145

145146
if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux")
146147
add_executable(dmdserver
147-
src/dmdServer.cpp
148+
src/server.cpp
148149
src/Logger.cpp
149150
)
150151
target_link_libraries(dmdserver PUBLIC dmdutil_shared)

include/DMDUtil/DMDServer.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include <atomic>
4+
#include <mutex>
5+
#include <thread>
6+
#include <vector>
7+
8+
#include "DMDUtil/DMD.h"
9+
#include "sockpp/tcp_acceptor.h"
10+
11+
#define DMDSERVER_MAX_WIDTH 256
12+
#define DMDSERVER_MAX_HEIGHT 64
13+
14+
namespace DMDUtil
15+
{
16+
17+
class DMDUTILAPI DMDServer
18+
{
19+
public:
20+
DMDServer(DMD* dmd, bool fixedAltColorPath = false, bool fixedPupPath = false);
21+
~DMDServer();
22+
23+
bool Start(const char* addr, in_port_t port);
24+
void Stop();
25+
bool IsRunning() const { return m_running; }
26+
27+
private:
28+
void AcceptLoop();
29+
void ClientThread(sockpp::tcp_socket sock, uint32_t threadId);
30+
31+
DMD* m_dmd;
32+
bool m_fixedAltColorPath;
33+
bool m_fixedPupPath;
34+
std::atomic<bool> m_running{false};
35+
sockpp::tcp_acceptor m_acceptor;
36+
37+
uint32_t m_currentThreadId{0};
38+
std::mutex m_threadMutex;
39+
uint32_t m_disconnectOtherClients{0};
40+
std::vector<uint32_t> m_threads;
41+
std::thread* m_acceptThread{nullptr};
42+
};
43+
44+
} // namespace DMDUtil

include/DMDUtil/DMDUtil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
#include "LevelDMD.h"
1818
#include "RGB24DMD.h"
1919
#include "SceneGenerator.h"
20+
#include "DMDServer.h"

0 commit comments

Comments
 (0)