69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#include "ApiGateway.h"
|
|
|
|
#include "lib/logging/logging.h"
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <mutex>
|
|
|
|
using namespace bts::api::gateway;
|
|
|
|
namespace bts {
|
|
namespace http {
|
|
|
|
struct ApiGatewayImpl {
|
|
std::mutex _m;
|
|
const api::ServiceContext& _ctx;
|
|
std::unordered_map<std::string, api::ApiClient*> _apiclient;
|
|
std::vector<api::TableSubscription> _subscriptions;
|
|
|
|
ApiGatewayImpl(const api::ServiceContext& ctx) :
|
|
_m(),
|
|
_ctx(ctx),
|
|
_apiclient(),
|
|
_subscriptions()
|
|
{ }
|
|
|
|
void handle_login(const GatewayLogin& login, GatewayLoginResult* presult) {
|
|
LOG(Api,Info, "Logon request for {}", login.username());
|
|
if (login.username() == "bts") {
|
|
presult->set_is_valid(true);
|
|
presult->set_token("SuperSecretToken");
|
|
}
|
|
else {
|
|
presult->set_is_valid(false);
|
|
presult->set_reason("Your mother is a hamster and your father smelt of elderberries.");
|
|
}
|
|
}
|
|
|
|
// void handle_call()
|
|
// void handle_subscribe()
|
|
// void handle_unsubscribe()
|
|
|
|
};
|
|
|
|
|
|
ApiGatewaySession::ApiGatewaySession() : _me() {}
|
|
ApiGatewaySession::ApiGatewaySession(const api::ServiceContext& ctx) :
|
|
_me(std::make_unique<ApiGatewayImpl>(ctx))
|
|
{}
|
|
ApiGatewaySession::~ApiGatewaySession(){}
|
|
|
|
|
|
|
|
const GatewayResponse ApiGatewaySession::handle(const api::gateway::GatewayRequest& request) {
|
|
GatewayResponse response;
|
|
switch(request.request_case()) {
|
|
case GatewayRequest::kLogin:
|
|
_me->handle_login(request.login(), response.mutable_logon());
|
|
break;
|
|
case GatewayRequest::kCall:
|
|
case GatewayRequest::kSubscribe:
|
|
case GatewayRequest::kUnsubscribe:
|
|
case GatewayRequest::REQUEST_NOT_SET:
|
|
break;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
}} |