Beispiel #1
0
bool
SUMOSAXReader::parseFirst(std::string systemID) {
    if (systemID.substr(systemID.length() - 4) == ".sbx") {
        myBinaryInput = new BinaryInputDevice(systemID, true, myValidationScheme == XERCES_CPP_NAMESPACE::SAX2XMLReader::Val_Always);
        *myBinaryInput >> mySbxVersion;
        if (mySbxVersion < 1 || mySbxVersion > 2) {
            throw ProcessError("Unknown sbx version");
        }
        std::string sumoVer;
        *myBinaryInput >> sumoVer;
        std::vector<std::string> elems;
        *myBinaryInput >> elems;
        // !!! check elems here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check attrs here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check node types here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check edge types here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check edges here
        std::vector< std::vector<int> > followers;
        *myBinaryInput >> followers;
        // !!! check followers here
        return parseNext();
    } else {
bool
SUMOSAXReader::parseFirst(std::string systemID) {
    if (systemID.substr(systemID.length() - 4) == ".sbx") {
        myBinaryInput = new BinaryInputDevice(systemID, true, myEnableValidation);
        char sbxVer;
        *myBinaryInput >> sbxVer;
        if (sbxVer != 1) {
            throw ProcessError("Unknown sbx version");
        }
        std::string sumoVer;
        *myBinaryInput >> sumoVer;
        std::vector<std::string> elems;
        *myBinaryInput >> elems;
        // !!! check elems here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check attrs here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check node types here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check edge types here
        elems.clear();
        *myBinaryInput >> elems;
        // !!! check edges here
        std::vector< std::vector<unsigned int> > followers;
        *myBinaryInput >> followers;
        // !!! check followers here
        return parseNext();
    } else {
Beispiel #3
0
void
SUMOSAXReader::parse(std::string systemID) {
    if (systemID.length() >= 4 && systemID.substr(systemID.length() - 4) == ".sbx") {
        if (parseFirst(systemID)) {
            while (parseNext());
        }
    } else {
        if (myXMLReader == 0) {
            myXMLReader = getSAXReader();
        }
        myXMLReader->parse(systemID.c_str());
    }
}
Beispiel #4
0
void Runtime::run( int cycles )
{
  while ( cycles > 0 )
  {
    if ( thing->paused() ) break;

    if ( ip >= length(program) ) break;

    KILLENUM kill = parseNext();

    if ( kill == PROCEED ) cycles --;
    else if ( kill != FREEBIE ) break;
  }
}
void
RoutingXmlparser::doParse()
{
    uint64_t parsedElementCount = 0;
    while(!isParsingComplete())
    {
        if(AnimatorMode::getInstance()->keepAppResponsive())
        {
            //AnimatorMode::getInstance()->setParsingCount(parsedElementCount);

        }
       RoutingParsedElement parsedElement = parseNext();
       switch(parsedElement.type)
       {
           case RoutingParsedElement::XML_ANIM:
           {
               AnimatorMode::getInstance()->setVersion(parsedElement.version);
               //qDebug(QString("XML Version:") + QString::number(version));
               break;
           }
           case RoutingParsedElement::XML_RT:
           {
               RoutingStatsScene::getInstance()->add(parsedElement.nodeId, parsedElement.updateTime, parsedElement.rt);
               ++parsedElementCount;
               break;
           }
           case RoutingParsedElement::XML_RP:
           {
                RoutingStatsScene::getInstance()->addRp(parsedElement.nodeId, parsedElement.destination, parsedElement.updateTime, parsedElement.rpes);
                ++parsedElementCount;
                break;
           }
           case RoutingParsedElement::XML_INVALID:
           default:
           {
               //qDebug("Invalid XML element");
           }
       } //switch
    } // while loop
}
Beispiel #6
0
/*
    Parse an XML file. Return 0 for success, -1 for error.
 */ 
int mprXmlParse(MprXml *xp)
{
    mprAssert(xp);

    return parseNext(xp, MPR_XML_BEGIN);
}
Beispiel #7
0
/*
    XML recursive descent parser. Return -1 for errors, 0 for EOF and 1 if there is still more data to parse.
 */
static int parseNext(MprXml *xp, int state)
{
    MprXmlHandler   handler;
    MprXmlToken     token;
    MprBuf          *tokBuf;
    char            *tname, *aname;
    int             rc;

    mprAssert(state >= 0);

    tokBuf = xp->tokBuf;
    handler = xp->handler;
    tname = aname = 0;
    rc = 0;
    
    /*
        In this parse loop, the state is never assigned EOF or ERR. In such cases we always return EOF or ERR.
     */
    while (1) {

        token = getXmlToken(xp, state);

        if (token == MPR_XMLTOK_TOO_BIG) {
            xmlError(xp, "XML token is too big");
            return MPR_ERR_WONT_FIT;
        }

        switch (state) {
        case MPR_XML_BEGIN:     /* ------------------------------------------ */
            /*
                Expect to get an element, comment or processing instruction 
             */
            switch (token) {
            case MPR_XMLTOK_EOF:
                return 0;

            case MPR_XMLTOK_LS:
                /*
                    Recurse to handle the new element, comment etc.
                 */
                rc = parseNext(xp, MPR_XML_AFTER_LS);
                if (rc < 0) {
                    return rc;
                }
                break;

            default:
                xmlError(xp, "Syntax error");
                return MPR_ERR_BAD_SYNTAX;
            }
            break;

        case MPR_XML_AFTER_LS: /* ------------------------------------------ */
            switch (token) {
            case MPR_XMLTOK_COMMENT:
                state = MPR_XML_COMMENT;
                rc = (*handler)(xp, state, "!--", 0, mprGetBufStart(tokBuf));
                if (rc < 0) {
                    return rc;
                }
                return 1;

            case MPR_XMLTOK_CDATA:
                state = MPR_XML_CDATA;
                rc = (*handler)(xp, state, "!--", 0, mprGetBufStart(tokBuf));
                if (rc < 0) {
                    return rc;
                }
                return 1;

            case MPR_XMLTOK_INSTRUCTIONS:
                /* Just ignore processing instructions */
                return 1;

            case MPR_XMLTOK_TEXT:
                state = MPR_XML_NEW_ELT;
                tname = sclone(mprGetBufStart(tokBuf));
                if (tname == 0) {
                    mprAssert(!MPR_ERR_MEMORY);
                    return MPR_ERR_MEMORY;
                }
                rc = (*handler)(xp, state, tname, 0, 0);
                if (rc < 0) {
                    return rc;
                }
                break;

            default:
                xmlError(xp, "Syntax error");
                return MPR_ERR_BAD_SYNTAX;
            }
            break;

        case MPR_XML_NEW_ELT:   /* ------------------------------------------ */
            /*
                We have seen the opening "<element" for a new element and have not yet seen the terminating 
                ">" of the opening element.
             */
            switch (token) {
            case MPR_XMLTOK_TEXT:
                /*
                    Must be an attribute name
                 */
                aname = sclone(mprGetBufStart(tokBuf));
                token = getXmlToken(xp, state);
                if (token != MPR_XMLTOK_EQ) {
                    xmlError(xp, "Missing assignment for attribute \"%s\"", aname);
                    return MPR_ERR_BAD_SYNTAX;
                }

                token = getXmlToken(xp, state);
                if (token != MPR_XMLTOK_TEXT) {
                    xmlError(xp, "Missing value for attribute \"%s\"", aname);
                    return MPR_ERR_BAD_SYNTAX;
                }
                state = MPR_XML_NEW_ATT;
                rc = (*handler)(xp, state, tname, aname, mprGetBufStart(tokBuf));
                if (rc < 0) {
                    return rc;
                }
                state = MPR_XML_NEW_ELT;
                break;

            case MPR_XMLTOK_GR:
                /*
                    This is ">" the termination of the opening element
                 */
                if (*tname == '\0') {
                    xmlError(xp, "Missing element name");
                    return MPR_ERR_BAD_SYNTAX;
                }

                /*
                    Tell the user that the opening element is now complete
                 */
                state = MPR_XML_ELT_DEFINED;
                rc = (*handler)(xp, state, tname, 0, 0);
                if (rc < 0) {
                    return rc;
                }
                state = MPR_XML_ELT_DATA;
                break;

            case MPR_XMLTOK_SLASH_GR:
                /*
                    If we see a "/>" then this is a solo element
                 */
                if (*tname == '\0') {
                    xmlError(xp, "Missing element name");
                    return MPR_ERR_BAD_SYNTAX;
                }
                state = MPR_XML_SOLO_ELT_DEFINED;
                rc = (*handler)(xp, state, tname, 0, 0);
                if (rc < 0) {
                    return rc;
                }
                return 1;
    
            default:
                xmlError(xp, "Syntax error");
                return MPR_ERR_BAD_SYNTAX;
            }
            break;

        case MPR_XML_ELT_DATA:      /* -------------------------------------- */
            /*
                We have seen the full opening element "<name ...>" and now await data or another element.
             */
            if (token == MPR_XMLTOK_LS) {
                /*
                    Recurse to handle the new element, comment etc.
                 */
                rc = parseNext(xp, MPR_XML_AFTER_LS);
                if (rc < 0) {
                    return rc;
                }
                break;

            } else if (token == MPR_XMLTOK_LS_SLASH) {
                state = MPR_XML_END_ELT;
                break;

            } else if (token != MPR_XMLTOK_TEXT) {
                return rc;
            }
            if (mprGetBufLength(tokBuf) > 0) {
                /*
                    Pass the data between the element to the user
                 */
                rc = (*handler)(xp, state, tname, 0, mprGetBufStart(tokBuf));
                if (rc < 0) {
                    return rc;
                }
            }
            break;

        case MPR_XML_END_ELT:           /* -------------------------------------- */
            if (token != MPR_XMLTOK_TEXT) {
                xmlError(xp, "Missing closing element name for \"%s\"", tname);
                return MPR_ERR_BAD_SYNTAX;
            }
            /*
                The closing element name must match the opening element name 
             */
            if (strcmp(tname, mprGetBufStart(tokBuf)) != 0) {
                xmlError(xp, "Closing element name \"%s\" does not match on line %d. Opening name \"%s\"",
                    mprGetBufStart(tokBuf), xp->lineNumber, tname);
                return MPR_ERR_BAD_SYNTAX;
            }
            rc = (*handler)(xp, state, tname, 0, 0);
            if (rc < 0) {
                return rc;
            }
            if (getXmlToken(xp, state) != MPR_XMLTOK_GR) {
                xmlError(xp, "Syntax error");
                return MPR_ERR_BAD_SYNTAX;
            }
            return 1;

        case MPR_XML_EOF:       /* ---------------------------------------------- */
            return 0;

        case MPR_XML_ERR:   /* ---------------------------------------------- */
        default:
            return MPR_ERR;
        }
    }
    mprAssert(0);
}
Beispiel #8
0
errorCode decode(EXIPSchema* schemaPtr, unsigned char outFlag, FILE *infile, size_t (*inputStream)(void* buf, size_t size, void* stream))
{
	Parser testParser;
	char buf[INPUT_BUFFER_SIZE];
	BinaryBuffer buffer;
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	struct appData parsingData;

	buffer.buf = buf;
	buffer.bufLen = INPUT_BUFFER_SIZE;
	buffer.bufContent = 0;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any, otherwise set to NULL
	buffer.ioStrm.readWriteToStream = inputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	TRY(initParser(&testParser, buffer, &parsingData));

	// III: Initialize the parsing data and hook the callback handlers to the parser object.
	//      If out-of-band options are defined use testParser.strm.header.opts to set them
	parsingData.expectAttributeData = 0;
	parsingData.stack = NULL;
	parsingData.unclosedElement = 0;
	parsingData.prefixesCount = 0;
	parsingData.outputFormat = outFlag;

	testParser.handler.fatalError = sample_fatalError;
	testParser.handler.error = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument = sample_endDocument;
	testParser.handler.startElement = sample_startElement;
	testParser.handler.attribute = sample_attribute;
	testParser.handler.stringData = sample_stringData;
	testParser.handler.endElement = sample_endElement;
	testParser.handler.decimalData = sample_decimalData;
	testParser.handler.intData = sample_intData;
	testParser.handler.floatData = sample_floatData;
	testParser.handler.booleanData = sample_booleanData;
	testParser.handler.dateTimeData = sample_dateTimeData;
	testParser.handler.binaryData = sample_binaryData;

	// IV: Parse the header of the stream

	TRY(parseHeader(&testParser, FALSE));

	// IV.1: Set the schema to be used for parsing.
	// The schemaID mode and schemaID field can be read at
	// parser.strm.header.opts.schemaIDMode and
	// parser.strm.header.opts.schemaID respectively
	// If schemaless mode, use setSchema(&parser, NULL);

	TRY(setSchema(&testParser, schemaPtr));

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser

	destroyParser(&testParser);

	if(tmp_err_code == PARSING_COMPLETE)
		return ERR_OK;
	else
		return tmp_err_code;
}
Beispiel #9
0
int main(int argc, char *argv[]) {
	int ret; //fuer getopt funktion
	char player = '3';
	char gameId[15];
	char *confDateiName = malloc(256);
	strcpy(confDateiName, "client.conf");
	pid_t pid;

  //Config-Datei einlesen und struct betanken
	log_printf(LOG_DEBUG,"Using config-file %s\n",confDateiName);
	configstruct = get_config(confDateiName);

	log_printf(LOG_PRINTF,"\n");

	//11-stellige Game-Id aus Kommandozeile auslesen
	if (argc < 2) {
		printf("Keine Game-Id angegeben!\n");
		help();
		exit(EXIT_FAILURE);
	}
	strcpy(gameId,argv[1]);
	
	if(strlen(gameId) != 11) {
		printf("Game-Id muss 11-stellig sein!\n");
		help();
		exit(EXIT_FAILURE);
	}

	//optional gewunschte Spielernummer, config Dateiname oder log Level einlesen 
	while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
	switch (ret) {
	case 'p':
		player = optarg[0];
		if (player!='0' && player != '1') {
			printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
			help();
			exit(EXIT_FAILURE);
		}
		break;
	case 'c':
		strcpy(confDateiName, optarg);
		break;
	case 'l':
		configstruct.loglevel = atoi(optarg);
		break;
	default:
		help();
		exit(EXIT_FAILURE);
	}
	}

	//Shared-Memory erstellen 
	//shmSegment() um die ID zu erstellen -> vor fork()
	int shmid = shmSegment(sizeof(struct shmInfos));

	//shmAnbinden(shmid); um es an den Prozess zu binden
	shmPtr = shmAnbinden(shmid);

	//shm automatisch entfernen, wenn alle prozesse detached sind
	shmDelete(shmid);
	
	//Pipe anlegen
	int pipe_fd[2];
	if(pipe(pipe_fd)<0){
		log_printf(LOG_ERROR,"Fehler bei Pipe anlegen");
	};

	// zweiten Prozess erstellen.
	// Connector ist der Kindprozess
	// Thinker der Elternprozess
	switch (pid = fork ()) {
	case -1:
		log_printf (LOG_ERROR,"Fehler bei fork()\n");
		break;
	case 0: // Connector
		shmPtr->pid1=pid;
		char *getText;
		
		//Verbindung mit Server herstellen
		netConnect(configstruct.port, configstruct.hostname);

		while (1) {
			getText = netReadLine();

			if (strncmp(getText, "+ MNM ",6) == 0) {
				//+ MNM Gameserver v1.0 accepting connections
				sendVersion();
			} else if (strncmp(getText, "+ Clie",6) == 0) {
				//+ Client version accepted - please send Game-ID to join
				sendGameId(gameId);
			} else if (strncmp(getText, "+ PLAY",6) == 0) {
				//+ PLAYING Quarto
				parseGamekind(getText, shmPtr);
				sendPlayer(player, shmPtr);
			} else if (strncmp(getText, "+ ENDP",6) == 0) {
				//+ ENDPLAYERS
				//noop
			} else if (strncmp(getText, "+ MOVE",6) == 0) {
				//+ MOVE 3000
				parseMovetimeout(getText, shmPtr);
			} else if (strncmp(getText, "+ NEXT",6) == 0) {
				//+ NEXT 7
				parseNext(getText, shmPtr);
			} else if (strncmp(getText, "+ FIEL",6) == 0) {
				//+ FIELD 4,4
				parseField(getText);
			} else if (strncmp(getText, "+ ENDF",6) == 0) {
				//+ ENDFIELD
        if (shmPtr->gameover != 1) {
  				sendThinking();
        }
			} else if (strncmp(getText, "+ OKTH",6) == 0) {
				
				//Hier Zug erhalten und per sendMove(stein, naechsterstein) senden
				if(ueberwacheFd(pipe_fd,getText)==1){
					log_printf(LOG_DEBUG,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
					sendMove(getText);
				}
				else{
					log_printf(LOG_PRINTF,"Gandalf ist ersoffen\n");
				}
			} else if (strncmp(getText, "+ WAIT",6) == 0) {
				//+ WAIT
				sendOkwait();
			} else if (strncmp(getText, "+ GAME",6) == 0) {
				//+ GAMEOVER [[ hh Spielernummer des Gewinners ii hh Spielername des Gewinners ii ]]
        shmPtr->gameover = 1;
				parseGameover(getText);
			} else if (strncmp(getText, "+ QUIT",6) == 0) {
				//+ QUIT
				netDisconnect();
				break;
			} else if (strncmp(getText, "-",1) == 0) {
				//Well, f**k.

				//aufraeumen + signal an parent schicken, damit der sich beendet
				netDisconnect();
				free(confDateiName);
				kill(getppid(),SIGCHLD);
				break;
			}
		}

		break;

	default: // Thinker
		
		shmPtr->pid0=pid;

		//wenn das Signal kommt, dass er denken soll
		signal(SIGUSR1, signalHandler);
		//wenn das Signal vom Kind kommt, dass er sich beenden soll (wegen Fehler)
		signal(SIGCHLD, endHandler);
		
		while (1){
			// Auf Signal warten	
			pause();
			
			log_printf(LOG_DEBUG,"thinker hat fertig gedacht\n");
			// In die Pipe schreiben
			pipe_write(pipe_fd);
		}

		if (wait (NULL) != pid) {
			log_printf(LOG_ERROR,"Fehler beim Warten auf den Kindprozess\n");
			return EXIT_FAILURE;
		}
		break;
	}

	return 0;
}
Beispiel #10
0
void
Animxmlparser::doParse ()
{
  uint64_t parsedElementCount = 0;
  AnimatorMode * pAnimatorMode = AnimatorMode::getInstance ();
  while (!isParsingComplete ())
    {
      if (AnimatorMode::getInstance ()->keepAppResponsive ())
        {
          AnimatorMode::getInstance ()->setParsingCount (parsedElementCount);

        }
      ParsedElement parsedElement = parseNext ();
      switch (parsedElement.type)
        {
        case XML_ANIM:
        {
          AnimatorMode::getInstance ()->setVersion (parsedElement.version);
          //qDebug (QString ("XML Version:") + QString::number (version));
          break;
        }
        case XML_NODE:
        {
            m_minNodeX = qMin (m_minNodeX, parsedElement.node_x);
            m_minNodeY = qMin (m_minNodeY, parsedElement.node_y);
            m_maxNodeX = qMax (m_maxNodeX, parsedElement.node_x);
            m_maxNodeY = qMax (m_maxNodeY, parsedElement.node_y);
          AnimNodeAddEvent * ev = new AnimNodeAddEvent (parsedElement.nodeId,
              parsedElement.nodeSysId,
              parsedElement.node_x,
              parsedElement.node_y,
              parsedElement.nodeDescription,
              parsedElement.node_r,
              parsedElement.node_g,
              parsedElement.node_b);
          pAnimatorMode->addAnimEvent (0, ev);
          AnimNodeMgr::getInstance ()->addAPosition (parsedElement.nodeId, 0, QPointF (parsedElement.node_x,
                                                                                    parsedElement.node_y));
          break;
        }
        case XML_PACKET_TX_REF:
        {
          m_packetRefs[parsedElement.uid] = parsedElement;
          break;
        }
        case XML_WPACKET_RX_REF:
        {
            ParsedElement & ref = m_packetRefs[parsedElement.uid];
            parsedElement.packetrx_fromId = ref.packetrx_fromId;
            parsedElement.packetrx_fbTx = ref.packetrx_fbTx;
            parsedElement.packetrx_lbTx = ref.packetrx_lbTx;
            parsedElement.meta_info = ref.meta_info;
        }
        case XML_WPACKET_RX:
        case XML_PACKET_RX:
        {
          m_firstPacketTime = qMin (m_firstPacketTime, parsedElement.packetrx_fbTx);
          if (parsedElement.packetrx_fromId == parsedElement.packetrx_toId)
            break;
          uint8_t numWirelessSlots = 3;
          AnimPacketEvent * ev = new AnimPacketEvent (parsedElement.packetrx_fromId,
              parsedElement.packetrx_toId,
              parsedElement.packetrx_fbTx,
              parsedElement.packetrx_fbRx,
              parsedElement.packetrx_lbTx,
              parsedElement.packetrx_lbRx,
              parsedElement.isWpacket,
              parsedElement.meta_info,
              numWirelessSlots);
          pAnimatorMode->addAnimEvent (parsedElement.packetrx_fbTx, ev);
          ++parsedElementCount;
          m_lastPacketEventTime = parsedElement.packetrx_fbRx;
          if (parsedElementCount == 50)
            m_thousandThPacketTime = parsedElement.packetrx_lbRx;

          if (!parsedElement.isWpacket)
            {
              qreal fullDuration = parsedElement.packetrx_lbRx - parsedElement.packetrx_fbTx;
              uint32_t numSlots = WIRED_PACKET_SLOTS;
              qreal step = fullDuration/numSlots;
              for (uint32_t i = 1; i <= numSlots; ++i)
                {
                  qreal point = parsedElement.packetrx_fbTx + (i * step);
                  //NS_LOG_DEBUG ("Point:" << point);
                  pAnimatorMode->addAnimEvent (point, new AnimWiredPacketUpdateEvent ());
                }
            }

          //NS_LOG_DEBUG ("Packet Last Time:" << m_lastPacketEventTime);
          break;
        }
        case XML_LINK:
        {
          //AnimLinkMgr::getInstance ()->add (parsedElement.link_fromId, parsedElement.link_toId);
          AnimLinkAddEvent * ev = new AnimLinkAddEvent (parsedElement.link_fromId,
              parsedElement.link_toId,
              parsedElement.linkDescription,
              parsedElement.fromNodeDescription,
              parsedElement.toNodeDescription);
          pAnimatorMode->addAnimEvent (0, ev);
          break;
        }
        case XML_NONP2P_LINK:
        {
          AnimLinkAddEvent * ev = new AnimLinkAddEvent (parsedElement.link_fromId,
              parsedElement.link_toId,
              parsedElement.linkDescription,
              parsedElement.fromNodeDescription,
              parsedElement.toNodeDescription,
              false);
          pAnimatorMode->addAnimEvent (0, ev);
          break;


        }
        case XML_LINKUPDATE:
        {
          AnimLinkUpdateEvent * ev = new AnimLinkUpdateEvent (parsedElement.link_fromId,
              parsedElement.link_toId,
              parsedElement.linkDescription);
          pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
          break;
        }
        case XML_BACKGROUNDIMAGE:
        {
          BackgroudImageProperties_t bgProp;
          bgProp.fileName = parsedElement.fileName;
          bgProp.x = parsedElement.x;
          bgProp.y = parsedElement.y;
          bgProp.scaleX = parsedElement.scaleX;
          bgProp.scaleY = parsedElement.scaleY;
          bgProp.opacity = parsedElement.opacity;
          AnimatorMode::getInstance ()->setBackgroundImageProperties (bgProp);
          break;
        }

        case XML_RESOURCE:
        {
          AnimResourceManager::getInstance ()->add (parsedElement.resourceId, parsedElement.resourcePath);
          break;
        }
        case XML_CREATE_NODE_COUNTER:
        {
            AnimCreateNodeCounterEvent * ev = 0;
            if (parsedElement.nodeCounterType == ParsedElement::UINT32_COUNTER)
              ev = new AnimCreateNodeCounterEvent (parsedElement.nodeCounterId, parsedElement.nodeCounterName, AnimCreateNodeCounterEvent::UINT32_COUNTER);
            if (parsedElement.nodeCounterType == ParsedElement::DOUBLE_COUNTER)
              ev = new AnimCreateNodeCounterEvent (parsedElement.nodeCounterId, parsedElement.nodeCounterName, AnimCreateNodeCounterEvent::DOUBLE_COUNTER);
            if (ev)
              {
                pAnimatorMode->addAnimEvent (0, ev);
              }
            break;
        }
        case XML_NODECOUNTER_UPDATE:
        {
            AnimNodeCounterUpdateEvent * ev = new AnimNodeCounterUpdateEvent (parsedElement.nodeCounterId,
                                                                              parsedElement.nodeId,
                                                                              parsedElement.nodeCounterValue);
            pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
            break;
        }
        case XML_NODEUPDATE:
        {
          if (parsedElement.nodeUpdateType == ParsedElement::POSITION)
            {
              AnimNodePositionUpdateEvent * ev = new AnimNodePositionUpdateEvent (parsedElement.nodeId,
                  parsedElement.node_x,
                  parsedElement.node_y);
              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
              AnimNodeMgr::getInstance ()->addAPosition (parsedElement.nodeId, parsedElement.updateTime, QPointF (parsedElement.node_x,
                                                                                        parsedElement.node_y));
              m_minNodeX = qMin (m_minNodeX, parsedElement.node_x);
              m_minNodeY = qMin (m_minNodeY, parsedElement.node_y);
              m_maxNodeX = qMax (m_maxNodeX, parsedElement.node_x);
              m_maxNodeY = qMax (m_maxNodeY, parsedElement.node_y);

            }
          if (parsedElement.nodeUpdateType == ParsedElement::COLOR)
            {
              AnimNodeColorUpdateEvent * ev = new AnimNodeColorUpdateEvent (parsedElement.nodeId,
                  parsedElement.node_r,
                  parsedElement.node_g,
                  parsedElement.node_b);

              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
            }
          if (parsedElement.nodeUpdateType == ParsedElement::DESCRIPTION)
            {
              AnimNodeDescriptionUpdateEvent * ev = new AnimNodeDescriptionUpdateEvent (parsedElement.nodeId,
                  parsedElement.nodeDescription);
              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);

            }
          if (parsedElement.nodeUpdateType == ParsedElement::SIZE)
            {
              AnimNodeSizeUpdateEvent * ev = new AnimNodeSizeUpdateEvent (parsedElement.nodeId,
                  parsedElement.node_width,
                  parsedElement.node_height);
              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);

            }
          if (parsedElement.nodeUpdateType == ParsedElement::IMAGE)
            {
              AnimNodeImageUpdateEvent * ev = new AnimNodeImageUpdateEvent (parsedElement.nodeId,
                  parsedElement.resourceId);
              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
            }
          if (parsedElement.nodeUpdateType == ParsedElement::SYSTEM_ID)
            {
              AnimNodeSysIdUpdateEvent * ev = new AnimNodeSysIdUpdateEvent (parsedElement.nodeId,
                                parsedElement.nodeSysId);
              pAnimatorMode->addAnimEvent (parsedElement.updateTime, ev);
            }
          break;

        }
        case XML_INVALID:
        default:
        {
          //qDebug ("Invalid XML element");
        }
        } //switch
    } // while loop
}
static error_code parseIOMsg(char* buf, unsigned int buf_size, BoolValue *val)
{
	Parser lkabParser;
	BinaryBuffer buffer;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	struct appDataLKAB parsingData;
	EXIPSchema lkab_schema;
	const char *schemafname = "SchemaStrict/lkab-devices-xsd.exi";

	buffer.buf = buf;
	buffer.bufLen = buf_size;
	buffer.bufContent = buf_size;
	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &lkab_schema);

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm.stream = NULL;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&lkabParser, buffer, &parsingData);
	if(tmp_err_code != EXIP_OK)
		return tmp_err_code;

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.currElementNumber = 0;
	parsingData.val.quality = Good;
	parsingData.val.val = 0;
	parsingData.val.ts.year = 0;
	parsingData.val.ts.month = 0;
	parsingData.val.ts.mday = 0;
	parsingData.val.ts.hour = 0;
	parsingData.val.ts.min = 0;
	parsingData.val.ts.sec = 0;
	parsingData.val.ts.msec = 0;

	lkabParser.handler.fatalError = lkab_fatalError;
	lkabParser.handler.error = lkab_fatalError;
	lkabParser.handler.startElement = lkab_startElement_io;
	lkabParser.handler.stringData = lkab_stringData_io;
	lkabParser.handler.endElement = lkab_endElement;
	lkabParser.handler.booleanData = lkab_booleanData_io;
	lkabParser.handler.dateTimeData = lkab_dateTimeData;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&lkabParser, FALSE);

	tmp_err_code = setSchema(&lkabParser, &lkab_schema);
	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&lkabParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&lkabParser);

	val->ts = parsingData.val.ts;
	val->val = parsingData.val.val;
	val->quality = parsingData.val.quality;

	if(tmp_err_code == EXIP_PARSING_COMPLETE)
		return EXIP_OK;
	else
		return tmp_err_code;
}
Beispiel #12
0
errorCode decodeHeader(EXIStream* strm, boolean outOfBandOpts)
{
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	unsigned int bits_val = 0;
	boolean boolVal = FALSE;

	DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">Start EXI header decoding\n"));
	TRY(readBits(strm, 2, &bits_val));
	if(bits_val == 2)  // The header Distinguishing Bits i.e. no EXI Cookie
	{
		strm->header.has_cookie = 0;
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI cookie detected\n"));
	}
	else if(bits_val == 0)// ASCII code for $ = 00100100  (36)
	{
		TRY(readBits(strm, 6, &bits_val));
		if(bits_val != 36)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 69)   // ASCII code for E = 01000101  (69)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 88)   // ASCII code for X = 01011000  (88)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 73)   // ASCII code for I = 01001001  (73)
			return INVALID_EXI_HEADER;

		strm->header.has_cookie = 1;
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI cookie detected\n"));
		TRY(readBits(strm, 2, &bits_val));
		if(bits_val != 2)  // The header Distinguishing Bits are required
			return INVALID_EXI_HEADER;
	}
	else
	{
		return INVALID_EXI_HEADER;
	}

	// Read the Presence Bit for EXI Options
	TRY(readNextBit(strm, &boolVal));

	if(boolVal == TRUE) // There are EXI options
	{
		strm->header.has_options = TRUE;
		// validation checks. If the options are included then
		// they cannot be set by an out-of-band mechanism.
		// If out-of-band options are set -
		// rise a warning and overwrite them.
		// Only the options from the header will be used
		if(outOfBandOpts == TRUE)
		{
			DEBUG_MSG(WARNING, DEBUG_CONTENT_IO, (">Ignored out-of-band set EXI options\n"));
			makeDefaultOpts(&strm->header.opts);
		}
	}
	else // Out-of-band set EXI options
	{
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI options field in the header\n"));
		strm->header.has_options = FALSE;
		if(outOfBandOpts == FALSE)
		{
			DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">No EXI options in the header and no out-of-band options specified. \n"));
			return HEADER_OPTIONS_MISMATCH;
		}
	}

	// Read the Version type
	TRY(readNextBit(strm, &boolVal));

	strm->header.is_preview_version = boolVal;
	strm->header.version_number = 1;

	do
	{
		TRY(readBits(strm, 4, &bits_val));
		strm->header.version_number += bits_val;
		if(bits_val < 15)
			break;
	} while(1);

	DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI version: %d\n", strm->header.version_number));

	if(strm->header.has_options == 1)
	{
		Parser optionsParser;
		struct ops_AppData appD;

		TRY(initParser(&optionsParser, strm->buffer, &appD));

		optionsParser.strm.context.bitPointer = strm->context.bitPointer;
		optionsParser.strm.context.bufferIndx = strm->context.bufferIndx;
		optionsParser.strm.gStack = NULL;

		makeDefaultOpts(&optionsParser.strm.header.opts);
		SET_STRICT(optionsParser.strm.header.opts.enumOpt);

		optionsParser.handler.fatalError = ops_fatalError;
		optionsParser.handler.error = ops_fatalError;
		optionsParser.handler.startDocument = ops_startDocument;
		optionsParser.handler.endDocument = ops_endDocument;
		optionsParser.handler.startElement = ops_startElement;
		optionsParser.handler.attribute = ops_attribute;
		optionsParser.handler.stringData = ops_stringData;
		optionsParser.handler.endElement = ops_endElement;
		optionsParser.handler.intData = ops_intData;
		optionsParser.handler.booleanData = ops_boolData;

		appD.o_strm = &optionsParser.strm;
		appD.parsed_ops = &strm->header.opts;
		appD.prevElementLnID = 0;
		appD.prevElementUriID = 0;
		appD.permanentAllocList = &strm->memList;

		TRY_CATCH(setSchema(&optionsParser, (EXIPSchema*) &ops_schema), destroyParser(&optionsParser));
		TRY_CATCH(createValueTable(&optionsParser.strm.valueTable), destroyParser(&optionsParser));

		while(tmp_err_code == ERR_OK)
		{
			tmp_err_code = parseNext(&optionsParser);
		}

		destroyParser(&optionsParser);

		if(tmp_err_code != PARSING_COMPLETE)
			return tmp_err_code;

		strm->buffer.bufContent = optionsParser.strm.buffer.bufContent;
		strm->context.bitPointer = optionsParser.strm.context.bitPointer;
		strm->context.bufferIndx = optionsParser.strm.context.bufferIndx;

		if(WITH_COMPRESSION(strm->header.opts.enumOpt) ||
			GET_ALIGNMENT(strm->header.opts.enumOpt) != BIT_PACKED)
		{
			// Padding bits
			if(strm->context.bitPointer != 0)
			{
				strm->context.bitPointer = 0;
				strm->context.bufferIndx += 1;
			}
		}
	}

	return checkOptionValues(&strm->header.opts);
}
static error_code parseDevDescMsg(char* buf, unsigned int buf_size, DevDescribtion* devDesc)
{
	Parser lkabParser;
	BinaryBuffer buffer;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	struct appDataLKAB parsingData;
	EXIPSchema lkab_schema;
	const char *schemafname = "SchemaStrict/lkab-devices-xsd.exi";

	buffer.buf = buf;
	buffer.bufLen = buf_size;
	buffer.bufContent = buf_size;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &lkab_schema);

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm.stream = NULL;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&lkabParser, buffer, &parsingData);
	if(tmp_err_code != EXIP_OK)
		return tmp_err_code;

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.currElementNumber = 0;
	parsingData.devDesc.id[0] = '\0';
	parsingData.devDesc.location[0] = '\0';
	parsingData.devDesc.name[0] = '\0';
	parsingData.devDesc.type[0] = '\0';
	parsingData.devDesc.processValue.description[0] = '\0';
	parsingData.devDesc.processValue.name[0] = '\0';
	parsingData.devDesc.processValue.isReadOnly = 0;
	parsingData.devDesc.processValue.type = Bool;

	lkabParser.handler.fatalError = lkab_fatalError;
	lkabParser.handler.error = lkab_fatalError;
	lkabParser.handler.startElement = lkab_startElement_desc;
	lkabParser.handler.stringData = lkab_stringData_desc;
	lkabParser.handler.endElement = lkab_endElement;
	lkabParser.handler.booleanData = lkab_booleanData_desc;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&lkabParser, FALSE);

	tmp_err_code = setSchema(&lkabParser, &lkab_schema);
	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&lkabParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&lkabParser);

	strcpy(devDesc->id, parsingData.devDesc.id);
	strcpy(devDesc->location, parsingData.devDesc.location);
	strcpy(devDesc->name, parsingData.devDesc.name);
	strcpy(devDesc->type, parsingData.devDesc.type);
	strcpy(devDesc->processValue.description, parsingData.devDesc.processValue.description);
	strcpy(devDesc->processValue.name, parsingData.devDesc.processValue.name);
	devDesc->processValue.isReadOnly = parsingData.devDesc.processValue.isReadOnly;
	devDesc->processValue.type = parsingData.devDesc.processValue.type;

	if(tmp_err_code == EXIP_PARSING_COMPLETE)
		return EXIP_OK;
	else
		return tmp_err_code;
}
Beispiel #14
0
 Token Lexer::nextToken()
 {
     //and then parse and return the next token
     _lastToken = parseNext();
     return _lastToken;
 }
