Beispiel #1
0
static void KprServicesLoop(void* theParameter)
{
	xsAllocation allocation = {
		1100000,		// 700 * 1024,
		32 * 1024,
		70000,			// 62000,
		4096,
		2048,
		16000,
		1993
	};
	FskErr err = kFskErrNone;
	KprService service = gServices;
	FskThread thread = FskThreadGetCurrent();
	gServiceMachine = xsAliasMachine(&allocation, gShell->root, "services", gShell);
	bailIfNULL(gServiceMachine);

	while (service) {
		if (service->flags & kprServicesThread) {
			FskInstrumentedTypePrintfNormal(&KprServiceInstrumentation, "Starting %s", service->id);
			(*service->start)(service, thread, gServiceMachine);
		}
		service = service->next;
	}
	FskThreadInitializationComplete(thread);
	while (!gServicesThreadQuitting)
		FskThreadRunloopCycle(-1);
	service = gServices;
	while (service) {
		if (service->flags & kprServicesThread) {
			FskInstrumentedTypePrintfNormal(&KprServiceInstrumentation, "Stopping %s", service->id);
			(*service->stop)(service);
		}
		service = service->next;
	}
bail:
	if (gServiceMachine) {
		xsDeleteMachine(gServiceMachine);
		gServiceMachine = NULL;
	}
	return;
}
Beispiel #2
0
void FskECMAScriptInitializeThread()
{
	FskRectangleRecord bounds;
	char* shellPath;
	KprShell shell;

	bounds.x = 0;
	bounds.y = 0;
	bounds.width = KprEnvironmentGetUInt32("windowWidth", 800);
	bounds.height = KprEnvironmentGetUInt32("windowHeight", 600);
 	shellPath = FskEnvironmentGet("shellPath");
#if !TARGET_OS_ANDROID
    KprShellNew(&shell, NULL, &bounds, shellPath, NULL, NULL, NULL, 0);
#else
	if (kFskErrNone == KprShellNew(&shell, NULL, &bounds, shellPath, NULL, NULL, NULL, 0)) {
		while (!gQuitting) // (!gQuitting && !vmi->vm->quitting)
			FskThreadRunloopCycle(-1);
	}
#endif
}
Beispiel #3
0
static void fxDoConnect(txMachine *the)
{
	if (!FskStrLen(debugAddress)) {
        char *address = FskEnvironmentGet("debugger");
		if (address)
			FskStrCopy(debugAddress, address);
#if TARGET_OS_WIN32 || (TARGET_OS_MAC && !TARGET_OS_IPHONE)
		else
			FskStrCopy(debugAddress, "localhost");
#endif
	}
	if (FskStrLen(debugAddress) && !debugAddressFailed) {
		FskErr err;
		char host[64];
		char* colon;
		int port;
		FskTimeRecord expireTime, now;
		SInt32 waitMS;
		
		colon = FskStrNCopyUntil(host, debugAddress, 63, ':');
		if (*colon)
			port = FskStrToNum(colon);
		else
			port = 5002;
			
#if TARGET_OS_MAC
		waitMS = 0;
#else
		waitMS = -1;
#endif
		// Connect to the host asynchronously
		err = FskNetConnectToHostPrioritized(host, port, false, fxConnectComplete, the, 0, 0, NULL, "fxConnect");
		if (err) goto bail;
		
		// Allow two seconds for the connection to resolve and for the socket to become readable and writable
		FskTimeGetNow(&expireTime);
		FskTimeAddSecs(&expireTime, 2);
		while (!the->connection) {
			FskTimeGetNow(&now);
			if (FskTimeCompare(&expireTime, &now) > 0)
				goto bail;
			FskThreadRunloopCycle(waitMS);
		}
		while (!FskNetSocketIsReadable((FskSocket)the->connection) && !FskNetSocketIsWritable((FskSocket)the->connection)) {
			FskTimeGetNow(&now);
			if (FskTimeCompare(&expireTime, &now) > 0)
				goto bail;
			FskThreadRunloopCycle(waitMS);
		}
		
		// Make the socket blocking
		FskNetSocketMakeBlocking((FskSocket)the->connection);
		return;
		
bail:
		if (the->connection) {
			FskNetSocketClose((FskSocket)the->connection);
			the->connection = 0;
		}
		debugAddressFailed = true;
	}
}