Beispiel #1
0
//-------------------------------------------------------------------------
void reply_cp_fromPCtoNode_type1(uint8_t * receivebuffer)
{
    uint8_t blockid;
    char filename[13];
    int fid;
    uint8_t newblockid;
      
    releaseAllFid();
    blockid = receivebuffer[3];
    mystrncpy(filename, (char *)&receivebuffer[4], receivebuffer[0] - 4);
    filename[receivebuffer[0] - 4] = '\0';
    newblockid = createFileFromDirectory(filename, (int)blockid);
    chunksequencenum = 0;
    expectNextNum = 1;
    reply[0] = 4;
    reply[1] = 121;
    reply[2] = nodeid;
    reply[3] = newblockid;
    fid = getFreeFid();
    openFile(newblockid, fid, 2);
    openedfile = &fidtable[fid];
	 sleepThread(20);
    // printStringN(reply,32);      
    StandardSocketSend(0xefef, 0xffff, 32, reply);
}
Beispiel #2
0
//Get the block information of sub directory and files using long version 
void reply_ls_long(uint8_t block)
{
    uint8_t blockindex;
    uint8_t childblock;
    uint8_t seq = 0;

    if (openedfile != NULL)
    {
        //fclose2( openedfile );
        openedfile = NULL;
    }
    for (blockindex = 0; blockindex < 10; blockindex++)
    {
        childblock = fsread8uint(block, DIR_ADDRSUBOFFSET + blockindex);
        if (childblock == 0)
        {
            continue;
        }
        reply[0] = 32;
        reply[1] = 104;
        reply[2] = nodeid;
        reply[3] = childblock;
        reply[4] = seq;
        seq++;
        finfonode((char *)&reply[5], (int)childblock);
	    sleepThread(20);
	
        StandardSocketSend(0xefef, 0xffff, 32, reply);
        //     printStringN(reply,32); 
    }
}
void ModelValidationHelper::applyFixes(void)
{
	if(fix_mode)
	{
		bool validate_rels=false;

		while(!val_infos.empty() && !valid_canceled)
		{
			for(unsigned i=0; i < val_infos.size() && !valid_canceled; i++)
			{
				validate_rels=(val_infos[i].getValidationType()==ValidationInfo::BROKEN_REFERENCE ||
											 val_infos[i].getValidationType()==ValidationInfo::NO_UNIQUE_NAME);
				resolveConflict(val_infos[i]);
			}

			emit s_fixApplied();

			validateModel();
			sleepThread(5);
		}

		if(!valid_canceled && val_infos.empty())
		{
			if(validate_rels)
				db_model->validateRelationships();

			fix_mode=false;
		}
	}
}
Beispiel #4
0
void PeriodicTaskScheduler::schedulerThreadRun(TaskThread& task) {
  while (sleepThread(task.tmoMs)) {
    try {
      task.func(*this);
    } catch (const std::exception& ex) {
      LOG_FAILURE("mcrouter", failure::Category::kOther,
                  "Error while executing periodic function: {}", ex.what());
      break;
    } catch (...) {
      LOG_FAILURE("mcrouter", failure::Category::kOther,
                  "Unknown error occured while executing periodic function");
      break;
    }
  }
}
Beispiel #5
0
//-------------------------------------------------------------------------
void StandardSocketSend(uint16_t port, uint16_t address, uint8_t msglength,
                        uint8_t * msg)
{
//    #ifdef PLATFORM_AVR_IRIS
//     sleepThread(20);
//    #endif

    radiosocketdata.socket_port = port;
    radiosocketdata.socket_addr = address;
    radiosocketdata.socket_msg_len = msglength;
    radiosocketdata.socket_msg = msg;
    postTask(send_task, 9);
    sleepThread(20);
    restoreRadioState();
    return;
}
Beispiel #6
0
//-------------------------------------------------------------------------
void reply_mkdir(uint8_t * receivebuffer)
{
    uint8_t blockid;
    char dirname[13];
    uint8_t newblockid;

    blockid = receivebuffer[3];
    mystrncpy(dirname, (char *)&receivebuffer[4], receivebuffer[0] - 4);
    dirname[receivebuffer[0] - 4] = '\0';
    newblockid = createDir(dirname, (int)blockid);
    reply[0] = 4;
    reply[1] = 141;
    reply[2] = nodeid;
    reply[3] = newblockid;
	 sleepThread(20);
    StandardSocketSend(0xefef, 0xffff, 32, reply);
    // printStringN(reply,32);      
}
Beispiel #7
0
//-------------------------------------------------------------------------
void reply_ls_nodename(uint8_t * receivebuffer)
{
    uint8_t temp = receivebuffer[0] - 3;
    uint16_t randomsleep;

    if (mystrncmp((char *)receivebuffer, 3, (char *)networkid, 0, temp) == 0)
    {
        temp = mystrlen(filenameid);
        reply[0] = temp + 3;
        reply[1] = 102;
        reply[2] = nodeid;
        mystrncpy((char *)&reply[3], filenameid, temp);
        randomsleep = getRandomNumber() % 400;
        sleepThread(randomsleep);
        StandardSocketSend(0xefef, 0xffff, 32, reply);
        //printStringN(reply,32); 
    }
}
Beispiel #8
0
//-------------------------------------------------------------------------
void reply_ls_networkname()
{
    //   uint16_t temp2; 
    uint8_t temp = mystrlen(networkid);
    uint16_t randomsleep;

    reply[0] = temp + 3;
    reply[1] = 101;
    //   foobar(); 
    reply[2] = nodeid;
    mystrncpy((char *)&reply[3], networkid, temp);
    randomsleep = getRandomNumber() % 400;
    sleepThread(randomsleep);
    // for (temp2=0;temp2<9000;temp2++)
    // {
    StandardSocketSend(0xefef, 0xffff, 32, reply);
    // sleepThread(20);
    // }
    //   printStringN(reply,32); 
    //printString("hello,reply2!\n\0");
}
void ModelExportHelper::exportToDBMS(DatabaseModel *db_model, Connection conn, const QString &pgsql_ver, bool ignore_dup, bool drop_db, bool simulate)
{
	int type_id;
	QString  version, sql_buf, sql_cmd, lin;
	Connection new_db_conn;
	unsigned i, count;
	ObjectType types[]={OBJ_ROLE, OBJ_TABLESPACE};
	BaseObject *object=nullptr;
	vector<Exception> errors;
	QTextStream ts;
	bool ddl_tk_found=false;

	/* Error codes treated in this method
			42P04 	duplicate_database
			42723 	duplicate_function
			42P06 	duplicate_schema
			42P07 	duplicate_table
			42710 	duplicate_object
			42701   duplicate_column
			42P16   invalid_table_definition

		 Reference:
			http://www.postgresql.org/docs/current/static/errcodes-appendix.html*/
	QString error_codes[]={"42P04", "42723", "42P06", "42P07", "42710", "42701", "42P16"};
	vector<QString> err_codes_vect(error_codes, error_codes + sizeof(error_codes) / sizeof(QString));

	try
	{
		if(!db_model)
			throw Exception(ERR_ASG_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		/* If the export is called using ignore duplications or drop database and simulation mode at same time
		an error is raised because the simulate mode (mainly used as SQL validation) cannot
		undo column addition (this can be changed in the future) */
		if(simulate && (ignore_dup || drop_db))
			throw Exception(ERR_MIX_INCOMP_EXPORT_OPTS,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		connect(db_model, SIGNAL(s_objectLoaded(int,QString,uint)), this, SLOT(updateProgress(int,QString,uint)));

		export_canceled=false;
		db_created=false;
		progress=sql_gen_progress=0;
		created_objs[OBJ_ROLE]=created_objs[OBJ_TABLESPACE]=-1;
		conn.connect();

		//Retrive the DBMS version in order to generate the correct code
		version=(conn.getPgSQLVersion()).mid(0,3);

		//Overriding the DBMS version case the version is informed on parameter
		if(!pgsql_ver.isEmpty())
		{
			SchemaParser::setPgSQLVersion(pgsql_ver);
			emit s_progressUpdated(progress, trUtf8("PostgreSQL version detection overrided. Using version %1...").arg(pgsql_ver));
		}
		else
		{
			SchemaParser::setPgSQLVersion(version);
			emit s_progressUpdated(progress, trUtf8("PostgreSQL %1 server detected...").arg(version));
		}

		if(ignore_dup)
		{
			emit s_progressUpdated(progress, trUtf8("Ignoring object duplication errors..."));

			//Save the current status for ALTER command generation for table columns/constraints
			saveGenAtlerCmdsStatus(db_model);
		}

		if(drop_db)
		{
			emit s_progressUpdated(progress, trUtf8("Trying to drop database `%1'...").arg(db_model->getName()));
			conn.executeDDLCommand(QString("DROP DATABASE IF EXISTS %1;").arg(db_model->getName(true)));
		}

		if(simulate)
			emit s_progressUpdated(progress, trUtf8("Simulation mode activated..."));

		//Creates the roles and tablespaces separately from the other objects
		for(type_id=0; type_id < 2 && !export_canceled; type_id++)
		{
			count=db_model->getObjectCount(types[type_id]);

			for(i=0; i < count && !export_canceled; i++)
			{
				object=db_model->getObject(i, types[type_id]);
				progress=((10 * (type_id+1)) + ((i/static_cast<float>(count)) * 10));

				try
				{
					if(!object->isSQLDisabled())
					{
						//Emits a signal indicating that the object is being exported
						emit s_progressUpdated(progress,
																	 trUtf8("Creating object `%1' (%2)...").arg(Utf8String::create(object->getName())).arg(object->getTypeName()),
																	 object->getObjectType());

						sql_cmd=object->getCodeDefinition(SchemaParser::SQL_DEFINITION);
						conn.executeDDLCommand(sql_cmd);
					}
				}
				catch(Exception &e)
				{
					/* Raises an error if the object is duplicated and the ignore duplicity is not set or the error
					returned by the server is other than object duplicity */
					if(!ignore_dup ||
						 (ignore_dup &&
							std::find(err_codes_vect.begin(), err_codes_vect.end(), e.getExtraInfo())==err_codes_vect.end()))
						throw Exception(e.getErrorMessage(),
														e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e, sql_cmd);
					else
						//If the object is duplicated store the error on a vector
						errors.push_back(e);
				}

				created_objs[types[type_id]]++;
			}
		}

		try
		{
			if(!db_model->isSQLDisabled() && !export_canceled)
			{
				//Creating the database on the DBMS
				emit s_progressUpdated(progress,
															 trUtf8("Creating database `%1'...").arg(Utf8String::create(db_model->getName())),
															 OBJ_DATABASE);
				sql_cmd=db_model->__getCodeDefinition(SchemaParser::SQL_DEFINITION);
				conn.executeDDLCommand(sql_cmd);
				db_created=true;
			}
		}
		catch(Exception &e)
		{
			/* Raises an error if the object is duplicated and the ignore duplicity is not set or the error
			returned by the server is other than object duplicity */
			if(!ignore_dup ||
				 (ignore_dup &&
					std::find(err_codes_vect.begin(), err_codes_vect.end(), e.getExtraInfo())==err_codes_vect.end()))
				throw Exception(e.getErrorMessage(),
												e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e, sql_cmd);
			else
				errors.push_back(e);
		}

		if(!export_canceled)
		{
			//Connects to the new created database to create the other objects
			progress=20;
			new_db_conn=conn;
			new_db_conn.setConnectionParam(Connection::PARAM_DB_NAME, db_model->getName());
			emit s_progressUpdated(progress,
														 trUtf8("Connecting to database `%1'...").arg(Utf8String::create(db_model->getName())));

			new_db_conn.connect();
			progress=30;
			//Creating the other object types
			emit s_progressUpdated(progress, trUtf8("Creating objects on database `%1'...").arg(Utf8String::create(db_model->getName())));

			//Generates the sql from entire model
			sql_buf=db_model->getCodeDefinition(SchemaParser::SQL_DEFINITION, false);

			/* Extract each SQL command from the buffer and execute them separately. This is done
			 to permit the user, in case of error, identify what object is wrongly configured. */
			ts.setString(&sql_buf);
			unsigned aux_prog=0, curr_size=0, buf_size=sql_buf.size();

			progress+=(sql_gen_progress/progress);
			sql_cmd.clear();

			while(!ts.atEnd() && !export_canceled)
			{
				try
				{
					//Cleanup single line comments
					lin=ts.readLine();
					curr_size+=lin.size();
					aux_prog=progress + ((curr_size/static_cast<float>(buf_size)) * 70);

					ddl_tk_found=(lin.indexOf(ParsersAttributes::DDL_END_TOKEN) >= 0);
					lin.remove(QRegExp("^(--)+(.)+$"));

					//If the line isn't empty after cleanup it will be included on sql command
					if(!lin.isEmpty())
						sql_cmd += lin + "\n";

					//If the ddl end token is found
					if(ddl_tk_found || (!sql_cmd.isEmpty() && ts.atEnd()))
					{
						//Regexp used to extract the object being created
						QRegExp reg=QRegExp("(CREATE)(.)+(\n)", Qt::CaseSensitive);
												//sql_cmd = sql_cmd.simplified();

						//Check if the regex matches the sql command
						if(reg.exactMatch(sql_cmd))
						{
							QString obj_type, obj_name;
							QRegExp reg_aux;
							unsigned obj_id;
							ObjectType obj_types[]={ OBJ_FUNCTION, OBJ_TRIGGER, OBJ_INDEX,
																			 OBJ_RULE,	OBJ_TABLE, OBJ_VIEW, OBJ_DOMAIN,
																			 OBJ_SCHEMA,	OBJ_AGGREGATE, OBJ_OPFAMILY,
																			 OBJ_OPCLASS, OBJ_OPERATOR,  OBJ_SEQUENCE,
																			 OBJ_CONVERSION, OBJ_CAST,	OBJ_LANGUAGE,
																			 OBJ_COLLATION, OBJ_EXTENSION, OBJ_TYPE };
							unsigned count=sizeof(obj_types)/sizeof(ObjectType);
							int pos=0;

							//Get the fisrt line of the sql command, that contains the CREATE ... statement
							lin=sql_cmd.mid(0, sql_cmd.indexOf('\n'));

							for(obj_id=0; obj_id < count; obj_id++)
							{
								//Check if the keyword for the current object exists on string
								reg_aux.setPattern(QString("(CREATE)(.)*(%1)%2")
																	 .arg(BaseObject::getSQLName(obj_types[obj_id]))
																	 .arg(obj_types[obj_id]==OBJ_INDEX ? "( )*(CONCURRENTLY)?" : ""));
								pos=reg_aux.indexIn(lin);

								if(pos >= 0)
								{
									//Extracts from the line the string starting with the object's name
									lin=lin.mid(reg_aux.matchedLength(), sql_cmd.indexOf('\n')).simplified();

									//Stores the object type name
									obj_type=BaseObject::getTypeName(obj_types[obj_id]);

									if(obj_types[obj_id]!=OBJ_CAST)
									{
										//The object name is the first element when splitting the string with space separator
										obj_name=lin.split(' ').at(0);
										obj_name.remove('(');
									}
									else
									{
										obj_name="cast" + lin.replace(" AS ",",");
									}

									obj_name.remove(';');
									break;
								}
							}

							emit s_progressUpdated(aux_prog,
																		 trUtf8("Creating object `%1' (%2)...").arg(obj_name).arg(obj_type),
																		 obj_types[obj_id]);
						}
						else
							//General commands like alter / set aren't explicitly shown
							emit s_progressUpdated(aux_prog, trUtf8("Executing auxiliary command..."));

						//Executes the extracted SQL command
						if(!sql_cmd.isEmpty())
							new_db_conn.executeDDLCommand(sql_cmd);

						sql_cmd.clear();
						ddl_tk_found=false;
					}
				}
				catch(Exception &e)
				{
					if(ddl_tk_found) ddl_tk_found=false;

					if(!ignore_dup ||
						 (ignore_dup &&
							std::find(err_codes_vect.begin(), err_codes_vect.end(), e.getExtraInfo())==err_codes_vect.end()))
						throw Exception(Exception::getErrorMessage(ERR_EXPORT_FAILURE).arg(Utf8String::create(sql_cmd)),
														ERR_EXPORT_FAILURE,__PRETTY_FUNCTION__,__FILE__,__LINE__,&e, sql_cmd);
					else
					{
						sql_cmd.clear();
						errors.push_back(e);
						sleepThread(10);
					}
				}
			}
		}

		disconnect(db_model, nullptr, this, nullptr);

		if(ignore_dup)
			restoreGenAtlerCmdsStatus();

		//Closes the new opened connection
		if(new_db_conn.isStablished()) new_db_conn.close();

		/* If the process was a simulation or even canceled undo the export
		removing the created objects */
		if(simulate || export_canceled)
			undoDBMSExport(db_model, conn);

		if(conn.isStablished())
			conn.close();

		if(!export_canceled)
			emit s_exportFinished();
		else
			emit s_exportCanceled();

		sleepThread(20);
	}
	catch(Exception &e)
	{
		disconnect(db_model, nullptr, this, nullptr);

		if(ignore_dup)
			restoreGenAtlerCmdsStatus();

		try
		{
			//Closes the new opened connection
			if(new_db_conn.isStablished()) new_db_conn.close();

			//Undo the export removing the created objects
			undoDBMSExport(db_model, conn);
		}
		catch(Exception &){}

		if(conn.isStablished())	conn.close();

		/* When running in a separated thread (other than the main application thread)
		redirects the error in form of signal */
		if(this->thread() && this->thread()!=qApp->thread())
		{
			errors.push_back(e);
			emit s_exportAborted(Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, errors));
		}
		else
		{
			//Redirects any error to the user
			if(errors.empty())
				throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
			else
			{
				errors.push_back(e);
				throw Exception(e.getErrorMessage(),__PRETTY_FUNCTION__,__FILE__,__LINE__, errors);
			}
		}
	}
}
void  ModelValidationHelper::resolveConflict(ValidationInfo &info)
{
	try
	{
		vector<BaseObject *> refs=info.getReferences();
		BaseObject *obj=nullptr;

		//Resolving broken references by swaping the object ids
		if(info.getValidationType()==ValidationInfo::BROKEN_REFERENCE)
		{
			unsigned obj_id=info.getObject()->getObjectId();

			//Search for the object with the minor id
			while(!refs.empty() && !valid_canceled)
			{
				if(obj_id > refs.back()->getObjectId())
				{
					obj=refs.back();
					obj_id=obj->getObjectId();
				}

				refs.pop_back();
			}

			//Swap the id of the validation object and the found object (minor id)
			if(obj)
				BaseObject::swapObjectsIds(info.getObject(), obj, true);

			sleepThread(5);
		}
		//Resolving no unique name by renaming the constraints/indexes
		else if(info.getValidationType()==ValidationInfo::NO_UNIQUE_NAME)
		{
			unsigned suffix=1;
			QString new_name;
			Table *table=nullptr;
			ObjectType obj_type;
			BaseObject *obj=info.getObject();
			TableObject *tab_obj=nullptr;

			/* If the last element of the referrer objects is a table or view the
			info object itself need to be renamed since tables and views will not be renamed */
			bool rename_obj=(refs.back()->getObjectType()==OBJ_TABLE ||
											 refs.back()->getObjectType()==OBJ_VIEW);

			if(rename_obj)
			{
				table=dynamic_cast<Table *>(dynamic_cast<TableObject *>(obj)->getParentTable());
				obj_type=obj->getObjectType();

				do
				{
					//Configures a new name for the object [name]_[suffix]
					new_name=QString("%1_%2").arg(obj->getName()).arg(suffix);
					suffix++;
				}
				//Generates a new name until no object is found on parent table
				while(table->getObjectIndex(new_name, obj_type) >= 0);

				//Renames the object
				obj->setName(new_name);
			}

			//Renaming the referrer objects
			while(!refs.empty() && !valid_canceled)
			{
				obj_type=refs.back()->getObjectType();
				tab_obj=dynamic_cast<TableObject *>(refs.back());

				//Tables and view aren't renamed only table child objects (constraints, indexes)
				if(tab_obj && !tab_obj->isAddedByRelationship())
				{
					table=dynamic_cast<Table *>(tab_obj->getParentTable());

					do
					{
						//Configures a new name for the object [name]_[suffix]
						new_name=QString("%1_%2").arg(refs.back()->getName()).arg(suffix);
						suffix++;
					}
					//Generates a new name until no object is found on parent table
					while(table->getObjectIndex(new_name, obj_type) >= 0);

					//Renames the referrer object
					refs.back()->setName(new_name);
				}

				refs.pop_back();
				sleepThread(5);
			}
		}
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
void ModelValidationHelper::validateModel(void)
{
	if(!db_model)
		throw Exception(ERR_OPR_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

	try
	{
		ObjectType types[]={ OBJ_ROLE, OBJ_TABLESPACE, OBJ_SCHEMA, OBJ_LANGUAGE, OBJ_FUNCTION,
												 OBJ_TYPE, OBJ_DOMAIN, OBJ_SEQUENCE, OBJ_OPERATOR, OBJ_OPFAMILY,
												 OBJ_OPCLASS, OBJ_COLLATION, OBJ_TABLE, OBJ_EXTENSION, OBJ_VIEW },
								aux_types[]={ OBJ_TABLE, OBJ_VIEW },
							 tab_obj_types[]={ OBJ_CONSTRAINT, OBJ_INDEX };
		unsigned i, i1, cnt, aux_cnt=sizeof(aux_types)/sizeof(ObjectType),
						count=sizeof(types)/sizeof(ObjectType), count1=sizeof(tab_obj_types)/sizeof(ObjectType);
		BaseObject *object=nullptr, *refer_obj=nullptr;
		vector<BaseObject *> refs, refs_aux, *obj_list=nullptr;
		vector<BaseObject *>::iterator itr;
		TableObject *tab_obj=nullptr;
		ValidationInfo info;
		Table *table=nullptr;
		Constraint *constr=nullptr;
		map<QString, vector<BaseObject *> > dup_objects;
		map<QString, vector<BaseObject *> >::iterator mitr;
		QString name, signal_msg="`%1' (%2)";

		warn_count=error_count=progress=0;
		val_infos.clear();
		valid_canceled=false;

		/* Step 1: Validating broken references. This situation happens when a object references another
		whose id is smaller than the id of the first one. */
		for(i=0; i < count && !valid_canceled; i++)
		{
			obj_list=db_model->getObjectList(types[i]);
			itr=obj_list->begin();

			while(itr!=obj_list->end()&& !valid_canceled)
			{
				object=(*itr);
				itr++;

				//Excluding the validation of system objects (created automatically)
				if(!object->isSystemObject())
				{
					emit s_objectProcessed(signal_msg.arg(object->getName()).arg(object->getTypeName()), object->getObjectType());

					db_model->getObjectReferences(object, refs);
					refs_aux.clear();

					while(!refs.empty() && !valid_canceled)
					{
						//Checking if the referrer object is a table object. In this case its parent table is considered
						tab_obj=dynamic_cast<TableObject *>(refs.back());
						constr=dynamic_cast<Constraint *>(tab_obj);

						/* If the current referrer object has an id less than reference object's id
						then it will be pushed into the list of invalid references. The only exception is
						for foreign keys that are discarded from any validation since they are always created
						at end of code defintion being free of any reference breaking. */
						if(object != refs.back() &&
							 (!constr || (constr && constr->getConstraintType()!=ConstraintType::foreign_key)) &&
							 ((!tab_obj && refs.back()->getObjectId() <= object->getObjectId()) ||
								(tab_obj && !tab_obj->isAddedByRelationship() &&
								 tab_obj->getParentTable()->getObjectId() <= object->getObjectId())))
						{
							if(tab_obj)
								refer_obj=tab_obj->getParentTable();
							else
								refer_obj=refs.back();

							//Push the referrer object only if not exists on the list
							if(std::find(refs_aux.begin(), refs_aux.end(), refer_obj)==refs_aux.end())
								refs_aux.push_back(refer_obj);
						}

						refs.pop_back();
					}

					//Case there is broken refereces to the object
					if(!refs_aux.empty())
					{
						//Configures a validation info
						info=ValidationInfo(ValidationInfo::BROKEN_REFERENCE, object, refs_aux);
						error_count++;

						val_infos.push_back(info);

						//Emit the signal containing the info
						emit s_validationInfoGenerated(info);
					}
				}
			}

			//Emit a signal containing the validation progress
			progress=((i+1)/static_cast<float>(count))*20;
			emit s_progressUpdated(progress, "");

			sleepThread(5);
		}


		/* Step 2: Validating name conflitcs between primary keys, unique keys, exclude constraints
		and indexs of all tables/views. The table and view names are checked too. */
		obj_list=db_model->getObjectList(OBJ_TABLE);
		itr=obj_list->begin();

		//Searching the model's tables and gathering all the constraints and index
		while(itr!=obj_list->end() && !valid_canceled)
		{
			table=dynamic_cast<Table *>(*itr);

			emit s_objectProcessed(signal_msg.arg(table->getName()).arg(object->getTypeName()), table->getObjectType());

			itr++;

			for(i=0; i < count1 && !valid_canceled; i++)
			{
				cnt=table->getObjectCount(tab_obj_types[i]);

				for(i1=0; i1 < cnt && !valid_canceled; i1++)
				{
					//Get the table object (constraint or index)
					tab_obj=dynamic_cast<TableObject *>(table->getObject(i1, tab_obj_types[i]));

					//Configures the full name of the object including the parent name
					name=tab_obj->getParentTable()->getSchema()->getName(true) + "." + tab_obj->getName(true);
					name.remove("\"");

					//Trying to convert the object to constraint
					constr=dynamic_cast<Constraint *>(tab_obj);

					/* If the object is an index or	a primary key, unique or exclude constraint,
					insert the object on duplicated	objects map */
					if((!constr ||
							(constr && (constr->getConstraintType()==ConstraintType::primary_key ||
													constr->getConstraintType()==ConstraintType::unique ||
													constr->getConstraintType()==ConstraintType::exclude))))
						dup_objects[name].push_back(tab_obj);
				}
			}

			sleepThread(5);
		}

		/* Inserting the tables and views to the map in order to check if there is table objects
			 that conflicts with thems */
		for(i=0; i < aux_cnt && !valid_canceled; i++)
		{
			obj_list=db_model->getObjectList(aux_types[i]);
			itr=obj_list->begin();
			while(itr!=obj_list->end() && !valid_canceled)
			{
				dup_objects[(*itr)->getName(true).remove("\"")].push_back(*itr);
				itr++;
			}

			sleepThread(5);
		}

		//Checking the map of duplicated objects
		mitr=dup_objects.begin();
		i=1;
		while(mitr!=dup_objects.end() && !valid_canceled)
		{
			/* If the vector of the current map element has more the one object
			indicates the duplicity thus generates a validation info */
			if(mitr->second.size() > 1)
			{
				refs.assign(mitr->second.begin() + 1, mitr->second.end());

				//Configures a validation info
				info=ValidationInfo(ValidationInfo::NO_UNIQUE_NAME, mitr->second.front(), refs);
				error_count++;
				refs.clear();

				val_infos.push_back(info);

				//Emit the signal containing the info
				emit s_validationInfoGenerated(info);
			}

			//Emit a signal containing the validation progress
			progress=20 + ((i/static_cast<float>(dup_objects.size()))*20);
			emit s_progressUpdated(progress, "");

			i++; mitr++;
			sleepThread(5);
		}

		if(!valid_canceled && !fix_mode)
		{
			//Step 3 (optional): Validating the SQL code onto a local DBMS.
			//Case the connection isn't specified indicates that the SQL validation will not be executed
			if(!conn)
			{
				//Emit a signal indicating the final progress
				emitValidationFinished();
			}
			//SQL validation only occurs when the model is completely validated.
			else
			{
				//If there is no errors start the dbms export thread
				if(error_count==0)
				{
					export_thread->start();
					emit s_sqlValidationStarted(true);
				}
				else
				{
					warn_count++;
					emitValidationFinished();
					emit s_validationInfoGenerated(ValidationInfo(trUtf8("There are pending errors! SQL validation will not be executed.")));
				}
			}
		}
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
Beispiel #12
0
void appflooding()
{
  fromnode = 2; 
  __asm__ __volatile__("sei" ::); 
 
  nodeid = lib_get_node_id();
  while (1)
 	{
      if (nodeid == fromnode)
      {    
      sig = lib_random();
      msg[0] = nodeid%256;
	  msg[1] = nodeid/256;
	  msg[2] = sig%256;
	  msg[3] = sig/256;
	  msg[4] = 90; 
	  msg[5] = 0xff;
	  msg[6] = 0xff;
	  msg[7] = 'h';
	  msg[8] = 'e';
	  msg[9] = 'l';
	  msg[10] = 'l';
	  msg[11] = 'o';
	  msg[12] = floodingcounter++; 
	 
	  lib_radio_send_msg(20, 0, 16, msg);
	  
	   if (floodingcounter%3==0)
	   { lib_red_on();
		 lib_green_off();
		 lib_yellow_off();
	   }
	   else if (floodingcounter%3==1)
	    {lib_red_off();
		 lib_green_on();
		 lib_yellow_off();
	    }
		else 
	   {
		 lib_red_off();
		 lib_green_off();
		 lib_yellow_on();
	   }				
	   
      sleepThread(2000);
      }
    else 
 	  {
	  lib_radio_receive(90, 16, msg); 
      incomingnode = (uint16_t)msg[0]+ (((uint16_t)msg[1]) *256); 
	  floodingcounter = msg[12]; 
	  if (floodingcounter%3==0)
	   { lib_red_on();
		 lib_green_off();
		 lib_yellow_off();
	   }
	   else if (floodingcounter%3==1)
	    {lib_red_off();
		 lib_green_on();
		 lib_yellow_off();
	    }
		else 
	   {
		 lib_red_off();
		 lib_green_off();
		 lib_yellow_on();
	   }				
	  }
	
	  
  	}	 
	  
	//should never reach here.
	return; 
}
OMXCAM_ERROR OMXCAM_startVideo (OMXCAM_VIDEO_SETTINGS* settings, uint32_t ms){
  OMXCAM_trace ("Starting video");
  
  if (!settings->bufferCallback){
    OMXCAM_error ("The 'bufferCallback' field must be defined");
    return OMXCAM_ErrorBadParameter;
  }
  if (running){
    OMXCAM_error ("Video capture is already running");
    return OMXCAM_ErrorVideo;
  }
  
  bgError = 0;
  OMXCAM_ERROR error;
  
  if ((error = OMXCAM_init ())) return error;
  
  if ((error = initOMX (settings))) return error;
  
  //Start the background thread
  OMXCAM_trace ("Creating background thread");
  
  if (pthread_mutex_init (&mutex, 0)){
    OMXCAM_error ("pthread_mutex_init");
    return OMXCAM_ErrorVideo;
  }
  
  running = 1;
  
  if (pthread_create (&bgThread, 0, captureVideo, &threadArg)){
    OMXCAM_error ("pthread_create");
    return OMXCAM_ErrorVideo;
  }
  
  //Block the main thread
  if (ms){
    if (sleepThread (ms)) return OMXCAM_ErrorSleep;
  }else{
    if (lockThread ()) return OMXCAM_ErrorLock;
  }
  
  if (bgError){
    //The video was already stopped due to an error
    OMXCAM_trace ("Video stopped due to an error");
    
    int err = bgError;
    bgError = 0;
    
    if (pthread_join (bgThread, 0)){
      OMXCAM_error ("pthread_join");
      return OMXCAM_ErrorVideo;
    }
    
    return err;
  }
  
  if (!running){
    //The video was already stopped by the client
    OMXCAM_trace ("Video stopped by the client");
    
    if (pthread_join (bgThread, 0)){
      OMXCAM_error ("pthread_join");
      return OMXCAM_ErrorVideo;
    }
    
    return OMXCAM_ErrorNone;
  }
  
  return OMXCAM_stopVideo ();
}
Beispiel #14
0
/*
 * Put current thread to sleep for a time.
 */
void
java_lang_Thread_sleep(jlong time)
{
	sleepThread(time);
}