void WINAPI winServiceMain(DWORD, LPTSTR *) { auto serviceName = getServiceName(GetCurrentProcessId()); statusHandle = RegisterServiceCtrlHandler((const wchar_t*)serviceName.utf16(), serviceHandler); if (! statusHandle) { return; } // Service status serviceStatus.dwCurrentState = SERVICE_RUNNING; SetServiceStatus(statusHandle, &serviceStatus); // Main function int ret = 1; QString pathstr = getServiceFilePath(serviceName); if (!pathstr.isEmpty()) { auto argList = parseArguments(pathstr); auto *args = new char*[argList.count()]; for (int i = 0; i < argList.count(); i++) { args[i] = argList[i].data(); } ret = managerMain(argList.count(), args); delete[] args; } // Cleanup code must be executed before setting status to SERVICE_STOPPED tSystemInfo("Windows service stopped"); Tf::releaseSystemLogger(); // Service status serviceStatus.dwCurrentState = SERVICE_STOPPED; serviceStatus.dwWin32ExitCode = ret; SetServiceStatus(statusHandle, &serviceStatus); }
static void writeStartupLog() { tSystemInfo("TreeFrog Framework version " TF_VERSION_STR); QString qtversion = QLatin1String("Qt ") + qVersion(); #if defined(Q_OS_WIN) qtversion += QLatin1String(" / ") + winVersion()->value(QSysInfo::WindowsVersion, "Windows"); #elif defined(Q_OS_DARWIN) qtversion += QLatin1String(" / ") + macxVersion()->value(QSysInfo::MacintoshVersion, "Mac OS X"); #elif defined(Q_OS_UNIX) struct utsname uts; if (uname(&uts) == 0) { qtversion += QString(" / %1 %2").arg(uts.sysname).arg(uts.release); } #endif tSystemInfo("%s", qtversion.toLatin1().data()); }
void TThreadApplicationServer::timerEvent(QTimerEvent *event) { if (event->timerId() != reloadTimer.timerId()) { QTcpServer::timerEvent(event); } else { if (newerLibraryExists()) { tSystemInfo("Detect new library of application. Reloading the libraries."); Tf::app()->exit(127); } } }
void TLoggerFactory::loadPlugins() { if (!lggIfMap) { lggIfMap = new QMap<QString, TLoggerInterface *>(); qAddPostRoutine(::cleanup); QDir dir(Tf::app()->pluginPath()); QStringList list = dir.entryList(QDir::Files); for (QStringListIterator i(list); i.hasNext(); ) { QPluginLoader loader(dir.absoluteFilePath(i.next())); tSystemDebug("plugin library for logger: %s", qPrintable(loader.fileName())); if (!loader.load()) { tSystemError("plugin load error: %s", qPrintable(loader.errorString())); continue; } TLoggerInterface *iface = qobject_cast<TLoggerInterface *>(loader.instance()); if ( iface ) { #if QT_VERSION >= 0x050000 QVariantList array = loader.metaData().value("MetaData").toObject().value("Keys").toArray().toVariantList(); for (QListIterator<QVariant> it(array); it.hasNext(); ) { QString key = it.next().toString().toLower(); tSystemInfo("Loaded logger plugin: %s", qPrintable(key)); lggIfMap->insert(key, iface); } #else QStringList keys = iface->keys(); for (QStringListIterator j(keys); j.hasNext(); ) { QString key = j.next().toLower(); tSystemInfo("Loaded logger plugin: %s", qPrintable(key)); lggIfMap->insert(key, iface); } #endif } } } }
void ServerManager::ajustServers() { if (isRunning()) { tSystemDebug("serverCount: %d", serverCount()); if (serverCount() < maxServers && serverCount() < minServers) { startServer(); } else { if (managerState != Running) { tSystemInfo("TreeFrog application servers started up."); managerState = Running; } } } }
static void WINAPI serviceHandler(DWORD ctrl) { switch (ctrl) { case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: tSystemInfo("Windows service: Received a stop-service request."); serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; serviceStatus.dwWaitHint = 30000; SetServiceStatus(statusHandle, &serviceStatus); Tf::app()->exit(0); break; case SERVICE_CONTROL_PAUSE: case SERVICE_CONTROL_CONTINUE: case SERVICE_CONTROL_INTERROGATE: tSystemWarn("Windows service: Received ctrl code: %ld ", ctrl); SetServiceStatus(statusHandle, &serviceStatus); break; default: tSystemWarn("Windows service: Invalid ctrl code: %ld ", ctrl); break; } }