Ejemplo n.º 1
0
bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
	checkHeader("<CLASS_REGISTRY_TABLE>", persistMgr);

	// reset SavedID of current instances
	Classes::iterator it;
	for (it = _classes.begin(); it != _classes.end(); ++it) {
		(it->_value)->resetSavedIDs();
	}

	for (it = _classes.begin(); it != _classes.end(); ++it) {
		if ((it->_value)->isPersistent()) {
			continue;
		}
		(it->_value)->removeAllInstances();
	}

	_instanceMap.clear();

	uint32 numClasses = persistMgr->getDWORD();

	for (uint32 i = 0; i < numClasses; i++) {
		gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)numClasses / (float)(i + 1))));

		Common::String className = persistMgr->getStringObj();
		NameMap::iterator mapIt = _nameMap.find(className);
		if (mapIt != _nameMap.end()) {
			(*mapIt)._value->loadTable(gameRef,  persistMgr);
		}
	}

	checkHeader("</CLASS_REGISTRY_TABLE>", persistMgr);

	return STATUS_OK;
}
Ejemplo n.º 2
0
bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
	// get total instances
	int numInstances = persistMgr->getDWORD();

	for (int i = 0; i < numInstances; i++) {
		if (i % 20 == 0) {
			gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)numInstances / (float)(i + 1))));
		}

		checkHeader("<INSTANCE_HEAD>", persistMgr);

		int classID = persistMgr->getDWORD();
		int instanceID = persistMgr->getDWORD();
		void *instance = idToPointer(classID, instanceID);

		checkHeader("</INSTANCE_HEAD>", persistMgr);

		Classes::iterator it;
		for (it = _classes.begin(); it != _classes.end(); ++it) {
			if ((it->_value)->getSavedID() == classID) {
				(it->_value)->loadInstance(instance, persistMgr);
				break;
			}
		}
		checkHeader("</INSTANCE>", persistMgr);
	}

	_savedInstanceMap.clear();

	return STATUS_OK;
}
Ejemplo n.º 3
0
static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
{
   OMX_COMPONENTTYPE *comp = handle;
   vid_dec_PrivateType *priv = comp->pComponentPrivate;
   OMX_ERRORTYPE r;

   if (!param)
      return OMX_ErrorBadParameter;

   switch(idx) {
   case OMX_IndexParamStandardComponentRole: {
      OMX_PARAM_COMPONENTROLETYPE *role = param;

      r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
      if (r)
         return r;

      if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
         strcpy((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE);
      else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
         strcpy((char *)role->cRole, OMX_VID_DEC_AVC_ROLE);
      else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN)
         strcpy((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE);

      break;
   }

   case OMX_IndexParamVideoInit:
      r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE));
      if (r)
         return r;

      memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE));
      break;

   case OMX_IndexParamVideoPortFormat: {
      OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
      omx_base_video_PortType *port;

      r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
      if (r)
         return r;

      if (format->nPortIndex > 1)
         return OMX_ErrorBadPortIndex;

      port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
      memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
      break;
   }

   default:
      return omx_base_component_GetParameter(handle, idx, param);

   }
   return OMX_ErrorNone;
}
OMX_ERRORTYPE omx_volume_component_GetParameter(
  OMX_IN  OMX_HANDLETYPE hComponent,
  OMX_IN  OMX_INDEXTYPE nParamIndex,
  OMX_INOUT OMX_PTR ComponentParameterStructure) {

  OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;  
  OMX_AUDIO_PARAM_PCMMODETYPE *pAudioPcmMode;
  OMX_ERRORTYPE err = OMX_ErrorNone;
  omx_base_audio_PortType *port;
  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
  if (ComponentParameterStructure == NULL) {
    return OMX_ErrorBadParameter;
  }
  DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
  /* Check which structure we are being fed and fill its header */
  switch(nParamIndex) {
    case OMX_IndexParamAudioInit:
      if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) { 
        break;
      }
      memcpy(ComponentParameterStructure, &omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio], sizeof(OMX_PORT_PARAM_TYPE));
      break;    
    case OMX_IndexParamAudioPortFormat:
      pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
      if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) { 
        break;
      }
      if (pAudioPortFormat->nPortIndex <= 1) {
        port= (omx_base_audio_PortType *)omx_volume_component_Private->ports[pAudioPortFormat->nPortIndex];
        memcpy(pAudioPortFormat, &port->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
      } else {
        err = OMX_ErrorBadPortIndex;
      }
    break;    
    case OMX_IndexParamAudioPcm:
      pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
      if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) { 
        break;
      }

      if (pAudioPcmMode->nPortIndex > 1) {
        return OMX_ErrorBadPortIndex;
      }
      pAudioPcmMode->nChannels = 2;
      pAudioPcmMode->eNumData = OMX_NumericalDataSigned;
      pAudioPcmMode->eEndian = OMX_EndianBig;
      pAudioPcmMode->bInterleaved = OMX_TRUE;
      pAudioPcmMode->nBitPerSample = 16;
      pAudioPcmMode->nSamplingRate = 0;
      pAudioPcmMode->ePCMMode = OMX_AUDIO_PCMModeLinear;
      break;
    default:
      err = omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
  }
  return err;
}
Ejemplo n.º 5
0
bool yarp::os::impl::HttpCarrier::checkHeader(const Bytes& header) {
    bool ok = checkHeader(header,"GET /");
    if (!ok) {
        // http carrier accepts POST /form but not general posts
        // (leave that to xmlrpc carrier)
        ok = checkHeader(header,"POST /fo");
    } else {
        // make sure it isn't a MJPEG stream get
        ok = !checkHeader(header,"GET /?ac");
    }
    return ok;
}
Ejemplo n.º 6
0
/* Demarshall - Get the values of the header:
 * Set the values of data structure to the values of header field
 * of received packet and initialize other values
 *	@param:
 *        msgsize - size of the UDP msg
 *        last - is this the last packet of a message
 *        seq - sequence number of the packet
 *        len - length of the packet
 *        mID - message id
 *        dta - pointer to the data field of dataGram
 *	@return: true, if this packet is the whole message
 *         false, otherwise
 */
