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

📄 stafperlservicehelper.xs

📁 Software Testing Automation Framework (STAF)的开发代码
💻 XS
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************/ //* Software Testing Automation Framework (STAF)                              *///* (C) Copyright IBM Corp. 2004                                              *///*                                                                           *///* This software is licensed under the Common Public License (CPL) V1.0.     *///*****************************************************************************/#include "STAF.h"#include <queue>#include <map>#include "STAFEventSem.h"#include "STAFMutexSem.h"#include "STAFServiceInterface.h"#include "STAFString.h"#include "STAFConnectionProvider.h"#include <EXTERN.h>#include <perl.h>#include <XSUB.h>#include "STAFPerlService.h"#include "STAFPerlServiceHelper.h"//XXX: need to find a better solution here//     someone defined read, read write and wait macros.#undef wait#undef write#undef readstruct PerlServiceRequestData{    PerlServiceRequestData()    {        fReqNum = 0;        fReqType = 0;        fServiceName = STAFString("");        fExecInfo = STAFString("");        fWriteLocation = STAFString("");        fParms = STAFString("");        fMachine = STAFString("");        fMachineNickname = STAFString("");        fHandleName = STAFString("");        fHandle = 0;        fTrustLevel = 0;        fRequest = STAFString("");        fDiagEnabled = 0;        fUser = STAFString("");        fEndpoint = STAFString("");        fSTAFInstanceUUID = STAFString("");        fIsLocalRequest = 0;        //fConnPtr = NULL;  need to initialize    }    unsigned int fReqNum;    unsigned int fReqType;    STAFString fServiceName; //XXX: Don't need this, because each service has it's own interpreter    STAFString fExecInfo;    STAFString fWriteLocation;    STAFString fParms;    STAFString fMachine;    STAFString fMachineNickname;    STAFString fHandleName;    unsigned int fHandle;    unsigned int fTrustLevel;    STAFString fRequest;    unsigned int fDiagEnabled;    STAFString fUser;    STAFString fEndpoint;    STAFString fSTAFInstanceUUID;    unsigned int fIsLocalRequest;    STAFConnectionPtr fConnPtr;    };typedef STAFRefPtr<PerlServiceRequestData> PerlServiceRequestDataPtr;typedef std::queue<PerlServiceRequestDataPtr> PerlServiceRequestQueue;typedef std::map<unsigned int, PerlServiceRequestDataPtr> PerlServiceRequestMap;//function prototypesSTAFRC_t HandleRequest(const STAFConnectionProvider *provider,                       STAFConnectionPtr &connection);void HandleServiceConstruct(STAFConnectionPtr &connection);void HandleServiceInit(STAFConnectionPtr &connection);void HandleServiceRequest(STAFConnectionPtr &connection);void HandleServiceTerm(STAFConnectionPtr &connection);static PerlServiceRequestQueue requestQueue; //this holds the requests while waiting for perl to get themstatic PerlServiceRequestMap requestMap; //this holds the requests while waiting for perl to handle themstatic STAFEventSem gReceivedRequestSem;static STAFEventSem gPerlInterpreterExitedSem;static STAFMutexSem gRequestQueueMutex;static STAFMutexSem gRequestMapMutex;static STAFMutexSem gReqCountMutex;static STAFString sIPCName("IPCNAME");static STAFMutexSem gDebugPrintLock;int reqCount = 0;void initConnection(char* serviceName){    try    {        // interprocess communication name        STAFString ipcName = STAFString(serviceName);        //option data to create a connection provider        STAFStringConst_t optionData[] = { sIPCName.getImpl(),                                           ipcName.getImpl() };        STAFConnectionProviderConstructInfoLevel1 constructInfo =        {            kSTAFConnectionProviderInbound,            1,            optionData,            &optionData[1]        };        STAFConnectionProvider *connProv =            STAFConnectionProvider::create(ipcName, "STAFLIPC",                                                 &constructInfo, 1);        // when the connProv receives traffic, dispatch it to handleRequest        connProv->start(HandleRequest);    }    catch (STAFException &se)    {        se.write("STAFPerlServiceHelper.initConnection()");    }    catch (...)    {        cout << "Caught unknown exception in STAFServiceHelper.initConnection()" << endl;    }}STAFRC_t HandleRequest(const STAFConnectionProvider *provider,                       STAFConnectionPtr &connection){    unsigned int doShutdown = 0;    try    {        unsigned int reqType = connection->readUInt();        switch (reqType)        {            case PERL_SERVICE_PERL_INTERPRETER_PING:            {                connection->writeUInt(kSTAFOk);                connection->writeString(STAFString());                break;            }            case PERL_SERVICE_LOAD:            {                HandleServiceConstruct(connection);                gReceivedRequestSem.post();                break;            }            case PERL_SERVICE_INIT:            {                HandleServiceInit(connection);                gReceivedRequestSem.post();                break;            }            case PERL_SERVICE_ACCEPT_REQUEST:            {                HandleServiceRequest(connection);                gReceivedRequestSem.post();                break;            }            case PERL_SERVICE_TERM:            {                HandleServiceTerm(connection);                gReceivedRequestSem.post();                break;            }            case PERL_SERVICE_PERL_INTERPRETER_EXIT:            {                gPerlInterpreterExitedSem.post();                connection->writeUInt(kSTAFOk);                connection->writeString(STAFString());                break;            }            default:            {                cout << "Unrecognized Request Type Received" << endl;                connection->writeUInt(kSTAFInvalidValue);                connection->writeString(STAFString("Invalid Perl service ") +                                        "request type: " + STAFString(reqType));                break;            }        }    }    catch (STAFException &se)    {        se.write("PLSTAFSH.HandleRequest()");    }    catch (...)    {        cout << "Caught unknown exception in PLSTAFSH.HandleRequest()" << endl;    }    return 0;}void HandleServiceConstruct(STAFConnectionPtr &connection){    STAFString serviceName   = connection->readString();    STAFString execInfo = connection->readString();    STAFString writeLocation = connection->readString();        STAFServiceType_t serviceType =        static_cast<STAFServiceType_t>(connection->readUInt());    PerlServiceRequestDataPtr reqData = PerlServiceRequestDataPtr(new PerlServiceRequestData(),                                              PerlServiceRequestDataPtr::INIT);    {        STAFMutexSemLock lock(gReqCountMutex);        reqData->fReqNum = reqCount++;    }    reqData->fReqType = PERL_SERVICE_LOAD;    reqData->fServiceName = serviceName;    reqData->fExecInfo = execInfo;    reqData->fWriteLocation = writeLocation;    reqData->fConnPtr = connection;    {        STAFMutexSemLock lock(gRequestQueueMutex);        requestQueue.push(reqData);    }}void HandleServiceInit(STAFConnectionPtr &connection){    STAFString serviceName   = connection->readString();    STAFString parms = connection->readString();    STAFString writeLocation = connection->readString();        PerlServiceRequestDataPtr reqData = PerlServiceRequestDataPtr(new PerlServiceRequestData(),                                              PerlServiceRequestDataPtr::INIT);    {        STAFMutexSemLock lock(gReqCountMutex);        reqData->fReqNum = reqCount++;    }    reqData->fReqType = PERL_SERVICE_INIT;    reqData->fServiceName = serviceName;    reqData->fParms = parms;    reqData->fWriteLocation = writeLocation;    reqData->fConnPtr = connection;    {        STAFMutexSemLock lock(gRequestQueueMutex);        requestQueue.push(reqData);    }}void HandleServiceRequest(STAFConnectionPtr &connection){cout << "handlerequest" << endl;

⌨️ 快捷键说明

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