HRESULT CG_CConsole::genTaskFiles(const CG_Task* pTask) { FC_CString jot(MAX_PATH); FC_CString jot2(MAX_PATH); FC_CGArray<const CG_SymEntry*> instancePath(50); bool isIoSync = (m_pIFront->lookUpTaskInit(pTask, CG_TASK_IOSYNC) != NULL); m_dmpTaskList << pTask->pszId << _T("\n") _T(" CLASS;") << (isIoSync?_T("RTCE TASK\n"):_T("TASK\n")) << _T(" PATH;[") << jot.load(m_sControlAddr) << _T("].") << jot2.load(m_sResourceName) << _T("\n") _T(" OUT;__state;DINT;r\n") _T(" OUT;__prio;DINT;r\n") _T(" OUT;__cycle;DINT;r\n") _T(" OUT;__etmax;DINT;r\n") _T(" OUT;__errno;DINT;r\n"); m_dmpChildren << _T("3;16;0;") << pTask->pszId << _T(';') << (isIoSync?_T("RTCE TASK\n"): _T("TASK;;CP_Task.asp;") CONSOLE_CONFIG_DIR _T("\\") VIS_TASK_FILE _T("\n")); for (int jj = 0; jj < pTask->nPrgs; jj++) { const CG_SymEntry* pPrg = pTask->pPrgs[jj]; genConfiFiles(4, pPrg, &instancePath, isIoSync); } return S_OK; }
QList<unsigned int> GLC_WorldTo3dxml::instancePath(const GLC_StructOccurence* pOccurence) { QList<unsigned int> path; if (!pOccurence->isOrphan()) { GLC_StructInstance* pInstance= pOccurence->structInstance(); Q_ASSERT(m_InstanceToIdHash.contains(pInstance)); path.prepend(m_InstanceToIdHash.value(pInstance)); QList<unsigned int> subPath(instancePath(pOccurence->parent())); subPath.append(path); path= subPath; } return path; }
int main(int argc, char** argv) { CIMClient client; Boolean verbose = false; Uint32 numObjects; Array<CIMObjectPath> resultObjectPaths; Array<CIMObject> resultObjects; CIMName assocClass; CIMName resultClass; String role; String resultRole; // // Check command line option // if (argc > 2) { cerr << "Usage: AssociationClient [-v]" << endl; return 1; } if (argc == 2) { const char *opt = argv[1]; if (strcmp(opt, "-v") == 0) { verbose = true; } else { cerr << "Usage: AssociationClient [-v]" << endl; return 1; } } try { // =================================================================== // connectLocal // // The connectLocal Client API creates a connection to the server for // a local client. The connection is automatically authenticated // for the current user. (The connect Client API can be used to create // an HTTP connection with the server defined by the URL in address. // User name and Password information can be passed using the connect // Client API.) // =================================================================== client.connectLocal(); // =================================================================== // associators // // Get the CIM instances (Sample_Student instances) that are associated // to the source CIM instance (Sample_Teacher.Name = "Teacher1") via an // instance of the Sample_TeacherStudent association class. // =================================================================== assocClass = SAMPLE_TEACHERSTUDENT; CIMObjectPath instancePath("Sample_Teacher.Name=\"Teacher1\""); resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // =================================================================== // associators // // Validate role and resultRole parameters syntax. // =================================================================== // invalid role parameter syntax String invalidRole = "Teaches_*student"; Boolean gotException = false; try { resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, invalidRole, resultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // invalid resultRole parameter syntax String invalidResultRole = "3Taught_By"; gotException = false; try { resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, invalidResultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test resultRole parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // associatorNames // // Get the names of the CIM instances (Sample_Student instances) that // are associated to the source CIM instance (Sample_Teacher.Name = // "Teacher1") via an instance of the Sample_TeacherStudent association // class. // =================================================================== resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // associatorNames // // Validate role and resultRole parameters syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, invalidRole, resultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // invalid resultRole parameter syntax gotException = false; try { resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, invalidResultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test resultRole parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // references // // Get the association instances (Sample_TeacherStudent instances) that // refer to the specified target CIM instance (Sample_Teacher.Name = // "Teacher1"). // =================================================================== resultObjects = client.references( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 5) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // =================================================================== // references // // Validate role parameter syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjects = client.references( NAMESPACE, instancePath, resultClass, invalidRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // referenceNames // // Get the names of the association instances (Sample_TeacherStudent // instances) that refer to the specified target CIM instance // (Sample_Teacher.Name = "Teacher1"). // =================================================================== resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 5) != 0) return -1; // display result // cout << "Number of reference name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // referenceNames // // Validate role parameter syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, invalidRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // Call the association methods with different filters specified. // Filters used are: role, resultClass, resultRole, assocClass. // =================================================================== // // get all the students who are taught by 'Teacher1' // role = "Teaches"; resultRole = "TaughtBy"; resultClass = CIMName("Sample_Student"); assocClass = SAMPLE_TEACHERSTUDENT; resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // // get all the students who have 'Teacher1' as an advisor // role = "Advises"; resultRole = "AdvisedBy"; resultClass = CIMName("Sample_Student"); assocClass = SAMPLE_ADVISORSTUDENT; resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of associator name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // // get all the TeacherStudent association instances in which 'Teacher1' // plays the role of a teacher. // role = "Teaches"; resultClass = CIMName("Sample_TeacherStudent"); resultObjects = client.references( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // // get all the AdvisorStudent association instances in which 'Teacher1' // plays the role of an advisor. // role = "Advises"; resultClass = CIMName("Sample_AdvisorStudent"); resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // Pass Class object to the Association Methods // =================================================================== // // get the CIM classes that are associated with the Sample_Teacher class // CIMObjectPath classPath("Sample_Teacher"); assocClass = CIMName(); resultClass = CIMName(); role = String::EMPTY; resultRole = String::EMPTY; resultObjects = client.associators( NAMESPACE, classPath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 1) != 0) return -1; // display result // cout << "Number of associated class objects = " << // numObjects << endl; _displayResult(resultObjects, verbose); // // get the association classes that refer to the Sample_Teacher class // resultObjects = client.references( NAMESPACE, classPath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of association class objects = " << // numObjects << endl; _displayResult(resultObjects, verbose); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; return -1; } cout << "AssociationClient +++++ passed all tests" << endl; return 0; }
HRESULT CG_CConsole::genVisFiles() { //example dump for the children.txt file: //#<Level>;<Type>;<Properties>;<Name>[;[<ClassName>][;[Server][;[<ASP File>][;[<Config File>][;[<Child Objects File>]]]]]] //2;8;0;Station_M1;RESOURCE;;CP_TaskList.asp;config/tasks.txt //3;16;0;T_500ms;TASK;;CP_Task.asp;config/tasks.txt //4;32;0;P_500ms_1 //5;64;0;mean;MEAN;;config/lib/FC_Control.4cl/mean/mean.asp;config/cp_conf4.txt FC_CString childrenFileName, taskListFileName; FC_CString jot(MAX_PATH); FC_CString consoleName; childrenFileName << m_sVisPath << VIS_CHILD_OBJ_FILE; taskListFileName << m_sVisPath << VIS_TASK_FILE; const CG_POU4CPInfo* pCON = m_pIFront->FCPgetCONinfo(NULL); assert(pCON); if(!pCON) return E_FAIL; ICG_Config* pICon = m_pIFront->loadConfig(pCON); assert(pICon); if(!pICon) return E_FAIL; m_LoaderList.addFile(VIS_CHILD_OBJ_FILE); m_LoaderList.addFile(VIS_TASK_FILE); consoleName.load(pICon->getName()); genTargets(); const CG_ResImpInfo* pResImp = pICon->getResImpByName(jot.load(m_sResourceName)); const CG_Resource* pRes = m_pIFront->loadResource(pResImp->pszImpFile); FC_RELEASE_PTR(pICon); assert(pRes); if(!pRes) return E_FAIL; //dump the header m_dmpChildren << _T("#<Level>;<Type>;<Properties>;<Name>[;[<ClassName>][;[Server]") _T("[;[<ASP File>][;[<Config File>][;[<Child Objects File>]]]]]]\n"); m_dmpChildren << _T("2;8;0;") << jot << _T(";RESOURCE;;CP_Resource.asp;") CONSOLE_CONFIG_DIR _T("\\") VIS_RESOURCE_FILE _T("\n") _T("3;128;0;Task List;;;CP_TaskList.asp;") CONSOLE_CONFIG_DIR _T("\\") VIS_TASK_FILE _T("\n") _T("3;128;0;Message History;;;CP_MsgHistory.asp\n"); for (int jj = 0; jj < pRes->nTasks; jj++) genTaskFiles(&pRes->pTasks[jj]); FC_CGArray<const CG_SymEntry*> instancePath(20); for(jj=0; jj<pRes->pGVL->nGVLImp; jj++) { genConfiFiles(2, pRes->pGVL->pGVLImp[jj].pSym, &instancePath); } parseConsoleSection(); parseConsoleSection(m_sResourceName); if(!CGT_DmpToFile(&m_dm, NULL, childrenFileName, m_dmpChildren, false)) return E_FAIL; if(!CGT_DmpToFile(&m_dm, NULL, taskListFileName, m_dmpTaskList, false)) return E_FAIL; checkOutLibCommonFiles(); FC_CString sLoaderListHeader; sLoaderListHeader << _T("console;") << jot.load(m_sWebServerAddr) << _T("\n") _T("project;") << m_pIFront->FCPgetPrjName() << _T("\n") _T("version;2.0\n") _T("config;") << consoleName << _T("\n") _T("resource;") << m_sResourceName << _T("\n") _T("targettype;4cconsole\n"); m_LoaderList.dump(&m_dm, m_sVisPath, sLoaderListHeader); return S_OK; }
void GLC_WorldTo3dxml::writeOccurenceDefaultViewProperty(const GLC_StructOccurence* pOccurence) { QList<unsigned int> path= instancePath(pOccurence); GLC_3DViewInstance* pInstance= m_World.collection()->instanceHandle(pOccurence->id()); Q_ASSERT(NULL != pInstance); const bool isVisible= pOccurence->isVisible(); m_pOutStream->writeStartElement("DefaultViewProperty"); m_pOutStream->writeStartElement("OccurenceId"); const QString prefix= "urn:3DXML:" + QFileInfo(m_FileName).fileName() + "#"; const int pathSize= path.size(); for (int i= 0; i < pathSize; ++i) { m_pOutStream->writeTextElement("id", prefix + QString::number(path.at(i))); } m_pOutStream->writeEndElement(); // OccurenceId if (pOccurence->isFlexible()) { m_pOutStream->writeTextElement("RelativePosition", matrixString(pOccurence->occurrenceRelativeMatrix())); } if (!isVisible || !pInstance->renderPropertiesHandle()->isDefault()) { qDebug() << "(!isVisible || !pInstance->renderPropertiesHandle()->isDefault())"; m_pOutStream->writeStartElement("GraphicProperties"); m_pOutStream->writeAttribute("xsi:type", "GraphicPropertiesType"); if (! isVisible) { m_pOutStream->writeStartElement("GeneralAttributes"); m_pOutStream->writeAttribute("xsi:type", "GeneralAttributesType"); m_pOutStream->writeAttribute("visible", "false"); m_pOutStream->writeAttribute("selectable", "true"); m_pOutStream->writeEndElement(); // GeneralAttributes } if (!pInstance->renderPropertiesHandle()->isDefault()) { const GLC_RenderProperties* pProperties= pInstance->renderPropertiesHandle(); if ((pProperties->renderingMode() == glc::OverwriteTransparency)) { m_pOutStream->writeStartElement("SurfaceAttributes"); m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType"); m_pOutStream->writeStartElement("Color"); m_pOutStream->writeAttribute("xsi:type", "RGBAColorType"); m_pOutStream->writeAttribute("red", "-1"); m_pOutStream->writeAttribute("green", "-1"); m_pOutStream->writeAttribute("blue", "-1"); m_pOutStream->writeAttribute("alpha", QString::number(pProperties->overwriteTransparency())); m_pOutStream->writeEndElement(); // Color m_pOutStream->writeEndElement(); // SurfaceAttributes } else if ((pProperties->renderingMode() == glc::OverwriteTransparencyAndMaterial)) { GLC_Material* pMaterial= pProperties->overwriteMaterial(); m_pOutStream->writeStartElement("SurfaceAttributes"); m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType"); m_pOutStream->writeStartElement("Color"); m_pOutStream->writeAttribute("xsi:type", "RGBAColorType"); m_pOutStream->writeAttribute("red", QString::number(pMaterial->diffuseColor().redF())); m_pOutStream->writeAttribute("green", QString::number(pMaterial->diffuseColor().greenF())); m_pOutStream->writeAttribute("blue", QString::number(pMaterial->diffuseColor().blueF())); m_pOutStream->writeAttribute("alpha", QString::number(pProperties->overwriteTransparency())); m_pOutStream->writeEndElement(); // Color m_pOutStream->writeEndElement(); // SurfaceAttributes } else if ((pProperties->renderingMode() == glc::OverwriteMaterial)) { GLC_Material* pMaterial= pProperties->overwriteMaterial(); m_pOutStream->writeStartElement("SurfaceAttributes"); m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType"); m_pOutStream->writeStartElement("Color"); m_pOutStream->writeAttribute("xsi:type", "RGBAColorType"); m_pOutStream->writeAttribute("red", QString::number(pMaterial->diffuseColor().redF())); m_pOutStream->writeAttribute("green", QString::number(pMaterial->diffuseColor().greenF())); m_pOutStream->writeAttribute("blue", QString::number(pMaterial->diffuseColor().blueF())); m_pOutStream->writeAttribute("alpha", QString::number(pMaterial->opacity())); m_pOutStream->writeEndElement(); // Color m_pOutStream->writeEndElement(); // SurfaceAttributes } } m_pOutStream->writeEndElement(); // GraphicProperties } m_pOutStream->writeEndElement(); // DefaultViewProperty }