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

📄 stafproc.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    gGlobalVariablePool->set(configHead + "OS/MinorVersion",                             configInfo.osMinorVersion);    gGlobalVariablePool->set(configHead + "OS/Revision",                             configInfo.osRevision);    gGlobalVariablePool->set(configHead + "Mem/Physical/Bytes",                             STAFString(configInfo.physicalMemory));    gGlobalVariablePool->set(configHead + "Mem/Physical/KB",                             STAFString(configInfo.physicalMemory / 1024));    gGlobalVariablePool->set(configHead + "Mem/Physical/MB",                             STAFString(configInfo.physicalMemory /                                           (1024 * 1024)));    gGlobalVariablePool->set(configHead + "STAFRoot", configInfo.exePath);    gGlobalVariablePool->set(configHead + "Sep/Line",                             configInfo.lineSeparator);    gGlobalVariablePool->set(configHead + "Sep/File",                             configInfo.fileSeparator);    gGlobalVariablePool->set(configHead + "Sep/Path",                             configInfo.pathSeparator);    gGlobalVariablePool->set(configHead + "Sep/Command",                             configInfo.commandSeparator);    gGlobalVariablePool->set(configHead + "CodePage",                             STAFConverter::determineCodePage());    gLineSeparator = configInfo.lineSeparator;    gFileSeparator = configInfo.fileSeparator;    gPathSeparator = configInfo.pathSeparator;    gCommandSeparator = configInfo.commandSeparator;    // Set the default writeable STAF location (if not changed by the DATADIR    // operational parameter.  The default is:    //   {STAF/Config/STAFRoot}/data/{STAF/Config/InstanceName}    STAFFSPath writeLocation;    writeLocation.setRoot(configInfo.exePath);    writeLocation.addDir("data");    writeLocation.addDir(gSTAFInstanceName);    gSTAFWriteLocation = writeLocation.asString();    gGlobalVariablePool->set("STAF/DataDir", gSTAFWriteLocation);    // Set the config file to use    STAFString configFile;    if (argc == 2)    {        configFile = argv[1];    }    else if (argc > 2)    {        cout << "Usage: STAFProc [Config file]" << endl;        return 1;    }    else    {        configFile = STAFString(configInfo.exePath) +                     STAFString(configInfo.fileSeparator) + "bin" +                     STAFString(configInfo.fileSeparator) + "STAF.cfg";    }    // Set environment buffer for use by Process service    STAFString envHead("STAF/Env/");    for (int envi = 0; envp[envi] != 0; ++envi)    {        STAFString envVar(envp[envi]);        unsigned int equalPos = envVar.find(kUTF8_EQUAL);        STAFString envName(envVar.subString(0, equalPos));        STAFString envValue;        if (equalPos != STAFString::kNPos)            envValue = envVar.subString(equalPos + 1);        gEnvMap[envName] = envValue;        gGlobalVariablePool->set(envHead + envName, envValue);    }    int envc = 0;    for(; envp[envc] != 0; ++envc)        gEnvSize += strlen(envp[envc]) + 1;    gEnvBuffer = new unsigned char[++gEnvSize];    memset(gEnvBuffer, 0, gEnvSize);    for(gEnvSize = 0, envc = 0; envp[envc] != 0; ++envc)    {        int length = strlen(envp[envc]);        memcpy(gEnvBuffer + gEnvSize, envp[envc], length);        gEnvSize += length + 1;    }    STAFRC_t regRC = gHandleManager.registerHandle(                          gSTAFProcHandle, gSTAFProcPID, "STAF_Process");    if (regRC)    {        cout << "Error registering STAF Process handle, RC: " << regRC << endl;        return 1;    }    STAFRC_t createRC = STAFHandle::create(gSTAFProcHandle, gSTAFProcHandlePtr);    if (createRC)    {        cout << "Error creating STAF Process handle, RC: " << createRC << endl;        return 1;    }    try    {        // Add all the internal services        gServiceManager.add(STAFServicePtr(new STAFDelayService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFDiagService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFEchoService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFHelpService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFFSService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFHandleService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFMiscService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFPingService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFProcessService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFQueueService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFSemService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFServiceService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFShutdownService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFTraceService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFTrustService(),                                           STAFServicePtr::INIT));        gServiceManager.add(STAFServicePtr(new STAFVariableService(),                                           STAFServicePtr::INIT));                // Add local interface        STAFRC_t localInterfaceRC =            gConnectionManager.addConnectionProvider(                "local", "STAFLIPC",                STAFConnectionManager::ConnectionProviderOptionList(),                errorBuffer);        if (localInterfaceRC != kSTAFOk)        {            cout << "Error creating local interface" << endl;            cout << "Error code: " << localInterfaceRC << endl;            cout << "Reason    : " << errorBuffer << endl;            return 1;        }        // Process the config file        gGlobalVariablePool->set(configHead + "ConfigFile", configFile);        unsigned int configRC = readConfigFile(configFile);        if (configRC != 0)        {            cout << "Error reading config file" << endl;            return 1;        }                // Set default interface (aka Connection Provider) variable after        // all interfaces, including the local interface, have been added                STAFString defaultInterface =             gConnectionManager.getDefaultConnectionProvider();        gGlobalVariablePool->set(            configHead + "DefaultInterface", defaultInterface);        // Set default authenticator variable after all authenticators        // have been added        gDefaultAuthenticator = gServiceManagerPtr->getDefaultAuthenticator();        gGlobalVariablePool->set(configHead + "DefaultAuthenticator",                                 gDefaultAuthenticator);        // Obtaining the lock on data directory        osRC = 0;        errorBuffer = "";        int stafOSLockDataDirRC = STAFProcOSLockDataDir(errorBuffer, osRC);        if (stafOSLockDataDirRC != 0)        {            cout << "Error obtaining lock on data directory "                 << gSTAFWriteLocation << endl;            cout << errorBuffer << ", osRC: " << osRC << endl;            return 1;        }        // Set initial number of threads        gThreadManagerPtr->growThreadPool(gNumInitialThreads);        // Make performance adjustments        STAFPerfInfo perfInfo = { (unsigned int)gMaxFiles };        if (makePerformanceAdjustments(perfInfo, errorBuffer, osRC) != 0)        {            cout << errorBuffer << ", RC:" << osRC << endl;            return 1;        }        gShutdownSemaphore = STAFEventSemPtr(new STAFEventSem(),                                             STAFEventSemPtr::INIT);        gGCPollingSem->reset();        // Start interfaces        STAFString logicalInterfaceID = STAFString();        STAFString physicalInterfaceID = STAFString();        STAFConnectionManager::ConnectionProviderList connProvList =            gConnectionManager.getConnectionProviderListCopy();        for (STAFConnectionManager::ConnectionProviderList::iterator iter =                 connProvList.begin();             iter != connProvList.end();             ++iter)        {            try            {                (*iter)->start(HandleRequest);            }            catch (STAFException &se)            {                cout << "Error starting " << (*iter)->getName() << " interface"                     << endl;                cout << "Error code: " << se.getErrorCode() << endl;                cout << "Reason    : " << se.getText() << endl;                return 1;            }            if ((*iter)->getName() == defaultInterface)            {                (*iter)->getMyNetworkIDs(logicalInterfaceID,                                         physicalInterfaceID);            }        }        // Get rid of connection provider references        connProvList = STAFConnectionManager::ConnectionProviderList();        // Determine the machine name                    gMachine = logicalInterfaceID;        // If SET MACHINE not specified in STAF Configuration file, assign        // machine nickname based on the default interface's logical ID.                if (gMachineNickname == STAFString())        {            gMachineNickname = logicalInterfaceID;                    if (gMachineNickname == STAFString())            {                cout << "Unknown machine nickname" << endl;                return 1;            }        }        // Set the Machine and MachineNickname variables        gGlobalVariablePool->set(configHead + "Machine", gMachine);        gGlobalVariablePool->set(configHead + "MachineNickname",                                 gMachineNickname);        // Determine startup time        STAFTimestamp startupTime = STAFTimestamp::now();        gGlobalVariablePool->set(configHead + "StartupTime",                                 startupTime.asString());        // Calculate STAF Instance UUID        //        // This is a 128-bit/16-byte value.  The first four bytes are computed        // from the current timestamp.  The second four bytes are computed from        // the PID.  The third four bytes are computed from the physical        // interface ID.  The fourth four bytes are computed from the logical        // interface ID.        //        // The 128-bit value is turned into a 32 character hexadecimal string.        // We are going to use the last four significant numbers of the        // physical address, going on the assumption we are dealing with        // TCP/IP.  If we aren't using TCP/IP, then our UUID might not be        // as unique.        // - If the physical address is an IPv4 address, use a Period as the        //   separator and base 10.        // - If the physical address is an IPv6 address, use a Colon as the        //   separator and base 16.                STAFString physicalID = physicalInterfaceID;        std::deque<unsigned char> physicalIDValues;        STAFString physicalIDSeparator = STAFString(kUTF8_PERIOD);        int base = 10;                if (physicalID.find(kUTF8_COLON) != STAFString::kNPos)        {            physicalIDSeparator = STAFString(kUTF8_COLON);            base = 16;        }        unsigned int separatorPos = 0;        while ((separatorPos = physicalID.find(physicalIDSeparator)) !=               STAFString::kNPos)        {            STAFString thisValueString = physicalID.subString(0, separatorPos);            physicalID = physicalID.subString(separatorPos + 1);            physicalIDValues.push_back(                thisValueString.asUIntWithDefault(0, base) & 0xFF);        }        physicalIDValues.push_back(            physicalID.asUIntWithDefault(0, base) & 0xFF);        unsigned char UUIDBytes[16];        *(reinterpret_cast<unsigned int *>(UUIDBytes)) =            STAFTimestamp::now().getImpl();        *(reinterpret_cast<unsigned int *>(UUIDBytes + 4)) = STAFUtilGetPID();        for (unsigned int physicalIDValuesIndex = 0;             (physicalIDValuesIndex < 4) && (physicalIDValues.size() != 0);             ++physicalIDValuesIndex)        {            UUIDBytes[8 + physicalIDValuesIndex] = physicalIDValues.front();            physicalIDValues.pop_front();        }

⌨️ 快捷键说明

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