Ejemplo n.º 1
0
/*
    删除表中的一个数据
*/
bool userDatabase::DeleteData(){
    int Size = mySql.sqlWord.size();
    if(mySql.sqlWord[1] == "from"){
        string name = mySql.sqlWord[2];
        int tableid = FindTable(name);
        if(tableid != -1){
            Condition selectValue,whereValue;
            if(canRead(4) && mySql.sqlWord[3]  == "where"){
                    string na,sy,va;
                    for(int pos = 4;pos < Size;pos++){
                        if(canRead(pos))
                            na = mySql.sqlWord[pos++];
                        if(canRead(pos))
                            sy = mySql.sqlWord[pos++];
                        if(canRead(pos))
                            va = mySql.sqlWord[pos++];
                        //cout << na << " " << sy << " " << va << endl;
                        if(!whereValue.addValue(na,sy,va)){
                            return false;
                        }
                    }
            }
            if(myTable[tableid].findCondition(3,selectValue,whereValue))
                return true;
            else
                return false;
        }
        else
            kLine::NotFindTable(name);
    }
    return false;
}
Ejemplo n.º 2
0
//判断键值
//NOT NULL,UNIQUE,PRIMARY KEY
int userDatabase::JudgeKey(int &pos){
    int cnt = 0;
    //利用二进制的位进行判断
    /*
        第零位 为 PRIMARY KEY
        第一位 为 UNIQUE
        第二位 为 NOT NULL
    */
    while(true){
        if(canRead(pos + 1) && mySql.sqlWord[pos] == "primary" && mySql.sqlWord[pos + 1] == "key"){
            cnt |= (1 << 0);
            pos += 2;
        }
        else if(canRead(pos) && mySql.sqlWord[pos] == "unique"){
            cnt |= (1 << 1);
            pos ++;
        }
        else if(canRead(pos + 1) && mySql.sqlWord[pos] == "not" && mySql.sqlWord[pos + 1] == "null"){
            cnt |= (1 << 2);
            pos +=2;
        }
        else
            break;
    }
    return cnt;
};
Ejemplo n.º 3
0
	int AccessMap::mergeCruds(int crud1, int crud2) const
	{
		if ((crud1 == PROCEDURE_ONLY) || (crud2 == PROCEDURE_ONLY)) return PROCEDURE_ONLY;
		int crud = 0;
		if (canCreate(crud1) || canCreate(crud2)) crud += CREATE;		
		if (canRead(crud1) || canRead(crud2)) crud += READ;
		if (canUpdate(crud1) || canUpdate(crud2)) crud += UPDATE;
		if (canDelete(crud1) || canDelete(crud2)) crud += DELETE;
		return crud;
	}
Ejemplo n.º 4
0
/*
 * A simple interrupt handler for CAN message reception
 */
void canHandler(void) {
  if (canReady(CAN_PORT_1)) {
    canRead(CAN_PORT_1, &can1RxBuffer);
    can1RxDone = true;
  }
  if (canReady(CAN_PORT_2)) {
    canRead(CAN_PORT_2, &can2RxBuffer);
    can2RxDone = true;
  }
}
Ejemplo n.º 5
0
int
FileAction::onOpenRead(ServerContext& ctxt, FileServer& server, handle_t **handle, const char *path)
{
	int status = 0;
	
	if (!canRead(ctxt, server, path))
	{
		return -EPERM;
	}
	*handle = ctxt.getSession().createHandle(HDL_FILE);
	TAG_HANDLE(*handle);
	_DEBUG("onOpenRead: created handle for %s", path);
	if (*handle == NULL)
	{
		return -EIO;
	}
	HANDLE_PATH(**handle) = path;
	(*handle)->h_special_data = true;
	(*handle)->h_action = this;
	status = onRead(ctxt, server, translate(path).c_str(), HANDLE_CONTENTS(**handle));
	if (status >= 0)
	{
		status = 0;
		(*handle)->h_count = status;
	}
	return status;
}
Ejemplo n.º 6
0
/*
 * An interrupt handler for CAN message reception on CAN1
 * When a message is recieved the ID is checked and local
 * variables are updated within the conveyor sub-system.
 */
