void CHandleMessage::handleLeaveEarly(Buf* p) { #ifdef __DEBUG_HANDLE_HEAD_ cout << "CT_LeaveEarly\n"; #endif epTeacher* p_teacher = const_cast<epTeacher*>(EPMANAGER->getTeacherByFd(p->getfd())); CHECK_P(p_teacher); cLeaveEarly tmp; UNPACKET(p, tmp); epClassroom* p_classroom = EPMANAGER->getClassroomByFd(p->getfd()); CHECK_P(p_classroom); const epStudent* p_student = EPMANAGER->getStudentByIdFromClassroom(tmp.student_id()); CHECK_P(p_student); Buf* p_buf_1 = packet(ST_LeaveEarly, p_student->fd_); CHECK_P(p_buf_1); SINGLE->sendqueue.enqueue(p_buf_1); sUpdateStudentStatus suss; suss.set_student_id(tmp.student_id()); suss.set_us(US_OFFLINE); suss.set_login_type(LT_STUDENT); Buf* p_buf = packet(ST_UpdateStudentStatus, suss, p->getfd()); CHECK_P(p_buf); p_classroom->sendtoAll(p_buf); EPMANAGER->moveStudentToUser(tmp.student_id()); RETURN(p); }
void CHandleMessage::handleGetPuzzleInfo(Buf* p) { #ifdef __DEBUG_HANDLE_HEAD_ cout << "CT_GetPuzzleInfo\n"; #endif epClassroom* p_classroom = EPMANAGER->getClassroomByFd(p->getfd()); CHECK_P(p_classroom); PuzzleInfo pi; UNPACKET(p, pi); const epGroup* p_group = pi.has_group_id() ? p_classroom->getGroupById(pi.group_id()) : p_classroom->getGroupByFd(p->getfd()); CHECK_P(p_group); std::cout << "CHandleMessage::handleGetPuzzleInfo : " << "group_id = " << pi.group_id() << std::endl; std::cout << "CHandleMessage::handleGetPuzzleInfo : " << "puzzle_id = " << pi.puzzle_id() << std::endl; PuzzleInfo tmp; int random = p_group->random_ + pi.puzzle_id(); if (0 != random) tmp.set_random(random); if (0 != p_group->id_) tmp.set_group_id(p_group->id_); tmp.set_puzzle_id(pi.puzzle_id()); Buf* pBuf = packet(ST_GetPuzzleInfo, tmp, p->getfd()); CHECK_P(pBuf); SINGLE->sendqueue.enqueue(pBuf); RETURN(p); }
//joinPoint is the point on the sphere closest to this line. void C3dBoundedLine::closestPointOnSphere(const C3dPolylineControlPointWithThickness & closestHeadPart, C3dWorldPoint & joinPoint, double & dDistance) const { const C3dWorldPoint closestOnLine = closestPoint(closestHeadPart.getPoint()); const TEigen3dPoint vectorToCentre = closestHeadPart.getPoint() - closestOnLine; const double dDistCentreToLine = vectorToCentre.norm(); const double dRad = closestHeadPart.getRad(); //2 cases: 1: line intersects sphere if(dDistCentreToLine < dRad) { //The line might poke a little way into the sphere. Change to unbounded to simplify computations: const C3dWorldPoint closestOnUnboundedLine = unboundedLine().closestPoint(closestHeadPart.getPoint()); const double dDistCentreToUnboundedLine = (closestHeadPart.getPoint() - closestOnUnboundedLine).norm(); //The closest on the sphere, the closest point on the line, and the intersection point form a right angle triangle. //Select the point on the line where the hypotenuse has length dRad // dRad^2 = dDistCentreToLine^2 + offset^2 const double dOffset = sqrt(sqr(dRad) - sqr(dDistCentreToUnboundedLine)); joinPoint = closestOnUnboundedLine - dOffset*direction(); dDistance = 0; } else { //2: line doesn't intersect sphere joinPoint = closestHeadPart.getPoint() - dRad*vectorToCentre.normalized(); dDistance = dDistCentreToLine - dRad; } const double dDistJoinPointToSphere = (joinPoint - closestHeadPart.getPoint()).norm(); CHECK_P(!zero(dDistJoinPointToSphere-dRad), dDistJoinPointToSphere, "Error computing closestPointOnSphere"); }
void CHandleMessage::handleGetStoreBooksList (Buf *p) { #ifdef __DEBUG_HANDLE_HEAD_ cout << "CT_GetStoreBooksList" << endl; #endif const epUser* pUser = EPMANAGER->getUserByFd(p->getfd()); CHECK_P(pUser); cGetPublicBooksList cgbl; UNPACKET(p, cgbl); bookList book_list; bookNode* book_node; try { MutexLockGuard guard(DATABASE->m_mutex); PreparedStatement* pstmt = DATABASE->preStatement(SQL_GET_COURSE_LIST_IN_STORE); ResultSet* prst = pstmt->executeQuery (); while (prst->next ()) { book_node = book_list.add_book_list(); book_node->set_book_id (prst->getInt ("book_id")); book_node->set_book_name(prst->getString("book_name")); book_node->set_book_type(prst->getInt ("book_type")); book_node->set_auth_id (prst->getInt ("auth_id")); book_node->set_auth_type((enum LoginType)prst->getInt ("auth_type")); #ifdef __DEBUG__ std::cout << "book_node->book_id () = " << book_node->book_id () << std::endl; std::cout << "book_node->book_name() = " << book_node->book_name() << std::endl; std::cout << "book_node->book_type() = " << book_node->book_type() << std::endl; std::cout << "book_node->auth_id () = " << book_node->auth_id () << std::endl; std::cout << "book_node->auth_type() = " << book_node->auth_type() << std::endl; #endif } delete prst; delete pstmt; }catch (SQLException e) { PRINT_CATCH(e); RETURN(p); } Buf* pBuf = packet_list(ST_GetStoreBooksList, book_list, p->getfd()); CHECK_P(pBuf); SINGLE->sendqueue.enqueue(pBuf); RETURN(p); }