Skip to content

Commit

Permalink
Manual fixes to the cpp sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
roberthbailey committed Jul 12, 2019
1 parent a16ac8f commit b80766b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions sdks/cpp/include/agones/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ class SDK {

// Retrieve the current GameServer data
AGONES_EXPORT grpc::Status GameServer(
stable::agones::dev::sdk::GameServer* response);
agones::dev::sdk::GameServer* response);

// Marks the Game Server as ready to shutdown
AGONES_EXPORT grpc::Status Shutdown();

// SetLabel sets a metadata label on the `GameServer` with the prefix
// stable.agones.dev/sdk-
// agones.dev/sdk-
AGONES_EXPORT grpc::Status SetLabel(std::string key, std::string value);

// SetAnnotation sets a metadata annotation on the `GameServer` with the
// prefix stable.agones.dev/sdk-
// prefix agones.dev/sdk-
AGONES_EXPORT grpc::Status SetAnnotation(std::string key, std::string value);

// Watch the GameServer configuration, and fire the callback
// when an update occurs.
// This is a blocking function, and as such you will likely want to run it
// inside a thread.
AGONES_EXPORT grpc::Status WatchGameServer(
const std::function<void(stable::agones::dev::sdk::GameServer)>&
const std::function<void(agones::dev::sdk::GameServer)>&
callback);

private:
Expand Down
38 changes: 19 additions & 19 deletions sdks/cpp/src/agones/sdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace agones {
class SDKImpl final {
public:
std::shared_ptr<grpc::Channel> channel_;
std::unique_ptr<stable::agones::dev::sdk::SDK::Stub> stub_;
std::unique_ptr<grpc::ClientWriter<stable::agones::dev::sdk::Empty>> health_;
std::unique_ptr<agones::dev::sdk::SDK::Stub> stub_;
std::unique_ptr<grpc::ClientWriter<agones::dev::sdk::Empty>> health_;
};

SDK::SDK() : pimpl_{std::make_unique<SDKImpl>()} {
Expand All @@ -43,10 +43,10 @@ bool SDK::Connect() {
return false;
}

pimpl_->stub_ = stable::agones::dev::sdk::SDK::NewStub(pimpl_->channel_);
pimpl_->stub_ = agones::dev::sdk::SDK::NewStub(pimpl_->channel_);

// make the health connection
stable::agones::dev::sdk::Empty response;
agones::dev::sdk::Empty response;
pimpl_->health_ = pimpl_->stub_->Health(new grpc::ClientContext(), &response);

return true;
Expand All @@ -56,33 +56,33 @@ grpc::Status SDK::Ready() {
grpc::ClientContext *context = new grpc::ClientContext();
context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)));
stable::agones::dev::sdk::Empty request;
stable::agones::dev::sdk::Empty response;
agones::dev::sdk::Empty request;
agones::dev::sdk::Empty response;

return pimpl_->stub_->Ready(context, request, &response);
}

bool SDK::Health() {
stable::agones::dev::sdk::Empty request;
agones::dev::sdk::Empty request;
return pimpl_->health_->Write(request);
}

grpc::Status SDK::GameServer(stable::agones::dev::sdk::GameServer *response) {
grpc::Status SDK::GameServer(agones::dev::sdk::GameServer *response) {
grpc::ClientContext *context = new grpc::ClientContext();
context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)));
stable::agones::dev::sdk::Empty request;
agones::dev::sdk::Empty request;

return pimpl_->stub_->GetGameServer(context, request, response);
}

grpc::Status SDK::WatchGameServer(
const std::function<void(stable::agones::dev::sdk::GameServer)> &callback) {
const std::function<void(agones::dev::sdk::GameServer)> &callback) {
grpc::ClientContext *context = new grpc::ClientContext();
stable::agones::dev::sdk::Empty request;
stable::agones::dev::sdk::GameServer gameServer;
agones::dev::sdk::Empty request;
agones::dev::sdk::GameServer gameServer;

std::unique_ptr<grpc::ClientReader<stable::agones::dev::sdk::GameServer>>
std::unique_ptr<grpc::ClientReader<agones::dev::sdk::GameServer>>
reader = pimpl_->stub_->WatchGameServer(context, request);
while (reader->Read(&gameServer)) {
callback(gameServer);
Expand All @@ -94,8 +94,8 @@ grpc::Status SDK::Shutdown() {
grpc::ClientContext *context = new grpc::ClientContext();
context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)));
stable::agones::dev::sdk::Empty request;
stable::agones::dev::sdk::Empty response;
agones::dev::sdk::Empty request;
agones::dev::sdk::Empty response;

return pimpl_->stub_->Shutdown(context, request, &response);
}
Expand All @@ -105,11 +105,11 @@ grpc::Status SDK::SetLabel(std::string key, std::string value) {
context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)));

stable::agones::dev::sdk::KeyValue request;
agones::dev::sdk::KeyValue request;
request.set_key(key);
request.set_value(value);

stable::agones::dev::sdk::Empty response;
agones::dev::sdk::Empty response;

return pimpl_->stub_->SetLabel(context, request, &response);
}
Expand All @@ -119,11 +119,11 @@ grpc::Status SDK::SetAnnotation(std::string key, std::string value) {
context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)));

stable::agones::dev::sdk::KeyValue request;
agones::dev::sdk::KeyValue request;
request.set_key(key);
request.set_value(value);

stable::agones::dev::sdk::Empty response;
agones::dev::sdk::Empty response;

return pimpl_->stub_->SetAnnotation(context, request, &response);
}
Expand Down

0 comments on commit b80766b

Please sign in to comment.