1
0
forked from blue/pica
pica/server/session.cpp

45 lines
1.2 KiB
C++
Raw Normal View History

2023-12-30 22:42:11 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
2023-12-23 20:23:38 +00:00
#include "session.h"
2023-12-28 20:26:08 +00:00
#include "handler/poll.h"
2024-01-03 01:11:56 +00:00
Session::Session(
std::weak_ptr<TM::Scheduler> scheduler,
unsigned int id,
const std::string& access,
const std::string& renew
):
scheduler(scheduler),
2023-12-23 20:23:38 +00:00
id(id),
access(access),
2023-12-28 20:26:08 +00:00
renew(renew),
polling(nullptr)
2023-12-23 20:23:38 +00:00
{}
std::string Session::getAccessToken() const {
return access;
}
std::string Session::getRenewToken() const {
return renew;
}
2023-12-28 20:26:08 +00:00
void Session::accept(std::unique_ptr<Request> request) {
if (polling) {
2024-01-03 01:11:56 +00:00
Handler::Poll::error(*request.get(), Handler::Poll::Result::replace, Response::Status::ok);
//TODO unschedule
}
2023-12-28 20:26:08 +00:00
2024-01-03 01:11:56 +00:00
std::shared_ptr<TM::Scheduler> sch = scheduler.lock();
if (!sch) {
std::cerr << "Was unable to schedule polling timeout, replying with an error" << std::endl;
Handler::Poll::error(*request.get(), Handler::Poll::Result::unknownError, Response::Status::internalError);
return;
2023-12-28 20:26:08 +00:00
}
2024-01-03 01:11:56 +00:00
sch->schedule(std::bind(&Session::onTimeout, this), TM::Scheduler::Delay(5000));
2023-12-28 20:26:08 +00:00
polling = std::move(request);
2023-12-30 22:42:11 +00:00
}