⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stafhandleservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************//* 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 "STAFHandleService.h"#include "STAFHandleManager.h"#include "STAFProcUtil.h"#include "STAFServiceManager.h"#include "STAFTrace.h"STAFHandleService *STAFHandleService::sHandleService = 0;STAFHandleService::STAFHandleService() : STAFService("HANDLE"){    sHandleService = this;    // query options    fQueryParser.addOption("QUERY",      1,        STAFCommandParser::kValueNotAllowed);    fQueryParser.addOption("HANDLE",    1,        STAFCommandParser::kValueRequired);     // query groups    fQueryParser.addOptionGroup("QUERY",    1, 1);    // query needs    fQueryParser.addOptionNeed("QUERY", "HANDLE");    // create options    fCreateParser.addOption("CREATE",      1,        STAFCommandParser::kValueNotAllowed);    fCreateParser.addOption("HANDLE",      1,        STAFCommandParser::kValueNotAllowed);    fCreateParser.addOption("NAME",        1,        STAFCommandParser::kValueRequired);    // create needs    fCreateParser.addOptionNeed("CREATE", "HANDLE");    fCreateParser.addOptionNeed("CREATE", "NAME");    // notify options    fNotifyParser.addOption("STAF_NOTIFY", 1,        STAFCommandParser::kValueNotAllowed);    fNotifyParser.addOption("REGISTER", 1,        STAFCommandParser::kValueNotAllowed);    fNotifyParser.addOption("ONENDOFHANDLE", 1,        STAFCommandParser::kValueRequired);    fNotifyParser.addOption("MACHINE", 1,        STAFCommandParser::kValueRequired);    fNotifyParser.addOption("UUID", 1,        STAFCommandParser::kValueRequired);    fNotifyParser.addOption("SERVICE", 1,        STAFCommandParser::kValueRequired);    fNotifyParser.addOption("KEY", 1,        STAFCommandParser::kValueRequired);    // notify needs    fNotifyParser.addOptionNeed("STAF_NOTIFY", "REGISTER");    fNotifyParser.addOptionNeed("STAF_NOTIFY", "ONENDOFHANDLE");    fNotifyParser.addOptionNeed("STAF_NOTIFY", "MACHINE");    fNotifyParser.addOptionNeed("STAF_NOTIFY", "SERVICE");    fNotifyParser.addOptionNeed("STAF_NOTIFY", "KEY");    // list options    fListParser.addOption("LIST",          1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("NOTIFICATIONS", 1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("HANDLE",        1,        STAFCommandParser::kValueRequired);    fListParser.addOption("MACHINE",       1,        STAFCommandParser::kValueRequired);    // these are for LIST HANDLES    fListParser.addOption("HANDLES",        1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("NAME",           1,        STAFCommandParser::kValueRequired);    fListParser.addOption("PENDING",        1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("REGISTERED",     1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("INPROCESS",      1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("STATIC",         1,        STAFCommandParser::kValueNotAllowed);    fListParser.addOption("LONG",           1,        STAFCommandParser::kValueNotAllowed);    // LIST groups    fListParser.addOptionGroup("HANDLES NOTIFICATIONS", 0, 1);    // list needs    fListParser.addOptionNeed("PENDING REGISTERED INPROCESS STATIC LONG",                              "HANDLES");    fListParser.addOptionNeed("HANDLE MACHINE", "NOTIFICATIONS");    // unregister options    fUnregisterParser.addOption("UNREGISTER", 1,        STAFCommandParser::kValueNotAllowed);    fUnregisterParser.addOption("ONENDOFHANDLE", 1,        STAFCommandParser::kValueRequired);    fUnregisterParser.addOption("MACHINE", 1,        STAFCommandParser::kValueRequired);    fUnregisterParser.addOption("NOTIFYSERVICE", 1,        STAFCommandParser::kValueRequired);    fUnregisterParser.addOption("NOTIFYMACHINE", 1,        STAFCommandParser::kValueRequired);    // unregister needs    fUnregisterParser.addOptionNeed("STAF_NOTIFY", "ONENDOFHANDLE");    fUnregisterParser.addOptionNeed("STAF_NOTIFY", "MACHINE");    fUnregisterParser.addOptionGroup("NOTIFYSERVICE NOTIFYMACHINE", 0, 1);    // delete options    fDeleteParser.addOption("DELETE",      1,        STAFCommandParser::kValueNotAllowed);    fDeleteParser.addOption("HANDLE",      1,        STAFCommandParser::kValueRequired);    // delete needs    fDeleteParser.addOptionNeed("DELETE", "HANDLE");    // authenticate options    fAuthParser.addOption("AUTHENTICATE", 1,        STAFCommandParser::kValueNotAllowed);    fAuthParser.addOption("USER",         1,        STAFCommandParser::kValueRequired);    fAuthParser.addOption("CREDENTIALS",  1,        STAFCommandParser::kValueRequired);    fAuthParser.addOption("AUTHENTICATOR",  1,        STAFCommandParser::kValueRequired);    // authenticate needs    fAuthParser.addOptionNeed("AUTHENTICATE", "USER");    fAuthParser.addOptionNeed("USER", "CREDENTIALS");    // un-authenticate options    fUnAuthParser.addOption("UNAUTHENTICATE", 1,        STAFCommandParser::kValueNotAllowed);    // Construct map class for handle information used in QUERY HANDLE    fQueryHandleClass = STAFMapClassDefinition::create(        "STAF/Service/Handle/QueryHandle");    fQueryHandleClass->addKey("handle", "Handle");    fQueryHandleClass->addKey("name", "Handle Name");    fQueryHandleClass->addKey("state", "State");    fQueryHandleClass->addKey("lastUsedTimestamp", "Last Used Date-Time");    fQueryHandleClass->addKey("pid", "PID");    fQueryHandleClass->addKey("user", "User");    // Construct map class for handle information used in LIST HANDLES    fHandleInfoClass = STAFMapClassDefinition::create(        "STAF/Service/Handle/HandleInfo");    fHandleInfoClass->addKey("handle", "Handle");    fHandleInfoClass->setKeyProperty("handle", "display-short-name", "H#");    fHandleInfoClass->addKey("name", "Handle Name");    fHandleInfoClass->setKeyProperty("name", "display-short-name", "Name");    fHandleInfoClass->addKey("state", "State");    fHandleInfoClass->addKey("lastUsedTimestamp", "Last Used Date-Time");    fHandleInfoClass->setKeyProperty("lastUsedTimestamp",                                     "display-short-name", "Last Used");        // Construct map class for handle information used in LIST HANDLES LONG    fHandleInfoLongClass = STAFMapClassDefinition::create(        "STAF/Service/Handle/HandleInfoLong");    fHandleInfoLongClass->addKey("handle", "Handle");    fHandleInfoLongClass->setKeyProperty("handle", "display-short-name", "H#");    fHandleInfoLongClass->addKey("name", "Handle Name");    fHandleInfoLongClass->setKeyProperty("name", "display-short-name", "Name");    fHandleInfoLongClass->addKey("state", "State");    fHandleInfoLongClass->addKey("lastUsedTimestamp", "Last Used Date-Time");    fHandleInfoLongClass->setKeyProperty("lastUsedTimestamp",                                     "display-short-name", "Last Used");    fHandleInfoLongClass->addKey("pid", "PID");    // Construct map class for notifiee information used in LIST NOTIFICATIONS    fNotificationClass = STAFMapClassDefinition::create(        "STAF/Service/Handle/NotificationInfo");     fNotificationClass->addKey("handle", "Handle");    fNotificationClass->addKey("machine", "Machine");    fNotificationClass->addKey("notifyService", "Notify Service");}STAFHandleService::~STAFHandleService(){    /* Do Nothing */}STAFString STAFHandleService::info(unsigned int) const{    return name() + ": Internal";}void STAFHandleService::handleRemoved(STAFHandle_t handle){    if (debug) // XXX        cout << "STAFHandleService handleRemoved handle=" << handle << "\n";    STAFHandleManager::NotificationList notificationList =        gHandleManagerPtr->getNotificationListCopy();    STAFHandleManager::NotificationList::iterator iter;    for (iter = notificationList.begin();         iter != notificationList.end(); iter++)    {        STAFHandleManager::NotificationData notifiee(*iter);        if (notifiee.handle == handle)        {            if (debug) // XXX                cout << "Found a matching handle " << handle << "\n";            STAFString request = "STAF_CALLBACK HANDLEDELETED HANDLE ";            request += notifiee.handle;            request += " MACHINE ";            request += gMachinePtr->getImpl();            request += " UUID ";            request += notifiee.uuid;            request += " KEY ";            request += notifiee.key;            if (debug) // XXX                cout << notifiee.machine << " " << notifiee.notifyService << " " << request << "\n";            STAFResultPtr result =                 gSTAFProcHandlePtr->submit(notifiee.machine,                                           notifiee.notifyService,                                           request,                                           kSTAFReqFireAndForget);            if (debug) // XXX                cout << "rc: " << result->rc << " result: " << result->result << "\n";            gHandleManagerPtr->deleteNotification(handle,                                                  notifiee.machine,                                                  notifiee.uuid,                                                  notifiee.notifyService);        }        else        {            if (debug) // XXX                cout << "Found an unmatching handle " << handle << " " << notifiee.handle << "\n";        }    }}STAFServiceResult STAFHandleService::acceptRequest(    const STAFServiceRequest &requestInfo){    STAFString action = requestInfo.fRequest.subWord(0, 1).lowerCase();    if      (action == "query")        return handleQuery(requestInfo);    else if (action == "list")         return handleList(requestInfo);    else if (action == "staf_notify")  return handleNotify(requestInfo);    else if (action == "create")       return handleCreate(requestInfo);    else if (action == "delete")       return handleDelete(requestInfo);    else if (action == "authenticate") return handleAuthenticate(requestInfo);    else if (action == "unauthenticate")    {        return handleUnAuthenticate(requestInfo);    }    else if (action == "help")         return handleHelp(requestInfo);    else return STAFServiceResult(kSTAFInvalidRequestString, "");}STAFServiceResult STAFHandleService::handleCreate(    const STAFServiceRequest &requestInfo){    // Verify that this request came from the local machine and that    // the requesting machine/user has at least trust level 5    IVALIDATE_LOCAL_TRUST(5, "CREATE");        // Parse the request    STAFCommandParseResultPtr parsedResult = fCreateParser.parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFString errorBuffer;    STAFString name;    STAFRC_t rc = RESOLVE_STRING_OPTION("NAME", name);    if (rc) return STAFServiceResult(rc, errorBuffer);    STAFHandle_t theHandle = 0;    rc = gHandleManagerPtr->addAndGetStaticHandle(theHandle, name);    if (rc) return rc;    return STAFServiceResult(kSTAFOk, theHandle);}STAFServiceResult STAFHandleService::handleDelete(    const STAFServiceRequest &requestInfo){    // Verify that this request came from the local machine and that    // the requesting machine/user has at least trust level 5    IVALIDATE_LOCAL_TRUST(5, "DELETE");    // Parse the request    STAFCommandParseResultPtr parsedResult =                              fDeleteParser.parse(requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFString errorBuffer;    STAFHandle_t theHandle = 0;    STAFRC_t rc = RESOLVE_UINT_OPTION("HANDLE", theHandle);    if (rc) return STAFServiceResult(rc, errorBuffer);    rc = gHandleManagerPtr->removeStaticHandle(theHandle);    handleRemoved(theHandle);    if (rc) return STAFServiceResult(rc, theHandle);    return kSTAFOk;}STAFServiceResult STAFHandleService::handleQuery(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 2    IVALIDATE_TRUST(2, "QUERY");        // Parse the request    STAFCommandParseResultPtr parsedResult = fQueryParser.parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    // Resolve the HANDLE option value    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFString errorBuffer;    unsigned int handleNumber;        STAFRC_t rc = RESOLVE_OPTIONAL_UINT_OPTION("HANDLE", handleNumber);    if (rc) return STAFServiceResult(rc, errorBuffer);    // Get a copy of the handle list    STAFHandleManager::HandleList handleList =                                  gHandleManagerPtr->getHandleListCopy();    STAFHandleManager::HandleList::iterator iter;        // Create a marshalled map containing information about the handle    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fQueryHandleClass->reference());    STAFObjectPtr handleMap = fQueryHandleClass->createInstance();    for (iter = handleList.begin(); iter != handleList.end(); iter++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -