[Jsmooth-cvs] jsmooth/skeletons/winservice WinService.cpp, 1.3, 1.4 WinService.h, 1.3, 1.4 descript
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-04-12 20:01:58
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/winservice In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12205/skeletons/winservice Modified Files: WinService.cpp WinService.h description.skel main.cpp Log Message: Windows service wrapper update Index: description.skel =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/winservice/description.skel,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** description.skel 9 Apr 2007 22:21:23 -0000 1.2 --- description.skel 12 Apr 2007 20:01:50 -0000 1.3 *************** *** 23,33 **** </skeletonProperties> <skeletonProperties> - <description>SKEL_WINSERVICE_DESCRIPTION_DESCRIPTION</description> - <idName>ServiceDescription</idName> - <label>SKEL_WINSERVICE_DESCRIPTION_LABEL</label> - <type>textarea</type> - <value>A description of the service</value> - </skeletonProperties> - <skeletonProperties> <description>SKEL_WINSERVICE_PROPERTY_MESSAGE_DESCRIPTION</description> <idName>Message</idName> --- 23,26 ---- *************** *** 51,54 **** --- 44,54 ---- </skeletonProperties> <skeletonProperties> + <description>SKEL_WINSERVICE_INTERACTIVE_DESCRIPTION</description> + <idName>Interactive</idName> + <label>SKEL_WINSERVICE_INTERACTIVE_LABEL</label> + <type>boolean</type> + <value>0</value> + </skeletonProperties> + <skeletonProperties> <description>SKEL_GENERIC_PROPERTY_DEBUG_DESCRIPTION</description> <idName>Debug</idName> Index: main.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/winservice/main.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 9 Apr 2007 22:21:23 -0000 1.3 --- main.cpp 12 Apr 2007 20:01:50 -0000 1.4 *************** *** 35,42 **** extern WinService* winservice_ref; void _debugOutput(const std::string& text) { ! if (winservice_ref != 0) winservice_ref->log(text); } --- 35,43 ---- extern WinService* winservice_ref; + bool global_debug; void _debugOutput(const std::string& text) { ! if ((winservice_ref != 0) && global_debug) winservice_ref->log(text); } *************** *** 46,51 **** --- 47,55 ---- int main(int argc, char *argv[]) { + global_debug = false; winservice_ref = 0; ResourceManager resman("JAVA", PROPID, JARID); + + std::string rootdir = FileUtils::getExecutablePath(); std::string serviceName = resman.getProperty("skel_ServiceName"); *************** *** 55,70 **** serviceDisplayName = serviceName; ! std::string autostart = resman.getProperty("skel_Autostart"); ! std::string logfile = resman.getProperty("skel_Logile"); if (logfile == "") logfile = "service.log"; WinService winserv(serviceName, logfile); winserv.setDisplayName(serviceDisplayName); winserv.setDescription(serviceDescription); ! winserv.setAutostart( (StringUtils::parseInt(autostart)==1)?true:false ); ! ! winserv.setAutostart( true ); if (argc>1) --- 59,76 ---- serviceDisplayName = serviceName; ! global_debug = resman.getBooleanProperty("skel_Debug"); ! std::string logfile = resman.getProperty("skel_Logfile"); if (logfile == "") logfile = "service.log"; + if (!FileUtils::isAbsolute(logfile)) + logfile = FileUtils::concFile(rootdir, logfile); + WinService winserv(serviceName, logfile); winserv.setDisplayName(serviceDisplayName); winserv.setDescription(serviceDescription); ! winserv.setAutostart( resman.getBooleanProperty("skel_Autostart") ); ! winserv.setInteractive( resman.getBooleanProperty("skel_Interactive") ); if (argc>1) Index: WinService.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/winservice/WinService.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WinService.cpp 9 Apr 2007 22:21:23 -0000 1.3 --- WinService.cpp 12 Apr 2007 20:01:50 -0000 1.4 *************** *** 80,83 **** --- 80,89 ---- } + WinService::~WinService() + { + if (m_jvm != 0) + m_jvm->callDLLStaticMethodInt("java.lang.System", "exit", "(I)V", 0); + } + void WinService::connect() { *************** *** 100,107 **** return false; std::string exepath = FileUtils::concFile(FileUtils::getExecutablePath(), FileUtils::getExecutableFileName()); HANDLE service = (HANDLE)CreateService((SC_HANDLE)scman, m_cname, m_serviceDisplayName.c_str(), // service name to display SERVICE_ALL_ACCESS, // desired access ! SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, // service type m_autostart?SERVICE_AUTO_START:SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type --- 106,114 ---- return false; std::string exepath = FileUtils::concFile(FileUtils::getExecutablePath(), FileUtils::getExecutableFileName()); + HANDLE service = (HANDLE)CreateService((SC_HANDLE)scman, m_cname, m_serviceDisplayName.c_str(), // service name to display SERVICE_ALL_ACCESS, // desired access ! SERVICE_WIN32_OWN_PROCESS | (m_interactive?SERVICE_INTERACTIVE_PROCESS:0), // service type m_autostart?SERVICE_AUTO_START:SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type *************** *** 217,221 **** setStatus(SERVICE_STOP_PENDING); m_serviceThread.start(winservice_thread_stop, (void*)this); - setStatus(SERVICE_STOP_PENDING); return; --- 224,227 ---- *************** *** 251,261 **** setStatus(SERVICE_RUNNING); ! launcher->dllInstanciate(*globalResMan, "wsreg"); ! ! log("Launched successfully the DLL (" + launcher->toString() + ")"); } else { ! log("ERROR: could not launch the JVM DLL"); } --- 257,274 ---- setStatus(SERVICE_RUNNING); ! if ( ! launcher->dllInstanciate(*globalResMan, "wsreg") ) ! { ! log("Failed to launch the service: can't instanciate the JVM DLL"); ! } ! else ! log("Launched successfully the DLL (" + launcher->toString() + ")"); } else { ! log("ERROR: could not find any suitable Java Virtual Machine"); ! std::string errmsg = globalResMan->getProperty("skel_Message"); ! MessageBox(NULL, ! errmsg.c_str(), FileUtils::getExecutableFileName().c_str(), ! MB_OK|MB_ICONQUESTION|MB_APPLMODAL); } *************** *** 267,280 **** void WinService::kill() { ! log("requesting stop..."); ! setStatus(SERVICE_STOP_PENDING); if (m_jvm != 0) { setStatus(SERVICE_STOPPED); ! m_jvm->callDLLStaticMethod("java.lang.System", "exit", "()V"); ! log("exit called"); ! m_jvm->destroyVM(); ! log("vm destroyed"); } } --- 280,294 ---- void WinService::kill() { ! log("Stopping the service..."); if (m_jvm != 0) { setStatus(SERVICE_STOPPED); ! // We are never here for a very long time, as the ! // SERVICE_STOPPED signal kills this thread asap. Therefore, we ! // do nothing here, we delay the java.lang.System.exit() call to ! // the destructor of this class } + else + log("no jvm available"); } *************** *** 336,339 **** --- 350,358 ---- } + void WinService::setInteractive(bool b) + { + m_interactive = b; + } + void WinService::setDisplayName(const std::string& displayname) { Index: WinService.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/winservice/WinService.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WinService.h 9 Apr 2007 22:21:23 -0000 1.3 --- WinService.h 12 Apr 2007 20:01:50 -0000 1.4 *************** *** 40,43 **** --- 40,44 ---- std::string m_serviceDescription; bool m_autostart; + bool m_interactive; SERVICE_TABLE_ENTRY m_dispatchTable[2]; *************** *** 54,57 **** --- 55,59 ---- public: WinService(const std::string& name, const std::string& filename); + ~WinService(); void connect(); *************** *** 80,83 **** --- 82,86 ---- void setDescription(const std::string& description); void setAutostart(bool b); + void setInteractive(bool b); }; |