static FskErr newSSLVM(FskECMAScript *vmp) { FskECMAScript vm; FskErr err; #ifdef KPR_CONFIG if ((err = FskMemPtrNewClear(sizeof(FskECMAScriptRecord), &vm)) != kFskErrNone) return err; if ((vm->the = xsAliasMachine(&anAllocation, gShell->root, "SSL", vm)) == NULL) { FskMemPtrDispose(vm); return kFskErrMemFull; } #else if (gSSLVM == NULL) return kFskErrUnimplemented; if ((err = FskMemPtrNewFromData(sizeof(FskECMAScriptRecord), gSSLVM, &vm)) != kFskErrNone) return err; vm->the = NULL; vm->context = NULL; vm->refcon = NULL; vm->libraries = NULL; vm->name = FskStrDoCopy("SSL"); vm->thread = FskThreadGetCurrent(); vm->id = (UInt32)vm; if ((vm->the = xsAliasMachine(&anAllocation, gSSLVM->the, vm->name, vm)) == NULL) { FskMemPtrDispose(vm); return kFskErrMemFull; } #endif *vmp = vm; return err; }
FskErr KprApplicationNew(KprApplication* it, char* url, char* id, Boolean breakOnStart, Boolean breakOnExceptions) { KprCoordinatesRecord coordinates = { kprLeftRight, kprTopBottom, 0, 0, 0, 0, 0, 0 }; xsAllocation allocation = { 2 * 1024 * 1024, 1024 * 1024, 64 * 1024, 8 * 1024, 2048, 16000, 1993 }; FskErr err = kFskErrNone; KprApplication self; bailIfError(FskMemPtrNewClear(sizeof(KprApplicationRecord), it)); self = *it; FskInstrumentedItemNew(self, NULL, &KprApplicationInstrumentation); self->dispatch = &KprApplicationDispatchRecord; self->flags = kprContainer | kprClip | kprVisible; KprContentInitialize((KprContent)self, &coordinates, NULL, NULL); bailIfError(KprURLMerge(gShell->url, url, &self->url)); if (id) { self->id = FskStrDoCopy(id); bailIfNULL(self->id); } self->the = xsAliasMachine(&allocation, gShell->root, self->url, self); if (!self->the) BAIL(kFskErrMemFull); FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentCreateMachine, self); xsBeginHost(self->the); xsResult = xsNewHostFunction(KPR_include, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("include"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewHostFunction(KPR_require, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("require"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("application"))); self->slot = xsResult; xsSetHostData(xsResult, self); (void)xsCall1(xsGet(xsGlobal, xsID("Object")), xsID("seal"), xsResult); xsNewHostProperty(xsGlobal, xsID("application"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsNewHostProperty(xsGlobal, xsID("shell"), xsNull, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); if (breakOnStart) xsDebugger(); if (breakOnExceptions) (void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakOnException"), xsBoolean(breakOnExceptions)); (void)xsCall1(xsGlobal, xsID("include"), xsString(self->url)); xsEndHost(self->the); KprContentChainPrepend(&gShell->applicationChain, self, 0, NULL); bail: return err; }
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; }