1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00
Beef/IDEHelper/NetManager.h

124 lines
2.2 KiB
C
Raw Normal View History

2019-08-23 11:56:54 -07:00
#pragma once
#include "BeefySysLib/Common.h"
#include "BeefySysLib/FileStream.h"
#include "BeefySysLib/util/Deque.h"
#include "BeefySysLib/util/ThreadPool.h"
#include "BeefySysLib/util/Dictionary.h"
NS_BF_BEGIN
2019-09-20 16:07:04 -07:00
#ifdef BF_PLATFORM_WINDOWS
2019-08-23 11:56:54 -07:00
#define BF_CURL
2019-09-20 16:07:04 -07:00
#endif
2019-08-23 11:56:54 -07:00
class DebugManager;
class NetManager;
class NetResult;
#ifdef BF_CURL
typedef void CURL;
2019-09-04 10:27:37 -07:00
typedef void CURLM;
2019-08-23 11:56:54 -07:00
#endif
class NetRequest : public ThreadPool::Job
{
public:
NetManager* mNetManager;
String mURL;
String mOutPath;
String mOutTempPath;
SysFileStream mOutFile;
2019-08-23 11:56:54 -07:00
#ifdef BF_CURL
CURL* mCURL;
2019-09-04 10:27:37 -07:00
CURLM* mCURLMulti;
2019-08-23 11:56:54 -07:00
#else
#endif
2019-09-04 10:27:37 -07:00
volatile bool mCancelling;
2019-08-23 11:56:54 -07:00
bool mFailed;
String mError;
uint32 mLastUpdateTick;
bool mShowTracking;
NetResult* mResult;
NetResult* mCancelOnSuccess;
2019-08-23 11:56:54 -07:00
NetRequest()
{
mLastUpdateTick = 0;
#ifdef BF_CURL
mCURL = NULL;
2019-09-04 10:27:37 -07:00
mCURLMulti = NULL;
2019-08-23 11:56:54 -07:00
#else
#endif
mCancelling = false;
mFailed = false;
mShowTracking = false;
mResult = NULL;
mCancelOnSuccess = NULL;
2019-08-23 11:56:54 -07:00
}
~NetRequest();
void DoTransfer();
2019-08-23 11:56:54 -07:00
void Cleanup();
void Fail(const StringImpl& error);
bool Cancel() override;
2019-08-23 11:56:54 -07:00
void Perform() override;
void ShowTracking();
};
class NetResult
{
public:
String mURL;
String mOutPath;
bool mFailed;
NetRequest* mCurRequest;
bool mRemoved;
SyncEvent* mDoneEvent;
2019-08-23 11:56:54 -07:00
NetResult()
{
mFailed = false;
mCurRequest = NULL;
mRemoved = false;
mDoneEvent = NULL;
}
~NetResult()
{
delete mDoneEvent;
2019-08-23 11:56:54 -07:00
}
};
class NetManager
{
public:
Dictionary<String, NetResult*> mCachedResults;
ThreadPool mThreadPool;
DebugManager* mDebugManager;
Deque<NetRequest*> mRequests;
Array<NetResult*> mOldResults;
SyncEvent mRequestDoneEvent;
NetResult* mWaitingResult;
2019-09-04 10:27:37 -07:00
NetRequest* mWaitingRequest;
2019-08-23 11:56:54 -07:00
public:
NetManager();
~NetManager();
2019-09-23 13:48:11 -07:00
NetRequest* CreateGetRequest(const StringImpl& url, const StringImpl& destPath, bool useCache);
NetResult* QueueGet(const StringImpl& url, const StringImpl& destPath, bool useCache);
2019-08-23 11:56:54 -07:00
bool Get(const StringImpl& url, const StringImpl& destPath);
void CancelAll();
void Clear();
void CancelCurrent();
void Cancel(NetResult* netResult);
void SetCancelOnSuccess(NetResult* dependentResult, NetResult* cancelOnSucess);
};
NS_BF_END