-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Salavat
committed
Nov 7, 2022
1 parent
205e68d
commit 42b32d4
Showing
3 changed files
with
283 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_ANDROID) || defined(__EMSCRIPTEN__) | ||
#include <dmsdk/sdk.h> | ||
#include <stdlib.h> // free | ||
|
||
#include "native_logger_utils.h" | ||
|
||
static void PushError(lua_State* L, const char* error) | ||
{ | ||
// Could be extended with error codes etc | ||
if (error != 0) { | ||
lua_newtable(L); | ||
lua_pushstring(L, "error"); | ||
lua_pushstring(L, error); | ||
lua_rawset(L, -3); | ||
} else { | ||
lua_pushnil(L); | ||
} | ||
} | ||
|
||
void dmNativeLogger::QueueCreate(CommandQueue* queue) | ||
{ | ||
queue->m_Mutex = dmMutex::New(); | ||
} | ||
|
||
void dmNativeLogger::QueueDestroy(CommandQueue* queue) | ||
{ | ||
{ | ||
DM_MUTEX_SCOPED_LOCK(queue->m_Mutex); | ||
queue->m_Commands.SetSize(0); | ||
} | ||
dmMutex::Delete(queue->m_Mutex); | ||
} | ||
|
||
void dmNativeLogger::QueuePush(CommandQueue* queue, Command* cmd) | ||
{ | ||
DM_MUTEX_SCOPED_LOCK(queue->m_Mutex); | ||
|
||
if(queue->m_Commands.Full()) | ||
{ | ||
queue->m_Commands.OffsetCapacity(2); | ||
} | ||
queue->m_Commands.Push(*cmd); | ||
} | ||
|
||
void dmNativeLogger::QueueFlush(CommandQueue* queue, CommandFn fn) | ||
{ | ||
assert(fn != 0); | ||
if (queue->m_Commands.Empty()) | ||
{ | ||
return; | ||
} | ||
|
||
dmArray<Command> tmp; | ||
{ | ||
DM_MUTEX_SCOPED_LOCK(queue->m_Mutex); | ||
tmp.Swap(queue->m_Commands); | ||
} | ||
|
||
for(uint32_t i = 0; i != tmp.Size(); ++i) | ||
{ | ||
fn(&tmp[i]); | ||
} | ||
} | ||
|
||
#endif // DM_PLATFORM_ANDROID || DM_PLATFORM_IOS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_ANDROID) || defined(__EMSCRIPTEN__) | ||
#ifndef DM_PUSH_UTILS | ||
#define DM_PUSH_UTILS | ||
|
||
#include <dmsdk/sdk.h> | ||
|
||
namespace dmNativeLogger | ||
{ | ||
struct Command | ||
{ | ||
Command() | ||
{ | ||
memset(this, 0, sizeof(Command)); | ||
} | ||
int32_t m_Severity; | ||
const char* m_Domain; | ||
const char* m_Message; | ||
}; | ||
|
||
struct CommandQueue | ||
{ | ||
dmArray<Command> m_Commands; | ||
dmMutex::HMutex m_Mutex; | ||
}; | ||
|
||
typedef void (*CommandFn)(Command* cmd); | ||
|
||
void QueueCreate(CommandQueue* queue); | ||
void QueueDestroy(CommandQueue* queue); | ||
void QueuePush(CommandQueue* queue, Command* cmd); | ||
void QueueFlush(CommandQueue* queue, CommandFn fn); | ||
} | ||
|
||
#endif | ||
#endif // DM_PLATFORM_ANDROID || DM_PLATFORM_IOS || __EMSCRIPTEN__ |