static void canHandler(void) {
  if (canReady(CAN_PORT_1)) {
    interfaceLedToggle(D1_LED);
    canRead(CAN_PORT_1, &can1RxBuf);
    canMessage_t msg;
    msg = can1RxBuf;
    if (msg.id == PICKED_UP_PAD1){
       checkForInputBlock = true;
       stopConveyorForLoad = true;
    }    
    if(msg.id == EMERGENCY_STOP){
      emergencyStop = true;
    }
    if(msg.id == PAUSE){
      paused = true;
    }
    if(msg.id == RESUME){
      paused = false;
      conveyorSetState(pausedState);
    }
    if(msg.id == RESET){
      __iar_program_start();
    }
    if(msg.id == START){
      stopped = false;
    }
    if(msg.id == STOP){
      stopped = true;
    }
  }
}
Ejemplo n.º 7
0
/**
 * Lists the contents of the directory denoted by this File. If the current
 * File doesn't point to a directory or does not exist, an exception is thrown.
 *
 * @param result matching names will be put here
 * @param filter optional filter filter which can be used to filter filenames.
 * @return the number of items put into the result
 */
size_t File::listDirectory(FileList &result, FileFilter *filter) const
{
    if (!exists())
        throw std::logic_error("Cannot list a non-existing directory");
    if (!isDirectory())
        throw std::logic_error("Cannot list file which isn't a directory");
    if (!canRead())
        throw std::logic_error(std::string("No read access for directory ") + fullname);

    DIR *dir = opendir(fullname.c_str());
    if (dir == NULL) {
        throw std::logic_error("opendir() failed for a directory");
    }

    size_t numItems = 0;
    struct dirent *pEntry;

    pEntry = readdir(dir);
    while (pEntry)
    {
        // do not include "." and ".." in the list
        if (strcmp(pEntry->d_name, ".") && strcmp(pEntry->d_name, ".."))
        {
            File f(*this, pEntry->d_name);
            if (!filter || (*filter)(f))
            {
                result.push_back(std::move(f));
                ++numItems;
            }
        }
        pEntry = readdir(dir);
    }
    closedir(dir);
    return numItems;
}
int CESDDevice::waitForStartMotionAll()
{
	int iRetVal = 0;
	bool bRecieved = false;
	long iNumberOfMessages = 1;
	CMSG clESDProtocolMessage;
	m_iErrorState = 0;

	do
	{	
		iRetVal = canRead(m_hSyncDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);			
		if(iRetVal != NTCAN_SUCCESS)
		{
			warning("can read failed Errorcode: %d", iRetVal);
			m_iErrorState = getDeviceError(iRetVal);
			return m_iErrorState;
		}
		bRecieved = true;
		if(clESDProtocolMessage.id != MSGID_ALL)
		{
			debug(1, "received CAN-ID %x, expected %x", clESDProtocolMessage.id, MSGID_ALL);
			bRecieved = false;
		}
		if(clESDProtocolMessage.data[0] != CMDID_STARTMOVE)
		{
			debug(1, "wrong command ID");
			bRecieved = false;
		}
	}
	while(!bRecieved);
	return m_iErrorState;
}
Ejemplo n.º 9
0
int32_t readNTCAN(NTCAN_HANDLE handle, CMSG *msg, int32_t len)
 {
   NTCAN_RESULT 	result;
   int32_t			i,j;
   int32_t 			timeout=0; 
/* Reading Object of NTCAN device */  
	do {
		result = canRead(handle,msg, &len, NULL); 
		timeout++;
/* If timeout error is recieved repeatly then read is aborted */
      if(timeout > MAX_TIMEOUT) 
			{
      	result = canIoctl(handle, NTCAN_IOCTL_ABORT_RX, NULL);
         if(errorCheck(CAN_IO_CTL,result != 0))
         	{ return 1; } 									// error check
            printf("Repeated Timeout, read aborted\n");
            return 2; 
			}
      } while(errorCheck(CAN_READ,result) == 2); 
	if(errorCheck(CAN_READ,result) != 0)
		{ return 1; }  										// error check
/* Printing read object of NTCAN device to screen */
	printf("readNTCAN() successfull\n") ;
	printf("Length of message recieved: %d\n", (len & 0x0F) );
	for(j=0;j<len;j++)
	{
		printf("ID of NTCAN device: %x\n", msg->id); 
   		for(i=0;i<(msg->len);i++) 
		{
			printf("Byte %d of recieved message: %d\n", i, msg->data[i]);
   		}  
 	}
	return 0; 
}
Ejemplo n.º 10
0
bool QTgaHandler::read(QImage *image)
{
    if (!canRead())
        return false;
    *image = tga->readImage();
    return !image->isNull();
}
Ejemplo n.º 11
0
void flushSerial(uint8_t usartn)
{
   volatile char null;

   while (canRead(usartn))
      null = __readByte(usartn);
}
Ejemplo n.º 12
0
void ConnectTrd::run()
{
    QString ip;
    QString ipHead = m_Ip.left(m_Ip.lastIndexOf(".")+1);

    for(int i=0; i<255; i++)
    {
        if(!sockets[i])
        {
            sockets[i] = new QTcpSocket();
            connect(sockets[i],SIGNAL(readyRead()),this,SLOT(canRead()));

        }
        else
        {
            sockets[i]->disconnectFromHost();
        }

        //msleep(1);
        ip = ipHead + QString::number(i+1);
        sockets[i]->connectToHost(ip,AKHMI_PORT);
        //sockets[i]->waitForConnected(1);
        //qDebug() << "connect to Host :"<< ip;
        //qDebug() << sockets[i]->errorString();
    }

    exec();
}
Ejemplo n.º 13
0
bool PaletteIO::read(Palettes &palettes) const
{
	if(!canRead()) {
		return false;
	}

	QByteArray palData = device()->read(12);

	if(palData.size() != 12) {
		qWarning() << "PaletteIO::read Pal size too short";
		return false;
	}

	quint16 palH;

	memcpy(&palH, palData.constData() + 10, 2);

	palData = device()->read(palH * 512);

	if(palData.size() != palH * 512) {
		qWarning() << "PaletteIO::read Pal size too short 2";
		return false;
	}

	for(quint32 i=0 ; i<palH ; ++i) {
		palettes.append(createPalette(palData.constData() + i*512));
	}

	return readAfter(palettes);
}
Ejemplo n.º 14
0
void *
ConsoleUI::threadMain(void *arg) {
	rl_callback_handler_install("", ConsoleUICallbacks::lineRead);
	while (!quit) {
		while (canRead()) {
			lineProcessed = false;
			rl_callback_read_char();
			if (lineProcessed && rl_prompt != NULL && rl_prompt[0] != '\0') {
				// If a line has been processed, reset the prompt
				// so we don't see it again after an Enter.
				rl_set_prompt("");
				rl_display_prompt = NULL;
				rl_redisplay();
			}
		}

		pthread_mutex_lock(&outputLock);
		if (!output.empty()) {
			processOutput();
			pthread_cond_broadcast(&outputCond);
		}
		pthread_mutex_unlock(&outputLock);

		usleep(10000);
	}
	rl_callback_handler_remove();
	return NULL;
}
Ejemplo n.º 15
0
		/**
		* \brief Tries to reads an item from the buffer.
		*
		* If the buffer cannot currently be read from, this operation returns
		* with an appropriate status code.
		*
		* \param item out: The read item. If the return code is false, the 
		*				value is undefined.
		* \returns true if an item was read, false otherwise
		*/
		inline bool tryRead(register rbdata_t *item) { 
			assert(NULL != item);
			
			// loop until the buffer has a full slot
			if (!canRead()) return false;

			// fetch fresh
			_MemoryBarrier();	

			// since we read, the fill level will be decreased
			--_fillLevel;
				
			// write to the current write index
			*item = _buffer[_read_index];
		
			// advance the read pointer
			_read_index = (_read_index+1) & this->_sizeMask;
		
			// since we read, the capacity will be increased
			++_capacity;
		
			// there we go
			_MemoryBarrier();
			return true;
		}
