62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "lib/utils/bts_export.h"
|
|
|
|
// client
|
|
#include "../core/ApiClientInterop.h"
|
|
#include "../core/ApiServerInterop.h"
|
|
// server
|
|
#include "ServerChannel.h"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace bts {
|
|
namespace api {
|
|
|
|
class ClientChannel;
|
|
struct ServiceContextImpl;
|
|
|
|
struct LoginResult {
|
|
LoginResult();
|
|
LoginResult(const std::string &);
|
|
bool success;
|
|
std::string reason;
|
|
};
|
|
|
|
class BTS_EXPORT ServiceContext {
|
|
std::shared_ptr<ServiceContextImpl> _self;
|
|
|
|
public:
|
|
ServiceContext(Quickbus *maybe_bus = nullptr);
|
|
// ServiceContext(ServiceContext& other) = default;
|
|
~ServiceContext();
|
|
|
|
template <class T> T locate(const char *qualifier = "") const {
|
|
return T(create_channel(T::name(), qualifier));
|
|
}
|
|
|
|
Quickbus &bus() const;
|
|
bool is_authenticated() const;
|
|
const std::shared_ptr<AuthToken> token() const;
|
|
const LoginResult
|
|
login(const std::string &username, const std::string &password);
|
|
void login(const AuthToken &token);
|
|
|
|
typedef std::function<void()> Action;
|
|
void post(const Action &, uint64_t delayms = 0);
|
|
|
|
private:
|
|
friend class ApiServer;
|
|
std::unique_ptr<ClientChannel>
|
|
create_channel(const char *, const char *) const;
|
|
ServerChannel publish(
|
|
ApiServer &service,
|
|
const std::string &service_type,
|
|
const std::string &qualifier) const;
|
|
};
|
|
|
|
} // namespace api
|
|
} // namespace bts
|