int _condorPacket::getHeader(int /* msgsize */,
                             bool &last,
                             int &seq,
                             int &len,
                             _condorMsgID &mID,
                             void *&dta)
{
    uint16_t stemp;
    uint32_t ltemp;
	
    if (md_) {
        free(md_);
        md_ = 0;
    }

    if(memcmp(&dataGram[0], SAFE_MSG_MAGIC, 8)) {
        if(len >= 0) {
            length = len;
        }
        dta = data = &dataGram[0];
        checkHeader(len , dta);
        return true;
	}   

	last = (bool)dataGram[8];

	memcpy(&stemp, &dataGram[9], 2);
	seq = ntohs(stemp);

	memcpy(&stemp, &dataGram[11], 2);
	len = length = ntohs(stemp);

	memcpy(&ltemp, &dataGram[13], 4);
	mID.ip_addr = ntohl(ltemp);

	memcpy(&stemp, &dataGram[17], 2);
	mID.pid = ntohs(stemp);

	memcpy(&ltemp, &dataGram[19], 4);
	mID.time = ntohl(ltemp);

	memcpy(&stemp, &dataGram[23], 2);
	mID.msgNo = ntohs(stemp);

    dta = data = &dataGram[25];
    dprintf(D_NETWORK, "Fragmentation Header: last=%d,seq=%d,len=%d,data=[25]\n",
           last, seq, len); 

    checkHeader(len, dta);    

    return false;
}
OMX_ERRORTYPE omx_audio_capturer_GetParameter(
  OMX_HANDLETYPE hComponent,
  OMX_INDEXTYPE nParamIndex,
  OMX_PTR ComponentParameterStructure)
{
  OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
  OMX_ERRORTYPE err = OMX_ErrorNone;
  OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE*)hComponent;
  omx_audio_capturer_component_PrivateType* pPrivate = (omx_audio_capturer_component_PrivateType*) pComponent->pComponentPrivate;
  omx_base_audio_PortType *pPort = (omx_base_audio_PortType *) pPrivate->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];

  if (ComponentParameterStructure == NULL) {
    return OMX_ErrorBadParameter;
  }
  DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
  /* Check which structure we are being fed and fill its header */
  switch(nParamIndex) {
  case OMX_IndexParamAudioInit:
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
      break;
    }
    memcpy(ComponentParameterStructure, &pPrivate->sPortTypesParam[OMX_PortDomainAudio], sizeof(OMX_PORT_PARAM_TYPE));
    break;
  case OMX_IndexParamAudioPortFormat:
    pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
      break;
    }
    if (pAudioPortFormat->nPortIndex < 1) {
      memcpy(pAudioPortFormat, &pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
    } else {
      return OMX_ErrorBadPortIndex;
    }
    break;
  case OMX_IndexParamAudioPcm:
    if(((OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure)->nPortIndex != 0) {
      return OMX_ErrorBadParameter;
    }
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) {
      break;
    }
    omx_audio_capturer_component_PortType* pPort;
    pPort = (omx_audio_capturer_component_PortType *) pPrivate->ports[0];
    memcpy(ComponentParameterStructure, &pPort->sPCMModeParam, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
    break;
  default: /*Call the base component function*/
  return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
  }
  return err;
}
Ejemplo n.º 8
0
OMX_ERRORTYPE omx_clocksrc_component_GetParameter(
  OMX_HANDLETYPE hComponent,
  OMX_INDEXTYPE nParamIndex,
  OMX_PTR ComponentParameterStructure)
{
  OMX_ERRORTYPE                          err = OMX_ErrorNone;
  OMX_OTHER_PARAM_PORTFORMATTYPE         *pOtherPortFormat;
  OMX_COMPONENTTYPE                      *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
  omx_clocksrc_component_PrivateType*    omx_clocksrc_component_Private = openmaxStandComp->pComponentPrivate;
  omx_base_clock_PortType*               pPort; // = (omx_base_clock_PortType *) omx_clocksrc_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
  OMX_PARAM_COMPONENTROLETYPE     *pComponentRole;

  if (ComponentParameterStructure == NULL) {
    return OMX_ErrorBadParameter;
  }
  DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
  /* Check which structure we are being fed and fill its header */
  switch(nParamIndex) {
  case OMX_IndexParamOtherInit:
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
      break;
    }
    memcpy(ComponentParameterStructure, &omx_clocksrc_component_Private->sPortTypesParam[OMX_PortDomainOther], sizeof(OMX_PORT_PARAM_TYPE));
    break;
  case OMX_IndexParamOtherPortFormat:
    pOtherPortFormat = (OMX_OTHER_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
      break;
    }
    if (pOtherPortFormat->nPortIndex < omx_clocksrc_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) {
      pPort = (omx_base_clock_PortType *) omx_clocksrc_component_Private->ports[pOtherPortFormat->nPortIndex];
      memcpy(pOtherPortFormat, &pPort->sOtherParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
    } else {
      return OMX_ErrorBadPortIndex;
    }
    break;
  case OMX_IndexParamStandardComponentRole:
    pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
      break;
    }
    strcpy( (char*) pComponentRole->cRole, "");
    break;
  default: /*Call the base component function*/
    return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
  }
  return err;
}
Ejemplo n.º 9
0
// Build a PPM from given attributes
//-------------------------------------------------------------------------------------------------
bool PPM::build(const std::string &format, unsigned int width, unsigned int height, unsigned int maxrgb, 
		const std::vector<unsigned char> &r, 
		const std::vector<unsigned char> &g, 
		const std::vector<unsigned char> &b)
{
	// Copy the header values
	m_format = format;
	m_width = width;
	m_height = height;
	m_maxrgb = maxrgb;

	// Check that the values are valid
	if(!checkHeader())
	{
		std::cerr << "Error in build: invalid header values" << std::endl;
		close(); // Prevent inconsistant state
		return false;
	}

	// Copy each of the vectors
	m_pR = new std::vector<unsigned char>(r);
	m_pG = new std::vector<unsigned char>(g);
	m_pB = new std::vector<unsigned char>(b);

	// Check that the data is valid
	if(!checkData())
	{
		std::cerr << "Error in build: invalid data" << std::endl;
		close(); // Prevent inconsistant state
		return false;
	}

	return true;
}
Ejemplo n.º 10
0
void Connection::readData()
{
    QByteArray data;
    lastRead.start();
    if(newRequest)
    {
        buffer += port->readAll();
        // czeka na wczytanie calego naglowka
        if(buffer.size() < 18) return;

        // zapisuje naglowek i przechodzi dalej
        header = buffer.mid(0, 18);
        checkHeader();
        samplesRead = buffer.size();
        buffer = buffer.mid(18);
        newRequest = false;
    }
    else
    {
        data = port->readAll();
        samplesRead += data.size();
        buffer += data;
        if(buffer.size() >= INTERVAL && samplesRead < (chunkSize+18))
        {
            rawSamples = Container::data8ToInt8Vec(buffer.mid(0, INTERVAL));
            buffer = buffer.mid(INTERVAL);
            handleWithSamples();
        }
    }
    if(samplesRead >= (chunkSize+22))
    {
        endReading();
    }

}
Ejemplo n.º 11
0
/*
*   Receive response waiting timeout millisec
*/
char* HTTP::getResponse(int sk,int timeout)
{
	int len;
	char* line;
  int i;
  for(i=-1;i<timeout;i=i+10){line=readLine(sk);if(line!=NULL) break;delay(10);}
	if (line==NULL) return NULL;
	if (memcmp(line,"HTTP/1.1",8)!=0) 
        {strcpy(respmess,"ERR");cleanBuff(sk);return "Err!";}
	strncpy(respmess,(line+9),3);
	if (memcmp(line,"HTTP/1.1 200",12)!=0)  {cleanBuff(sk);return NOPAGE;} 
	while (line!=NULL)
	{
		line=readLine(sk);
		if (line!=NULL) 
		{
		  char *param=checkHeader(line,headerLen); 
      if (param!=NULL) sscanf(param,"%i",&len);  
			if (strlen(line)<2) {break;}
		}
	}
	readLine(sk);
	char* p=strchr(linebuff,'\0');*p='\n';
	if (len>LINEBUFFLEN) len=LINEBUFFLEN;
  linebuff[len]='\0';
  resetBuff();
  uint8_t tmp[8];while (readData(sk,tmp,8)>0);
	return linebuff;
}
Ejemplo n.º 12
0
/*
* With timeout (millisec)
*/
unsigned int HTTP::getResponse(int sk,uint8_t rbuff[],int rbufflen,int timeout)
{
	int len;
	char* line;
  int i;
  for(i=-1;i<timeout;i=i+10){line=readLine(sk);if(line!=NULL) break;delay(10);}
	if (line==NULL) return -1;
	if (memcmp(line,"HTTP/1.1",8)!=0) 
        {strcpy(respmess,"ERR");cleanBuff(sk);return -2;}
	strncpy(respmess,(line+9),3);	
	if (line==NULL) return -1;
	if (memcmp(line,"HTTP/1.1 200",12)!=0) {cleanBuff(sk);return -2;} 
	while (line!=NULL)
	{
		line=readLine(sk);
		if (line!=NULL) 
		{
		  char *param=checkHeader(line,headerLen); 
      if (param!=NULL) sscanf(param,"%i",&len);  
			if (strlen(line)<2) {break;}
		}
	}
  resetBuff();
  if (len==0) return 0;
  uint16_t nb=readData(sk,rbuff,rbufflen);
	return nb;
}
Ejemplo n.º 13
0
QmcUnit *QmcUnit::loadUnit(QDataStream &stream, QQmlEngine *engine, QmcLoader *loader, const QUrl &loadedUrl)
{
    //qDebug() << "Loading" << loadedUrl;
    QmcUnitHeader *header = new QmcUnitHeader;

    bool ret = readData((char *)header, sizeof(QmcUnitHeader), stream);
    if (!ret || !checkHeader(header)) {
        delete header;
        return NULL;
    }

    QString name;
    QString urlString;
    if (!readString(name, stream) || !readString(urlString, stream)) {
        delete header;
        return NULL;
    }

    QUrl url;
    url.setUrl(urlString);

    QmcUnit *unit = new QmcUnit(header, url, urlString, engine, loader, name, loadedUrl);

    if (unit->loadUnitData(stream))
        return unit;

    unit->blob->release();
    return NULL;
}
Ejemplo n.º 14
0
bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile, int depth) {
	if (!node.exists() || !node.isReadable() || !node.isDirectory())
		return false;

	// Check if we can find the file in this directory
	// Since File::open(FSNode) makes all the needed tests, it is not really
	// necessary to make them here. But it avoid printing warnings.
	FSNode fileNode = node.getChild("translations.dat");
	if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) {
		if (inFile.open(fileNode)) {
			if (checkHeader(inFile))
				return true;
			inFile.close();
		}
	}

	// Check if we exceeded the given recursion depth
	if (depth - 1 == -1)
		return false;

	// Otherwise look for it in sub-directories
	FSList fileList;
	if (!node.getChildren(fileList, FSNode::kListDirectoriesOnly))
		return false;

	for (FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) {
		if (openTranslationsFile(*i, inFile, depth == -1 ? - 1 : depth - 1))
			return true;
	}

	// Not found in this directory or its sub-directories
	return false;
}
int main(int argc, char *argv[])
{
	FILE *forigin;

	char mbr[SECTOR];

	int i;
	for(i=1; i < argc ; i++) {
	  args |= parse_arg(argv[i], (argc-i > 1)?argv[i+1]:NULL);
	}


	if (argc ==  1 || (args & A_HELP)) { usage(argv[0]); }

	forigin = fopen(origin, "rb");


	if (!forigin)
		ERROR("ERROR: failed to open input %s\n", origin);


	if (fread(mbr, SECTOR, 1, forigin) != 1) ERROR("ERROR: Can't load MBR\n");

  	checkHeader((mainheader*) mbr);
	if (args & A_INFO) {
		printinfo(mbr, 0);
		putchar('\n');
		printinfo(mbr, MBR_HDR_LEN);
	}

	if (memcmp(mbr, mbr+MBR_HDR_LEN, MBR_HDR_LEN - 8))
		  MESSAGE("WARNING: divergent MBR image records, using the %s one\n", (second)?"second":"first");
	process_mbr(mbr, (second)?MBR_HDR_LEN:0, forigin);
	return 0;
}
Ejemplo n.º 16
0
void TranslationManager::loadLanguageDat(int index) {
	_currentTranslationMessages.clear();
	_currentCharset.clear();
	// Sanity check
	if (index < 0 || index >= (int)_langs.size()) {
		if (index != -1)
			warning("Invalid language index %d passed to TranslationManager::loadLanguageDat", index);
		return;
	}

	File in;
	if (!openTranslationsFile(in))
		return;

	if (!checkHeader(in))
		return;

	char buf[1024];
	int len;

	// Get number of translations
	int nbTranslations = in.readUint16BE();
	if (nbTranslations != (int)_langs.size()) {
		warning("The 'translations.dat' file has changed since starting ScummVM. GUI translation will not be available");
		return;
	}

	// Get size of blocks to skip.
	int skipSize = 0;
	for (int i = 0; i < index + 2; ++i)
		skipSize += in.readUint16BE();
	// We also need to skip the remaining block sizes
	skipSize += 2 * (nbTranslations - index);

	// Seek to start of block we want to read
	in.seek(skipSize, SEEK_CUR);

	// Read number of translated messages
	int nbMessages = in.readUint16BE();
	_currentTranslationMessages.resize(nbMessages);

	// Read charset
	len = in.readUint16BE();
	in.read(buf, len);
	_currentCharset = String(buf, len - 1);

	// Read messages
	for (int i = 0; i < nbMessages; ++i) {
		_currentTranslationMessages[i].msgid = in.readUint16BE();
		len = in.readUint16BE();
		in.read(buf, len);
		_currentTranslationMessages[i].msgstr = String(buf, len - 1);
		len = in.readUint16BE();
		if (len > 0) {
			in.read(buf, len);
			_currentTranslationMessages[i].msgctxt = String(buf, len - 1);
		}
	}
}
Ejemplo n.º 17
0
Archivo: conf.cpp Proyecto: AsamK/qconf
	bool findHeader(const QString &h, const QStringList &ext, QString *inc)
	{
		if(checkHeader("/usr/include", h)) {
			*inc = "";
			return true;
		}
		QStringList dirs;
		dirs += "/usr/local/include";
		dirs += ext;
		for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
			if(checkHeader(*it, h)) {
				*inc = *it;
				return true;
			}
		}
		return false;
	}
