agones.dev/agones@v1.53.0/sdks/cpp/include/agones/sdk.h (about) 1 // Copyright 2017 Google LLC All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef AGONES_CPP_SDK_H_ 16 #define AGONES_CPP_SDK_H_ 17 18 #include "agones_global.h" 19 #include "sdk.grpc.pb.h" 20 21 namespace agones { 22 23 // The Agones SDK 24 class SDK { 25 public: 26 // Creates a new instance of the SDK. 27 // Does not connect to anything. 28 AGONES_EXPORT SDK(); 29 AGONES_EXPORT ~SDK(); 30 SDK(const SDK&) = delete; 31 SDK& operator=(const SDK&) = delete; 32 33 // Must be called before any other functions on the SDK. 34 // This will attempt to do a handshake with the sdk server, timing out 35 // after 30 seconds. 36 // Returns true if the connection was successful, false if not. 37 AGONES_EXPORT bool Connect(); 38 39 // Marks the Game Server as ready to receive connections 40 AGONES_EXPORT grpc::Status Ready(); 41 42 // Self marks this gameserver as Allocated. 43 AGONES_EXPORT grpc::Status Allocate(); 44 45 // Marks the Game Server as Reserved for a given number of seconds, at which 46 // point it will return the GameServer to a Ready state. 47 AGONES_EXPORT grpc::Status Reserve(std::chrono::seconds seconds); 48 49 // Send Health ping. This is a synchronous request. 50 AGONES_EXPORT bool Health(); 51 52 // Retrieve the current GameServer data 53 AGONES_EXPORT grpc::Status GameServer(agones::dev::sdk::GameServer* response); 54 55 // Marks the Game Server as ready to shutdown 56 AGONES_EXPORT grpc::Status Shutdown(); 57 58 // SetLabel sets a metadata label on the `GameServer` with the prefix 59 // agones.dev/sdk- 60 AGONES_EXPORT grpc::Status SetLabel(std::string key, std::string value); 61 62 // SetAnnotation sets a metadata annotation on the `GameServer` with the 63 // prefix agones.dev/sdk- 64 AGONES_EXPORT grpc::Status SetAnnotation(std::string key, std::string value); 65 66 // Watch the GameServer configuration, and fire the callback 67 // when an update occurs. 68 // This is a blocking function, and as such you will likely want to run it 69 // inside a thread. 70 AGONES_EXPORT grpc::Status WatchGameServer( 71 const std::function<void(const agones::dev::sdk::GameServer&)>& callback); 72 73 private: 74 struct SDKImpl; 75 std::unique_ptr<SDKImpl> pimpl_; 76 }; 77 78 } // namespace agones 79 #endif // AGONES_CPP_SDK_H_