void KPR_debug_file(xsMachine *the) { KprDebug self = xsGetHostData(xsThis); KprDebugMachine machine = NULL; int command = mxNoCommand; char* path = NULL; char* value = NULL; xsIntegerValue line = -1; xsIntegerValue c = xsToInteger(xsArgc); xsVars(4); if ((c >= 2) && (xsTypeOf(xsArg(0)) == xsStringType) && (xsTypeOf(xsArg(1)) == xsIntegerType)) { char* address = xsToString(xsArg(0)); command = xsToInteger(xsArg(1)); machine = KprDebugFindMachine(self, address); } if ((c >= 4) && (xsTypeOf(xsArg(2)) == xsStringType) && (xsTypeOf(xsArg(3)) == xsIntegerType)) { path = FskStrDoCopy(xsToString(xsArg(2))); line = xsToInteger(xsArg(3)); } if ((c >= 5) && (xsTypeOf(xsArg(4)) == xsStringType)) { value = FskStrDoCopy(xsToString(xsArg(4))); } if (machine && ((command == mxFramesView) || (command == mxFilesView) || (command == mxLogView) || (command == mxBreakpointsView))) { xsEnterSandbox(); KprDebugMachineDispatchCommand(machine, command, path, value, line); xsLeaveSandbox(); } else xsThrowIfFskErr(kFskErrInvalidParameter); FskMemPtrDispose(value); FskMemPtrDispose(path); }
void Library_cacheQuery(xsMachine* the) { KprLibraryServer self = gLibraryServer; UInt32 index; KprLibraryQuery query; FskMutexAcquire(self->queryMutex); index = self->queryIndex % kQueryCount; query = self->queries[index]; if (query) { KprLibraryQueryDispose(query); self->queries[index] = NULL; } KprLibraryQueryNew(&query); FskInstrumentedItemSetOwner(query, self); xsEnterSandbox(); query->index = self->queryIndex; query->info = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("info")))); query->kind = xsToInteger(xsGet(xsArg(0), xsID("kind"))); query->mime = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("mime")))); query->url = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("url")))); xsResult = xsGet(xsArg(0), xsID("authorization")); if (xsTest(xsResult)) query->authorization = FskStrDoCopy(xsToString(xsResult)); xsLeaveSandbox(); self->queries[index] = query; xsResult = xsInteger(self->queryIndex); self->queryIndex++; FskMutexRelease(self->queryMutex); }
void KPR_canvas_set_size(xsMachine *the) { FskErr err = kFskErrNone; KprCanvas self = xsGetHostData(xsThis); SInt32 width = 0, height = 0; if (self->shell) { KprShellAdjust(self->shell); xsEnterSandbox(); if (xsFindInteger(xsArg(0), xsID_width, &width)) width -= self->bounds.width; if (xsFindInteger(xsArg(0), xsID_height, &height)) height -= self->bounds.height; xsLeaveSandbox(); KprContentSizeBy((KprContent)self, width, height); } else { FskRectangleRecord bounds; xsEnterSandbox(); if (!xsFindInteger(xsArg(0), xsID_width, &width)) width = self->coordinates.width; if (!xsFindInteger(xsArg(0), xsID_height, &height)) height = self->coordinates.height; xsLeaveSandbox(); if (self->cnv) FskBitmapGetBounds(FskGetCanvasBitmap(self->cnv), &bounds); else FskRectangleSetEmpty(&bounds); if ((width != bounds.width) || (height != bounds.height)) { FskCanvasDispose(self->cnv); self->cnv = NULL; if (width && height) { bailIfError(FskCanvasNew(width, height, PreferredPixelFormat(), &self->cnv)); FskCanvas2dSetOpenGLSourceAccelerated(self->cnv, true); } } } bail: return; }
void KPR_debug_get_machines(xsMachine *the) { KprDebug self = xsGetHostData(xsThis); KprDebugMachine machine = NULL; xsEnterSandbox(); xsVars(1); { xsResult = xsNewInstanceOf(xsArrayPrototype); for (machine = self->machine; machine; machine = machine->next) { xsVar(0) = xsNewInstanceOf(xsObjectPrototype); xsNewHostProperty(xsVar(0), xsID("address"), xsString(machine->address), xsDefault, xsDontScript); if (machine->title) xsNewHostProperty(xsVar(0), xsID("title"), xsString(machine->title), xsDefault, xsDontScript); xsCall1(xsResult, xsID_push, xsVar(0)); } } xsLeaveSandbox(); }
void KPR_Debug(xsMachine *the) { KprDebug self = NULL; UInt32 port = 0; xsEnterSandbox(); if (xsIsInstanceOf(xsArg(0), xsObjectPrototype)) { (void)(xsFindInteger(xsArg(0), xsID_port, &port)); // add behavior? } xsLeaveSandbox(); xsThrowIfFskErr(KprDebugNew(&self, port)); xsSetHostData(xsResult, self); self->the = the; self->slot = xsResult; self->code = the->code; self->behavior = xsUndefined; xsRemember(self->slot); return; }
// hit regions void KPR_canvasRenderingContext2D_addHitRegion(xsMachine *the) { FskCanvas2dContext ctx = xsGetHostData(xsThis); const char *id = NULL, *control = NULL; FskConstCanvas2dPath path = NULL; xsVars(1); xsEnterSandbox(); /* Enter sandbox to access the properties of an object */ xsFindString(xsArg(0), xsID("id"), &id); xsFindString(xsArg(0), xsID("control"), &control); if (xsHasOwn(xsArg(0), xsID("path"))) path = xsGetHostData(xsGet(xsArg(0), xsID("path"))); //xsFindString(xsArg(0), xsID("parentID"), &parentID); //xsFindString(xsArg(0), xsID("cursor"), &cursor); //xsFindString(xsArg(0), xsID("fillRule"), &fillRuleStr); //xsFindString(xsArg(0), xsID("label"), &label); //xsFindString(xsArg(0), xsID("role"), &label); xsLeaveSandbox(); (void)FskCanvas2dAddHitRegion(ctx, path, id, control); }
void KPR_serializeURI(xsMachine *the) { KprURLPartsRecord parts; xsStringValue target; FskMemSet(&parts, 0, sizeof(KprURLPartsRecord)); xsEnterSandbox(); if (xsFindString(xsArg(0), xsID_scheme, &parts.scheme)) parts.schemeLength = FskStrLen(parts.scheme); if (xsFindString(xsArg(0), xsID_authority, &parts.authority)) parts.authorityLength = FskStrLen(parts.authority); if (xsFindString(xsArg(0), xsID_path, &parts.path)) parts.pathLength = FskStrLen(parts.path); if (xsFindString(xsArg(0), xsID_query, &parts.query)) parts.queryLength = FskStrLen(parts.query); if (xsFindString(xsArg(0), xsID_fragment, &parts.fragment)) parts.fragmentLength = FskStrLen(parts.fragment); xsLeaveSandbox(); xsThrowIfFskErr(KprURLJoin(&parts, &target)); xsResult = xsString(target); FskMemPtrDispose(target); }
void Zeroconf_Advertisement(xsMachine *the) { KprZeroconfAdvertisement self = NULL; char* serviceType = xsToString(xsArg(0)); char* servicName = xsToString(xsArg(1)); int servicPort = xsToInteger(xsArg(2)); xsIntegerValue c = xsToInteger(xsArgc); FskAssociativeArray txt = NULL; if ((c > 3) && xsIsInstanceOf(xsArg(3), xsObjectPrototype)) { xsVars(2); xsEnterSandbox(); fxPush(xsArg(3)); fxRunForIn(the); txt = FskAssociativeArrayNew(); for (xsVar(0) = fxPop(); xsTypeOf(xsVar(0)) != xsNullType; xsVar(0) = fxPop()) { if (xsTypeOf(xsVar(0)) == xsStringType) { xsVar(1) = xsGetAt(xsArg(3), xsVar(0)); if (!xsIsInstanceOf(xsVar(1), xsObjectPrototype)) { char* name = xsToString(xsVar(0)); char* value = xsToString(xsVar(1)); FskAssociativeArrayElementSetString(txt, name, value); } } } xsLeaveSandbox(); } xsThrowIfFskErr(KprZeroconfAdvertisementNew(&self, serviceType, servicName, servicPort, txt)); xsSetHostData(xsResult, self); self->registeredCallback = Zeroconf_advertisement_registeredCallback; self->unregisteredCallback = Zeroconf_advertisement_unregisteredCallback; self->the = the; self->slot = xsResult; self->code = the->code; self->behavior = xsUndefined; xsRemember(self->slot); }
void KPR_mqttclient_publish(xsMachine* the) { KPR_MQTTClientRecord *self = xsGetHostData(xsThis); FskErr err = kFskErrNone; xsIntegerValue c = xsToInteger(xsArgc); char *topic = NULL; void *payload = NULL; UInt32 payloadLength = 0; UInt8 qos = 0; Boolean retain = false, hasPayload = false, hasQos = false, hasRetain = false; UInt16 token; /* Case 1. topic, string_or_chunk, qos, retain Case 2 topic, { payload: string_or_chunk}, qos, retain Case 3 topic, { payload: string_or_chunk, qos: 0, retain: true } */ if (c < 1) goto invalidParams; topic = xsToString(xsArg(0)); if (c >= 2) { if (isChunk(xsArg(1))) { payload = xsGetHostData(xsArg(1)); payloadLength = xsToInteger(xsGet(xsArg(1), xsID_length)); } else if (isObject(xsArg(1))) { xsVars(1); xsEnterSandbox(); { hasPayload = xsHas(xsArg(1), xsID("data")); if (hasPayload) xsVar(0) = the->scratch; hasQos = xsHas(xsArg(1), xsID("qos")); if (hasQos) qos = xsToInteger(the->scratch); hasRetain = xsHas(xsArg(1), xsID("retain")); if (hasRetain) retain = xsToInteger(the->scratch); } xsLeaveSandbox(); if (hasPayload) { if (isChunk(xsVar(0))) { payload = xsGetHostData(xsVar(0)); payloadLength = xsToInteger(xsGet(xsVar(0), xsID_length)); } else { payload = xsToString(xsVar(0)); payloadLength = FskStrLen(payload); } } } else { payload = xsToString(xsArg(1)); payloadLength = FskStrLen(payload); } } if (c >= 3 && !hasQos) { qos = xsToInteger(xsArg(2)); } if (c >= 4 && !hasRetain) { retain = xsToBoolean(xsArg(3)); } if (!KprMQTTIsValidTopic(topic, false)) goto badParam; if (qos > 2) goto badParam; bailIfError(KprMQTTClientPublish(self->client, topic, payload, payloadLength, qos, retain, &token)); xsResult = xsInteger(token); goto bail; invalidParams: err = kFskErrInvalidParameter; goto bail; badParam: err = kFskErrBadData; goto bail; bail: xsThrowIfFskErr(err); }
void KPR_mqttclient_connect(xsMachine* the) { KPR_MQTTClientRecord *self = xsGetHostData(xsThis); xsIntegerValue c = xsToInteger(xsArgc); char *host; UInt16 port; KprMQTTClientConnectOptions options; if (c >= 1) { host = xsToString(xsArg(0)); } else { host = "localhost"; } if (c >= 2) { port = xsToInteger(xsArg(1)); } else { port = 1883; } options.isSecure = (port == 1884); options.keepAlive = 60; options.password = NULL; options.username = NULL; options.willIsRetained = false; options.willQualityOfService = 0; options.willTopic = NULL; options.willPayload = NULL; options.willPayloadLength = 0; if (c >= 3) { xsVars(1); xsEnterSandbox(); { if (xsHas(xsArg(2), xsID("secure"))) options.isSecure = xsToBoolean(the->scratch); if (xsHas(xsArg(2), xsID("keepAlive"))) options.keepAlive = xsToInteger(the->scratch); if (xsHas(xsArg(2), xsID("username"))) options.username = xsToString(the->scratch); if (xsHas(xsArg(2), xsID("password"))) options.password = xsToString(the->scratch); if (xsHas(xsArg(2), xsID("will"))) { xsVar(0) = the->scratch; if (xsHas(xsVar(0), xsID("topic"))) options.willTopic = xsToString(the->scratch); if (xsHas(xsVar(0), xsID("qos"))) options.willQualityOfService = xsToInteger(the->scratch); if (xsHas(xsVar(0), xsID("retain"))) options.willIsRetained = xsToBoolean(the->scratch); if (xsHas(xsVar(0), xsID("data"))) { xsVar(0) = the->scratch; if (isChunk(xsVar(0))) { options.willPayload = xsGetHostData(xsVar(0)); options.willPayloadLength = xsToInteger(xsGet(xsVar(0), xsID_length)); } else { options.willPayload = xsToString(xsVar(0)); options.willPayloadLength = FskStrLen(options.willPayload); } } } } xsLeaveSandbox(); } if (options.willQualityOfService > 2 || (options.willTopic && !KprMQTTIsValidTopic(options.willTopic, false))) { xsThrowIfFskErr(kFskErrBadData); } xsThrowIfFskErr(KprMQTTClientConnect(self->client, host, port, &options)); }