///////////////////////////////////////////////////////
// RADEventsXML::Persist
//
// Replace the XML document on this object with a new one,
// using the RADEventsList parameter. Then save the XML
// document out to it's persistent representation (a file).
// Note: the current XML document is replaced, not updated,
// by this operation.
//
// Input/Output:
//	rel	- the RADEventsList instance that is converted to an
//		XML document and serialized.
//
///////////////////////////////////////////////////////
void RADEventsXML::Persist(RADEventsList& rel)
{
	HRESULT hr = 0;

	DomFromCOM();
	if (!m_pXMLDom) throw NULL;

	try
	{
		if (rel.bChanged)
			ConstructXMLDoc(rel);

		if (m_pXMLDom)
		{
			_variant_t vSrc = m_fullpath;
			hr = m_pXMLDom->save(vSrc);
			TESTHR(hr);
			rel.bChanged = false;
		}
	}
	catch(...)
	{
		dprintf( "%s:%d  HRCALL Failed: %s\n  0x%.8x = %s\n",
			__FILE__, __LINE__, "Persist Exception" , hr);
	}
}
///////////////////////////////////////////////////////
// RADEventsXML::Populate
//
// Update the XML document on this object from the external
// persistent representation (a file). Then, 
// for each RADEvent object extracted from the current XML document,
// insert it on the RADEventsList. Note: the list is not
// emptied or cleared prior to processing.
//
// Input/Output:
//	rel	- the RADEventsList instance that is populated from
//      an XML document.
//
///////////////////////////////////////////////////////
void RADEventsXML::Populate(RADEventsList& rel)
{
	/*  using the path and file name,
	find the XML file,
	open it in memory,
	get the event tree from it,
	extract the n events on the event tree,
	populate the local data structure with thr n events
	*/

	HRESULT hr;
	IXMLDOMParseError * pObjError = NULL;
	VARIANT_BOOL status;
	_variant_t vSrc;
	_bstr_t bstr;
	_bstr_t filepath(m_fullpath);
	
	DomFromCOM();
	if (!m_pXMLDom) goto clean;

	vSrc = m_fullpath;

	hr = m_pXMLDom->load(vSrc, &status);

	if(status!=VARIANT_TRUE)
	{
		hr = m_pXMLDom->get_parseError(&pObjError);
		VARIANT varValue;
		::VariantInit(&varValue);
		hr = pObjError->get_reason( &(varValue.bstrVal));
		dprintf("Failed to load DOM from %s. %S\n",m_fullpath, varValue.bstrVal);
		::VariantClear(&varValue);
		goto clean;
	}

	if (m_pIRNode)
		m_pIRNode->Release();
	m_pIRNode = NULL;
	bstr = m_xirevspath;
	HRCALL(m_pXMLDom->selectSingleNode(bstr, &m_pIRNode), "selectSingleNode");
	if (m_pIRNode)
	{
		ProcessEvents(rel, true);
	}

clean: 
	if (pObjError)
		pObjError->Release();
}
/// \param[in] configSection @copydoc initArg1
/// \param[in] configFile @copydoc initArg2
/// \param[in] host @copydoc initArg3
/// \param[in] options @copydoc initArg4
/// \param[in] progid @copydoc initArg5
/// \param[in] username @copydoc initArg6
/// \param[in] password @copydoc initArg7
lvDCOMInterface::lvDCOMInterface(const char *configSection, const char* configFile, const char* host, int options, const char* progid, const char* username, const char* password) : 
m_configSection(configSection), m_pidentity(NULL), m_pxmldom(NULL), m_options(options), 
	m_progid(progid != NULL? progid : ""), m_username(username != NULL? username : ""), m_password(password != NULL ? password : ""),
	m_mac_env(NULL)
	
