예제 #1
0
void
xs_ctr_init(xsMachine *the)
{
	crypt_mode_t *mode = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);

	mode->encrypt = ctr_process;
	mode->decrypt = ctr_process;
	mode->setIV = ctr_setIV;
	mode->maxSlop = 0;
	c_memset(mode->em_buf, 0, sizeof(mode->em_buf));
	if (ac > 0 && xsTest(xsArg(0))) {
		/* iv */
		void *iv = xsToArrayBuffer(xsArg(0));
		size_t ivsize = xsGetArrayBufferLength(xsArg(0));
		ctr_setIV(mode, iv, ivsize);
	}
	(*mode->cipher->keysched)(mode->cipher->ctx, KCL_DIRECTION_ENCRYPTION);	/* CTR uses encryption only */
}
예제 #2
0
파일: i2c.c 프로젝트: dadongdong/kinomajs
void xs_i2c_readWordDataSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
    UInt8 command = (UInt8)xsToInteger(xsArg(0));
	FskErr err;
    UInt16 val;
  
    DBG_I2C("xs_i2c_readWordDataSMB Call SMB to register %d\n", command);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

    err = FskPinI2CReadDataWord(i2c->pin, command, &val);
//@@        if (! (i2c->address == 0x36) ) xsTraceDiagnostic("I2C readWordDataSMB register %d failed %s.", (int)reg, i2c->diagnosticID);
	xsThrowDiagnosticIfFskErr(err, "I2C readWordDataSMB register %d failed %s.", (int)command, i2c->diagnosticID);

    xsResult = xsInteger(val);
}
예제 #3
0
파일: xsInfoset.c 프로젝트: basuke/kinomajs
void fxParse(xsMachine* the, void* theStream, xsGetter theGetter, xsStringValue thePath, xsIntegerValue theLine, xsFlag theFlag)
{
	xsStreamGetter streamGetter;
	xsSlot* stack = the->stack;
	xsIntegerValue c = xsToInteger(stack[0]);
	stack[c] = xsGet(xsGet(xsGlobal, xsID("xs")), xsID("infoset"));
	stack[c - 1] = xsNewHostObject(NULL);
	streamGetter.stream = theStream;
	streamGetter.getter = theGetter;
	xsSetHostData(stack[c - 1], &streamGetter);
	if (thePath && theLine)
		stack[c - 2] = xsCall3(stack[c], xsID("scan"), stack[c - 1], xsString(thePath), xsInteger(theLine));
	else if (thePath)
		stack[c - 2] = xsCall2(stack[c], xsID("scan"), stack[c - 1], xsString(thePath));
	else
		stack[c - 2] = xsCall1(stack[c], xsID("scan"), stack[c - 1]);
	stack[c] = xsCall2(stack[c], xsID("parse"), stack[c - 2], xsInteger(theFlag));
	the->stack = stack + c;
}
예제 #4
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
int
FskSSLGetBytesAvailable(void *a)
{
	FskSSL *fssl = a;
	int ret = 0;

	if (fssl->skt == NULL)
		return -1;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsResult = xsGet(fssl->ssl, xsID("bytesAvailable"));
		ret = xsToInteger(xsResult);
	} xsCatch {
		ret = -1;
	}
	xsEndHost(fssl->vm->the);
	return ret;
}
예제 #5
0
void
xs_cbc_init(xsMachine *the)
{
	crypt_mode_t *mode = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);

	mode->encrypt = cbc_encrypt;
	mode->decrypt = cbc_decrypt;
	mode->direction = -1;
	mode->maxSlop = mode->cipher->blockSize;
	memset(mode->em_buf, 0, sizeof(mode->em_buf));
	if (ac > 0 && xsTest(xsArg(0))) {
		/* iv */
		size_t ivsize = xsGetArrayBufferLength(xsArg(0));
		void *iv = xsToArrayBuffer(xsArg(0));
		cbc_setIV(mode, iv, ivsize);
	}
	mode->padding = ac > 1 && xsToBoolean(xsArg(1));
}
예제 #6
0
파일: i2c.c 프로젝트: dadongdong/kinomajs
void xs_i2c_writeBlock(xsMachine* the)
{
	FskErr err;
	xsI2C i2c = xsGetHostData(xsThis);
	int argc = xsToInteger(xsArgc), i;
	UInt8 buffer[32], *bufPtr = buffer;

	xsThrowIfNULL(i2c);

    DBG_I2C("xs_i2c_writeBlock\n");

	for (i = 0; i < argc; i++)
		bufPtr = writeOne(the, i2c, &xsArg(i), bufPtr, buffer + sizeof(buffer));

	FskPinI2CSetAddress(i2c->pin, i2c->address);

	err = FskPinI2CWriteBytes(i2c->pin, bufPtr - buffer, buffer);
    xsThrowDiagnosticIfFskErr(err, "I2C FskI2CWriteBlock failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
예제 #7
0
파일: io_i2c.c 프로젝트: basuke/kinomajs
void
xs_i2c_readChar(xsMachine *the)
{
	wm_i2c *i2c = xsGetHostData(xsThis);
	int reg;
	uint8_t c;

	switch (xsTypeOf(xsArg(0))) {
	case xsNumberType:
	case xsIntegerType:
		reg = xsToInteger(xsArg(0));
		break;
	default:
		reg = -1;
		break;
	}
	if (mc_i2c_read(i2c, reg, &c, 1) == 0)
		xsSetInteger(xsResult, c);
}
예제 #8
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLLoadCerts(void *a, FskSocketCertificateRecord *cert)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	xsBeginHost(fssl->vm->the);

	xsTry {
		xsVars(2);

		xsVar(0) = xsUndefined;
		xsVar(1) = xsUndefined;
		if (cert != NULL) {
			if (cert->certificates != NULL && cert->certificatesSize > 0) {
				xsVar(0) = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(cert->certificatesSize));
				FskMemCopy(xsGetHostData(xsVar(0)), cert->certificates, cert->certificatesSize);
			}
			if (cert->policies != NULL) {
				if (cert->certificates == NULL)
					xsVar(0) = xsNew0(xsGlobal, xsID("Chunk"));	// create a null chunk just for setting the polices
				xsSet(xsVar(0), xsID("policies"), xsString(cert->policies));
			}
			if (cert->hostname != NULL) {
				xsSet(fssl->socket, xsID("hostname"), xsString(cert->hostname));	// too easy but should work...
			}
			if (cert->key != NULL && cert->keySize > 0) {
				xsVar(1) = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(cert->keySize));
				FskMemCopy(xsGetHostData(xsVar(1)), cert->key, cert->keySize);
			}
		}
		xsCall2_noResult(fssl->ssl, xsID("loadCerts"), xsVar(0), xsVar(1));
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}

	xsEndHost(fssl->vm->the);
	return err;
}
예제 #9
0
void
xs_digest_update(xsMachine *the)
{
	crypt_digest_t *digest = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc), i;
	int len;
	void *data;

	for (i = 0; i < ac; i++) {
		if (xsTypeOf(xsArg(i)) == xsStringType) {
			data = xsToString(xsArg(i));
			len = strlen(data);
		}
		else {
			len = xsGetArrayBufferLength(xsArg(i));
			data = xsToArrayBuffer(xsArg(i));
		}
		(*digest->update)(digest->ctx, data, len);
	}
}
예제 #10
0
void
xs_curve25519_dh(xsMachine *the)
{
	void *secret, *basepoint;
	xsIntegerValue sz;

	xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(32));
	getChunkData(the, &xsArg(0), &secret, &sz);
	if (sz != 32)
		cryptThrowFSK(kFskErrInvalidParameter);
	if (xsToInteger(xsArgc) > 1) {
		getChunkData(the, &xsArg(1), &basepoint, &sz);
		if (sz != 32)
			cryptThrowFSK(kFskErrInvalidParameter);
	}
	else
		basepoint = (void *)c25519_base_x;
	c25519_prepare(secret);
	c25519_smult(xsGetHostData(xsResult), basepoint, secret);
}
예제 #11
0
void KPR_canvasRenderingContext2D_isPointInPath(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	FskCanvas2dPath		path		= NULL;
	SInt32				fillRule	= kFskCanvas2dFillRuleNonZero;
	int					numArgs		= xsToInteger(xsArgc);
	xsNumberValue		x, y;

	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {	/* ctx.isPointInPath(path, x, y) */
		path = xsGetHostData(xsArg(0));
		x = xsToNumber(xsArg(1));
		y = xsToNumber(xsArg(2));
		if (numArgs > 3)	fillRule = GetFillRule(xsToString(xsArg(3)));				/* ctx.isPointInPath(path, x, y, fillRule) */
	} else {																			/* ctx.isPointInPath(x, y) */
		x = xsToNumber(xsArg(0));
		y = xsToNumber(xsArg(1));
		if (numArgs > 2)	fillRule = GetFillRule(xsToString(xsArg(2)));				/* ctx.isPointInPath(x, y, fillRule) */
	}
	xsResult = xsBoolean(FskCanvas2dIsPointInPathFill(ctx, path, x, y, fillRule));
}
예제 #12
0
void xs_parse(xsMachine* the)
{
	xsIntegerValue c = xsToInteger(xsArgc);
	xsVars(2);
	if (c < 1)
		xsSyntaxError("no buffer");
	xsVar(0) = xsGet(xsGet(xsGlobal, xsID_xs), xsID_infoset);
	if (c > 3)
		xsVar(1) = xsCall3(xsVar(0), xsID_scan, xsArg(0), xsArg(2), xsArg(3));
	else if (c > 2)
		xsVar(1) = xsCall2(xsVar(0), xsID_scan, xsArg(0), xsArg(2));
	else if (c > 1)
		xsVar(1) = xsCall1(xsVar(0), xsID_scan, xsArg(0));
	else
		xsVar(1) = xsCall1(xsVar(0), xsID_scan, xsArg(0));
	if (c > 1)
		xsResult = xsCall2(xsVar(0), xsID_parse, xsVar(1), xsArg(1));
	else
		xsResult = xsCall1(xsVar(0), xsID_parse, xsVar(1));
}
예제 #13
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLAttach(void **fsslp, FskSocket skt)
{
	FskSSL *fssl;
	FskErr err;

	if ((err = FskMemPtrNewClear(sizeof(FskSSL), (FskMemPtr*)(void*)&fssl)) != kFskErrNone)
		return err;
	if ((err = newSSLVM(&fssl->vm)) != kFskErrNone) {
		FskMemPtrDispose(fssl);
		return err;
	}

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsVars(2);
		xsVar(0) = xsNew1(xsGet(xsGlobal, xsID("Stream")), xsID("Socket"), xsHostData(skt));
		xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
		(void)xsSet(xsVar(1), xsID("raw"), xsTrue);
		xsCall1_noResult(xsVar(0), xsID("setProperties"), xsVar(1));
		fssl->socket = xsVar(0); xsRemember(fssl->socket);
		xsVar(0) = xsNew0(xsGet(xsGlobal, xsID("FskSSL")), xsID("Session"));
		fssl->ssl = xsVar(0); xsRemember(fssl->ssl);
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);

	if (err == kFskErrNone) {
		if (fsslp != NULL)
			*fsslp = fssl;
	}
	else {
		disposeSSLVM(fssl->vm);
		FskMemPtrDispose(fssl);
	}
	return err;
}
예제 #14
0
파일: kprMQTT.c 프로젝트: VzqzAc/kinomajs
void KPR_MQTTClient(xsMachine* the)
{
	FskErr err;
	KPR_MQTTClientRecord *self = NULL;
	KprMQTTClient client = NULL;
	FskDeferrer deferrer = NULL;
	char *clientIdentifier;
	Boolean cleanSession;

	if (xsToInteger(xsArgc) != 2) xsThrowIfFskErr(kFskErrParameterError);

	clientIdentifier = xsToString(xsArg(0));
	cleanSession = xsToBoolean(xsArg(1));

	bailIfError(FskMemPtrNewClear(sizeof(KPR_MQTTClientRecord), &self));
	bailIfError(FskDeferrerNew(&deferrer));
	bailIfError(KprMQTTClientNew(&client, clientIdentifier, cleanSession, kKprMQTTProtocol311, self));

	client->connectCallback = KPR_mqttclient_onConnect;
	client->subscribeCallback = KPR_mqttclient_onSubscribe;
	client->unsubscribeCallback = KPR_mqttclient_onUnsubscribe;
	client->publishCallback = KPR_mqttclient_onPublish;
	client->messageCallback = KPR_mqttclient_onMessage;
	client->disconnectCallback = KPR_mqttclient_onDisconnect;
	client->errorCallback = KPR_mqttclient_onError;

	self->client = client;
	self->deferrer = deferrer;
	self->the = the;
	self->slot = xsThis;
	xsSetHostData(self->slot, self);

bail:

	if (err) {
		KprMQTTClientDispose(client);
		FskDeferrerDispose(deferrer);
		FskMemPtrDispose(self);
		xsThrowIfFskErr(err);
	}
}
예제 #15
0
void KPR_system_setClipboardText(xsMachine* the)
{
	HWND window = (HWND)FskWindowGetNativeWindow(gShell->window);
	xsStringValue string, src, buffer, dst;
	char c;
	xsIntegerValue length;
	HGLOBAL data;
	if (OpenClipboard(window)) {
		EmptyClipboard(); 
		if (xsToInteger(xsArgc) > 0) {
			string = xsToString(xsArg(0));
			src = string;
			length = 0;
			while ((c = *src++)) {
				length++;
				if (c == 10)
					length++;
			}
			length++;
			if (FskMemPtrNew(length, &buffer) == kFskErrNone) {
				src = string;
				dst = buffer;
				while ((c = *src++)) {
					if (c == 10)
						*dst++ = 13;
					*dst++ = c;
				}
				*dst = 0;
				length = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, NULL, 0);
				data = GlobalAlloc(GMEM_MOVEABLE, 2 * length);
				if (data) {
					MultiByteToWideChar(CP_UTF8, 0, buffer, -1, (LPWSTR)GlobalLock(data), length);
					GlobalUnlock(data);
					SetClipboardData(CF_UNICODETEXT, data);
				}
				FskMemPtrDispose(buffer);
			}
		}
		CloseClipboard();
	}
}
예제 #16
0
void
xs_wdt_start(xsMachine *the)
{
    int index = xsToInteger(xsArg(0));
    WDT_Config_Type cfg;

    cfg.timeoutVal = index;
    cfg.mode = WDT_MODE_RESET;
    cfg.resetPulseLen = WDT_RESET_PULSE_LEN_2;
    WDT_Init(&cfg);

    CLK_ModuleClkEnable(CLK_WDT);
#if defined(CONFIG_CPU_MW300)
    /* For 88MW300, APB1 bus runs at 50MHz whereas for 88MC200 it runs at
     * 25MHz, hence following clk divider is added to keep timeout same.
     */
    CLK_ModuleClkDivider(CLK_WDT, 1);
#endif
    WDT_Enable();
    wdt_enable = 1;
}
예제 #17
0
파일: xm_debug.c 프로젝트: basuke/kinomajs
void
xs_dbg_report(xsMachine *the)
{
	if (xsToInteger(xsArgc) > 0 && xsTest(xsArg(0))) {
		/* silence - return the memory use */
		xsMemoryUse slot, chunk;
		xsReportMemoryUse(the, &slot, &chunk);
		xsVars(1);
		xsResult = xsNewInstanceOf(xsObjectPrototype);
		xsSetInteger(xsVar(0), chunk.current);
		xsSet(xsResult, xsID("chunk"), xsVar(0));
		xsSetInteger(xsVar(0), slot.current);
		xsSet(xsResult, xsID("slot"), xsVar(0));
	}
	else {
#if mxMC
		mc_mstats(true);
#endif
		xsReportMemoryUse(the, NULL, NULL);
	}
}
예제 #18
0
void xscAppendPattern(txMachine* the, txByte theCode)
{
	xsIntegerValue c, i;

	xscAppend1(the, theCode);
	c = xsToInteger(xsGet(xsVar(1), the->lengthID));
	xscAppend1(the, (txByte)c);
	for (i = 0; i < c; i++) {
		xsVar(2) = xsGet(xsVar(1), (xsIndex)i);
		xsVar(3) = xsGet(xsVar(2), xsID("namespace"));
		if (xsTest(xsVar(3)))
			xscAppend2(the, xsToID(xsVar(3)));
		else
			xscAppend2(the, XS_NO_ID);
		xsVar(3) = xsGet(xsVar(2), xsID("name"));
		if (xsTest(xsVar(3)))
			xscAppend2(the, xsToID(xsVar(3)));
		else
			xscAppend2(the, XS_NO_ID);
	}
}
예제 #19
0
void KPR_canvasRenderingContext2D_putImageData(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	FskCanvas2dImageData data = xsGetHostData(xsArg(0));
	xsNumberValue dx = xsToNumber(xsArg(1));
	xsNumberValue dy = xsToNumber(xsArg(2));
	xsNumberValue dirtyX, dirtyY, dirtyWidth, dirtyHeight;
	if (xsToInteger(xsArgc) > 6) {
		dirtyX = xsToNumber(xsArg(3));
		dirtyY = xsToNumber(xsArg(4));
		dirtyWidth = xsToNumber(xsArg(5));
		dirtyHeight = xsToNumber(xsArg(6));
	}
	else {
		dirtyX = 0;
		dirtyY = 0;
		dirtyWidth = data->width;
		dirtyHeight = data->height;
	}
	FskCanvas2dPutImageData(ctx, data, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);
}
예제 #20
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLClose(void *a)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsResult = xsCall1(fssl->ssl, xsID("close"), fssl->socket);
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
예제 #21
0
파일: xsInfoset.c 프로젝트: basuke/kinomajs
void scanNamespace(xsMachine* the, const char *prefix)
{
	xsIntegerValue i, c;
	char* name;
	xsVar(PARENT) = xsResult;
	while (xsTest(xsVar(PARENT))) {
		xsVar(ATTRIBUTES) = xsGet(xsVar(PARENT), xsID_xmlnsAttributes);
		if (xsTest(xsVar(ATTRIBUTES))) {
			c = xsToInteger(xsGet(xsVar(ATTRIBUTES), xsID_length));
			for (i = 0; i < c; i++) {
				xsVar(ATTRIBUTE) = xsGet(xsVar(ATTRIBUTES), i);
				name = xsToString(xsGet(xsVar(ATTRIBUTE), xsID_name));
				if (c_strcmp(name, prefix) == 0) {
					xsVar(NAMESPACE) = xsGet(xsVar(ATTRIBUTE), xsID_value);
					return;
				}
			}
		}
		xsVar(PARENT) = xsGet(xsVar(PARENT), xsID_parent);
	}
	xsVar(NAMESPACE) = xsNull;
}
예제 #22
0
void KPR_system_networkInterfaceIndexToName(xsMachine* the)
{
	SInt32 index = xsToInteger(xsArg(0));
	PIP_ADAPTER_ADDRESSES pAddresses = NULL, pAddress;
	ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
	ULONG family = AF_INET;
	ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
	BAIL_IF_ERR(FskMemPtrNewClear(outBufLen, &pAddresses));
	if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) {
		FskMemPtrDispose(pAddresses);
		BAIL_IF_ERR(FskMemPtrNewClear(outBufLen, &pAddresses));
	}
	if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == NO_ERROR) {
		for (pAddress = pAddresses; pAddress; pAddress = pAddress->Next)
			if (pAddress->IfIndex == index) break;
	}
	if (pAddress)
		xsResult = xsString(pAddress->AdapterName);
