ddnet/src/engine/shared/jobs.h
heinrich5991 36694d3852 Add a way to call for external moderator help
This is done by HTTP POSTing to a location specified by
`sv_modhelp_url`. We also provide a `src/modhelp/server.py` which can
use theses POSTs to forward them to Discord servers.

The POST contains a JSON object payload, with the keys `"port"` which
contains the server port, `"player_id"` which contains the calling
player's client ID, `"player_name"` which contains the calling player's
nick and `"message"` which is the user-specified message.

Make JSON-escaping function public, add tests and fix bugs uncovered by
these tests.

Supersedes #1129.
2018-06-19 23:27:35 +02:00

64 lines
1 KiB
C++

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef ENGINE_SHARED_JOBS_H
#define ENGINE_SHARED_JOBS_H
#include <base/system.h>
#include <atomic>
#include <memory>
class IJob;
class CJobPool;
class IJob
{
friend CJobPool;
private:
std::shared_ptr<IJob> m_pNext;
std::atomic<int> m_Status;
virtual void Run() = 0;
public:
IJob();
IJob(const IJob &Other);
IJob &operator=(const IJob &Other);
virtual ~IJob();
int Status();
enum
{
STATE_PENDING=0,
STATE_RUNNING,
STATE_DONE
};
};
class CJobPool
{
enum
{
MAX_THREADS=32
};
int m_NumThreads;
void *m_apThreads[MAX_THREADS];
std::atomic<bool> m_Shutdown;
LOCK m_Lock;
SEMAPHORE m_Semaphore;
std::shared_ptr<IJob> m_pFirstJob;
std::shared_ptr<IJob> m_pLastJob;
static void WorkerThread(void *pUser);
public:
CJobPool();
~CJobPool();
void Init(int NumThreads);
void Add(std::shared_ptr<IJob> pJob);
};
#endif