Skip to content

Commit 496aa2e

Browse files
Robert Baileymarkmandel
authored andcommitted
C++ SDK: Update the function signature of WatchGameServer to use a (agones-dev#951)
const-reference. Also update the simple cpp example so that it still compiles.
1 parent c3bd424 commit 496aa2e

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎examples/cpp-simple/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ REPOSITORY = gcr.io/agones-images
2828
# Directory that this Makefile is in.
2929
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
3030
project_path := $(dir $(mkfile_path))
31-
server_tag = $(REPOSITORY)/cpp-simple-server:0.9
31+
server_tag = $(REPOSITORY)/cpp-simple-server:0.10
3232
root_path = $(realpath $(project_path)/../..)
3333

3434
# _____ _

‎examples/cpp-simple/server.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void DoHealth(std::shared_ptr<agones::SDK> sdk) {
3434
// watch GameServer Updates
3535
void WatchUpdates(std::shared_ptr<agones::SDK> sdk) {
3636
std::cout << "Starting to watch GameServer updates...\n" << std::flush;
37-
sdk->WatchGameServer([](agones::dev::sdk::GameServer gameserver) {
37+
sdk->WatchGameServer([](const agones::dev::sdk::GameServer& gameserver) {
3838
std::cout << "GameServer Update:\n" //
3939
<< "\tname: " << gameserver.object_meta().name() << "\n" //
4040
<< "\tstate: " << gameserver.status().state() << "\n"

‎sdks/cpp/include/agones/sdk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SDK {
6868
// This is a blocking function, and as such you will likely want to run it
6969
// inside a thread.
7070
AGONES_EXPORT grpc::Status WatchGameServer(
71-
const std::function<void(agones::dev::sdk::GameServer)>& callback);
71+
const std::function<void(const agones::dev::sdk::GameServer&)>& callback);
7272

7373
private:
7474
struct SDKImpl;

‎sdks/cpp/src/agones/sdk.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ grpc::Status SDK::GameServer(agones::dev::sdk::GameServer* response) {
9999
}
100100

101101
grpc::Status SDK::WatchGameServer(
102-
const std::function<void(agones::dev::sdk::GameServer)>& callback) {
102+
const std::function<void(const agones::dev::sdk::GameServer&)>& callback) {
103103
grpc::ClientContext context;
104104
agones::dev::sdk::Empty request;
105105
agones::dev::sdk::GameServer gameServer;

‎site/content/en/docs/Guides/Client SDKs/cpp.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ passing in a `stable::agones::dev::sdk::GameServer*` to push the results of the
119119
This function will return a grpc::Status object, from which we can call `status.ok()` to determine
120120
if the function completed successfully.
121121

122-
{{% feature expiryVersion="0.12.0" %}}
123122
```cpp
124123
stable::agones::dev::sdk::GameServer gameserver;
125124
grpc::Status status = sdk->GameServer(&gameserver);
@@ -140,31 +139,32 @@ sdk->WatchGameServer([](stable::agones::dev::sdk::GameServer gameserver){
140139
});
141140
```
142141
{{% /feature %}}
143-
{{% feature publishversion="0.12.0" %}}
142+
{{% feature publishVersion="0.12.0" %}}
144143
To get the details on the [backing `GameServer`]({{< relref "_index.md#gameserver" >}}) call `sdk->GameServer(&gameserver)`,
145144
passing in a `agones::dev::sdk::GameServer*` to push the results of the `GameServer` configuration into.
146145

147146
This function will return a grpc::Status object, from which we can call `status.ok()` to determine
148147
if the function completed successfully.
149148

150-
{{% feature expiryVersion="0.12.0" %}}
151149
```cpp
152150
agones::dev::sdk::GameServer gameserver;
153151
grpc::Status status = sdk->GameServer(&gameserver);
154152
if (!status.ok()) {...}
155153
```
156154
157155
To get [updates on the backing `GameServer`]({{< relref "_index.md#watchgameserver-function-gameserver" >}}) as they happen,
158-
call `sdk->WatchGameServer([](agones::dev::sdk::GameServer gameserver){...})`.
156+
call `sdk->WatchGameServer([](const agones::dev::sdk::GameServer& gameserver){...})`.
159157
160158
This will call the passed in `std::function`
161159
synchronously (this is a blocking function, so you may want to run it in its own thread) whenever the backing `GameServer`
162160
is updated.
163161
164162
```cpp
165-
sdk->WatchGameServer([](agones::dev::sdk::GameServer gameserver){
166-
std::cout << "GameServer Update, name: " << gameserver.object_meta().name() << std::endl;
167-
std::cout << "GameServer Update, state: " << gameserver.status().state() << std::endl;
163+
sdk->WatchGameServer([](const agones::dev::sdk::GameServer& gameserver){
164+
std::cout << "GameServer Update:\n" //
165+
<< "\tname: " << gameserver.object_meta().name() << "\n" //
166+
<< "\tstate: " << gameserver.status().state() << "\n"
167+
<< std::flush;
168168
});
169169
```
170170
{{% /feature %}}

0 commit comments

Comments
 (0)