Selaa lähdekoodia

Allowing HTTP requests for source servers

Brian Fiete 6 vuotta sitten
vanhempi
commit
c2d086fe8e

+ 41 - 0
BeefLibs/Beefy2D/src/utils/HTTP.bf

@@ -0,0 +1,41 @@
+using System;
+
+namespace Beefy2D.utils
+{
+	class HTTPRequest
+	{
+		public enum HTTPResult
+		{
+			NotDone = -1,
+			Failed = 0,
+			Success = 1
+		}
+
+		void* mNativeNetRequest;
+
+		[StdCall, CLink]
+		static extern void* HTTP_GetFile(char8* url, char8* destPath);
+
+		[StdCall, CLink]
+		static extern int32 HTTP_GetResult(void* netRequest, int32 waitMS);
+
+		[StdCall, CLink]
+		static extern void HTTP_Delete(void* netRequest);
+
+		public ~this()
+		{
+			if (mNativeNetRequest != null)
+				HTTP_Delete(mNativeNetRequest);
+		}
+
+		public void GetFile(StringView url, StringView destPath)
+		{
+			mNativeNetRequest = HTTP_GetFile(url.ToScopeCStr!(), destPath.ToScopeCStr!());
+		}
+
+		public HTTPResult GetResult()
+		{
+			return (HTTPResult)HTTP_GetResult(mNativeNetRequest, 0);
+		}
+	}
+}

+ 1 - 1
BeefySysLib/platform/win/Platform.cpp

@@ -2574,7 +2574,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpDirectory_GetSysDirectory(BfpSysDirectoryKind sy
 		return;
 		return;
 	case BfpSysDirectoryKind_Programs_Common:
 	case BfpSysDirectoryKind_Programs_Common:
 		_GetKnownFolder(FOLDERID_CommonPrograms);
 		_GetKnownFolder(FOLDERID_CommonPrograms);
-		return;
+		return;	
 	}
 	}
 
 
 	TryStringOut(path, outPath, inOutPathLen, (BfpResult*)outResult);
 	TryStringOut(path, outPath, inOutPathLen, (BfpResult*)outResult);

+ 36 - 0
IDEHelper/DebugManager.cpp

@@ -1616,6 +1616,42 @@ BF_EXPORT const char* BF_CALLTYPE Debugger_GetHotResolveData(uint8* outTypeData,
 	return outString.c_str();
 	return outString.c_str();
 }
 }
 
 
+BF_EXPORT NetResult* HTTP_GetFile(char* url, char* destPath)
+{
+	AutoCrit autoCrit(gDebugManager->mNetManager->mThreadPool.mCritSect);
+
+	auto netResult = gDebugManager->mNetManager->QueueGet(url, destPath);	
+	netResult->mDoneEvent = new SyncEvent();
+	return netResult;
+}
+
+BF_EXPORT int HTTP_GetResult(NetResult* netResult, int waitMS)
+{
+	if (netResult->mDoneEvent->WaitFor(waitMS))
+	{
+		return netResult->mFailed ? 0 : 1;
+	}
+	else
+	{
+		return -1;
+	}
+}
+
+BF_EXPORT void HTTP_Delete(NetResult* netResult)
+{
+	if (!netResult->mDoneEvent->WaitFor(0))
+	{
+		///
+		{
+			AutoCrit autoCrit(gDebugManager->mNetManager->mThreadPool.mCritSect);
+			if (netResult->mCurRequest != NULL)
+				netResult->mCurRequest->Cancel();
+		}
+		netResult->mDoneEvent->WaitFor(-1);
+	}				
+	delete netResult;
+}
+
 BF_EXPORT void Debugger_SetAliasPath(char* origPath, char* localPath)
 BF_EXPORT void Debugger_SetAliasPath(char* origPath, char* localPath)
 {
 {
 	gDebugger->SetAliasPath(origPath, localPath);
 	gDebugger->SetAliasPath(origPath, localPath);

+ 6 - 22
IDEHelper/DebugTarget.cpp

@@ -339,25 +339,11 @@ DbgSrcFile* DebugTarget::GetSrcFile(const String& srcFilePath)
 	return srcFile;
 	return srcFile;
 }
 }
 
 
-bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target* outOffset, DbgModule** outDWARF)
+bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target* outOffset, DbgModule** outDWARF, bool allowRemote)
 {	
 {	
 	//TODO: First search for symbol, then determine if the addr is within the defining DbgModule
 	//TODO: First search for symbol, then determine if the addr is within the defining DbgModule
 
 
 	DbgModule* insideDWARF = NULL;
 	DbgModule* insideDWARF = NULL;
-	/*for (auto dbgModule : mDbgModules)
-	{
-		for (int i = 0; i < (int)dbgModule->mSections.size(); i++)
-		{
-			auto section = &dbgModule->mSections[i];
-			if ((addr >= section->mAddrStart + dbgModule->mImageBase) && (addr < section->mAddrStart + dbgModule->mImageBase + section->mAddrLength))
-			{
-				insideDWARF = dbgModule;				
-			}
-		}
-	}*/
-	
-	//mDebugger->ReadMemory(addr, )
-
 	
 	
 	auto dbgModule = FindDbgModuleForAddress(addr);
 	auto dbgModule = FindDbgModuleForAddress(addr);
 	if (dbgModule != NULL)
 	if (dbgModule != NULL)
@@ -385,12 +371,13 @@ bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target*
 		{
 		{
 			if (dbgModule->HasPendingDebugInfo())
 			if (dbgModule->HasPendingDebugInfo())
 			{
 			{
-				if ((dbgModule->WantsAutoLoadDebugInfo()) && (!mDebugger->mPendingDebugInfoLoad.Contains(dbgModule)))
+				if (dbgModule->WantsAutoLoadDebugInfo())
 				{
 				{
-					mDebugger->mPendingDebugInfoLoad.Add(dbgModule);
+					DbgPendingDebugInfoLoad* dbgPendingDebugInfoLoad = NULL;
+					mDebugger->mPendingDebugInfoLoad.TryAdd(dbgModule, NULL, &dbgPendingDebugInfoLoad);					
+					dbgPendingDebugInfoLoad->mModule = dbgModule;
+					dbgPendingDebugInfoLoad->mAllowRemote |= allowRemote;					
 				}
 				}
-
-				//mDebugger->LoadDebugInfoForModule(dbgModule);
 			}
 			}
 
 
 			isInsideSomeSegment = true;
 			isInsideSomeSegment = true;
@@ -402,9 +389,6 @@ bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target*
 	if (!isInsideSomeSegment)
 	if (!isInsideSomeSegment)
 		return false;
 		return false;
 
 
-	//if ((addr < dwSymbol->mDbgModule->mImageBase) || (addr >= dwSymbol->mDbgModule->mImageBase + dwSymbol->mDbgModule->mImageSize))
-		//return false;
-
 	if (dwSymbol == NULL)
 	if (dwSymbol == NULL)
 		return false;
 		return false;
 
 

+ 1 - 1
IDEHelper/DebugTarget.h

@@ -86,7 +86,7 @@ public:
 	DbgSrcFile* AddSrcFile(const String& srcFilePath);
 	DbgSrcFile* AddSrcFile(const String& srcFilePath);
 	DbgSrcFile* GetSrcFile(const String& srcFilePath);
 	DbgSrcFile* GetSrcFile(const String& srcFilePath);
 
 
-	bool FindSymbolAt(addr_target addr, String* outSymbol, addr_target* outOffset = NULL, DbgModule** outDWARF = NULL);
+	bool FindSymbolAt(addr_target addr, String* outSymbol, addr_target* outOffset = NULL, DbgModule** outDWARF = NULL, bool allowRemote = true);
 	addr_target FindSymbolAddr(const StringImpl& name);	
 	addr_target FindSymbolAddr(const StringImpl& name);	
 		
 		
 	addr_target GetStaticAddress(DbgVariable* dwVariable);
 	addr_target GetStaticAddress(DbgVariable* dwVariable);

+ 13 - 4
IDEHelper/NetManager.cpp

@@ -95,7 +95,7 @@ void NetRequest::Cleanup()
 	}
 	}
 }
 }
 
 
-void NetRequest::Perform()
+void NetRequest::DoTransfer()
 {
 {
 	if (mCancelling)
 	if (mCancelling)
 		return;
 		return;
@@ -193,6 +193,11 @@ void NetRequest::Perform()
 	}
 	}
 }
 }
 
 
