67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
//SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <mutex>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "request/accepting.h"
|
|
#include "taskmanager/scheduler.h"
|
|
|
|
#include "database/schema/asset.h"
|
|
#include "database/schema/transaction.h"
|
|
|
|
class Session : public Accepting {
|
|
public:
|
|
Session (
|
|
std::weak_ptr<TM::Scheduler> scheduler,
|
|
unsigned int id,
|
|
unsigned int owner,
|
|
const std::string& access,
|
|
const std::string& renew,
|
|
unsigned int timeout
|
|
);
|
|
Session (const Session&) = delete;
|
|
Session (Session&& other) = delete;
|
|
~Session ();
|
|
Session& operator = (const Session&) = delete;
|
|
Session& operator = (Session&& other) = delete;
|
|
|
|
std::string getAccessToken () const;
|
|
std::string getRenewToken () const;
|
|
void accept (std::unique_ptr<Request> request) override;
|
|
|
|
const unsigned int id;
|
|
const unsigned int owner;
|
|
|
|
void assetAdded (const DB::Asset& asset);
|
|
void assetChanged (const DB::Asset& asset);
|
|
void assetRemoved (unsigned int assetId);
|
|
|
|
void transactionAdded(const DB::Transaction& txn);
|
|
void transactionChanged(const DB::Transaction& txn);
|
|
void transactionRemoved(unsigned int txnId);
|
|
|
|
private:
|
|
void onTimeout ();
|
|
void sendUpdates (std::unique_ptr<Request> request);
|
|
void checkUpdates ();
|
|
|
|
void static removeByID (nlohmann::json& array, unsigned int id);
|
|
|
|
private:
|
|
std::weak_ptr<TM::Scheduler> scheduler;
|
|
std::string access;
|
|
std::string renew;
|
|
std::unique_ptr<Request> polling;
|
|
TM::Record::ID timeoutId;
|
|
TM::Scheduler::Delay timeout;
|
|
std::mutex mtx;
|
|
|
|
std::map<std::string, std::map<std::string, nlohmann::json>> cache;
|
|
};
|