diff --git a/BeefLibs/Beefy2D/src/utils/HTTP.bf b/BeefLibs/Beefy2D/src/utils/HTTP.bf new file mode 100644 index 00000000..cbf0455b --- /dev/null +++ b/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); + } + } +} diff --git a/BeefySysLib/platform/win/Platform.cpp b/BeefySysLib/platform/win/Platform.cpp index a445bf96..e6d647e1 100644 --- a/BeefySysLib/platform/win/Platform.cpp +++ b/BeefySysLib/platform/win/Platform.cpp @@ -2574,7 +2574,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpDirectory_GetSysDirectory(BfpSysDirectoryKind sy return; case BfpSysDirectoryKind_Programs_Common: _GetKnownFolder(FOLDERID_CommonPrograms); - return; + return; } TryStringOut(path, outPath, inOutPathLen, (BfpResult*)outResult); diff --git a/IDEHelper/DebugManager.cpp b/IDEHelper/DebugManager.cpp index bf33bc0c..a4f31518 100644 --- a/IDEHelper/DebugManager.cpp +++ b/IDEHelper/DebugManager.cpp @@ -1616,6 +1616,42 @@ BF_EXPORT const char* BF_CALLTYPE Debugger_GetHotResolveData(uint8* outTypeData, 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) { gDebugger->SetAliasPath(origPath, localPath); diff --git a/IDEHelper/DebugTarget.cpp b/IDEHelper/DebugTarget.cpp index 5e8b6410..80c90e1e 100644 --- a/IDEHelper/DebugTarget.cpp +++ b/IDEHelper/DebugTarget.cpp @@ -339,25 +339,11 @@ DbgSrcFile* DebugTarget::GetSrcFile(const String& srcFilePath) 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 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); if (dbgModule != NULL) @@ -385,12 +371,13 @@ bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target* { 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; @@ -402,9 +389,6 @@ bool DebugTarget::FindSymbolAt(addr_target addr, String* outSymbol, addr_target* if (!isInsideSomeSegment) return false; - //if ((addr < dwSymbol->mDbgModule->mImageBase) || (addr >= dwSymbol->mDbgModule->mImageBase + dwSymbol->mDbgModule->mImageSize)) - //return false; - if (dwSymbol == NULL) return false; diff --git a/IDEHelper/DebugTarget.h b/IDEHelper/DebugTarget.h index 7831579c..7e4263fb 100644 --- a/IDEHelper/DebugTarget.h +++ b/IDEHelper/DebugTarget.h @@ -86,7 +86,7 @@ public: DbgSrcFile* AddSrcFile(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 GetStaticAddress(DbgVariable* dwVariable); diff --git a/IDEHelper/NetManager.cpp b/IDEHelper/NetManager.cpp index 2d8c35b6..4e56600c 100644 --- a/IDEHelper/NetManager.cpp +++ b/IDEHelper/NetManager.cpp @@ -95,7 +95,7 @@ void NetRequest::Cleanup() } } -void NetRequest::Perform() +void NetRequest::DoTransfer() { if (mCancelling) return; @@ -193,6 +193,11 @@ void NetRequest::Perform() } } +void NetRequest::Perform() +{ + DoTransfer(); +} + #else #include @@ -375,11 +380,16 @@ NetRequest::~NetRequest() { mResult->mFailed = mFailed; mResult->mCurRequest = NULL; + if (mResult->mDoneEvent != NULL) + { + mResult->mDoneEvent->Set(); + BF_ASSERT(!mResult->mRemoved); + } if (mResult->mRemoved) delete mResult; } - mNetManager->mRequestDoneEvent.Set(); + mNetManager->mRequestDoneEvent.Set(); } 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) { BfLogDbg("NetManager queueing %s\n", url.c_str()); - + auto netRequest = CreateGetRequest(url, destPath); auto netResult = netRequest->mResult; mThreadPool.AddJob(netRequest); @@ -592,4 +602,3 @@ void NetManager::SetCancelOnSuccess(NetResult* dependentResult, NetResult* cance dependentResult->mCurRequest->mCancelOnSuccess = cancelOnSucess; } } - diff --git a/IDEHelper/NetManager.h b/IDEHelper/NetManager.h index d3f62a8e..eb73e5fe 100644 --- a/IDEHelper/NetManager.h +++ b/IDEHelper/NetManager.h @@ -40,7 +40,7 @@ public: uint32 mLastUpdateTick; bool mShowTracking; NetResult* mResult; - NetResult* mCancelOnSuccess; + NetResult* mCancelOnSuccess; NetRequest() { @@ -54,13 +54,15 @@ public: mFailed = false; mShowTracking = false; mResult = NULL; - mCancelOnSuccess = NULL; + mCancelOnSuccess = NULL; } ~NetRequest(); + void DoTransfer(); + void Cleanup(); void Fail(const StringImpl& error); - bool Cancel() override; + bool Cancel() override; void Perform() override; void ShowTracking(); }; @@ -73,12 +75,19 @@ public: bool mFailed; NetRequest* mCurRequest; bool mRemoved; + SyncEvent* mDoneEvent; NetResult() { mFailed = false; mCurRequest = NULL; mRemoved = false; + mDoneEvent = NULL; + } + + ~NetResult() + { + delete mDoneEvent; } };