BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { char szSystemPath[MAX_PATH] = {0}; GetSystemDirectory(szSystemPath, MAX_PATH); char szLogPath[MAX_PATH] = {0}; sprintf(szLogPath, "%s\\FileSearch.log", szSystemPath); log.SetFile(szLogPath, true); log.SetMode(Log::ToFile); log.SetLevel(LL_DEBUG_INFO); } break; case DLL_PROCESS_DETACH: { } break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return TRUE; }
bool Engine::Initialize(const VariantMap& parameters) { if (initialized_) return true; PROFILE(InitEngine); // Set headless mode headless_ = GetParameter(parameters, "Headless", false).GetBool(); // Register the rest of the subsystems if (!headless_) { context_->RegisterSubsystem(new Graphics(context_)); context_->RegisterSubsystem(new Renderer(context_)); } else { // Register graphics library objects explicitly in headless mode to allow them to work without using actual GPU resources RegisterGraphicsLibrary(context_); } // In debug mode, check now that all factory created objects can be created without crashing #ifdef _DEBUG const HashMap<ShortStringHash, SharedPtr<ObjectFactory> >& factories = context_->GetObjectFactories(); for (HashMap<ShortStringHash, SharedPtr<ObjectFactory> >::ConstIterator i = factories.Begin(); i != factories.End(); ++i) SharedPtr<Object> object = i->second_->CreateObject(); #endif // Start logging Log* log = GetSubsystem<Log>(); if (log) { if (HasParameter(parameters, "LogLevel")) log->SetLevel(GetParameter(parameters, "LogLevel").GetInt()); log->SetQuiet(GetParameter(parameters, "LogQuiet", false).GetBool()); log->Open(GetParameter(parameters, "LogName", "Urho3D.log").GetString()); } // Set maximally accurate low res timer GetSubsystem<Time>()->SetTimerPeriod(1); // Configure max FPS if (GetParameter(parameters, "FrameLimiter", true) == false) SetMaxFps(0); // Set amount of worker threads according to the available physical CPU cores. Using also hyperthreaded cores results in // unpredictable extra synchronization overhead. Also reserve one core for the main thread unsigned numThreads = GetParameter(parameters, "WorkerThreads", true).GetBool() ? GetNumPhysicalCPUs() - 1 : 0; if (numThreads) { GetSubsystem<WorkQueue>()->CreateThreads(numThreads); LOGINFO(ToString("Created %u worker thread%s", numThreads, numThreads > 1 ? "s" : "")); } // Add resource paths ResourceCache* cache = GetSubsystem<ResourceCache>(); FileSystem* fileSystem = GetSubsystem<FileSystem>(); String exePath = fileSystem->GetProgramDir(); Vector<String> resourcePaths = GetParameter(parameters, "ResourcePaths", "CoreData;Data").GetString().Split(';'); Vector<String> resourcePackages = GetParameter(parameters, "ResourcePackages").GetString().Split(';'); for (unsigned i = 0; i < resourcePaths.Size(); ++i) { bool success = false; // If path is not absolute, prefer to add it as a package if possible if (!IsAbsolutePath(resourcePaths[i])) { String packageName = exePath + resourcePaths[i] + ".pak"; if (fileSystem->FileExists(packageName)) { SharedPtr<PackageFile> package(new PackageFile(context_)); if (package->Open(packageName)) { cache->AddPackageFile(package); success = true; } } if (!success) { String pathName = exePath + resourcePaths[i]; if (fileSystem->DirExists(pathName)) success = cache->AddResourceDir(pathName); } } else { String pathName = resourcePaths[i]; if (fileSystem->DirExists(pathName)) success = cache->AddResourceDir(pathName); } if (!success) { LOGERROR("Failed to add resource path " + resourcePaths[i]); return false; } } // Then add specified packages for (unsigned i = 0; i < resourcePackages.Size(); ++i) { bool success = false; String packageName = exePath + resourcePackages[i]; if (fileSystem->FileExists(packageName)) { SharedPtr<PackageFile> package(new PackageFile(context_)); if (package->Open(packageName)) { cache->AddPackageFile(package); success = true; } } if (!success) { LOGERROR("Failed to add resource package " + resourcePackages[i]); return false; } } // Initialize graphics & audio output if (!headless_) { Graphics* graphics = GetSubsystem<Graphics>(); Renderer* renderer = GetSubsystem<Renderer>(); if (HasParameter(parameters, "ExternalWindow")) graphics->SetExternalWindow(GetParameter(parameters, "ExternalWindow").GetPtr()); graphics->SetForceSM2(GetParameter(parameters, "ForceSM2", false).GetBool()); graphics->SetWindowTitle(GetParameter(parameters, "WindowTitle", "Urho3D").GetString()); if (!graphics->SetMode( GetParameter(parameters, "WindowWidth", 0).GetInt(), GetParameter(parameters, "WindowHeight", 0).GetInt(), GetParameter(parameters, "FullScreen", true).GetBool(), GetParameter(parameters, "WindowResizable", false).GetBool(), GetParameter(parameters, "VSync", false).GetBool(), GetParameter(parameters, "TripleBuffer", false).GetBool(), GetParameter(parameters, "MultiSample", 1).GetInt() )) return false; if (HasParameter(parameters, "RenderPath")) renderer->SetDefaultRenderPath(cache->GetResource<XMLFile>(GetParameter(parameters, "RenderPath").GetString())); renderer->SetDrawShadows(GetParameter(parameters, "Shadows", true).GetBool()); if (renderer->GetDrawShadows() && GetParameter(parameters, "LowQualityShadows", false).GetBool()) renderer->SetShadowQuality(SHADOWQUALITY_LOW_16BIT); if (GetParameter(parameters, "Sound", true).GetBool()) { GetSubsystem<Audio>()->SetMode( GetParameter(parameters, "SoundBuffer", 100).GetInt(), GetParameter(parameters, "SoundMixRate", 44100).GetInt(), GetParameter(parameters, "SoundStereo", true).GetBool(), GetParameter(parameters, "SoundInterpolation", true).GetBool() ); } } // Init FPU state of main thread InitFPU(); frameTimer_.Reset(); initialized_ = true; return true; }
main() { Log LogAlarm; Config CfgCred("credito.ini"); char buffer1[500]; char buffer2[500]; Queue XQueue,EQueue; long QueueID,QueuePerm; struct tm *newtime; time_t ltime; int ret; int len; Iso_Msg *IsoMsg; Iso_Msg *IsoRta; LogAlarm.Open("../log/Em.log"); LogAlarm.SetLevel(10); CfgCred.GetItem("CAVisaDaemon","QueueID",buffer1); QueueID=atol(buffer1); CfgCred.GetItem("CAVisaDaemon","QueuePerms",buffer2); QueuePerm=atol(buffer2); ret=XQueue.Create(QueueID,QueuePerm); if (ret!=OK) exit(ret); CfgCred.GetItem("Daemon","QueueID",buffer1); QueueID=atol(buffer1); CfgCred.GetItem("Daemon","QueuePerms",buffer2); QueuePerm=atol(buffer2); ret=EQueue.Open(QueueID,QueuePerm); if (ret!=OK) { exit(ret); } time(<ime); newtime=localtime(<ime); srandom(newtime->tm_sec); LogAlarm.Put(1,"Comenzando Operacion %s\n",asctime(newtime)); while (ret==OK) { len=XQueue.GetMsg(0, buffer1, sizeof(buffer1)); if (len==NOOK) { break; } IsoMsg=new Iso_Msg(buffer1,len); switch (IsoMsg->GetMsgType()) { case TYPE_VISA_VENTA: LogAlarm.Put(1,"Recibido PriceOn [%s] [%s]\n", IsoMsg->GetField(41),IsoMsg->GetField(11)); IsoRta = new Iso_Msg(TYPE_VISA_VENTA_RTA); IsoRta->PutField(2,IsoMsg->GetField(2)); IsoRta->PutField(11, IsoMsg->GetField(11)); IsoRta->PutField(24, IsoMsg->GetField(24)); sprintf(buffer1,"%012%d",random()); IsoRta->PutField(37,buffer1); sprintf(buffer1,"%06d",random()); IsoRta->PutField(38,buffer1); IsoRta->PutField(39,"00"); IsoRta->PutField(41, IsoMsg->GetField(41)); len=IsoRta->GetMsgString(buffer1); ret=EQueue.SendMsg(EVENT_PRICEONLINE_RTA,buffer1,len); break; } } }
/* +-----------------+------------------------------------------------------------+ | FUNCION | init | +-----------------+------------------------------------------------------------+ | DESCRIPCION | Inicia las estructuras y memoria compartida | | | | +-----------------+------------------------------------------------------------+ */ int init() { int ret; int cont; int max_entries; char aux_str1[100]; char aux_str2[100]; /* Configura las señales de terminacion */ signal(SIGINT, shut_down); signal(SIGTERM, shut_down); /* Obtiene el nombre del archivo de log */ Cfg.GetItem("TimeOutDaemon", "LogName", aux_str1); LogAlarm.Open(aux_str1); /* Setea el nivel de log */ Cfg.GetItem("TimeOutDaemon", "LogLevel", aux_str1); LogAlarm.SetLevel(atoi(aux_str1)); /* Loguea hora de comienzo */ LogAlarm.Put( 0,"TimeOutDaemon::init(): Comienzo [%s] - %s", NUM_VERSION, currentTimeLog()); /* Obtiene la cantidad maxima de entradas en la cola */ Cfg.GetItem("TimeOutDaemon", "MaxEntries", aux_str1); max_entries=atoi(aux_str1); /* Obtiene la cantidad maxima de entradas en la tabla de PIDs */ Cfg.GetItem("PIDTable", "ShMemID", aux_str1); Cfg.GetItem("PIDTable", "MaxEntries", aux_str2); /* Abre tabla de PIDs */ LogAlarm.Put(0, "TimeOutDaemon::init(): Abre tabla de PIDs [%s] [%s]\n", aux_str1, aux_str2); while (PTable.Open(atoi(aux_str1), atoi(aux_str2))==NOOK) { if (PTable.GetErrno()!=ENOENT) { LogAlarm.Put(0, "TimeOutDaemon::init(): Error (%d)!!\n", PTable.GetErrno()); exit(1); } } /* Pone el pid en la tabla */ LogAlarm.Put(0, "TimeOutDaemon::init(): Adding PID to PID table...\n"); ret=PTable.PutPid(getpid()); if (ret==NOOK) { LogAlarm.Put(0, "TimeOutDaemon::init(): Error (%d)!!\n", PTable.GetErrno()); exit(1); } /* Obtiene los identificadores y permisos de la cola de timeout */ Cfg.GetItem("TimeOutDaemon", "ShMemID", aux_str1); Cfg.GetItem("TimeOutDaemon", "ShMemPerms", aux_str2); /* Crea cola de timeout */ LogAlarm.Put(0, "TimeOutDaemon::init(): Creando area de memoria compartida para la Timeout_Queue\n"); ret=timeout_queue.Create(atoi(aux_str1), max_entries, atoi(aux_str2)); if (ret==NOOK) { LogAlarm.Put(0, "TimeOutDaemon::init(): Error (%d) al crear area para la Timeout_Queue \n", timeout_queue.GetErrno()); } /* Obtiene identificador de la cola de eventos */ Cfg.GetItem("VisaDaemon", "QueueID", aux_str1); /* Abre cola de eventos */ LogAlarm.Put(0, "TimeOutDaemon::init(): Abriendo cola de eventos...\n"); ret= EQueue.Open(atoi(aux_str1)); if (ret==NOOK) { LogAlarm.Put(1, "TimeOutDaemon::init(): Error (%d) al abrir cola de eventos!!\n", EQueue.GetErrno()); return NOOK; } return OK; }
int main(int argc, char** argv) { #ifdef WIN32 const Vector<String>& arguments = ParseArguments(GetCommandLineW()); #else const Vector<String>& arguments = ParseArguments(argc, argv); #endif bool dumpApiMode = false; String outputFile; if (arguments.Size() < 1) ErrorExit("Usage: ScriptCompiler <input file> [resource path for includes]\n" " ScriptCompiler -dumpapi [output file]"); else { if (arguments[0] != "-dumpapi") outputFile = arguments[0]; else { dumpApiMode = true; if (arguments.Size() > 1) outputFile = arguments[1]; } } SharedPtr<Context> context(new Context()); // Note: creating the Engine registers most subsystems which don't require engine initialization SharedPtr<Engine> engine(new Engine(context)); context->RegisterSubsystem(new Script(context)); Log* log = context->GetSubsystem<Log>(); // Register Log subsystem manually if compiled without logging support if (!log) { context->RegisterSubsystem(new Log(context)); log = context->GetSubsystem<Log>(); } log->SetLevel(LOG_WARNING); log->SetTimeStamp(false); if (!dumpApiMode) { String path, file, extension; SplitPath(outputFile, path, file, extension); ResourceCache* cache = context->GetSubsystem<ResourceCache>(); // Add resource path to be able to resolve includes if (arguments.Size() > 1) cache->AddResourceDir(arguments[1]); else cache->AddResourceDir(cache->GetPreferredResourceDir(path)); if (!file.StartsWith("*")) CompileScript(context, outputFile); else { Vector<String> scriptFiles; context->GetSubsystem<FileSystem>()->ScanDir(scriptFiles, path, file + extension, SCAN_FILES, false); for (unsigned i = 0; i < scriptFiles.Size(); ++i) CompileScript(context, path + scriptFiles[i]); } } else { if (!outputFile.Empty()) { log->SetQuiet(true); log->Open(outputFile); } // If without output file, dump to stdout instead context->GetSubsystem<Script>()->DumpAPI(); } return EXIT_SUCCESS; }