void loom_asset_initialize(const char *rootUri) { // Set up the lock for the mutex. lmAssert(gAssetLock == NULL, "Double initialization!"); gAssetLock = loom_mutex_create(); // Note the CWD. char tmpBuff[1024]; platform_getCurrentWorkingDir(tmpBuff, 1024); lmLog(gAssetLogGroup, "Current working directory ='%s'", tmpBuff); // And the allocator. //gAssetAllocator = loom_allocator_initializeTrackerProxyAllocator(loom_allocator_getGlobalHeap()); gAssetAllocator = (loom_allocator_getGlobalHeap()); // Clear, it might have been filled up before (for unit tests) gAssetLoadQueue.clear(); gAssetHash.clear(); // Asset server connection state. gAssetServerSocketLock = loom_mutex_create(); // And set up some default asset types. loom_asset_registerType(LATText, loom_asset_textDeserializer, loom_asset_textRecognizer); loom_asset_registerType(LATBinary, loom_asset_binaryDeserializer, loom_asset_binaryRecognizer); loom_asset_registerImageAsset(); loom_asset_registerSoundAsset(); loom_asset_registerScriptAsset(); // Listen to log and send it if we have a connection. loom_log_addListener(loom_asset_logListener, NULL); }
void DLLEXPORT assetAgent_run(IdleCallback idleCb, LogCallback logCb, FileChangeCallback changeCb) { loom_log_initialize(); platform_timeInitialize(); stringtable_initialize(); loom_net_initialize(); // Put best effort towards closing our listen socket when we shut down, to // avoid bugs on OSX where the OS won't release it for a while. #if LOOM_PLATFORM == LOOM_PLATFORM_OSX || LOOM_PLATFORM == LOOM_PLATFORM_LINUX atexit(shutdownListenSocket); signal(SIGINT, shutdownListenSocketSignalHandler); #endif // Set up mutexes. gActiveSocketsMutex = loom_mutex_create(); gFileScannerLock = loom_mutex_create(); gCallbackLock = loom_mutex_create(); // Note callbacks. gLogCallback = logCb; gFileChangeCallback = changeCb; utString *sdkPath = optionGet("sdk"); if (sdkPath != NULL) TelemetryServer::setClientRootFromSDK(sdkPath->c_str()); const char *ltcPath = getenv("LoomTelemetry"); if (ltcPath != NULL) TelemetryServer::setClientRoot(ltcPath); if (optionEquals("telemetry", "true")) TelemetryServer::start(); // Set up the log callback. loom_log_addListener(fileWatcherLogListener, NULL); lmLogDebug(gAssetAgentLogGroup, "Starting file watcher thread..."); gFileWatcherThread = loom_thread_start((ThreadFunction)fileWatcherThread, NULL); lmLogDebug(gAssetAgentLogGroup, " o OK!"); lmLogDebug(gAssetAgentLogGroup, "Starting socket listener thread..."); gSocketListenerThread = loom_thread_start((ThreadFunction)socketListeningThread, NULL); lmLogDebug(gAssetAgentLogGroup, " o OK!"); // Loop till it's time to quit. while (!gQuitFlag) { // Serve the idle callback. if (idleCb) { idleCb(); } // And anything in the queue. while (CallbackQueueNote *cqn = dequeueCallback()) { if (!cqn) { break; } // Issue the call. if (cqn->type == QNT_Change) { gFileChangeCallback(cqn->text.c_str()); } else if (cqn->type == QNT_Log) { gLogCallback(cqn->text.c_str()); } else { lmAssert(false, "Unknown callback queue note type."); } // Clean it up. //free((void *)cqn->text); lmDelete(NULL, cqn); } // Pump any remaining socket writes loom_net_pump(); // Poll at about 60hz. loom_thread_sleep(16); } // Clean up the socket. shutdownListenSocket(); }