MTConnectDataModel MTConnectDeviceParser::ReadDeviceDescription(std::string filename)
{
	MTConnectDataModel dataItems;
	dataItems.clear();
	if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES)
	{
		filename= ::ExeDirectory() + filename;
	}
	if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES)
		throw std::exception("MTConnectDeviceParser::ReadDeviceDescription invalid devices file");

	_devicesfilename = filename;

	try{
		ParseXMLDocument(_devicesfilename.c_str());

		MSXML2::IXMLDOMNodePtr root = m_pXMLDoc->GetdocumentElement();
		MSXML2::IXMLDOMNodeListPtr nodes = root->selectNodes(_bstr_t("//DataItem"));
		for(int i=0; i< nodes->length; i++)
		{
			MSXML2::IXMLDOMNodePtr pNode = NULL;	
			CDataItem dataItem;
			nodes->get_item(i, &pNode);

			dataItem.name = (LPCSTR)  GetAttribute(pNode, "name");
			dataItem.category = (LPCSTR) GetAttribute(pNode, "category");
			dataItem.id = (LPCSTR) GetAttribute(pNode, "id");
			dataItem.type = (LPCSTR) GetAttribute(pNode, "type");
			dataItem.subType = (LPCSTR) GetAttribute(pNode, "subType");
			dataItem.units = (LPCSTR) GetAttribute(pNode, "units");
			dataItem.nativeUnits = (LPCSTR) GetAttribute(pNode, "nativeUnits");
			if(dataItem.type == "ASSET_CHANGED")
			{
				dataItem.category = "ASSET_CHANGED";
			}

			dataItem.category=MakeLower(dataItem.category);
			
			if(!dataItem.name.empty())
			{
				dataItems[dataItem.name]=dataItem;
			}
			// Could get name or id via SHDR
			else if(!dataItem.id.empty())
			{
				dataItems[dataItem.id]=dataItem;
			}
			else
			{
				continue;
			}
		}
	}
	catch(_com_error error)
	{
		std::cout << "MTConnectDeviceParser::ReadDeviceDescription" << error.ErrorMessage();
	}
	return dataItems;

}
Ejemplo n.º 2
0
static CFURLRef FindJnlpURLInFile(char* fileName) {
    XMLNode* doc = NULL;
    CFURLRef returnValue = NULL;
    char* jnlbuffer = NULL;

    /* Parse XML document. */
    if (!ReadFileToBuffer(fileName, &jnlbuffer)) {
        return NULL;
    }

    doc = ParseXMLDocument(jnlbuffer);
    if (doc != NULL) {
        XMLNode* node = NULL;
        char *codebase = NULL;
        char *href = NULL;
        CFStringRef baseURLString = NULL;
        CFStringRef hrefString = NULL;
        CFMutableStringRef fullURL = NULL;

        node = FindXMLChild(doc, "jnlp");
        require(node != NULL, bail);
        codebase = FindXMLAttribute(node->_attributes, "codebase");
        require(codebase != NULL, bail);
        href = FindXMLAttribute(node->_attributes, "href");
        require(href != NULL, bail);

        baseURLString = CFStringCreateWithCString(NULL, codebase, kCFStringEncodingUTF8);
        require(baseURLString != NULL, bail);

        fullURL = CFStringCreateMutableCopy(NULL, 0, baseURLString);
        hrefString = CFStringCreateWithCString(NULL, href, kCFStringEncodingUTF8);
        require(hrefString != NULL, bail);

        // a relative JNLP path needs a URL that starts at the specificed codebase
        if (!CFStringHasSuffix(fullURL, CFSTR("/")))
            CFStringAppend(fullURL, CFSTR("/"));
        CFStringAppend(fullURL, hrefString);

        returnValue = CFURLCreateWithString(NULL, fullURL, NULL);
bail:
        if (baseURLString != NULL) CFRelease(baseURLString);
        if (hrefString != NULL) CFRelease(hrefString);
        if (fullURL != NULL) CFRelease(fullURL);
        FreeXMLDocument(doc);
    }

    free(jnlbuffer);
    return returnValue;
}
std::vector<DataDictionary> MTConnectStreamsParser::ReadStream(std::string filename)
{
	DataDictionary data;
	std::vector<DataDictionary> datums;
	int nProbed ;
	int nProbeSeq ;
	//	TimedDataDictionary::iterator _attimestamp =timeddata.end(); 

	_devicesfilename = "http://" + filename + "/current";

	// Not empty means error
	if(!ParseXMLDocument(_devicesfilename.c_str()).empty())
		return datums;

	data=ParseDataItems();

	datums.push_back(data);
	return datums;
}
Ejemplo n.º 4
0
/* Parse the XML Launch file 
 *
 * Looks for the following path: <jnlp><resources><j2se version=attr>
 */
