2016-06-15 16:38:37 +06:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
|
|
|
|
#define BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
|
|
|
|
|
2016-06-15 21:36:20 +06:00
|
|
|
#include "backends/networking/sdl_net/client.h"
|
2016-06-16 14:19:18 +06:00
|
|
|
#include "common/callback.h"
|
|
|
|
#include "common/hash-str.h"
|
2016-06-15 16:38:37 +06:00
|
|
|
#include "common/singleton.h"
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
|
|
|
typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
|
|
|
|
typedef struct _TCPsocket *TCPsocket;
|
|
|
|
|
|
|
|
namespace Networking {
|
|
|
|
|
|
|
|
class LocalWebserver : public Common::Singleton<LocalWebserver> {
|
|
|
|
static const uint32 FRAMES_PER_SECOND = 20;
|
|
|
|
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
|
|
|
|
static const uint32 SERVER_PORT = 12345;
|
|
|
|
static const uint32 MAX_CONNECTIONS = 10;
|
|
|
|
|
2016-06-16 14:19:18 +06:00
|
|
|
typedef Common::BaseCallback<Client &> *ClientHandler;
|
|
|
|
|
2016-06-15 16:38:37 +06:00
|
|
|
friend void localWebserverTimer(void *); //calls handle()
|
|
|
|
|
|
|
|
SDLNet_SocketSet _set;
|
|
|
|
TCPsocket _serverSocket;
|
2016-06-15 21:36:20 +06:00
|
|
|
Client _client[MAX_CONNECTIONS];
|
2016-06-15 16:38:37 +06:00
|
|
|
int _clients;
|
|
|
|
bool _timerStarted;
|
2016-06-16 14:19:18 +06:00
|
|
|
Common::HashMap<Common::String, ClientHandler> _pathHandlers;
|
2016-06-15 16:38:37 +06:00
|
|
|
|
|
|
|
void startTimer(int interval = TIMER_INTERVAL);
|
|
|
|
void stopTimer();
|
|
|
|
void handle();
|
2016-06-15 21:36:20 +06:00
|
|
|
void handleClient(uint32 i);
|
|
|
|
void acceptClient();
|
2016-06-15 23:54:53 +06:00
|
|
|
void setClientGetHandler(Client &client, Common::String response, long code = 200);
|
2016-06-15 16:38:37 +06:00
|
|
|
|
|
|
|
public:
|
|
|
|
LocalWebserver();
|
|
|
|
virtual ~LocalWebserver();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
2016-06-16 14:19:18 +06:00
|
|
|
void addPathHandler(Common::String path, ClientHandler handler);
|
2016-06-15 16:38:37 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Shortcut for accessing the local webserver. */
|
|
|
|
#define LocalServer Networking::LocalWebserver::instance()
|
|
|
|
|
|
|
|
} // End of namespace Networking
|
|
|
|
|
|
|
|
#endif
|