Ejemplo n.º 16
0
	int AccessMap::deriveFatherCrud(int fatherCrud) const
	{
		int crud = NO_ACCESS;
		if (canRead(fatherCrud)) crud += READ;
		if (canUpdate(fatherCrud)) crud += UPDATE + DELETE + CREATE;
		return crud;
	}
Ejemplo n.º 17
0
//判断类型 int char
int userDatabase::JudgeType(int pos){
    if(canRead(pos)){
        if(mySql.sqlWord[pos] == "int")  return 1;
        if(mySql.sqlWord[pos] == "char") return 2;
    }
    return -1;
};
		bool readMessage(unsigned id,  std::vector<char> & message) {
			if (false ==canRead(id))
				return false;
			message = subscriber_map_[id].read_itr_->data_;
			return true;
			
		}
Ejemplo n.º 19
0
/**
 * @brief MainWindow::uiUpdate
 */
void MainWindow::uiUpdate(){
    ui->pushButtonBusOn->setEnabled(connected);
    ui->comboBoxBaud->setEnabled(!busOn);
    ui->checkBox_Silent->setEnabled(!busOn);

    if(connected){
        canBusStatistics stats;
        canStatus stat;
        stat = canRequestBusStatistics(canHandle);
        if( stat < 0){
            qDebug() debugprefix << "canRequestBusStatistics failed";
        }else{
            stat = canGetBusStatistics(canHandle, &stats, sizeof(canBusStatistics));
            if(stat < 0){
                qDebug() debugprefix << "canGetBusStatistics failed";
            }else{
                ui->label_corruptCounter->setText(QString().setNum(stats.errFrame));
                unsigned long c = stats.stdData + stats.stdRemote + stats.extData + stats.extRemote;
                ui->label_packetCounter->setText(QString().setNum(c));
                ui->progressBarBusLoad->setValue(stats.busLoad);
            }
        }
        if(busOn){
            // Dirty but effective
            while(1){
                long id;
                unsigned char data[8];
                unsigned int dlc, flags;
                unsigned long timestamp;

                canStatus stat = canRead(canHandle, &id, data, &dlc, &flags, &timestamp);
                if (stat < 0) {
                    //qDebug() debugprefix << "canRead() end of queue";
                    break;
                }else{
                    QString l;
                    if(flags & canMSG_ERROR_FRAME){
                        l.sprintf("%ld",timestamp);
                        qDebug() debugprefix << "canRead() got error";
                    }else{
                        int rtr = 0;
                        if( flags & canMSG_RTR ) rtr = 1;
                        l.sprintf("%ld\tID:0x%08X\tRTR:%d\t",timestamp,id,rtr);
                        if( dlc > 0 ) l.append(QString().sprintf("DATA: %02X", (quint8)data[0]));
                        if( dlc > 1 ) l.append(QString().sprintf("%02X", (quint8)data[1]));
                        if( dlc > 2 ) l.append(QString().sprintf("%02X", (quint8)data[2]));
                        if( dlc > 3 ) l.append(QString().sprintf("%02X", (quint8)data[3]));
                        if( dlc > 4 ) l.append(QString().sprintf("%02X", (quint8)data[4]));
                        if( dlc > 5 ) l.append(QString().sprintf("%02X", (quint8)data[5]));
                        if( dlc > 6 ) l.append(QString().sprintf("%02X", (quint8)data[6]));
                        if( dlc > 7 ) l.append(QString().sprintf("%02X", (quint8)data[7]));
                    }
                    qDebug() debugprefix << "canRead() got valid message";
                    ui->textEditCanIn->append(l);
                }
            }
        }
    }
}
Ejemplo n.º 20
0
bool QXpmHandler::canRead() const
{
    if (state == Ready && canRead(device())) {
        setFormat("xpm");
        return true;
    }
    return state != Error;
}
Ejemplo n.º 21
0
bool EPSHandler::canRead() const
{
    if (canRead(device())) {
        setFormat("eps");
        return true;
    }
    return false;
}
Ejemplo n.º 22
0
string SoTeleportation::read()
{
	if (!canRead())
		return string();
	dungeon()->player()->initializeSpot();
	setAsRead();
	return "You read the scroll called scroll of enhance dexterity\nYou feel like less of a klutz.\n";
}
Ejemplo n.º 23
0
int8_t circularBuffer_read(CircularBuffer * buffer, char * data, uint8_t size){
	uint8_t amount = 0;
	while(canRead(buffer) && (size - amount > 0)){
		if(circularBuffer_readByte(buffer,(char *) data[amount]) == -1)
		return amount;
		amount++;
	}
	return amount;
}
Ejemplo n.º 24
0
uint8_t NetworkMessage::getU8()
{
	if(canRead(1)){
		return m_buffer[m_readPos++];
	}
	else{
		return 0;
	}
}
Ejemplo n.º 25
0
string SoRaiseStrength::read()
{
	if (!canRead())
		return string();
	dungeon()->player()->addStengthPoints(1 + randInt(3));
	setAsRead();
	return "You read the scroll called scroll of raise strength\nYou feel like less of a klutz.\n";

}
Ejemplo n.º 26
0
int readByte_nonblocking(char *dst, uint8_t usartn)
{
   if (canRead(usartn)) {
      *dst = __readByte(usartn);
      return 0;
   }

   return -1;
}
string SoEnhanceDexterity::read()
{
	if (!canRead())
		return string();
	dungeon()->player()->raiseDexterity();
	setAsRead();
	return "You read the scroll called scroll of enhance dexterity\nYou feel like less of a klutz.\n";

}
Ejemplo n.º 28
0
bool BackgroundTilesIO::read(BackgroundTiles &tiles) const
{
	if(!canRead()) {
		return false;
	}

	tiles.clear();

	return readData(tiles);
}
Ejemplo n.º 29
0
bool QPpmHandler::canRead() const
{
    if (state == Ready) {
        if (!canRead(device(), &subType))
            return false;
        setFormat(subType);
        return true;
    }
    return state != Error;
}
Ejemplo n.º 30
0
bool NetworkMessage::getU8(uint8_t& v)
{
	if(canRead(1)){
		v = m_buffer[m_readPos++];
		return true;
	}
	else{
		return false;
	}
}