bail:
	FskMemPtrDispose(pAddresses);
	return;
}
예제 #23
0
void KPR_Path2D(xsMachine *the)
{
	FskCanvas2dPath		path	= NULL;
	FskErr				err;

	bailIfError(FskCanvas2dPathNew(&path));
	if (xsToInteger(xsArgc) > 0) {
		if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {
			FskCanvas2dPath fromPath = xsGetHostData(xsArg(0));
			BAIL_IF_NULL(fromPath, err, kFskErrNotFound);
			bailIfError(FskCanvas2dPathAppendPath(NULL, path, fromPath, NULL));
		}
		else {
			xsStringValue str = xsToString(xsArg(0));
			(void)FskCanvas2dPathAppendPathString(NULL, path, str);
		}
	}
	xsSetHostData(xsResult, path);
bail:
	if (err) FskCanvas2dPathDispose(path);
	return;
}
예제 #24
0
void xsToolExecute(xsMachine* the)
{
	xsIntegerValue c = xsToInteger(xsArgc), i;
	char** parameters= NULL;
	int result;
	parameters = malloc(sizeof(char *)*(c + 1));
	for (i = 0; i < c; i++)
		parameters[i] = xsToString(xsArg(i));
	parameters[c] = NULL;
	fflush(NULL);
#if mxWindows
	result = _spawnvp(P_WAIT, xsToString(xsArg(0)), parameters);
	if (result == 0)
		xsResult = xsTrue;
	else {
		if (result < 0)
			fprintf(stderr, "### Cannot execute nmake!\n");
		xsResult = xsFalse;
	}
#else
	execvp(xsToString(xsArg(0)), parameters);
#endif
}
예제 #25
0
파일: pwm.c 프로젝트: Kazu-zamasu/kinomajs
void xs_pwm_write(xsMachine* the)
{
    SInt32 argc;
	FskErr err;
    double dutyCyclePercent;
    double dutyCycle;
    double period;
    FskPinPWM pwm = xsGetHostData(xsThis);
    if (!pwm) return;

    argc = xsToInteger(xsArgc);

    if (argc == 1){
        dutyCyclePercent = xsToNumber(xsArg(0));
        err = FskPinPWMSetDutyCycle(pwm, dutyCyclePercent);
    }else if(argc >= 2){
        dutyCycle = xsToNumber(xsArg(0));
        period = xsToNumber(xsArg(1));
        err = FskPinPWMSetDutyCycleAndPeriod(pwm, dutyCycle, period);
    }

	xsThrowDiagnosticIfFskErr(err, "PWM write of pin %d failed with error %d.", (int)-1, FskInstrumentationGetErrorString(err));
}
예제 #26
0
void KPR_WebSocketClient(xsMachine* the)
{
	FskErr err;
	xsIntegerValue c = xsToInteger(xsArgc);
	KPR_WebSocketClientRecord *self = NULL;
	KprWebSocketEndpoint endpoint = NULL;
	
	bailIfError(FskMemPtrNewClear(sizeof(KPR_WebSocketClientRecord), &self));
	
	xsThrowIfFskErr(KprWebSocketEndpointNew(&endpoint, self));
	
	endpoint->openCallback = KPR_WebSocketClient_onOpen;
	endpoint->closeCallback = KPR_WebSocketClient_onClose;
	endpoint->textCallback = KPR_WebSocketClient_onTextMessage;
	endpoint->binaryCallback = KPR_WebSocketClient_onBinaryMessage;
	endpoint->errorCallback = KPR_WebSocketClient_onError;
	
	self->endpoint = endpoint;
	self->the = the;
	self->slot = xsThis;
	self->code = the->code;
	xsSetHostData(self->slot, self);
	// xsCall1(xsGet(xsGlobal, xsID_Object), xsID_seal, self->slot);
	
	if (c >= 1) {
		bailIfError(KprWebSocketEndpointConnect(endpoint, xsToString(xsArg(0)), NULL));
	}

	xsRemember(self->slot);

	return;
	
bail:
	KprWebSocketEndpointDispose(endpoint);
	FskMemPtrDispose(self);
	xsThrowIfFskErr(err);
}
예제 #27
0
파일: pwm.c 프로젝트: Kazu-zamasu/kinomajs
void xs_pwm_init(xsMachine* the)
{
    FskErr err;
    FskPinPWM pwm;
    SInt32 pin = 0;
    char *pinName = NULL;

    xsVars(1);

    pwm = xsGetHostData(xsThis);
    if (pwm)
        xsThrowDiagnosticIfFskErr(kFskErrBadState, "PWM pin %d already initialized.", (int)pin);

    xsVar(0) = xsGet(xsThis, xsID("pin"));
    if (xsStringType == xsTypeOf(xsVar(0)))
        pinName = xsToString(xsVar(0));
    else
        pin = xsToInteger(xsVar(0));

	err = FskPinPWMNew(&pwm, pin, pinName);
    xsThrowDiagnosticIfFskErr(err, "PWM initialization of pin %d failed with error %d.", (int)pin, FskInstrumentationGetErrorString(err));

    xsSetHostData(xsThis, pwm);
}
예제 #28
0
파일: xm_env.c 프로젝트: basuke/kinomajs
void
xs_env_constructor(xsMachine *the)
{
	int ac = xsToInteger(xsArgc);
	const char *partname = ac > 0 ? xsToString(xsArg(0)) : MC_ENV_DEFAULT_PATH;
	int autosave = ac > 1 && xsTest(xsArg(1));
	int encrypt = ac > 2 && xsTest(xsArg(2));
	int recovery = ac <= 3 || xsTest(xsArg(3));
	mc_env_t *env;

	if (mc_env_init())
		mc_xs_throw(the, "mc_env: init fail");

	if (strcmp(partname, MC_ENV_DEFAULT_PATH) == 0)
		env = NULL;
	else {
		if ((env = mc_malloc(sizeof(mc_env_t))) == NULL)
			mc_xs_throw(the, "mc_env: no mem");
		if (mc_env_new(env, partname, encrypt, recovery) != 0)
			mc_xs_throw(the, "mc_env: new fail");
	}
	mc_env_autosave(env, autosave);
	xsSetHostData(xsThis, env);
}
예제 #29
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLFlush(void *a)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsVars(1);
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsResult = xsCall1(fssl->ssl, xsID("flush"), fssl->socket);
		err = xsToBoolean(xsResult) ? kFskErrNone: kFskErrNoData;
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
예제 #30
0
void KPR_system_openFile(xsMachine* the)
{
	FskErr err;
	xsIntegerValue argc = xsToInteger(xsArgc);
	xsStringValue prompt = NULL;
	xsStringValue initialPath = NULL;
	xsStringValue path = NULL;
	xsStringValue url = NULL;
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindResult(xsArg(0), xsID_prompt))
			prompt = xsToStringCopy(xsResult);
		if (xsFindResult(xsArg(0), xsID_url))
			KprURLToPath(xsToString(xsResult), &initialPath);
	}
	err = FskFileChoose(NULL, prompt, false, initialPath, &path);
	if ((kFskErrNone == err) && (NULL != path)) {
		KprPathToURL(path, &url);
		(void)xsCallFunction1(xsArg(1), xsNull, xsString(url));
	}
	FskMemPtrDispose(url);
	FskMemPtrDispose(path);
	FskMemPtrDispose(initialPath);
	FskMemPtrDispose(prompt);
}