static void ParseXMLLaunchFile(char* s, JNLFile* jnlfile) {   
    XMLNode* doc = NULL;
    XMLNode* node = NULL;
    XMLNode* resources = NULL;
    XMLNode* tempnode = NULL;
    char* str;
    char* codebase;
    char* href;
    char *name;
    char *value;

    /* added for getting canonical home */
    char* firstjar = NULL;
    char* mainjar = NULL;
    char* str2;  

    jnlfile->jreVersion = NULL;
    jnlfile->jreLocation = NULL;
    jnlfile->isPlayer = FALSE;
    jnlfile->canonicalHome = NULL;

    /* Parse XML document. */
    doc = ParseXMLDocument(s);
    if (doc != NULL) {
      node = FindXMLChild(doc, "jnlp");      
     
      if (node != NULL) {
        codebase = FindXMLAttribute(node->_attributes, "codebase");
        href = FindXMLAttribute(node->_attributes, "href");
	if ((codebase != NULL) && (href != NULL)) {
	  if (strstr(href, "http:") == href) { 
	    jnlfile->jnlp_url = href;
	  } else {
	    char *last;
	    jnlfile->jnlp_url = malloc(strlen(codebase) + strlen(href) + 2);
	    strcpy(jnlfile->jnlp_url, codebase);
	    last = codebase + (strlen(codebase) - 1);
	    if (*last != '/') {
	      strcat(jnlfile->jnlp_url, "/");
	    }
	    strcat(jnlfile->jnlp_url, href);
	  }
	  /* canonical home is equal to href if href exist */
	  jnlfile->canonicalHome = malloc(strlen(jnlfile->jnlp_url) + 1);
	  strcpy(jnlfile->canonicalHome, jnlfile->jnlp_url);	
	}
      }

      /* find main jar to generate canonical home if no href */
      if (node != NULL && jnlfile->canonicalHome == NULL) {
         tempnode = FindXMLChild(node->_sub, "resources");
         if (tempnode != NULL) { 
        
	    tempnode = FindXMLChild(tempnode->_sub, "jar");
	  
	    /* go thru all jars and find main jar */	   
	    while (tempnode && mainjar == NULL) {	     
	      str = FindXMLAttribute(tempnode->_attributes, "href");	     
	      if (firstjar == NULL) {
		firstjar = malloc(strlen(str) + 1);	      
		strcpy(firstjar, str);	     
	      }	    
	      str2 = FindXMLAttribute(tempnode->_attributes, "main");	     
	      if (str2 != NULL && sysStrCaseCmp(str2, "true") == 0) {
		mainjar = malloc(strlen(str) + 1);	      
		strcpy(mainjar, str);		
	      }	   
	      tempnode = tempnode->_next;	      
	    }
	    /* if no main jar, return first jar */
	    if (mainjar == NULL) {
	      mainjar = strdup(firstjar);	     
	    }

	    if (codebase != NULL && mainjar != NULL) {
	      /* generate canonicalHome */
	      char *last;
	      jnlfile->canonicalHome = malloc(strlen(codebase) + strlen(mainjar) + 2);
	      strcpy(jnlfile->canonicalHome, codebase);
	      last = codebase + (strlen(codebase) - 1);
	      if (*last != '/') {
		strcat(jnlfile->canonicalHome, "/");
	      }
	      strcat(jnlfile->canonicalHome, mainjar);
	     
	    }
	 }
      }
     

      if (node != NULL) {
         resources = FindXMLChild(node->_sub, "resources");
         if (resources != NULL) { 
            node = FindXMLChild(resources->_sub, "j2se");
            if (node != NULL) {
		  str = FindXMLAttribute(node->_attributes, "version");
		  if (str != NULL) jnlfile->jreVersion = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "href");
		  if (str != NULL) jnlfile->jreLocation = strdup(str);
		  
		  str = FindXMLAttribute(node->_attributes, "max-heap-size");
		  if (str != NULL) jnlfile->maxHeap = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "initial-heap-size");
		  if (str != NULL) jnlfile->initialHeap = strdup(str);
            }
            node = FindXMLChild(resources->_sub, "property");
            while (node != NULL) {
                name = FindXMLAttribute(node->_attributes, "name");
                if (name != NULL) {
                    value = FindXMLAttribute(node->_attributes, "value");
                    if (value != NULL) {
                        if (isSecureProperty(name)) {
                            char *auxArg = malloc(16+strlen(name)+strlen(value));
                            sprintf(auxArg, "%s=%s",name, value);
                            addAuxArg(jnlfile, auxArg);
                        }
                    }    
                }
                node = FindXMLChild(node->_next, "property");
            }
         }
      }
    }

    /* Check for player */
    if (doc != NULL && FindXMLChild(doc, "player") != NULL) {
         jnlfile->isPlayer = TRUE;
    }

    free(firstjar);
    free(mainjar);
    FreeXMLDocument(doc);
}