{
	epicsThreadOnce(&onceId, initCOM, NULL);
	if (host != NULL && host[0] != '\0') 
	{
		m_host = host;
	}
	else
	{
		//		char name_buffer[MAX_COMPUTERNAME_LENGTH + 1];
		//		DWORD name_size = MAX_COMPUTERNAME_LENGTH + 1;
		//		if ( GetComputerNameEx(ComputerNameNetBIOS, name_buffer, &name_size) != 0 )
		//		{
		//			m_host = name_buffer;
		//		}
		//		else
		//		{
		//			m_host = "localhost";
		//		}			
		m_host = "localhost";
	}
	if (macCreateHandle(&m_mac_env, NULL) != 0)
	{
		throw std::runtime_error("Cannot create mac handle");
	}
	// load current environment into m_mac_env, this is so we can create a macEnvExpand() equivalent 
	// but tied to the environment at a specific time. It is useful if we want to load the same 
	// XML file twice but with a macro defined differently in each case 
	for(char** cp = environ; *cp != NULL; ++cp)
	{
		char* str_tmp = strdup(*cp);
		char* equals_loc = strchr(str_tmp, '='); // split   name=value   string
		if (equals_loc != NULL)
		{
		    *equals_loc = '\0';
		    macPutValue(m_mac_env, str_tmp, equals_loc + 1);
		}
		free(str_tmp);
	}
	//	m_doc = new TiXmlDocument;
	//	if ( !m_doc->LoadFile(configFile) )
	//	{
	//		delete m_doc;
	//		m_doc = NULL;
	//		throw std::runtime_error("Cannot load " + std::string(configFile) + ": load failure");
	//	}
	//	m_root = m_doc->RootElement();
	DomFromCOM();
	short sResult = FALSE;
	char* configFile_expanded = envExpand(configFile);
	m_configFile = configFile_expanded;
	HRESULT hr = m_pxmldom->load(_variant_t(configFile_expanded), &sResult);
	free(configFile_expanded);
	if(FAILED(hr))
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	if (sResult != VARIANT_TRUE)
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	std::cerr << "Loaded XML config file \"" << m_configFile << "\" (expanded from \"" << configFile << "\")" << std::endl;
	m_extint = doPath("/lvinput/extint/@path").c_str();
	epicsAtExit(epicsExitFunc, this);
	if (m_progid.size() > 0)
	{
		if ( CLSIDFromProgID(CT2W(m_progid.c_str()), &m_clsid) != S_OK )
		{
			throw std::runtime_error("Cannot find progId " + m_progid);
		}
	}
	else
	{
		m_clsid = LabVIEW::CLSID_Application;
		wchar_t* progid_str = NULL;
		if ( ProgIDFromCLSID(m_clsid, &progid_str) == S_OK )
		{
			m_progid = CW2CT(progid_str);
			CoTaskMemFree(progid_str);
		}
		else
		{
			m_progid = "LabVIEW.Application";
		}
	}
	wchar_t* clsid_str = NULL;
	if ( StringFromCLSID(m_clsid, &clsid_str) == S_OK )
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" CLSID " << CW2CT(clsid_str) << std::endl;
		CoTaskMemFree(clsid_str);
	}
	else
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" but StringFromCLSID() failed" << std::endl;
	}
}
Esempio n. 4
0
long findControllerInfoXML(fwi::OHCI1394_DEV_INFO * devInfo)
{
    MSXML2::IXMLDOMNodeList *pNodes=NULL;
    MSXML2::IXMLDOMNode *pNode=NULL;
    static VARIANT_BOOL status;
    static VARIANT var;
    BSTR bstr = NULL;
    HRESULT hr;
    long num_controllers;
    long num_attributes;
    BOOL bVendorMatch = FALSE;
    BOOL bDeviceMatch = FALSE;
    long lMinutes = 0;

    MSXML2::IXMLDOMElementPtr pXMLDocElement = NULL;
    MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList = NULL;

    VariantInit(&var);

    // the URL below has a server-side redirect to the actual xml file in the svn repo
    var = VariantString(L"http://www.tctechnologies.tc/appdata/ohci1394db.xml");

    // reload online file if cached data is stale
    lMinutes = getDBCacheAge();
    if ( (lMinutes < 0) || (lMinutes > 10) )
    {
        if (gpXMLDom) gpXMLDom->Release();
        gpXMLDom = DomFromCOM();
        if (!gpXMLDom) return 1;

        HRCALL(gpXMLDom->load(var, &status), "dom->load(): ");

        if (status!=VARIANT_TRUE)
        {
            if (&var) VariantClear(&var);

            return FWI_ERROR_FILE_NOT_FOUND;
        }
        else
        {
            GetLocalTime(&gLastLoadTime);
        }
    }

    gpXMLDom->get_documentElement(&pXMLDocElement);
    pXMLDocElement->selectNodes(TEXT("//controller"), &pXMLDomNodeList);
    pXMLDomNodeList->get_length(&num_controllers);

    for (long n=0; n<num_controllers; n++)
    {
        TCHAR buf[32];
        StringCchPrintf( buf, 20, TEXT("//controller[%i]/*"), n);

        // Query the node-set.
        HRCALL(gpXMLDom->selectNodes(buf, &pNodes), "selectNodes ");
        if (!pNodes) {
            ReportParseError(gpXMLDom, "Error while calling selectNodes ");
        }
        else {
            HRCALL(pNodes->get_length(&num_attributes), "get_length: ");
            for (long i=0; i<num_attributes; i++) {
                if (pNode) pNode->Release();
                HRCALL(pNodes->get_item(i, &pNode), "get_item: ");
                if (bstr) SysFreeString(bstr);
                HRCALL(pNode->get_nodeName(&bstr), "get_nodeName: ");

                if (_tcsicmp((TCHAR*)bstr,TEXT("vendorid"))==0)
                {
                    BSTR nodeTextStr;
                    HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                    if (_tcsicmp((TCHAR*)nodeTextStr, devInfo->vendorId)==0)
                    {
                        bVendorMatch = TRUE;
                    }
                    SysFreeString(nodeTextStr);
                }
                else if (_tcsicmp((TCHAR*)bstr,TEXT("deviceid"))==0)
                {
                    BSTR nodeTextStr;
                    HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                    if (_tcsicmp((TCHAR*)nodeTextStr, devInfo->deviceId)==0)
                    {
                        bDeviceMatch = TRUE;
                    }
                    SysFreeString(nodeTextStr);
                }

                if (bVendorMatch)
                {
                    if ( (_tcsicmp((TCHAR*)bstr,TEXT("vendorname"))==0) && (_tcsicmp(TEXT("Unknown"),&devInfo->vendorName[0]))==0 )
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->vendorName[0], VENDOR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                }

                if (bVendorMatch && bDeviceMatch)
                {
                    devInfo->bFound = TRUE;
                    if (_tcsicmp((TCHAR*)bstr,TEXT("chipset"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->chipset[0], CHIPSET_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxtx"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->maxTx[0], NUM_STR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxrx"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->maxRx[0], NUM_STR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxspeed"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        swscanf_s(nodeTextStr, TEXT("%04d"), &devInfo->maxspeed);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("notes"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->notes[0], NOTES_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("support"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        swscanf_s(nodeTextStr, TEXT("%04x"), &devInfo->support);
                        devInfo->bValid = true;
                        SysFreeString(nodeTextStr);
                        if (&var) VariantClear(&var);
                        if (bstr) SysFreeString(bstr);
                        if (pNodes) pNodes->Release();
                        if (pNode) pNode->Release();

                        return FWI_NO_ERROR;
                    }
                }
            }
        }
    }
clean:
    if (&var) VariantClear(&var);
    if (bstr) SysFreeString(bstr);
    if (pNodes) pNodes->Release();
    if (pNode) pNode->Release();

    return FWI_ERROR_END_OF_FILE;
}
Esempio n. 5
0
void devsXMLInitialize(void)
{
    gpXMLDom = DomFromCOM();
}