Ejemplo n.º 18
0
// --------------------------------------------------------------------------
static void fsm_sendblk_waitForDataAck(fsm_sendblk_instance_t *instance)
{
	header_content_t hdr_content;
	nrf24com_frm_dataack *frame;

	UINT8 data_len = (instance->remaining_len > DATAFRAME_PAYLOAD_SIZE)?(DATAFRAME_PAYLOAD_SIZE):(instance->remaining_len);

	do
	{
		// consume all frames that are not dataack
		if (sizeof(nrf24com_frm_dataack) == nrf24Receive(instance->buffer, sizeof(nrf24com_frm_dataack), NULL, instance->timeout_ms))
		{
			hdr_content = checkHeader((nrf24com_hdr_t*)instance->buffer, NRF24COM_FRM_DATAACK);
			if (CHECKHDR_OK == hdr_content)
			{
				frame = (nrf24com_frm_dataack*)instance->buffer;
				if (checkDataAckFrame(frame))
				{
					// update status for next data frame
					instance->data_pos += data_len;
					instance->remaining_len -= data_len;
					if (0 == instance->remaining_len)
					{
						// we're done
						instance->ok = 1;
						instance->state = FSM_SENDBLK_END;
						return;
					}
					else
					{
						// send next frame
						instance->retransmit = 0;
						instance->seq_id++;
						instance->state = FSM_SENDBLK_SEND_DATA;
						return;
					}
				}
			}
		}
		else
			instance->state = FSM_SENDBLK_END;
	} while (nrf24UnreadData(NULL));

	if (instance->retransmit < instance->retries)
	{
		instance->retransmit++;
		nrf24comm_debug("no data ack received, retransmitting frame, retrying: %d/%d\n", instance->retransmit, instance->retries);
		instance->state = FSM_SENDBLK_SEND_DATA;
	}
	else
	{
		nrf24comm_debug("giving up\n");
		instance->state = FSM_SENDBLK_END;
	}
}
Ejemplo n.º 19
0
OMX_ERRORTYPE omx_clocksrc_component_SetParameter(
  OMX_HANDLETYPE hComponent,
  OMX_INDEXTYPE nParamIndex,
  OMX_PTR ComponentParameterStructure)
{
  OMX_ERRORTYPE                         err = OMX_ErrorNone;
  OMX_OTHER_PARAM_PORTFORMATTYPE        *pOtherPortFormat;
  OMX_COMPONENTTYPE                     *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
  omx_clocksrc_component_PrivateType*   omx_clocksrc_component_Private = openmaxStandComp->pComponentPrivate;
  omx_base_clock_PortType*              pPort;
  OMX_PARAM_COMPONENTROLETYPE     *pComponentRole;

  if (ComponentParameterStructure == NULL) {
    return OMX_ErrorBadParameter;
  }

  DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nParamIndex);
  /* Check which structure we are being fed and fill its header */
  switch(nParamIndex) {
  case OMX_IndexParamOtherPortFormat:
    pOtherPortFormat = (OMX_OTHER_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
    /*Check Structure Header and verify component state*/
    err = omx_base_component_ParameterSanityCheck(hComponent, pOtherPortFormat->nPortIndex, pOtherPortFormat, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
    if(err!=OMX_ErrorNone) {
      DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n", __func__, err);
      break;
    }
    if (pOtherPortFormat->nPortIndex < omx_clocksrc_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) {
      pPort = (omx_base_clock_PortType *) omx_clocksrc_component_Private->ports[pOtherPortFormat->nPortIndex];
      memcpy(&pPort->sOtherParam,pOtherPortFormat,sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
    } else {
      return OMX_ErrorBadPortIndex;
    }
    break;
  case OMX_IndexParamStandardComponentRole:
    pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;

    if (omx_clocksrc_component_Private->state != OMX_StateLoaded && omx_clocksrc_component_Private->state != OMX_StateWaitForResources) {
      DEBUG(DEB_LEV_ERR, "In %s Incorrect State=%x lineno=%d\n",__func__, omx_clocksrc_component_Private->state, __LINE__);
      return OMX_ErrorIncorrectStateOperation;
    }

    if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
      break;
    }

    if (strcmp( (char*) pComponentRole->cRole, "")) {
      return OMX_ErrorBadParameter;
    }
    break;
  default: /*Call the base component function*/
    return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
  }
  return err;
}
Ejemplo n.º 20
0
BMP_Image *BMP_open(const char *filename)
{
  FILE * fptr    = NULL; 
  BMP_Image *img = NULL;
  fptr = fopen(filename, "r"); // "rb" unnecessary in Linux
  if (fptr == NULL)
    {
      return cleanUp(fptr, img);
    }
  img = malloc(sizeof(BMP_Image));
  if (img == NULL)
    {
      return cleanUp(fptr, img);
    }
  // read the header
  if (fread(& (img -> header), sizeof(BMP_Header), 
	    1, fptr) != 1)
    {
      // fread fails
      return cleanUp(fptr, img);
    }
  if (checkHeader(& (img -> header)) == 0)
    {
      return cleanUp(fptr, img);      
    }
  img -> data_size = 
    (img -> header).size - sizeof(BMP_Header);
  img -> width     = (img -> header).width;
  img -> height    = (img -> header).height;
  img -> bytes_per_pixel = 
    (img -> header).bits / BITS_PER_BYTE;
  img -> data = 
    malloc(sizeof(unsigned char) * (img -> data_size));
  if ((img -> data) == NULL)
    {
      // malloc fail
      return cleanUp(fptr, img);
    }
  if (fread(img -> data, sizeof(char), img -> data_size, 
	    fptr) != (img -> data_size))
    {
      // fread fails
      return cleanUp(fptr, img);
    }
  char onebyte;
  if (fread(& onebyte, sizeof(char), 1, fptr) != 0)
    {
      // not at the of the file but the file still has data
      return cleanUp(fptr, img);
    }
  // everything successful
  fclose (fptr);
  return img;
}
OMX_ERRORTYPE omx_xvideo_sink_component_GetParameter(
  OMX_HANDLETYPE hComponent,
  OMX_INDEXTYPE nParamIndex,
  OMX_PTR ComponentParameterStructure) {

  OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
  OMX_ERRORTYPE err = OMX_ErrorNone;
  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
  omx_xvideo_sink_component_PrivateType* omx_xvideo_sink_component_Private = openmaxStandComp->pComponentPrivate;
  omx_xvideo_sink_component_PortType *pPort = (omx_xvideo_sink_component_PortType *) omx_xvideo_sink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];

  if (ComponentParameterStructure == NULL) {
    return OMX_ErrorBadParameter;
  }
  DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
  /* Check which structure we are being fed and fill its header */
  switch(nParamIndex) {
    case OMX_IndexParamVideoInit:
      if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
        break;
      }
      memcpy(ComponentParameterStructure, &omx_xvideo_sink_component_Private->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE));
      break;

    case OMX_IndexParamVideoPortFormat:
      pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
      if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
        break;
      }
      if (pVideoPortFormat->nPortIndex < 1) {
        memcpy(pVideoPortFormat, &pPort->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
      } else {
        return OMX_ErrorBadPortIndex;
      }
      break;

    default: /*Call the base component function*/
      return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
  }
  return err;
}
Ejemplo n.º 22
0
// Write current contents to file
//-------------------------------------------------------------------------------------------------
bool PPM::writeTo(const std::string &filename)
{
	// Cheak the header values are valid
	if(!checkHeader())
	{
		std::cerr << "Error in writeTo: invalid header values" << std::endl;
		return false;
	}

	// Check the data is valid
	if(!checkData())
	{
		std::cerr << "Error in writeTo: invalid data" << std::endl;
		return false;
	}

	std::ofstream outFile;
	// Open output file in binary mode
	outFile.open(filename.c_str(), std::ios::binary);
	
	// Check file open ok
	if(!outFile)
	{
		std::cerr << "Error in writeTo: could not open or create file '" << filename << "'" << std::endl;
		return false;
	}

	// Write header values
	outFile << m_format << std::endl;
	outFile << "# Created by PPM.cpp" << std::endl;
	outFile << m_width << " " << m_height << std::endl;
	outFile << m_maxrgb << std::endl;


	// Iterate through vectors and write data
	char c;
	unsigned int size = m_width * m_height;
	for(unsigned int i = 0; i < size; ++i)
	{
		c = (*m_pR)[i];
		outFile.write(&c, 1);
		c = (*m_pG)[i];
		outFile.write(&c, 1);
		c = (*m_pB)[i];
		outFile.write(&c, 1);		
	}

	// Close the file
	outFile.close();

	return true;
}
Ejemplo n.º 23
0
Archivo: FileFS.cpp Proyecto: cgars/nix
FileFS::FileFS(const std::string &name, FileMode mode)
    : DirectoryWithAttributes(name, mode, true){
    this->mode = mode;
    if (mode == FileMode::Overwrite) {
        removeAll();
    }
    setCreatedAt();
    setUpdatedAt();
    create_subfolders(name);
    if (!checkHeader()) {
        throw std::runtime_error("Invalid file header: either file format or file version not correct");
    }
}
Ejemplo n.º 24
0
void
srf_write(FILE *       const ofP,
          struct srf * const srfP) {

    uint8_t      srfCsum;    /* checksum value in SRF image */
    size_t       padLen;
    unsigned int i;
    size_t       bytesWritten;

    padLen = 1;  /* initial value */

    if (!checkHeader(&srfP->header))
        pm_error("invalid srf header");
    if (!writeHeader(ofP, &srfP->header))
        pm_error("write srf header");
    padLen += lenHeader(&srfP->header);

    for (i = 0; i < srfP->header.img_cnt; ++i) {
        if (!writeImg(ofP, i, &srfP->imgs[i]))
            pm_error("invalid srf image %u", i);
        padLen += lenImg(&srfP->imgs[i]);
    }

    /* Pad to 256 bytes */
    padLen = 256 - (padLen % 256);
    if (padLen) {
        char * d;
        size_t bytesWritten;

        MALLOCARRAY(d, padLen);

        if (!d)
            pm_error("Could not allocate memory for %u bytes of padding",
                     (unsigned)padLen);

        memset(d, 0xff, padLen);

        bytesWritten = fwrite(d, 1, padLen, ofP);

        if (bytesWritten != padLen)
            pm_error("unable to 0xff pad file");

        free(d);
    }

    /* Write out checksum byte */
    srfCsum = 0xff - csum(srfP, padLen) + 1;
    bytesWritten = fwrite(&srfCsum, 1, 1, ofP);
    if (bytesWritten != 1)
        pm_error("unable to write checksum");
}
Ejemplo n.º 25
0
PLYObject::PLYObject(FILE *in)
{
  int i;
  
  nproperties = 0;
  hasnormal = hascolor = hastexture = false;

  nv = nf = ne = 0;

  vertices = NULL;
#ifndef INTERLEAVED
  normals = NULL;
  colors = NULL;
#endif
  texcoords = NULL;
  faces = NULL;

  // init bounding box
  for (i = 0; i < 3; i++) {
    min[i] = FLT_MAX;
    max[i] = -FLT_MAX;
  }
  
  // default order
  for (i = 0; i < 11; i++)
    order[i] = -1;

  if (!checkHeader(in)) {
    fprintf(stderr, "Error: could not read PLY file.\n");
    return;
  }

#ifdef INTERLEAVED
  vertices = (RenderPoint*)calloc(nv, sizeof(RenderPoint));
#else
  vertices = (Vector3f*)calloc(nv, sizeof(Vector3f));
  normals = (Vector3f*)calloc(nv, sizeof(Vector3f));
  if (hascolor)
    colors = (Color3u*)calloc(nv, sizeof(Color3u));
#endif
  if (hastexture){
	texcoords = (Texture2f*)calloc(nf, sizeof(Texture2f));
  }

  faces = (Index3i*)calloc(nf, sizeof(Index3i));
  fnormals = (Vector3f*)calloc(nf, sizeof(Vector3f));

  readVertices(in);
  readFaces(in);
}
Ejemplo n.º 26
0
// receive state machine states
// --------------------------------------------------------------------------
static void fsm_recvblk_waitForInit(fsm_recvblk_instance_t *instance)
{
	header_content_t hdr_content;
	nrf24com_frm_init *frame;

	UINT8 rx_pipe;

	// there must be something in fifo, so we do not have to wait
	do
	{
		if (sizeof(nrf24com_frm_init) == nrf24Receive(instance->buffer, sizeof(nrf24com_frm_init), &rx_pipe, instance->timeout_ms))
		{
			if (NET_PIPE != rx_pipe)
			{
				nrf24comm_debug("something in private pipe, discarding it\n");
				continue;
			}
			hdr_content = checkHeader((nrf24com_hdr_t*)instance->buffer, NRF24COM_FRM_INIT);
			if (CHECKHDR_OK == hdr_content)
			{
				frame = (nrf24com_frm_init*)instance->buffer;
				if (checkInitFrame(frame))
				{
					instance->data_length = frame->length;
					// if data to receive is bigger then our expectation, just give up
					if (instance->data_length > instance->max_len)
						break;

					instance->remaining_len = frame->length;
					instance->data_chksum = frame->data_chksum;
					instance->sender_node_id = frame->src_node_id;

					// inform sender, that we are ready to go
					instance->initack_resp = NRF24COM_DST_STATE_ACK;
					instance->state = FSM_RECVBLK_SEND_INITACK;
					return;
				}
			}
			else if (CHECKHDR_UNKN_PROTO == hdr_content)
			{
				// inform sender, that it is using protocol we do not understand (currently this cannot happen)
				instance->initack_resp = NRF24COM_DST_STATE_UNKN_PROTO;
				instance->state = FSM_RECVBLK_SEND_INITACK;
				return;
			}
		}
	} while (nrf24UnreadData(NULL));

	instance->state = FSM_RECVBLK_END;
}
Ejemplo n.º 27
0
// --------------------------------------------------------------------------
static void fsm_sendblk_waitForInitAck(fsm_sendblk_instance_t *instance)
{
	header_content_t hdr_content;
	nrf24com_frm_initack *frame;
	UINT8 rx_pipe;
	
	UINT8 retry = 0;

	do
	{
		if (sizeof(nrf24com_frm_initack) == nrf24Receive(instance->buffer, sizeof(nrf24com_frm_initack), &rx_pipe, instance->timeout_ms))
		{
			if (NET_PIPE != rx_pipe)
			{
				nrf24comm_debug("something in private pipe, discarding it\n");
				continue;
			}
			hdr_content = checkHeader((nrf24com_hdr_t*)instance->buffer, NRF24COM_FRM_INITACK);
			if (CHECKHDR_OK == hdr_content)
			{
				frame = (nrf24com_frm_initack*)instance->buffer;
				if (checkInitAckFrame(frame))
				{
					if (NRF24COM_DST_STATE_ACK == frame->dst_state)
					{
						// now we know who replied, update recipient node_id, we want to talk only to this node
						instance->recipient_node_id = frame->src_node_id;
						instance->state = FSM_SENDBLK_ENABLE_PRIVATE_PIPE;
						return;
					}
					else if (NRF24COM_DST_STATE_WAIT == frame->dst_state)
					{
						nrf24comm_debug("receiver not ready, waiting\n");
						retry = 0;
						continue;
					}
					else
						break;
				}
			}
			else
				break;
		}
		++retry;
		nrf24comm_debug("retrying: %d/%d\n", retry, instance->retries);
	} while (retry < instance->retries);

	instance->state = FSM_SENDBLK_END;
}
Ejemplo n.º 28
0
void HTTP::reqPOST(int socket,char *buff,int nres,WEBRES rs[],char *key)
{
  char* query=NULL;
  char* endfield=strchr(&buff[5],' ');
	if (endfield==NULL) {respNOK(socket);return;}
	*endfield='\0';
	strlcpy(Resource.name,&buff[5],URILEN);	
	char* res=strdup(&buff[5]);
	int len=0;
	bool fauth;if (key!=NULL) fauth=false; else fauth=true;
	char *param;
	while (buff!=NULL)
	{
		buff=readLine(socket);
 #if HTTPDEBUG		
   Serial.println(buff);
 #endif   
		if (strcspn(buff,"\r\n")==0) {query=buff+2;buff=NULL;}
		if (buff!=NULL) 
		{
		  if (key!=NULL) 
       {param=checkHeader(buff,headerAuth);
        if (param!=NULL) fauth=checkUserPsw(param,key);}
      param=checkHeader(buff,headerLen); 
      if (param!=NULL) sscanf(param,"%i",&len);  
		}
	}
	if (len>QUERYLEN-1) len=QUERYLEN-1;
 	if (query!=NULL)strlcpy(Resource.query,query,len+1);
 #if HTTPDEBUG
  Serial.println(Resource.name);
  Serial.println(Resource.query);
 #endif
  if (fauth) activateRes(socket,nres,rs);
  else respNoAuth(socket);
}
Ejemplo n.º 29
0
void Packet2Blob::unpack() const
{
	if (!packedData)
	{
		return;
	}

	if (!checkHeader())
	{
		return;
	}

	blob = packedData + OFFSET_DATA;
	blobLength = dataLength - OFFSET_DATA;

	unpacked = true;
}
Ejemplo n.º 30
0
//void RefFile::open(const char* name, bool printLog)
void RefFile::open(const char* name)
{
    input.open(name);
    if( !input.is_open() ) {
        cout << "Could not open " << name << endl;
        exit(1);
        //or throw exception
    }
    //save path name
    path = name;
    size_t lastSlash = path.find_last_of('/');

    if(lastSlash != string::npos) {  //found it, remove filename
        path.erase(lastSlash+1);      //keep the slash
    } else {                          //erase filename from path
        path.clear();
    }

    checkHeader();
    //read in whole file
    while( readNextRef() ) {
        refs.push_back(curRef);
    }
    input.close();

    if( refs.size() > 0) {
        moreRef = true;
    } else {
        moreRef = false;
    }

    //  ofstream logfile("log");
    //  for(int i=0; i<refs.size(); i++) {
    //    RefFile::printRefToFile(refs.at(i), logfile);
    //  }

    //  if( !sorted )
    sort(refs.begin(), refs.end(), compRefData());

    //  logfile << "SORTED" << endl;
    //  for(int i=0; i<refs.size(); i++) {
    //    RefFile::printRefToFile(refs.at(i), logfile);
    //  }
}