Beispiel #15
0
static void *XoReadExiCommon(struct ioStream *ioStr, char *roottype,int flags,int *err) {
	Parser testParser;
	struct appData parsingData;
	char buf[INPUT_BUFFER_SIZE];
	BinaryBuffer buffer;
	errorCode tmp_err_code = UNEXPECTED_ERROR;

	memset	(&parsingData,0,sizeof(parsingData));
	parsingData.ctxt.roottype	= roottype;
	parsingData.ctxt.flags	= flags;
	parsingData.ctxt.ns.flags	= flags;
	parsingData.parser	= &testParser;
	_XoAllocCtxt(&parsingData.ctxt);

	buffer.buf = buf;
	buffer.bufLen = INPUT_BUFFER_SIZE;
	buffer.bufContent = 0;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm	= *ioStr;

	// II: Second, initialize the parser object
#if EXIP_VERSION==276
	tmp_err_code = initParser(&testParser, buffer, g_schemaPtr, &parsingData);
#endif
#if EXIP_VERSION>=289
	tmp_err_code = initParser(&testParser, buffer, &parsingData);
#endif
	if(tmp_err_code != ERR_OK) {
		_XoFreeCtxt(&parsingData.ctxt);
		return NULL;
	}

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.expectAttributeData = 0;
	parsingData.stack = NULL;
	parsingData.unclosedElement = 0;
	parsingData.prefixesCount = 0;

	testParser.handler.fatalError = sample_fatalError;
	testParser.handler.error = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument = sample_endDocument;
	testParser.handler.startElement = sample_startElement;
	testParser.handler.attribute = sample_attribute;
	testParser.handler.stringData = sample_stringData;
	testParser.handler.endElement = sample_endElement;
	testParser.handler.decimalData = sample_decimalData;
	testParser.handler.intData = sample_intData;
	testParser.handler.floatData = sample_floatData;
	testParser.handler.booleanData = sample_booleanData;
	testParser.handler.dateTimeData = sample_dateTimeData;
	testParser.handler.binaryData = sample_binaryData;
	testParser.handler.qnameData = sample_qnameData;
#if EXIP_VERSION==276
	testParser.handler.retrieveSchema = sample_retrieveSchema;
#endif

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser, FALSE);
#if EXIP_VERSION>=289
	// IV.1: Set the schema to be used for parsing.
	// The schemaID mode and schemaID field can be read at
	// parser.strm.header.opts.schemaIDMode and
	// parser.strm.header.opts.schemaID respectively
	// If schemaless mode, use setSchema(&parser, NULL);

	EXIPSchema *schemaPtr = sample_retrieveSchema(&parsingData);
	setSchema(&testParser, schemaPtr);
