/** * \brief OIL system initialization function. * * Calling this function initializes the OIL and starts the RIP. The function * first checks to ensure that the OIL is not in the \c OIL_Sys_JobActive or * \c OIL_Sys_Uninitialised states. This function: * \arg sets up the callback functions used by the Skin to allocate and free memory. * \n In addition, if the system is currently in the \c OIL_Sys_Inactive state and the next state * requested is the \c OIL_Sys_Active state, this function: * \arg allocates and initializes RIP memory; * \arg provides a list of embedded devices to the RIP; * \arg provides exit and reboot callback functions to the RIP; * \arg starts the RIP; * \arg registers resources, RIP modules and streams as required, and * \arg places the system into the \c OIL_Sys_Active state. * \n If the system is currently in the \c OIL_Sys_Suspended state, and the next state * requested is the \c OIL_Sys_Active state, this function: * \arg places the system into the \c OIL_Sys_Active state. * * During this call the RIP is started and claims * \c g_SystemState.cbRIPMemory bytes of memory. * * \param[in] eNextState The system state that is required by the end of the call; * expected to be \c OIL_Sys_Active. * \return Returns TRUE if the system is successfully initialized (as necessary) * and placed in the requested state, FALSE otherwise. */ int SysInit(OIL_eTySystemState eNextState) { struct SysMemFns tSkinMemoryFns; HQASSERT((OIL_Sys_JobActive != g_SystemState.eCurrentState), ("sys_init entered in state: OIL_Sys_JobActive")); HQASSERT((OIL_Sys_Uninitialised != g_SystemState.eCurrentState), ("sys_init entered in state: OIL_Sys_Uninitialised")); /* Initialise the memory helper functions */ /* - these are the memory allocation functions to be used by skin */ tSkinMemoryFns.pAllocFn = SysAllocFnCallback; tSkinMemoryFns.pFreeFn = SysFreeFnCallback; GG_SHOW(GG_SHOW_OIL, "SysInit:\n"); if ( g_profile_scope != NULL && !SwLeProfileOption(NULL, g_profile_scope) ) { oil_printf("sys_init: Invalid profile scope %s\n", g_profile_scope); return 0; } /* log the job start time */ GGglobal_timing(SW_TRACE_OIL_SYSSTART, 0); if ((g_SystemState.eCurrentState == OIL_Sys_Inactive) && (eNextState == OIL_Sys_Active)) { uint8 *reasonText ; /* allocate memory for the RIP, all systems ready for a job */ g_SystemState.pRIPMemory = NULL; #ifdef PMS_OIL_MERGE_DISABLE_MEM g_SystemState.pRIPMemory = OIL_malloc(OILMemoryPoolSys, OIL_MemBlock, g_SystemState.cbRIPMemory); #else g_SystemState.pRIPMemory = mmalloc(g_SystemState.cbRIPMemory); #endif if(g_SystemState.pRIPMemory == NULL) /*Bad Pointer*/ { oil_printf("sys_init: Failed to allocate RIP Memory\n"); return 0; } (void)SwLeInitRuntime(NULL) ; MemLogInit(g_mps_log, g_mps_telemetry) ; /* It is assumed that pthreads has been initialised. This is done earlier in the OIL boot process. */ /* initialize the SDK support libraries */ g_SystemState.cbmaxAddressSpace = g_SystemState.cbRIPMemory; if ( !SwLeSDKStart(&g_SystemState.cbmaxAddressSpace, &g_SystemState.cbRIPMemory, g_SystemState.pRIPMemory, &tSkinMemoryFns, &reasonText) ) { GG_SHOW(GG_SHOW_OIL, "sys_init: %s.\n", (char *)reasonText) ; return FALSE ; } /* Set number of RIP renderer threads */ SwLeSetRipRendererThreads( g_ConfigurableFeatures.nRendererThreads ); SwLeMemInit(g_SystemState.cbmaxAddressSpace, g_SystemState.cbRIPMemory, 0, g_SystemState.pRIPMemory); /* set MultipleCopies pgbdev param to true so that we get just 1 copy in rastercallback */ SwLePgbSetMultipleCopies(TRUE); SwLeSetRasterCallbacks(OIL_RasterStride, OIL_RasterRequirements, OIL_RasterDestination, OIL_RasterCallback); /* Add embedded devices to list passed to RIP */ SwLeAddCustomDevices( sizeof(ppEmbeddedDevices) / sizeof(ppEmbeddedDevices[0]), ppEmbeddedDevices ); /* set RIP exit callback */ SwLeSetRipExitFunction( OIL_RipExitCallback ); /* set RIP reboot callback */ SwLeSetRipRebootFunction( OIL_RipRebootCallback ); if (!oil_progress_init()) { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to start progress timeline \n"); return FALSE; } /* Start RIP */ if ( SwLeStart( g_SystemState.cbmaxAddressSpace, g_SystemState.cbRIPMemory, 0, g_SystemState.pRIPMemory, (SwLeMONITORCALLBACK *)OIL_MonitorCallback ) ) { g_SystemState.eCurrentState = eNextState; } else { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to start RIP \n"); return FALSE; } /* Report job processing times */ progevts_enable_times(); oil_events_initialise(); if(!RegisterResources()) { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to register resources\n"); return FALSE; } if(!RegisterRIPModules()) { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to register RIP modules\n"); return FALSE; } if(!Stream_Register()) { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to register Stream\n"); return FALSE; } } if ( !libjpeg_register() || !libjpegturbo_register() ) { GG_SHOW(GG_SHOW_OIL, "sys_init: Failed to register libjpeg\n"); return FALSE; } if ((g_SystemState.eCurrentState == OIL_Sys_Suspended) && (eNextState == OIL_Sys_Active)) { GG_SHOW(GG_SHOW_OIL, "**RIP awakes\n"); g_SystemState.eCurrentState = eNextState; return TRUE; } /* Reset the job error status */ g_JobErrorData.Code = 0; g_JobErrorData.bErrorPageComplete = FALSE; /* return TRUE if now in requested state */ return (g_SystemState.eCurrentState == eNextState); }
CppiaLoadedModule LoadCppia(const unsigned char *inData, int inDataLength) { if (!gAllCppiaModules.mPtr) { gAllCppiaModules = Array_obj<Dynamic>::__new(); GCAddRoot( (hx::Object **)&gAllCppiaModules.mPtr ); } CppiaModule *cppiaPtr = new CppiaModule(); CppiaLoadedModule loadedModule = new CppiaObject(cppiaPtr); gAllCppiaModules->push(loadedModule); CppiaModule &cppia = *cppiaPtr; CppiaStream stream(cppiaPtr,inData, inDataLength); String error; try { std::string tok = stream.getAsciiToken(); if (tok!="CPPIA" && tok!="CPPIB") throw "Bad magic"; stream.setBinary(tok=="CPPIB"); int stringCount = stream.getAsciiInt(); for(int s=0;s<stringCount;s++) cppia.strings[s] = stream.readString(); int typeCount = stream.getAsciiInt(); cppia.types.resize(typeCount); DBGLOG("Type count : %d\n", typeCount); for(int t=0;t<typeCount;t++) cppia.types[t] = new TypeData(stream.readString()); int classCount = stream.getAsciiInt(); DBGLOG("Class count : %d\n", classCount); if (stream.binary) { int newLine = stream.getByte(); if (newLine!='\n') throw "Missing new-line after class count"; } cppia.classes.reserve(classCount); for(int c=0;c<classCount;c++) { CppiaClassInfo *info = new CppiaClassInfo(cppia); if (info->load(stream)) cppia.classes.push_back(info); } tok = stream.getToken(); if (tok=="MAIN") { DBGLOG("Main...\n"); cppia.main = new ScriptCallable(createCppiaExpr(stream)); cppia.main->className = "cppia"; cppia.main->functionName = "__cppia_main"; } else if (tok!="NOMAIN") throw "no main specified"; tok = stream.getToken(); if (tok=="RESOURCES") { int count = stream.getInt( ); scriptResources.resize(count+1); for(int r=0;r<count;r++) { tok = stream.getToken(); if (tok!="RESO") throw "no reso tag"; scriptResources[r].mName = cppia.strings[stream.getInt()]; scriptResources[r].mDataLength = stream.getInt(); } if (!stream.binary) stream.skipChar(); for(int r=0;r<count;r++) { int len = scriptResources[r].mDataLength; unsigned char *buffer = (unsigned char *)malloc(len+5); *(unsigned int *)buffer = HX_GC_CONST_ALLOC_BIT; buffer[len+5-1] = '\0'; stream.readBytes(buffer+4, len); #ifdef HX_SMART_STRINGS_1 unsigned char *p = (unsigned char *)buffer+4; unsigned char *end = p + len; while(!hasBig && p<end) if (*p++>127) { *(unsigned int *)buffer |= HX_GC_STRING_CHAR16_T; break; } #endif scriptResources[r].mData = buffer + 4; } scriptResources[count].mDataLength = 0; scriptResources[count].mData = 0; scriptResources[count].mName = String(); RegisterResources(&scriptResources[0]); } else throw "no resources tag"; } catch(const char *errorString) { error = HX_CSTRING("Error reading file ") + String(errorString) + HX_CSTRING(", line ") + String(stream.line) + HX_CSTRING(", char ") + String(stream.pos); } if (!error.__s) try { DBGLOG("Link...\n"); cppia.link(); } catch(const char *errorString) { error = String(errorString); } if (gEnableJit) { #ifdef CPPIA_JIT if (!error.__s) try { DBGLOG("Compile...\n"); cppia.compile(); } catch(const char *errorString) { error = String(errorString); } #endif } if (error.__s) hx::Throw(error); cppia.registerDebugger(); return loadedModule; }