+void NetRequest::Perform()
+{	
+	DoTransfer();	
+}
+
 #else
 #else
 
 
 #include <windows.h>
 #include <windows.h>
@@ -375,11 +380,16 @@ NetRequest::~NetRequest()
 	{
 	{
 		mResult->mFailed = mFailed;
 		mResult->mFailed = mFailed;
 		mResult->mCurRequest = NULL;
 		mResult->mCurRequest = NULL;
+		if (mResult->mDoneEvent != NULL)
+		{
+			mResult->mDoneEvent->Set();
+			BF_ASSERT(!mResult->mRemoved);
+		}
 		if (mResult->mRemoved)
 		if (mResult->mRemoved)
 			delete mResult;
 			delete mResult;
 	}
 	}
 
 
-	mNetManager->mRequestDoneEvent.Set();
+	mNetManager->mRequestDoneEvent.Set();	
 }
 }
 
 
 void NetRequest::Fail(const StringImpl& error)
 void NetRequest::Fail(const StringImpl& error)
@@ -459,7 +469,7 @@ NetRequest* NetManager::CreateGetRequest(const StringImpl& url, const StringImpl
 NetResult* NetManager::QueueGet(const StringImpl& url, const StringImpl& destPath)
 NetResult* NetManager::QueueGet(const StringImpl& url, const StringImpl& destPath)
 {
 {
 	BfLogDbg("NetManager queueing %s\n", url.c_str());
 	BfLogDbg("NetManager queueing %s\n", url.c_str());
-
+	
 	auto netRequest = CreateGetRequest(url, destPath);
 	auto netRequest = CreateGetRequest(url, destPath);
 	auto netResult = netRequest->mResult;
 	auto netResult = netRequest->mResult;
 	mThreadPool.AddJob(netRequest);
 	mThreadPool.AddJob(netRequest);
@@ -592,4 +602,3 @@ void NetManager::SetCancelOnSuccess(NetResult* dependentResult, NetResult* cance
 		dependentResult->mCurRequest->mCancelOnSuccess = cancelOnSucess;
 		dependentResult->mCurRequest->mCancelOnSuccess = cancelOnSucess;
 	}
 	}
 }
 }
-

+ 12 - 3
IDEHelper/NetManager.h

@@ -40,7 +40,7 @@ public:
 	uint32 mLastUpdateTick;
 	uint32 mLastUpdateTick;
 	bool mShowTracking;
 	bool mShowTracking;
 	NetResult* mResult;	
 	NetResult* mResult;	
-	NetResult* mCancelOnSuccess;
+	NetResult* mCancelOnSuccess;	
 
 
 	NetRequest()
 	NetRequest()
 	{
 	{
@@ -54,13 +54,15 @@ public:
 		mFailed = false;		
 		mFailed = false;		
 		mShowTracking = false;
 		mShowTracking = false;
 		mResult = NULL;
 		mResult = NULL;
-		mCancelOnSuccess = NULL;
+		mCancelOnSuccess = NULL;		
 	}
 	}
 	~NetRequest();
 	~NetRequest();
 
 
+	void DoTransfer();
+
 	void Cleanup();
 	void Cleanup();
 	void Fail(const StringImpl& error);
 	void Fail(const StringImpl& error);
-	bool Cancel() override;
+	bool Cancel() override;	
 	void Perform() override;
 	void Perform() override;
 	void ShowTracking();
 	void ShowTracking();
 };
 };
@@ -73,12 +75,19 @@ public:
 	bool mFailed;
 	bool mFailed;
 	NetRequest* mCurRequest;	
 	NetRequest* mCurRequest;	
 	bool mRemoved;	
 	bool mRemoved;	
+	SyncEvent* mDoneEvent;
 
 
 	NetResult()
 	NetResult()
 	{
 	{
 		mFailed = false;
 		mFailed = false;
 		mCurRequest = NULL;
 		mCurRequest = NULL;
 		mRemoved = false;
 		mRemoved = false;
+		mDoneEvent = NULL;
+	}
+
+	~NetResult()
+	{
+		delete mDoneEvent;
 	}
 	}
 };
 };