1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-04 01:23:21 +00:00

1. Modified WebRTC_DataChannel to use union, to simplify struct def

2. Added ChainLink MetaData
3. Added 'ChainViewer' to allow JS to debug Chain events
This commit is contained in:
Bryan Roe
2019-02-01 23:33:02 -08:00
parent 88c63b2976
commit aeaa229e31
17 changed files with 148 additions and 32 deletions

View File

@@ -239,6 +239,7 @@ void ILibDuktape_Debugger_AsyncWaitConn(ILibDuktape_Debugger *dbg)
if (dbg->chainedObject == NULL)
{
dbg->chainedObject = ILibChain_Link_Allocate(sizeof(ILibChain_Link), sizeof(void*));
dbg->chainedObject->MetaData = "ILibDuktape_Debugger_AsyncWaitConn";
((void**)dbg->chainedObject->ExtraMemoryPtr)[0] = dbg;
dbg->chainedObject->PreSelectHandler = ILibDuktape_Debugger_AsyncWaitConn_PreSelect;
dbg->chainedObject->PostSelectHandler = ILibDuktape_Debugger_AsyncWaitConn_PostSelect;

View File

@@ -1086,6 +1086,7 @@ void ILibDuktape_HECI_Push(duk_context *ctx, void *chain)
duk_put_prop_string(ctx, -2, ILibDuktape_HECI_Descriptor); // [HECI]
HECI_chainLink *hlink = ILibMemory_Allocate(sizeof(HECI_chainLink), 0, NULL, NULL);
hlink->link.MetaData = "ILibDuktape_HECI";
hlink->ctx = ctx;
hlink->descriptor = h;
hlink->link.PreSelectHandler = ILibDuktape_HECI_PreSelect;

View File

@@ -1809,6 +1809,82 @@ void ILibDuktape_Polyfills_JS_Init(duk_context *ctx)
}
void ILibDuktape_ChainViewer_PostSelect(void* object, int slct, fd_set *readset, fd_set *writeset, fd_set *errorset)
{
duk_context *ctx = (duk_context*)((void**)((ILibTransport*)object)->ChainLink.ExtraMemoryPtr)[0];
void *hptr = ((void**)((ILibTransport*)object)->ChainLink.ExtraMemoryPtr)[1];
int i;
ILibDuktape_EventEmitter_SetupEmit(ctx, hptr, "PostSelect"); // [emit][this][name]
duk_push_int(ctx, slct); // [emit][this][name][select]
duk_push_array(ctx); // [emit][this][name][select][readset
for (i = 0; i < 4096; ++i)
{
if (FD_ISSET(i, readset))
{
duk_push_int(ctx, i);
duk_put_prop_index(ctx, -2, duk_get_length(ctx, -1)); // [emit][this][name][select][readset]
}
}
duk_push_array(ctx); // [emit][this][name][select][readset][writeset]
for (i = 0; i < 4096; ++i)
{
if (FD_ISSET(i, writeset))
{
duk_push_int(ctx, i);
duk_put_prop_index(ctx, -2, duk_get_length(ctx, -1)); // [emit][this][name][select][readset][writeset]
}
}
duk_push_array(ctx); // [emit][this][name][select][readset][writeset][errorset]
for (i = 0; i < 4096; ++i)
{
if (FD_ISSET(i, errorset))
{
duk_push_int(ctx, i);
duk_put_prop_index(ctx, -2, duk_get_length(ctx, -1)); // [emit][this][name][select][readset][writeset][errorset]
}
}
if (duk_pcall_method(ctx, 5) != 0) { ILibDuktape_Process_UncaughtExceptionEx(ctx, "ChainViewer.emit('PostSelect'): Error "); }
duk_pop(ctx);
}
duk_ret_t ILibDuktape_ChainViewer_GetDescriptorInfo(duk_context *ctx)
{
int fd = duk_require_int(ctx, 0);
void *chain = Duktape_GetChain(ctx);
void *module = ILibChain_GetObjectForDescriptor(chain, fd);
duk_push_object(ctx);
if (module != NULL)
{
duk_push_pointer(ctx, module);
duk_put_prop_string(ctx, -2, "_ptr");
duk_push_string(ctx, Duktape_GetStashKey(module));
duk_put_prop_string(ctx, -2, "pointer");
if (((ILibChain_Link*)module)->MetaData != NULL)
{
duk_push_string(ctx, ((ILibChain_Link*)module)->MetaData);
duk_put_prop_string(ctx, -2, "moduleType");
}
}
return(1);
}
void ILibDuktape_ChainViewer_Push(duk_context *ctx, void *chain)
{
duk_push_object(ctx); // [viewer]
ILibTransport *t = (ILibTransport*)ILibChain_Link_Allocate(sizeof(ILibTransport), 2*sizeof(void*));
t->ChainLink.MetaData = "ILibDuktape_ChainViewer";
t->ChainLink.PostSelectHandler = ILibDuktape_ChainViewer_PostSelect;
((void**)t->ChainLink.ExtraMemoryPtr)[0] = ctx;
((void**)t->ChainLink.ExtraMemoryPtr)[1] = duk_get_heapptr(ctx, -1);
ILibDuktape_EventEmitter *emitter = ILibDuktape_EventEmitter_Create(ctx);
ILibDuktape_EventEmitter_CreateEventEx(emitter, "PostSelect");
ILibDuktape_CreateInstanceMethod(ctx, "GetDescriptorInfo", ILibDuktape_ChainViewer_GetDescriptorInfo, 1);
ILibAddToChain(chain, (void*)t);
}
void ILibDuktape_Polyfills_Init(duk_context *ctx)
{
@@ -1823,6 +1899,7 @@ void ILibDuktape_Polyfills_Init(duk_context *ctx)
ILibDuktape_ModSearch_AddHandler(ctx, "bignum", ILibDuktape_bignum_Push);
ILibDuktape_ModSearch_AddHandler(ctx, "dataGenerator", ILibDuktape_dataGenerator_Push);
#endif
ILibDuktape_ModSearch_AddHandler(ctx, "ChainViewer", ILibDuktape_ChainViewer_Push);
// Global Polyfills
duk_push_global_object(ctx); // [g]

View File

@@ -192,9 +192,9 @@ void ILibDuktape_WebRTC_DataChannel_PUSH(duk_context *ctx, ILibWrapper_WebRTC_Da
if (dataChannel->userData != NULL) { duk_push_heapptr(((ILibDuktape_WebRTC_DataChannel*)dataChannel->userData)->ctx, ((ILibDuktape_WebRTC_DataChannel*)dataChannel->userData)->emitter->object); return; }
ILibDuktape_WebRTC_DataChannel *ptrs;
dataChannel->TransportSendOKPtr = ILibDuktape_WebRTC_OnDataChannelSendOK;
dataChannel->Header.transport.SendOkPtr = ILibDuktape_WebRTC_OnDataChannelSendOK;
dataChannel->OnClosed = ILibDuktape_WebRTC_DataChannel_OnClose;
dataChannel->OnRawData = ILibDuktape_WebRTC_DataChannel_OnData;
dataChannel->Header.DataChannelCallbacks.OnRawData = ILibDuktape_WebRTC_DataChannel_OnData;
duk_push_object(ctx); // [dataChannel]
ILibDuktape_WriteID(ctx, "webRTC.dataChannel");

View File

@@ -1309,6 +1309,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx)
else
{
notifyDispatcher = ILibMemory_Allocate(sizeof(ILibDuktape_fs_linuxWatcher), 0, NULL, NULL);
notifyDispatcher->chainLink.MetaData = "ILibDuktape_fs_linuxWatcher";
notifyDispatcher->chainLink.PreSelectHandler = ILibDuktape_fs_notifyDispatcher_PreSelect;
notifyDispatcher->chainLink.PostSelectHandler = ILibDuktape_fs_notifyDispatcher_PostSelect;
notifyDispatcher->chainLink.DestroyHandler = ILibDuktape_fs_notifyDispatcher_Destroy;