void NetworkStack_init(JNIEnv * env , jobject obj , jobjectArray initArgs , NetworkStackBase *networkStack){ JavaLog::setJavalogEnviroment(env,obj); // Check that the nwtwork stack is not initialized : if (networkStack->isReady()) { generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Network Stack must close before re initialization"); return; } int argc = env->GetArrayLength(initArgs); char** argv = new char*[argc]; for (int i=0; i<argc; i++) { jstring arg = (jstring)env->GetObjectArrayElement(initArgs , i); argv[i] = (char*)env->GetStringUTFChars(arg,0); } //char* localAddress = (char*)env->GetStringUTFChars(localAddressStr,0); bool success = networkStack->initialize(argv , argc); //env->ReleaseStringUTFChars(localAddressStr, localAddress); for (int i=0; i<argc; i++) { jstring arg = (jstring)env->GetObjectArrayElement(initArgs , i); env->ReleaseStringUTFChars(arg,argv[i]); } delete argv; if (!success) generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Uninitialized network stack"); }
const QList<Student*>& DBimpl::getAllStudents(){ QSqlQuery query; query.prepare(DatabaseQueries::selectAllStudents); if (!query.exec()) { qDebug() << query.lastError(); qDebug() << query.lastQuery(); throw generateException(query); } else { QString tempUsername; int tempID; Student* tempStudent; QList<Student*>* students = new QList<Student*>; while (query.next()) { //first column is 0 tempID = query.value(0).toInt(); tempUsername = QString(query.value(1).toString()); tempStudent = new Student(tempID,tempUsername); qDebug()<< "getAllQualifications"<<getAllQualifications(tempID); tempStudent->setQualifications(getAllQualifications(tempID)); students->append(tempStudent); } return *students; } }
const QList<Project*>& DBimpl::getAllProjects(){ QSqlQuery query; query.prepare(DatabaseQueries::selectAllProjects); if (!query.exec()) { throw generateException(query); } else { QList<Project*>* projects = new QList<Project*>; Student* tempStudent; QString tempDescription; QString tempTitle = ""; QString tempUsername; int tempTeamMin; int tempTeamMax; int tempID = -1; Project* tempProject = new Project(tempID,tempTitle); int tempStudentID; while (query.next()) { tempID = query.value(0).toInt(); qDebug () << "DB " << query.value(1).toInt(); if (tempProject->getID() != tempID) { tempTitle = QString(query.value(2).toString()); tempProject = new Project(tempID,tempTitle); tempProject->setResultsAvailable(query.value(1).toInt()); tempDescription = QString(query.value(3).toString()); tempTeamMin = query.value(4).toInt(); tempTeamMax = query.value(5).toInt(); tempProject->setDescription(tempDescription); tempProject->setTeamMax(tempTeamMax); tempProject->setTeamMin(tempTeamMin); projects->append(tempProject); } tempStudentID = query.value(8).toInt(); tempUsername = query.value(9).toString(); tempStudent = new Student(tempStudentID,tempUsername); tempProject->registerStudent(*tempStudent); tempStudent->setQualifications(getAllQualifications(tempStudentID)); } return *projects; } }
void NetworkStack_receive(JNIEnv * env , jobject obj , jlong listenTimeout , jobject buffer , jobject callbackContext, NetworkStackBase *networkStack) { if (!networkStack->isReady()) { generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Uninitialized network stack"); return ; } JavaLog::setJavalogEnviroment(env,obj); if (buffer == NULL && callbackContext == NULL) { generateException(env,"Native : No Buffer or callback context."); return; } networkStack->initializeCallback(env , buffer , callbackContext); networkStack->receive(listenTimeout); }
JNIEXPORT void JNICALL Java_dimes_measurements_nio_MacLevelNetworkStack_setPacketFilter (JNIEnv *env , jobject obj , jobjectArray filterIntArray){ #ifdef DIMES_WINDOWS if (!macLevelStack.isReady()) { generateException(env,"Network Stack must be initialized before setting Packet filter"); return; } int arraySize = env->GetArrayLength(filterIntArray); if (arraySize == 0) { generateException(env,"Empty Filter accepted."); return; } struct bpf_program filterProgram; filterProgram.bf_len=arraySize; filterProgram.bf_insns = new struct bpf_insn [arraySize]; for (int i=0; i<arraySize; i++) { jobject anObject = env->GetObjectArrayElement(filterIntArray , i); jintArray internalArray = (jintArray)anObject; int internalArraySize = env->GetArrayLength(internalArray); if (internalArraySize!=4) { generateException(env,"Malformed Filter instruction. Each instruction must have 4 integers."); return; } jint* instructions = env->GetIntArrayElements(internalArray , NULL); filterProgram.bf_insns[i].code = (USHORT)instructions[0]; filterProgram.bf_insns[i].jt = (UCHAR)instructions[1]; filterProgram.bf_insns[i].jf = (UCHAR)instructions[2]; filterProgram.bf_insns[i].k = (int)instructions[3]; } macLevelStack.serPacketFilter(&filterProgram); delete filterProgram.bf_insns; #endif }
void sehBegin(unsigned int interrupt_number) { msg("Initiating SEH processing of INT %d\n", interrupt_number); switch (interrupt_number) { case 0: generateException(DIV_ZERO_EXCEPTION); break; case 1: generateException(DEBUG_EXCEPTION); break; case 3: generateException(BREAKPOINT_EXCEPTION); break; case 6: generateException(UNDEFINED_OPCODE_EXCEPTION); break; case 14: generateException(MEM_ACCESS); break; } }
jlong NetworkStack_sendPacket(JNIEnv * env , jobject obj , jbyteArray array , jint timestampPosition , jint chksumPosition , NetworkStackBase *networkStack ){ // check for initialization : if (!networkStack->isReady()) { generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Uninitialized network stack"); return -1; } JavaLog::setJavalogEnviroment(env,obj); int arrayLength = env->GetArrayLength(array); jbyte *packetBytesArray = env->GetByteArrayElements(array,NULL); jlong sendTime = networkStack->sendPacket(packetBytesArray,arrayLength,(int)timestampPosition , (int)chksumPosition); return sendTime; }
jlongArray NetworkStack_send(JNIEnv * env , jobject obj ,NetworkStackBase *networkStack){ if (!networkStack->isReady()) { generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Uninitialized network stack"); return NULL; } JavaLog::setJavalogEnviroment(env,obj); int packetsNumber = networkStack->getRegisteredPacketsNum(); //JavaLog::javalogf(LEVEL_INFO , "Initializing %d send times...",packetsNumber); jlong *tempArray = new jlong[packetsNumber]; networkStack->sendRegisteredPackets(tempArray); jlongArray sendTimesArray = env->NewLongArray(packetsNumber); env->SetLongArrayRegion(sendTimesArray , 0 , packetsNumber , tempArray); delete tempArray; return sendTimesArray; }
int DBimpl::insertStudents() { QSqlQuery qry; qry.prepare("SELECT * FROM Students"); if (!qry.exec()) throw generateException(qry); else{ if (!qry.next()) { int num_students = 25; QString usernamePrefix = "Student"; Student* tempStudent; Qualification* qual; QList<Qualification*> qualList; for (int i = 0; i < num_students;i++) { tempStudent = new Student(-1,usernamePrefix+(65+i)); createStudent(*tempStudent); qualList = getAllQualifications(tempStudent->getID()); for (int i = 0;i < qualList.count();i++) { qual = qualList.at(i); qual->setExpectationRating(1 + (std::rand() % (int)(5- 1 + 1))); qual->setQualificationRating(1 + (std::rand() % (int)(5 - 1 + 1))); createQualificationEntry(tempStudent->getID(),*qualList.at(i)); } } } } return 1; }
const QList<Team*>& DBimpl::getTeamsbyProjectID (const int& projectID){ QSqlQuery query; query.prepare(DatabaseQueries::getTeamsByProject); query.bindValue(":projectID",projectID); if (!query.exec()) { throw generateException(query); } else { QList<Team*>* teams = new QList<Team*> (); int teamID = -1; int tempID; int tempStudentID; while (query.next()) { tempID = query.value(1).toInt(); if (teamID != tempID) { teamID = tempID; Team* team = new Team(teamID); teams->append(team); qDebug () << query.value(2).toString(); team->setResultDisplay(query.value(2).toString()); } tempStudentID = query.value(0).toInt(); teams->last()->addStudent(tempStudentID); } return *teams; } }
const QList<Qualification*>& DBimpl::getAllQualifications(const int& studentID) { QSqlQuery query; query.prepare(DatabaseQueries::getQualificationsByStudent); query.bindValue(":studentID",studentID); if (!query.exec()) { throw generateException(query); } else { QList<Qualification*>* qualifications = new QList<Qualification*>; Qualification* tempQualification; int displayID; QString title ; QString expectationValue; QString qualificationValue; int qualificationID ; int qualificationRating; int expectationRating; while (query.next()) { displayID = query.value(0).toInt(); title = query.value(1).toString(); expectationValue = QString(query.value(2).toString()); qualificationValue = QString(query.value(5).toString()); qualificationID = query.value(6).toInt(); qualificationRating = query.value(7).toInt(); expectationRating = query.value(8).toInt(); tempQualification = new Qualification(displayID,qualificationID,title,expectationValue, qualificationValue,qualificationRating,expectationRating); qualifications->append(tempQualification); } return *qualifications; } }
void NetworkStack_registerPacket(JNIEnv * env , jobject obj , jlong sendTime , jbyteArray packetBuffer , jint timestampPosition , jint chksumPosition , NetworkStackBase *networkStack) { if (!networkStack->isReady()) { generateException(env,MEASUREMENT_INITIALIZATION_EXCEPTION,"Uninitialized network stack"); return ; } JavaLog::setJavalogEnviroment(env,obj); int arrayLength = (int)env->GetArrayLength(packetBuffer); jboolean isCopy; jbyte *packetBytesArrayJava = env->GetByteArrayElements(packetBuffer,&isCopy); jbyte *packetBytesArray = new jbyte[arrayLength]; memcpy(packetBytesArray, packetBytesArrayJava, arrayLength); networkStack->registerPacket(sendTime , packetBytesArray,arrayLength,(int)timestampPosition,(int)chksumPosition); if (isCopy) { env->ReleaseByteArrayElements(packetBuffer, packetBytesArrayJava, JNI_ABORT); } }
int DBimpl::updateQualification(const int& studentID,const Qualification& qualification) { QSqlQuery query; query.prepare(DatabaseQueries::updateQualificationByStudent); query.bindValue(":qualificationRating",qualification.getQualificationRating()); query.bindValue(":expectationRating",qualification.getExpectationRating()); query.bindValue(":studentID",studentID); query.bindValue(":displayID",qualification.getDisplayID()); if(!query.exec()) { throw generateException(query); return 0; } else { return 1; } }
int DBimpl::removeStudentFromProject(const int projectID,const Student& student){ QSqlQuery query; query.prepare(DatabaseQueries::removeStudentFromProject); query.bindValue(":studentID",student.getID()); query.bindValue(":projectID",projectID); if(!query.exec()) { throw generateException(query); return 0; } else { return 1; } }
void CpuRiscV_Functional::updatePipeline() { IInstruction *instr; CpuContextType *pContext = getpContext(); if (dport.valid) { dport.valid = 0; updateDebugPort(); } pContext->pc = pContext->npc; if (isRunning()) { fetchInstruction(); } updateState(); if (pContext->reset) { updateQueue(); reset(); return; } instr = decodeInstruction(cacheline_); if (isRunning()) { last_hit_breakpoint_ = ~0; if (instr) { executeInstruction(instr, cacheline_); } else { pContext->npc += 4; generateException(EXCEPTION_InstrIllegal, pContext); RISCV_info("[%" RV_PRI64 "d] pc:%08x: %08x \t illegal instruction", getStepCounter(), static_cast<uint32_t>(pContext->pc), cacheline_[0]); } } updateQueue(); handleTrap(); }
const Student& DBimpl::getStudentByID(const int& studentID){ QSqlQuery query; query.prepare(DatabaseQueries::getStudentByID); query.bindValue(":studentID",studentID); if (!query.exec()) { qDebug() << query.lastError(); qDebug() << query.lastQuery(); throw generateException(query); } else { QString tempUsername; int tempID; Student* tempStudent = new Student; if (query.next()) { //first column is 0 tempID = query.value(0).toInt(); tempUsername = QString(query.value(1).toString()); tempStudent = new Student(tempID,tempUsername); qDebug()<< "getAllQualifications"<<getAllQualifications(tempID); tempStudent->setQualifications(getAllQualifications(tempID)); } return *tempStudent; } }
const Student* DBimpl::authenticate(const QString& username){ QSqlQuery query; query.prepare("SELECT * from Students where studentName = :username"); query.bindValue(":username",username); if (!query.exec()) { qDebug() << query.lastError(); qDebug() << query.lastQuery(); throw generateException(query); } else { QString tempUsername; int tempID; Student* tempStudent = 0; if (query.next()) { //first column is 0 tempID = query.value(0).toInt(); tempUsername = QString(query.value(1).toString()); tempStudent = new Student(tempID,tempUsername); QList<Qualification*> temp = getAllQualifications(tempID); tempStudent->qualifications = temp; return tempStudent; } else return 0; } }
void IllegalOpcodeException() { generateException(UNDEFINED_OPCODE_EXCEPTION); }
void memoryAccessException() { generateException(MEM_ACCESS); }
const QList<Project*>& DBimpl::getOpenProjectsByStudent(const int& studentID){ if (studentID > 0) { QSqlQuery query; query.prepare(DatabaseQueries::getAvailableProjects); query.bindValue(":studentID",studentID); if(!query.exec()) { throw generateException(query); } else { QList<Project*>* projects = new QList<Project*>; Student* tempStudent; QString tempDescription; QString tempTitle = ""; QString tempUsername; int tempTeamMin; int tempTeamMax; int tempID = -1; Project* tempProject = new Project(tempID,tempTitle); int tempStudentID; while (query.next()) { tempID = query.value(0).toInt(); tempProject->setResultsAvailable(query.value(1).toInt()); if (tempProject != NULL) { if (tempProject->getID() != tempID) { tempTitle = QString(query.value(2).toString()); tempProject = new Project(tempID,tempTitle); tempDescription = QString(query.value(3).toString()); tempTeamMin = query.value(4).toInt(); tempTeamMax = query.value(5).toInt(); tempProject->setDescription(tempDescription); tempProject->setTeamMax(tempTeamMax); tempProject->setTeamMin(tempTeamMin); projects->append(tempProject); } tempStudentID = query.value(8).toInt(); tempUsername = query.value(9).toString(); tempStudent = new Student(tempStudentID,tempUsername); tempStudent->qualifications = getAllQualifications(tempStudentID); tempProject->registerStudent(*tempStudent); } } return *projects; } } throw generateCustomSQLException("INVALID INPUT FOR STUDENT ID -> " + studentID); }
void generateException(JNIEnv * env , char *message ){ generateException(env,MEASUREMENT_EXCEPTION,message); }
int DBimpl::insertValuesintoQualifications(){ QSqlQuery qry; qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (1,'Core GPA','What is your core GPA?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (2,'Git Version Control','How familiar are you with the GIT?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (3, 'Object Oriented Programming', 'How familiar are you with object-oriented Programming?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (4, 'Systems Programming', 'How familiar are you with systems programming?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (5, 'Web Development', 'How much experience do you have in Web Development?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (6, 'UX Design','How much experience do you have in UX Design? ')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (7, 'Punctuality', 'How punctual are you?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (8, 'Night Owl', 'How much of a night owl are you?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (9, 'Documentation', ' How much experience do you have in documentation?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (10, 'Leadership Skills', ' How would you rate your leadership skills?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (11, 'Locally or Remotely ', ' Do you prefer to work locally or remotely?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Qualifications (qid,qtitle,qualificationValue) VALUES (12, 'Communication Skills', ' How would you rate you communication skills?')"); if (!qry.exec()) throw generateException(qry); return 1; }
void breakpointException() { generateException(BREAKPOINT_EXCEPTION); }
void divzeroException() { generateException(DIV_ZERO_EXCEPTION); }
void debugException() { generateException(DEBUG_EXCEPTION); }
int DBimpl::insertValuesintoExpectations(){ QSqlQuery qry; qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (1, 'Core GPA', 'What Core GPA do you expect from your team mates?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (2, 'Git Version Control','How familiar do you want your team mates to know Git?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (3, 'Object Oriented Programming', 'How familiar do you want your team mates to know Object Oriented Programming?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (4, 'Systems Programming','How familiar do you want your team mates to know Systems Programming?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (5, 'Web Development', 'How much experience do you expect your team mates to have in Web Development?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (6, 'UX Design', 'How much experience do you want your team mates to have in UX Design?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (7, 'Punctuality', 'How punctual do you want your team mates to be?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (8, 'Night Owl', 'How much of a night owl do you want your team mates to be?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (9, 'Documentation ', 'How much experience in documentation do you want your team mates to have?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (10, 'Leadership Skills', 'How much experience do you want your team mates to have in leadership?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (11, 'Locally or Remotely ', 'Do you want your team mates to work locally or remotely?')"); if (!qry.exec()) throw generateException(qry); qry.prepare("INSERT OR IGNORE INTO Expectations (eID,etitle,expectationValue) VALUES (12, 'Communication Skills', 'How important is it for your teams to have communication skills?')"); if (!qry.exec()) throw generateException(qry); return 1; }