#endif

	//_lookupSchema();

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
		PRINT ("parseNext ret=%d\n", tmp_err_code);
	}

	// PCA
	parsingData.xo_obj	= parsingData.ctxt.obj[0];

	// VI: Free the memory allocated by the parser and schema object

	destroyParser(&testParser);

	_XoFreeCtxt(&parsingData.ctxt);
	PRINT ("End parsing xo_obj=%p\n", parsingData.xo_obj);
	return	parsingData.xo_obj;
}
Beispiel #16
0
END_TEST

START_TEST (test_noLearning02)
{
	EXIStream testStrm;
	Parser testParser;
	String uri;
	String ln;
	QName qname= {&uri, &ln};
	String chVal;
	char buf[OUTPUT_BUFFER_SIZE];
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	BinaryBuffer buffer;
	EXITypeClass valueType;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = OUTPUT_BUFFER_SIZE;
	buffer.ioStrm.readWriteToStream = NULL;
	buffer.ioStrm.stream = NULL;

	// Serialization steps:

	// I: First initialize the header of the stream
	serialize.initHeader(&testStrm);

	// II: Set any options in the header, if different from the defaults
	testStrm.header.has_options = TRUE;
	testStrm.header.opts.schemaIDMode = SCHEMA_ID_EMPTY;

	// III: Define an external stream for the output if any

	// IV: Initialize the stream
	tmp_err_code = serialize.initStream(&testStrm, buffer, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "initStream returns an error code %d", tmp_err_code);

	// V: Start building the stream step by step: header, document, element etc...
	tmp_err_code = serialize.exiHeader(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.exiHeader returns an error code %d", tmp_err_code);

	tmp_err_code = serialize.startDocument(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startDocument returns an error code %d", tmp_err_code);

	getEmptyString(&uri);
	tmp_err_code += asciiToString("root", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("a", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("bla", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("b", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("23", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("a", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("bla", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("c", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("b", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("http://www.w3.org/2001/XMLSchema-instance", &uri, &testStrm.memList, FALSE);
	tmp_err_code += asciiToString("type", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.attribute(&testStrm, qname, TRUE, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.attribute returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("http://www.w3.org/2001/XMLSchema", &uri, &testStrm.memList, FALSE);
	tmp_err_code += asciiToString("integer", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.qnameData(&testStrm, qname);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.qnameData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.intData(&testStrm, 66);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += serialize.endElement(&testStrm);
	tmp_err_code += serialize.endDocument(&testStrm);

	if(tmp_err_code != EXIP_OK)
		fail_unless (tmp_err_code == EXIP_OK, "serialization ended with error code %d", tmp_err_code);

	// V: Free the memory allocated by the EXI stream object
	tmp_err_code = serialize.closeEXIStream(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.closeEXIStream ended with error code %d", tmp_err_code);


	buffer.bufContent = OUTPUT_BUFFER_SIZE;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser, TRUE);
	fail_unless (tmp_err_code == EXIP_OK, "parsing the header returns an error code %d", tmp_err_code);

	tmp_err_code = setSchema(&testParser, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "setSchema() returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&testParser);
	fail_unless (tmp_err_code == EXIP_PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
END_TEST

/* Verifies a single global element also used as a reference. */
START_TEST (test_acceptance_for_A_01_exip1)
{
	EXIPSchema schema;
	FILE *infile;
	Parser testParser;
	char buf[INPUT_BUFFER_SIZE];
	const char *schemafname = "testStates/acceptance-xsd.exi";
	const char *exifname = "testStates/acceptance_a_01a.exi";
	char exipath[MAX_PATH_LEN + strlen(exifname)];
	struct appData parsingData;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	BinaryBuffer buffer;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = INPUT_BUFFER_SIZE;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &schema);

	// I.B: Define an external stream for the input to the parser if any
	size_t pathlen = strlen(dataDir);
	memcpy(exipath, dataDir, pathlen);
	exipath[pathlen] = '/';
	memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
	
	infile = fopen(exipath, "rb" );
	if(!infile)
		fail("Unable to open file %s", exipath);
	
	buffer.ioStrm.readWriteToStream = readFileInputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, &parsingData);
	fail_unless (tmp_err_code == EXIP_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object
	parsingData.eventCount = 0;
	parsingData.expectAttributeData = 0;
	if (EXIP_OK != initAllocList(&parsingData.allocList))
		fail("Memory allocation error!");

	testParser.handler.fatalError    = sample_fatalError;
	testParser.handler.error         = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument   = sample_endDocument;
	testParser.handler.startElement  = sample_startElement;
	testParser.handler.attribute     = sample_attribute;
	testParser.handler.stringData    = sample_stringData;
	testParser.handler.endElement    = sample_endElement;
	testParser.handler.decimalData   = sample_decimalData;
	testParser.handler.intData       = sample_intData;
	testParser.handler.floatData     = sample_floatData;
	
	// IV: Parse the header of the stream
	tmp_err_code = parseHeader(&testParser, FALSE);
	fail_unless (tmp_err_code == EXIP_OK, "parsing the header returns an error code %d", tmp_err_code);

	tmp_err_code = setSchema(&testParser, &schema);
	fail_unless (tmp_err_code == EXIP_OK, "setSchema() returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream
	while(tmp_err_code == EXIP_OK)
	{
		switch (parsingData.eventCount)
		{
			case 0:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SD"));
				break;
			case 1:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SE"));
				fail_unless(stringEqualToAscii(parsingData.uri, "urn:foo"));
				fail_unless(stringEqualToAscii(parsingData.localName, "AB"));
				break;
			case 2:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "CH"));
				break;
			case 3:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "EE"));
				break;
			case 4:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));
				break;
			default:
				// Unexpected event count caught below.
				break;
		}

		tmp_err_code = parseNext(&testParser);
		parsingData.eventCount++;
	}
	
	fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));

	fail_unless(parsingData.eventCount == 4,
	            "Unexpected event count: %u", parsingData.eventCount);

	// VI: Free the memory allocated by the parser object
	freeAllocList(&parsingData.allocList);
	destroyParser(&testParser);
	fclose(infile);
	fail_unless (tmp_err_code == EXIP_PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
Beispiel #18
0
bool RC2UI::makeDialog()
{
    line = in->readLine();
    do {
        QFile fileOut;
	QString buffer;
	int count;
	QCString className;
	uint x, y, w, h;
	uint endDesc;
	bool space = FALSE;
	for ( endDesc = 0; endDesc < line.length() ; endDesc++ ) {
	    char c = (QChar)line.at(endDesc);
	    if ( space && (c >= '0') && (c <= '9') )
		break;
	    space = c==' ';
	}
	
	QString desc = line.left(endDesc-1);
	line = line.right( line.length() - endDesc );

	className = parseNext( desc, ' ' );

 	count = sscanf( line, "%d, %d, %d, %d", &x, &y, &w, &h );
	
	if ( !count && count == EOF )
	    return FALSE;

	char property[256];
	QStringList styles;
	QStringList extendedStyles;
	QString caption = "";
	QString baseClass = "";
	QString widgetType;
	QString widgetName;
	QString arguments;
	int pointsize;
	QString fontname;
	do {
	    if ( in->eof() )
		return TRUE;
	    line = "";
	    do {
		line += in->readLine();
	    } while ( line[(int)line.length()-1] == '|' || 
		      line[(int)line.length()-1] == ',' );
	    count = sscanf( line, "%s", property );
	    line = line.right( line.length() - line.find(" ") -1 );
	    if ( QString(property) == "STYLE" ) {
		styles = splitStyles(line);
		if ( styles.contains( "WS_CAPTION" ) )
		    baseClass = "QDialog";
		else
		    baseClass = "QWidget";
	    } else if ( QString(property) == "CAPTION" ) {
		caption = stripQM( line );
	    } else if ( QString(property) == "FONT" ) {
		QString pt = line.left( line.find(",") );
		pointsize = pt.toInt();
		fontname = stripQM(line.right( line.length() - line.find(",") - 2 ));
	    }
	} while ( line != "BEGIN" );

	if ( writeToFile ) {
	    
	    QString outputFile = QString(className) + ".ui";
	    fileOut.setName( outputFile );
	    if (!fileOut.open( IO_WriteOnly ) )
		qFatal( "rc2ui: Could not open output file '%s'", outputFile.latin1() );
	    out = new QTextStream( &fileOut );

	} else {
	    out = new QTextStream( &buffer, IO_WriteOnly );
	}

	*out << "<!DOCTYPE UI><UI>" << endl;
	writeClass( className );
	wi(); *out << "<widget>"<< endl; indent();
	writeClass( baseClass );
	writeCString( "name", className );
	writeRect( "geometry", x, y, w, h );
	writeString( "caption", caption );
	writeFont( fontname, pointsize );

	do {
	    line = in->readLine().stripWhiteSpace();
	    if ( line == "END" )
		continue;

	    widgetType = parseNext(line, ' ');
	    arguments = line.stripWhiteSpace();
	    while ( arguments[(int)arguments.length()-1] == ',' || 
		    arguments[(int)arguments.length()-1] == '|'  )
		arguments += " "+in->readLine().stripWhiteSpace();

	    wi(); *out << "<widget>" << endl; indent();

	    WidgetType ID = IDUnknown;
	    QString controlType;
	    QString widgetID;
	    QString widgetText;
	    bool hasText = FALSE;
	    bool isControl = FALSE;
	    bool isFrame = FALSE;

	    if ( widgetType == "PUSHBUTTON" ) {
		ID = IDPushButton;
		hasText = TRUE;
	    } else if ( widgetType == "DEFPUSHBUTTON" ) {
		ID = IDPushButton;
		hasText = TRUE;
	    } else if ( widgetType == "LTEXT" ) {
		ID = IDLabel;
		hasText = TRUE;
	    } else if ( widgetType == "CTEXT" ) {
		ID = IDLabel;
		hasText = TRUE;
	    } else if ( widgetType == "RTEXT" ) {
		ID = IDLabel;
		hasText = TRUE;
	    } else if ( widgetType == "EDITTEXT" ) {
		ID = IDLineEdit;
	    } else if ( widgetType == "GROUPBOX" ) {
		ID = IDGroupBox;
		hasText = TRUE;
	    } else if ( widgetType == "COMBOBOX" ) {
		ID = IDComboBox;
	    } else if ( widgetType == "LISTBOX" ) {
		ID = IDListBox;
	    } else if ( widgetType == "SCROLLBAR" ) {
		ID = IDScrollBar;
	    } else if ( widgetType == "CHECKBOX" ) {
		ID = IDCheckBox;
		hasText = TRUE;
	    } else if ( widgetType == "RADIOBUTTON" ) {
		ID = IDRadioButton;
		hasText = TRUE;
	    } else if ( widgetType == "CONTROL" ) {
		isControl = TRUE;
		widgetText = stripQM(parseNext( arguments ));
		widgetID = parseNext( arguments );
		controlType = stripQM(parseNext( arguments ));
		styles = splitStyles(parseNext( arguments ));
		
		if ( controlType == "Static" ) {
		    ID = IDLabel;
		} else if ( controlType == "Button" ) {
		    if ( styles.contains("BS_AUTOCHECKBOX") ||
			 styles.contains("BS_3STATE") )
			ID = IDCheckBox;
		    else if ( styles.contains("BS_AUTORADIOBUTTON") )
			ID = IDRadioButton;
		} else if ( controlType == "msctls_updown32" ) {
		    ID = IDSpinBox;
		} else if ( controlType == "msctls_progress32" ) {
		    ID = IDProgressBar;
		} else if ( controlType == "msctls_trackbar32" ) {
		    ID = IDSlider;
		} else if ( controlType == "SysListView32" ) {
		    ID = IDIconView;
		} else if ( controlType == "SysTreeView32" ) {
		    ID = IDListView;
		} else if ( controlType == "SysTabControl32" ) {
		    ID = IDTabWidget;
		} else if ( controlType == "SysAnimate32" ) {
		    ID = IDLabel;
		} else if ( controlType == "RICHEDIT" ) {
		    ID = IDMultiLineEdit;
		} else if ( controlType == "ComboBoxEx32" ) {
		    ID = IDComboBox;
		} else if ( controlType == "" ) {
		    ID = IDCustom;
		} else {
		    ID = IDUnknown;
		}
	    } else
		ID = IDUnknown;

	    if ( hasText )
		widgetText = stripQM(parseNext( arguments ));

	    if ( isControl ) {
		x = parseNext( arguments ).toInt();
		y = parseNext( arguments ).toInt();
		w = parseNext( arguments ).toInt();
		h = parseNext( arguments ).toInt();
	    } else {
		widgetID = parseNext( arguments );
		x = parseNext( arguments ).toInt();
		y = parseNext( arguments ).toInt();
		w = parseNext( arguments ).toInt();
		h = parseNext( arguments ).toInt();
		styles.clear();
	    }

	    do {
		extendedStyles = splitStyles(parseNext( arguments ));
		for ( uint i = 0; i < extendedStyles.count(); i++ )
		    styles << (*extendedStyles.at(i));
	    } while ( arguments.find(',') > -1 );

	    switch ( ID ) {
	    case IDWidget:
		break;
	    case IDPushButton: 
		{
		    writeClass("QPushButton");
		    writeCString( "name", useName("PushButton_"+widgetID) );
		    writeRect( "geometry", x, y, w, h );
		    writeString( "text", widgetText );
		    if ( widgetType == "DEFPUSHBUTTON" )
			writeBool( "default", TRUE );
		}
		break;
	    case IDLabel:
		{
		    isFrame = TRUE,
		    writeClass("QLabel");
		    writeCString( "name", useName("Label_"+widgetID) );
		    writeRect( "geometry", x,y,w,h );
		    writeString( "text", widgetText );
		    QString align;
		    if ( !styles.contains("SS_CENTERIMAGE") )
			align += "|AlignTop";
		    else
			align += "|AlignVCenter";
		    if ( widgetType == "LTEXT" ) {
			align += "|AlignLeft";
		    } else if ( widgetType == "CTEXT") {
			align += "|AlignHCenter";
		    } else if ( widgetType == "RTEXT") {
			align += "|AlignRight";
		    }
		    writeSet("alignment", align );
		}
		break;
	    case IDCheckBox:
		{
		    writeClass("QCheckBox");
		    writeCString("name", useName("CheckBox_"+widgetID) );
		    writeRect("geometry", x,y,w,h);
		    writeString("text", widgetText );
		    if ( styles.contains( "BS_3STATE" ) )
			writeBool( "tristate", TRUE );
		}
		break;
	    case IDRadioButton:
		{
		    writeClass("QRadioButton");
		    writeCString("name", useName("RadioButton_"+widgetID) );
		    writeRect("geometry", x,y,w,h);
		    writeString("text", widgetText );
		}
		break;
	    case IDGroupBox:
		{
		    isFrame = TRUE;
		    writeClass("QGroupBox");
		    writeCString( "name", useName("GroupBox_"+widgetID) );
		    writeRect( "geometry", x,y,w,h );
		    writeString( "title", widgetText );
		    if ( !styles.contains( "WS_BORDER" ) )
			styles.append( "WS_BORDER" );
		}
		break;
	    case IDLineEdit:
		{
		    if ( !styles.contains("ES_MULTILINE") ) {
			writeClass("QLineEdit");
			writeCString( "name", useName("LineEdit_"+widgetID) );
		    } else {
			writeClass("QMultiLineEdit");
			writeCString( "name", useName("MultiLineEdit_"+widgetID) );
		    }
		    writeRect( "geometry", x,y,w,h );
		    QString align = "AlignTop";
		    if ( styles.contains("ES_CENTER") )
			align+="|AlignHCenter";
		    else if ( styles.contains("ES_RIGHT") )
			align+="|AlignRight";
		    else
			align+="|AlignLeft";
		    writeSet("alignment", align);
		}
		break;
	    case IDMultiLineEdit:
		{
		    writeClass("QMultiLineEdit");
		    writeCString("name", useName("MultiLineEdit_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		}
		break;
	    case IDIconView:
		{
		    isFrame = TRUE;
		    writeClass("QIconView");
		    writeCString("name", useName("IconView_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    if ( !styles.contains( "LVS_SINGLESEL" ) )
			writeEnum( "selectionMode", "Extended" );
		    if ( styles.contains( "LVS_NOLABELWRAP" ) )
			writeBool("wordWrapIconText", FALSE );
		}
		break;
	    case IDListView:
		{
		    isFrame = TRUE;
		    writeClass("QListView");
		    writeCString("name", useName("ListView_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    if ( styles.contains( "TVS_LINESATROOT" ) )
			writeBool( "rootIsDecorated", TRUE );
		    if ( styles.contains( "TVS_FULLROWSELECT" ) )
			writeBool( "allColumnsShowFocus", TRUE );
		}
		break;
	    case IDProgressBar:
		{
		    isFrame = TRUE;
		    writeClass("QProgressBar");
		    writeCString("name", useName("ProgressBar_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    if ( styles.contains("TBS_VERT") )
			writeEnum("orientation", "Vertical");
		    else
			writeEnum("orientation", "Horizontal");
		}
		break;
	    case IDTabWidget:
		{
		    writeClass("QTabWidget");
		    writeCString("name", useName("TabWidget_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    wi(); *out << "<widget>" << endl; indent();
		    writeClass("QWidget");
		    wi(); *out << "<attribute>" << endl; indent();
		    wi(); *out << "<name>title</name>" << endl;
		    wi(); *out << "<string>Tab1</string>" << endl; undent();
		    wi(); *out << "</attribute>" << endl; undent();
		    wi(); *out << "</widget>" << endl;
		}
		break;
	    case IDSpinBox:
		{
		    isFrame = TRUE;
		    writeClass("QSpinBox");
		    writeCString("name", useName("SpinBox_"+widgetID) );
		    writeRect("geometry", x,y,w,h);
		}
		break;
	    case IDSlider:
		{
		    writeClass("QSlider");
		    writeCString("name", useName("Slider_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    if ( styles.contains("TBS_VERT") )
			writeEnum("orientation", "Vertical");
		    else
			writeEnum("orientation", "Horizontal");
		    if ( !styles.contains("TBS_NOTICKS") )
			writeEnum("tickmarks", "Left" );
		}
		break;
	    case IDComboBox:
		{
		    writeClass("QComboBox");
		    writeCString("name", useName("ComboBox_"+widgetID) );
		    if ( isControl )
			writeRect( "geometry", x,y,w,14 );
		    else 
			writeRect( "geometry", x,y,w,h );
		}
		break;
	    case IDListBox:
		{
		    isFrame = TRUE;
		    writeClass("QListBox");
		    writeCString("name", useName("ListBox_"+widgetID) );
		    writeRect( "geometry", x,y,w,h );
		    if ( styles.contains("WS_HSCROLL") )
			writeEnum("hScrollBarMode", "Auto");
		    else
			writeEnum("hScrollBarMode", "AlwaysOff");
		    if ( styles.contains("WS_VSCROLL") )
			writeEnum("vScrollBarMode", "Auto");
		    else
			writeEnum("vScrollBarMode", "AlwaysOff");
		    if ( styles.contains("LBS_EXTENDEDSEL") )
			writeEnum("selectionMode", "Extended");
		    else if ( styles.contains("LBS_MULTIPLESEL") )
			writeEnum("selectionMode", "Multi");
		    else if ( styles.contains("LBS_NOSEL") )
			writeEnum("selectionMode", "NoSelection");
		    else 
			writeEnum("selectionMode", "Single");
		    if ( !styles.contains( "NO WS_BORDER" ) )
			styles.append( "WS_BORDER" );
		}
		break;
	    case IDScrollBar:
		{
		    writeClass("QScrollBar");
		    writeCString("name", useName("ScrollBar_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    if ( styles.contains("SBS_VERT") )
			writeEnum("orientation", "Vertical");
		    else
			writeEnum("orientation", "Horizontal");
		}
		break;
	    case IDCustom:
		{
		    writeClass("QLabel");
		    writeCString("name", useName("Custom_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    writeString("text", "Create a custom widget and place it here." );
		}
	    default:
		{
		    writeClass("QLabel");
		    writeCString("name", useName("Unknown_"+widgetID) );
		    writeRect("geometry", x,y,w,h );
		    writeString("text", QString("No support for %1.").arg(controlType) );
		}
		break;
	    }

	    writeStyles( styles, isFrame );

	    styles.clear();

	    undent();
	    wi(); *out << "</widget>" << endl;
	} while ( line != "END" );

	undent();
	wi(); *out << "</widget>" << endl;
	*out << "</UI>" << endl;

	do {
	    line = in->readLine();
	} while ( line.isEmpty() );

	if ( !writeToFile )
	    target.append( buffer.copy() );

	if (out) {
	    delete out;
	    out = 0;
	}
	fileOut.close();

	if ( writeToFile )
	    printf( QDir::currentDirPath() + "/" + fileOut.name() + '\n' );

    } while ( line != blockStart1 );

    return TRUE;
}
Beispiel #19
0
bool RC2UI::makeStringTable()
{
    if ( !writeToFile )
	return TRUE;

    QFile fileOut;
    line = in->readLine();
    do {
	char stringtable[256];
	char discard[12];
	sscanf( line, "%s %s", stringtable, discard );
	if ( QString(stringtable) != "STRINGTABLE" )
	    return TRUE;
	do {
	    line = in->readLine();
	} while ( line != "BEGIN" );

	QString outputFile = QString(stringtable).lower() + ".h";
	if (outputFile ) {
	    fileOut.setName( outputFile );
	    if (!fileOut.open( IO_WriteOnly ) )
		qFatal( "rc2ui: Could not open output file '%s'", outputFile.latin1() );
	    out = new QTextStream( &fileOut );
	}

	*out << "#ifndef STRINGTABLE_H" << endl;
	*out << "#define STRINGTABLE_H" << endl;
	*out << endl;
	*out << "#include <qstring.h>" << endl;
	*out << "#include <qobject.h>" << endl;
	*out << endl;

	QString ID;
	QString value;
	do {
	    line = in->readLine().stripWhiteSpace();
	    if ( line == "END" )
		continue;
	    
	    ID = parseNext(line, ' ');
	    value = parseNext(line).stripWhiteSpace();

	    *out << "static const QString " << ID << "= QT_TR_NOOP(" << value << ");" << endl;

	} while ( line != "END" );

	*out << endl;
	*out << "#endif // STRINGTABLE_H" << endl;

	do {
	    line = in->readLine();
	} while ( line.isEmpty() );

	if ( out ) {
	    delete out;
	    out = 0;
	}
    } while ( line != blockStart1 );

    return TRUE;
}
Beispiel #20
0
END_TEST

START_TEST (test_strict_option)
{
	EXIPSchema schema;
	Parser testParser;
	char buf[OUTPUT_BUFFER_SIZE];
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	BinaryBuffer buffer;
	char exipath[MAX_PATH_LEN + strlen(EMPTY_TYPE_DEFAULT)];
	size_t pathlen;
	FILE *infile;
	struct appData parsingData;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = OUTPUT_BUFFER_SIZE;
	buffer.ioStrm.readWriteToStream = NULL;
	buffer.ioStrm.stream = NULL;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(EMPTY_TYPE_SCHEMA, &schema);

	// I.B: Define an external stream for the input to the parser if any
	pathlen = strlen(dataDir);
	memcpy(exipath, dataDir, pathlen);
	exipath[pathlen] = '/';
	memcpy(&exipath[pathlen+1], EMPTY_TYPE_STRICT, strlen(EMPTY_TYPE_STRICT)+1);

	infile = fopen(exipath, "rb" );
	if(!infile)
		fail("Unable to open file %s", exipath);

	buffer.ioStrm.readWriteToStream = readFileInputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, &schema, &parsingData);
	fail_unless (tmp_err_code == ERR_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object
	parsingData.eventCount = 0;
	parsingData.expectAttributeData = 0;

	testParser.handler.fatalError    = sample_fatalError;
	testParser.handler.error         = sample_fatalError;
	testParser.handler.startElement  = sample_startElement;
	testParser.handler.attribute     = sample_attribute;
	testParser.handler.stringData    = sample_stringData;
	testParser.handler.intData       = sample_intData;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser);
	fail_unless (tmp_err_code == ERR_OK, "parsing the header returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&testParser);
	fail_unless (tmp_err_code == PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
Beispiel #21
0
void
Animxmlparser::doParse()
{
    qreal currentNodeSize = AnimatorMode::getInstance()->getCurrentNodeSize();
    uint64_t parsedElementCount = 0;
    while(!isParsingComplete())
    {
        if(AnimatorMode::getInstance()->keepAppResponsive())
        {
            AnimatorMode::getInstance()->setParsingCount(parsedElementCount);

        }
        ParsedElement parsedElement = parseNext();
        switch(parsedElement.type)
        {
        case XML_ANIM:
        {
            AnimatorMode::getInstance()->setVersion(parsedElement.version);
            //qDebug(QString("XML Version:") + QString::number(version));
            break;
        }

        case XML_TOPOLOGY:
        {
            qreal maxValue = qMax(parsedElement.topo_width, parsedElement.topo_height);
            AnimatorScene::getInstance()->setWidth(maxValue);
            AnimatorScene::getInstance()->setHeight(maxValue);
            break;
        }
        case XML_NODE:
        {
            QColor * pColor = 0;
            uint8_t r = parsedElement.node_r;
            uint8_t g = parsedElement.node_g;
            uint8_t b = parsedElement.node_b;
            if (!(r == 255 && g == 0 && b == 0)) //If it is RED ignore it
            {
                if(m_version < 3.102)  // Color is not supported in version < 3.101
                    pColor = new QColor(255, 0, 0);
                else
                    pColor = new QColor(r, g, b);
            }
            AnimatorScene::getInstance()->addNode(parsedElement.nodeId,
                                                  parsedElement.node_x,
                                                  parsedElement.node_y,
                                                  CIRCLE,
                                                  currentNodeSize,
                                                  currentNodeSize,
                                                  parsedElement.nodeDescription, pColor);
            break;
        }
        case XML_LINK:
        {
            AnimatorScene::getInstance()->addLink(parsedElement.link_fromId,
                                                  parsedElement.link_toId,
                                                  parsedElement.fromNodeDescription,
                                                  parsedElement.toNodeDescription,
                                                  parsedElement.linkDescription);
            break;
        }
        case XML_NONP2P_LINK:
        {
            AnimatorScene::getInstance()->addLink(parsedElement.link_fromId,
                                                  parsedElement.link_fromId,
                                                  parsedElement.fromNodeDescription,
                                                  "",
                                                  "",
                                                  false);

        }
        case XML_LINKUPDATE:
        {

            AnimatorScene::getInstance()->updateLink(parsedElement.link_fromId, parsedElement.link_toId,
                    parsedElement.updateTime, parsedElement.linkDescription);
            break;
        }

        case XML_NODEUPDATE:
        {
            AnimatorScene::getInstance()->updateNode(parsedElement.updateTime, parsedElement.nodeId, parsedElement.node_r,
                    parsedElement.node_g, parsedElement.node_b, parsedElement.nodeDescription,
                    parsedElement.visible);
            break;
        }

        case XML_PACKET_RX:
        {
            AnimatorScene::getInstance()->addPacketRx(parsedElement.packetrx_fromId,
                    parsedElement.packetrx_fbTx,
                    parsedElement.packetrx_lbTx,
                    parsedElement.packetrx_toId,
                    parsedElement.packetrx_fbRx,
                    parsedElement.packetrx_lbRx,
                    parsedElement.type,
                    parsedElement.meta_info);
            ++parsedElementCount;
            break;

        }
        case XML_WPACKET_RX:
        {
            AnimatorScene::getInstance()->addPacketRx(parsedElement.packetrx_fromId,
                    parsedElement.packetrx_fbTx,
                    parsedElement.packetrx_lbTx,
                    parsedElement.packetrx_toId,
                    parsedElement.packetrx_fbRx,
                    parsedElement.packetrx_lbRx,
                    parsedElement.type,
                    parsedElement.meta_info);
            ++parsedElementCount;
            AnimatorMode::getInstance()->setWPacketDetected();
            break;
        }
        case XML_INVALID:
        default:
        {
            //qDebug("Invalid XML element");
        }
        } //switch
    } // while loop
}