📄 stafshutdownservice.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001, 2004, 2005 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAFProc.h"#include "STAFProcUtil.h"#include "STAFShutdownService.h"#include "STAFNotificationList.h"#include "STAFUtil.h"// SHUTDOWN// NOTIFY REGISTER [MACHINE <Machine>] [HANDLE <Handle> | NAME <Name>]// [PRIORITY <Priority>]// NOTIFY UNREGISTER [MACHINE <Machine>] [HANDLE <Handle> | NAME <Name>]// [PRIORITY <Priority>]// NOTIFY LISTSTAFShutdownService::STAFShutdownService() : STAFService("SHUTDOWN"){ fShutdownParser.addOption("NOTIFY", 1, STAFCommandParser::kValueNotAllowed); fShutdownParser.addOption("REGISTER", 1, STAFCommandParser::kValueNotAllowed); fShutdownParser.addOption("UNREGISTER", 1, STAFCommandParser::kValueNotAllowed); fShutdownParser.addOption("MACHINE", 1, STAFCommandParser::kValueRequired); fShutdownParser.addOption("HANDLE", 1, STAFCommandParser::kValueRequired); fShutdownParser.addOption("NAME", 1, STAFCommandParser::kValueRequired); fShutdownParser.addOption("PRIORITY", 1, STAFCommandParser::kValueRequired); fShutdownParser.addOptionGroup("HANDLE NAME", 0, 1); // Construct map class for shutdown notifiee information fNotifieeClass = STAFMapClassDefinition::create( "STAF/Service/Shutdown/Notifiee"); fNotifieeClass->addKey("priority", "Priority"); fNotifieeClass->addKey("machine", "Machine"); fNotifieeClass->addKey("notifyBy", "Notify By"); fNotifieeClass->addKey("notifiee", "Notifiee");}STAFString STAFShutdownService::info(unsigned int) const{ return name() + ": Internal";}STAFShutdownService::~STAFShutdownService(){ /* Do Nothing */}STAFServiceResult STAFShutdownService::acceptRequest( const STAFServiceRequest &requestInfo){ STAFString action = requestInfo.fRequest.subWord(0, 1).lowerCase(); if (action == "shutdown") return handleShutdown(requestInfo); else if (action == "notify") { STAFString subAction = requestInfo.fRequest.subWord(1, 1).lowerCase(); if (subAction == "register") return handleNotifyRegistration(true, requestInfo); else if (subAction == "unregister") return handleNotifyRegistration(false, requestInfo); else if (subAction == "list") return handleNotifyList(requestInfo); } else if (action == "help") return handleHelp(requestInfo); return STAFServiceResult(kSTAFInvalidRequestString);}STAFServiceResult STAFShutdownService::handleShutdown( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 5 IVALIDATE_TRUST(5, "SHUTDOWN"); return STAFServiceResult(kSTAFOk, "", 1);}STAFServiceResult STAFShutdownService::handleNotifyRegistration( bool isRegister, const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 3 if (isRegister) { IVALIDATE_TRUST(3, "REGISTER"); } else { IVALIDATE_TRUST(3, "UNREGISTER"); } // Parse the request STAFCommandParseResultPtr parsedResult = fShutdownParser.parse( requestInfo.fRequest); if (parsedResult->rc != kSTAFOk) { return STAFServiceResult(kSTAFInvalidRequestString, parsedResult->errorBuffer, 0); } DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo); unsigned int useName = parsedResult->optionTimes("NAME"); unsigned int theHandle = requestInfo.fHandle; unsigned int priority = 5; STAFString machine = requestInfo.fEndpoint; STAFString name; STAFString errorBuffer; STAFRC_t rc = RESOLVE_OPTIONAL_UINT_OPTION("HANDLE", theHandle); if (!rc) rc = RESOLVE_OPTIONAL_UINT_OPTION("PRIORITY", priority); if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("MACHINE", machine); if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("NAME", name); if (rc) return STAFServiceResult(rc, errorBuffer); if (isRegister) { if (useName) rc = gNotifyOnShutdownPtr->reg(machine, name, priority); else rc = gNotifyOnShutdownPtr->reg(machine, theHandle, priority); } else { if (useName) rc = gNotifyOnShutdownPtr->unregister(machine, name, priority); else rc = gNotifyOnShutdownPtr->unregister(machine, theHandle, priority); } return rc;}STAFServiceResult STAFShutdownService::handleNotifyList( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 2 IVALIDATE_TRUST(2, "NOTIFY LIST"); // Create a marshalled list of maps containing information about // the shutdown notifiees. STAFObjectPtr mc = STAFObject::createMarshallingContext(); mc->setMapClassDefinition(fNotifieeClass->reference()); STAFObjectPtr outputList = STAFObject::createList(); STAFNotificationList::NotifieeList notifieeList( gNotifyOnShutdownPtr->getNotifieeListCopy()); STAFNotificationList::NotifieeList::iterator iter; for (iter = notifieeList.begin(); iter != notifieeList.end(); iter++) { STAFNotificationList::Notifiee notifiee = *iter; STAFObjectPtr notifieeMap = fNotifieeClass->createInstance(); notifieeMap->put("priority", STAFString(notifiee.priority)); notifieeMap->put("machine", STAFString(notifiee.machine)); if (notifiee.nameOrHandle == STAFNotificationList::Notifiee::kName) { notifieeMap->put("notifyBy", STAFString("Name")); notifieeMap->put("notifiee", STAFString(notifiee.process)); } else { notifieeMap->put("notifyBy", STAFString("Handle")); notifieeMap->put("notifiee", STAFString(notifiee.handle)); } outputList->append(notifieeMap); } mc->setRootObject(outputList); return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFShutdownService::handleHelp( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 1 IVALIDATE_TRUST(1, "HELP"); STAFString result("SHUTDOWN Service Help" + *gLineSeparatorPtr + *gLineSeparatorPtr); result += "SHUTDOWN" + *gLineSeparatorPtr; result += "NOTIFY REGISTER [MACHINE <Machine>] [HANDLE <Handle> | " "NAME <Name>]" + *gLineSeparatorPtr; result += " [PRIORITY <Priority>]" + *gLineSeparatorPtr; result += "NOTIFY UNREGISTER [MACHINE <Machine>] [HANDLE <Handle> | " "NAME <Name>]" + *gLineSeparatorPtr; result += " [PRIORITY <Priority>]" + *gLineSeparatorPtr; result += "NOTIFY LIST" + *gLineSeparatorPtr; result += "HELP" + *gLineSeparatorPtr; return STAFServiceResult(kSTAFOk, result);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -