2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-06-12 17:02:52 -04:00
|
|
|
|
|
|
|
|
/*=============================================================================
|
|
|
|
|
NetworkFileServerHttp.h: Declares the NetworkFileServerHttp class.
|
|
|
|
|
|
|
|
|
|
This allows NFS to use a http server for serving Unreal Files.
|
|
|
|
|
|
|
|
|
|
=============================================================================*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-06-13 13:25:24 -04:00
|
|
|
#if ENABLE_HTTP_FOR_NFS
|
2014-11-06 15:46:19 -05:00
|
|
|
|
|
|
|
|
#if PLATFORM_WINDOWS
|
|
|
|
|
#include "AllowWindowsPlatformTypes.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "libwebsockets.h"
|
|
|
|
|
|
|
|
|
|
#if PLATFORM_WINDOWS
|
|
|
|
|
#include "HideWindowsPlatformTypes.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2014-06-12 17:02:52 -04:00
|
|
|
class FNetworkFileServerHttp
|
|
|
|
|
: public INetworkFileServer // It is a NetworkFileServer
|
|
|
|
|
, private FRunnable // Also spins up a thread but others don't need to know.
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FNetworkFileServerHttp(int32 InPort, const FFileRequestDelegate* InFileRequestDelegate,
|
|
|
|
|
const FRecompileShadersDelegate* InRecompileShadersDelegate, const TArray<ITargetPlatform*>& InActiveTargetPlatforms );
|
|
|
|
|
|
|
|
|
|
// INetworkFileServer Interface.
|
|
|
|
|
|
|
|
|
|
virtual bool IsItReadyToAcceptConnections(void) const;
|
2014-07-07 15:39:19 -04:00
|
|
|
virtual FString GetSupportedProtocol() const override;
|
|
|
|
|
virtual bool GetAddressList(TArray<TSharedPtr<FInternetAddr> >& OutAddresses) const override;
|
2014-06-12 17:02:52 -04:00
|
|
|
virtual int32 NumConnections() const;
|
|
|
|
|
virtual void Shutdown();
|
|
|
|
|
|
|
|
|
|
virtual ~FNetworkFileServerHttp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// static functions. callbacks for libwebsocket.
|
|
|
|
|
static int CallBack_HTTP( struct libwebsocket_context *context,
|
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
|
enum libwebsocket_callback_reasons reason, void *user,
|
|
|
|
|
void *in, size_t len);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
//FRunnable Interface.
|
|
|
|
|
virtual bool Init();
|
|
|
|
|
virtual uint32 Run();
|
|
|
|
|
virtual void Stop();
|
|
|
|
|
virtual void Exit();
|
|
|
|
|
|
2014-08-18 16:55:29 -04:00
|
|
|
static void Process (FArchive&, TArray<uint8>&, FNetworkFileServerHttp* );
|
2014-06-12 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// factory method for creating a new Client Connection.
|
2014-08-18 16:55:29 -04:00
|
|
|
class FNetworkFileServerClientConnectionHTTP* CreateNewConnection();
|
2014-06-12 17:02:52 -04:00
|
|
|
|
|
|
|
|
// Holds a delegate to be invoked on every sync request.
|
|
|
|
|
FFileRequestDelegate FileRequestDelegate;
|
|
|
|
|
|
|
|
|
|
// Holds a delegate to be invoked when a client requests a shader recompile.
|
|
|
|
|
FRecompileShadersDelegate RecompileShadersDelegate;
|
|
|
|
|
|
|
|
|
|
// cached copy of the active target platforms (if any)
|
|
|
|
|
const TArray<ITargetPlatform*> ActiveTargetPlatforms;
|
|
|
|
|
|
|
|
|
|
// libwebsocket context. All access to the library happens via this context.
|
2014-07-21 04:38:16 -04:00
|
|
|
struct libwebsocket_context *Context;
|
2014-06-12 17:02:52 -04:00
|
|
|
|
|
|
|
|
// Service Http connections on this thread.
|
|
|
|
|
FRunnableThread* WorkerThread;
|
|
|
|
|
|
|
|
|
|
// port on which this http server runs.
|
2014-07-07 15:39:19 -04:00
|
|
|
int32 Port;
|
2014-06-12 17:02:52 -04:00
|
|
|
|
|
|
|
|
// used to send simple message.
|
|
|
|
|
FThreadSafeCounter StopRequested;
|
|
|
|
|
|
|
|
|
|
// Has successfully Initialized;
|
|
|
|
|
FThreadSafeCounter Ready;
|
|
|
|
|
|
|
|
|
|
// Clients being served.
|
2014-08-18 16:55:29 -04:00
|
|
|
TMap< FGuid, FNetworkFileServerClientConnectionHTTP* > RequestHandlers;
|
2014-06-12 17:02:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|