This repository has been archived on 2018-05-28. You can view files and clone it, but cannot push or open issues or pull requests.
BBB-Simple-ACS/client/reader_timer.cpp

46 lines
1.3 KiB
C++

#include "reader_timer.hpp"
#include "factory.hpp"
#include <boost/date_time.hpp>
#include <boost/bind.hpp>
namespace acs
{
void reader_timer::callback_handler(const boost::system::error_code& ec)
{
if (ec)
exit(1);
auto factory = factory::get();
auto state = factory->get_state();
if (state->get_status() == state::idle) {
auto reader = factory->get_reader();
auto uid = reader->find_card();
if (uid) {
std::cout << "UID: " << uid << std::endl;
auto stu_num = reader->get_student_number();
if (conn_->get_stunum(uid) == stu_num) {
controller_->authorized();
} else {
controller_->forbidden();
}
}
}
defer();
}
void reader_timer::defer()
{
timer_.expires_from_now(boost::posix_time::millisec(200));
timer_.async_wait(boost::bind(
&reader_timer::callback_handler, this, boost::asio::placeholders::error));
}
reader_timer::reader_timer() : loop_(
factory::get()->get_loop()), timer_(
*loop_->get_io_service()), controller_(
factory::get()->get_controller()), conn_(factory::get()->get_mysql())
{
defer();
}
}