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

📄 stafhandlemanager.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    PollingData theNotification(handle, machine, uuid, key, service);        fPollingDataList.push_back(theNotification);    return kSTAFOk;}STAFRC_t STAFHandleManager::deletePolling(STAFHandle_t handle,                                          const STAFString machine,                                          const STAFString uuid,                                          const STAFString service){    if (debug) // XXX        cout << "Deleting polling for handle " << handle << "\n";    STAFMutexSemLock pollingLock(fPollingDataListSem);        PollingDataList::iterator pollingIter;        for (pollingIter = fPollingDataList.begin();        (pollingIter != fPollingDataList.end()) &&        (pollingIter->handle != handle) &&        (pollingIter->machine != machine) &&        (pollingIter->uuid != uuid);        ++pollingIter)    { /* Do Nothing */}    if (pollingIter != fPollingDataList.end() &&        (pollingIter->handle == handle) &&        (pollingIter->machine == machine) &&        (pollingIter->uuid == uuid))    {        fPollingDataList.erase(pollingIter);    }    return kSTAFOk;}STAFRC_t STAFHandleManager::registerHandle(STAFHandle_t &handle,                                           STAFProcessID_t pid,                                           const STAFString &name){    STAFString lowerName(name.toLowerCase());    STAFMutexSemLock handleLock(fHandleListSem);    HandleList::iterator handleIter;    STAFProcessHandle_t procHandle = 0;    for (handleIter = fHandleList.begin(); handleIter != fHandleList.end();         ++handleIter)    {        if (handleIter->second.pid != pid) continue;        if (pid == gSTAFProcPID)        {            if (lowerName == handleIter->second.lowerName)            {                // This is an existing kInProcess handle                if (handleIter->second.state != kInProcess)                {                    STAFTrace::trace(kSTAFTraceError,                                     "In STAFHandleManager::registerHandle(), "                                     "found handle with STAFProc PID, but not "                                     "state == kInProcess");                }                handle = handleIter->second.handle;                return kSTAFOk;            }            else continue;        }        if (!STAFProcess::isRunning(handleIter->second.procHandle))        {            // This is a program that is no longer running, but which has not            // been removed from the list yet.  Either our callback hasn't            // been called for a regular kRegistered process, or the            // ProcessManager has not told us to remove the kPending(Registered)            // handle.  Either way, this handle is not a match.            continue;        }        if (handleIter->second.state == kPending)        {            // This is an existing kPending handle, and the process is            // just now registering.            handle = handleIter->second.handle;            handleIter->second.name = name;            handleIter->second.state = kPendingRegistered;            handleIter->second.lastUsedTimestamp = STAFTimestamp::now();            return kSTAFOk;        }        procHandle = handleIter->second.procHandle;    }    // This is a valid new handle so register it    if (procHandle == 0)    {        unsigned int osRC = 0;        STAFRC_t rc = STAFProcess::getProcessHandleFromID(                      pid, procHandle, osRC);        if (rc != 0)        {            STAFTrace::trace(                kSTAFTraceError, STAFString(                    "In STAFHandleManager::registerHandle: "                    "getProcessHandleFromID failed with OS_RC: ") + osRC);        }    }    HandleData theHandle(fNextHandle++, pid, procHandle,                         (pid == gSTAFProcPID) ? kInProcess : kRegistered,                         STAFTimestamp::now(), name);    fHandleList[theHandle.handle] = theHandle;    handle = theHandle.handle;    if (pid == gSTAFProcPID) return kSTAFOk;    if (procHandle == 0)    {        // If an error occurred calling getProcessHandleFromID() above (e.g.        // osRC 5, AccessDenied), the procHandle will still be 0.  We are        // returning so that the callback will not be performed because it        // will result in a WAIT_FAILED from WaitForMultipleObjects in        // ProcessMonitorThread() with OS_RC: 6 (ERROR_INVALID_HANDLE) and        // it will loop continuously spitting out this error trace message.        // However, since we aren't doing the callback, the handle won't ever        // be garbage collected.        return kSTAFOk;    }        STAFProcessEndCallbackLevel1 callback = { processTerminated, 0 };    return STAFProcess::registerForProcessTermination(pid,           theHandle.procHandle, callback);}STAFRC_t STAFHandleManager::unRegister(STAFHandle_t handle,                                       STAFProcessID_t pid){    STAFRC_t rc = kSTAFOk;    STAFHandle_t unRegHandle;        {        STAFMutexSemLock handleLock(fHandleListSem);            if (fHandleList.find(handle) == fHandleList.end())        {            rc = kSTAFHandleDoesNotExist;            return rc;        }        else        {            HandleData &theHandle = fHandleList[handle];            if (debug) // XXX                cout << "Unregistering handle " << theHandle.handle << "\n";            unRegHandle = theHandle.handle;            if (theHandle.pid != pid)            {                rc = kSTAFInvalidHandle;                return rc;            }            else if (theHandle.state == kPendingRegistered)            {                theHandle.state = kPending;                return rc;            }            else if ((theHandle.state == kRegistered) ||                     (theHandle.state == kInProcess))                fHandleList.erase(handle);        }    }        STAFHandleService::getInstance()->handleRemoved(unRegHandle);        STAFMutexSemLock handleLock(fNotificationListSem);        STAFHandleManager::NotificationList::iterator iter;    STAFString result;        bool moreHandles = true;    if (debug) // XXX        cout << "Removing notifications for handle " << unRegHandle << "\n";        while (moreHandles)    {        for (iter = fNotificationList.begin();              iter != fNotificationList.end()  &&             (iter->handle != unRegHandle)             ; iter++)        {        }                    if (iter != fNotificationList.end())        {            fNotificationList.erase(iter);        }        else        {            moreHandles = false;        }    }    return rc;}STAFRC_t STAFHandleManager::removePendingHandle(STAFHandle_t handle,                                                STAFProcessID_t pid){    STAFRC_t rc = kSTAFOk;    STAFMutexSemLock handleLock(fHandleListSem);    if (fHandleList.find(handle) == fHandleList.end())    {        rc = kSTAFHandleDoesNotExist;    }    else    {        const HandleData &theHandle = fHandleList[handle];        if (theHandle.pid != pid)        {            rc = kSTAFInvalidHandle;        }        else if ((theHandle.state == kPending) ||                 (theHandle.state == kPendingRegistered))        {            fHandleList.erase(handle);        }        else        {            rc = kSTAFInvalidHandle;        }    }    return rc;}STAFRC_t STAFHandleManager::removeStaticHandle(STAFHandle_t handle){    STAFRC_t rc = kSTAFOk;    STAFMutexSemLock handleLock(fHandleListSem);    if (fHandleList.find(handle) == fHandleList.end())    {        rc = kSTAFHandleDoesNotExist;    }    else    {        const HandleData &theHandle = fHandleList[handle];        if (theHandle.state == kStatic)            fHandleList.erase(handle);        else            rc = kSTAFInvalidHandle;    }    return rc;}STAFHandleManager::HandleList STAFHandleManager::getHandleListCopy(){    STAFMutexSemLock handleLock(fHandleListSem);    return fHandleList;}STAFHandleManager::NotificationList STAFHandleManager::getNotificationListCopy(){    STAFMutexSemLock handleLock(fNotificationListSem);    return fNotificationList;}STAFHandleManager::PollingDataList STAFHandleManager::getPollingDataListCopy(){    STAFMutexSemLock handleLock(fPollingDataListSem);    return fPollingDataList;}STAFMutexSem &STAFHandleManager::getHandleManagerSem(){    return fHandleListSem;}// STAFHandleManager::authenticate//// Perform Authentication for the handle.  If credentials are input, check if// the handle is already authenticated, and if so, return an error.  If the// specified Authenticator service is not registered, return an error if// credentials are input; if authentication data is input, set authenticator to // "none" and set userIdentifier to "anonymous". If the specified Authenticator// is found and the authenticationType is kData (indicating a remote system),// check if there is cached authentication information for this remote// machine's handle.  If so, and the cached authentication information is the// same, then don't need to re-authenticate.  Otherwise, submit an// AUTHENTICATE request to the Authenticator service, passing the specified // authentication data or credentials.  If the AUTHENTICATE request is// successful and credentials were input, return authentication data in the // result.//// Parameters://   machine - machine name (Input)//   handle  - handle (Input)//   authenticator - name of authenticator service (Input/Output)//   userIdentifier - name of the user (Input/Output)//   authenticateType - authentication data type, kCredentials or kData (Input)//   authenticationData - authentication credentials or data (Input)//// Returns://   rc 0 if authenticate was successful and if credentials passed//   in via authenticationData, returns authentication data in result.//   Non-zero rc if authenticate failed and any additional info about the//   failure in the result.STAFServiceResult STAFHandleManager::authenticate(                                     const STAFString &machine,                                     const STAFHandle_t handle,                                     STAFString &authenticator,                                     STAFString &userIdentifier,                                     const AuthenticateType authenticateType,                                     const STAFString &authenticationData){    STAFRC_t rc = kSTAFOk;    if (authenticateType == kCredentials)    {        // Check if handle is already authenticated.  If so, return an error.        rc = isAuthenticated(handle);                if (rc != kSTAFOk)        {            return STAFServiceResult(rc);        }    }    // Check if the specified authenticator service is registered    STAFServiceResult serviceResult(kSTAFOk);    STAFServicePtr service;

⌨️ 快捷键说明

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