// // Copyright (C) 2014 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // namespace GooglePlayGames.BasicApi.Nearby { using GooglePlayGames.OurUtils; /// /// Represents a response to a connection request, including status, payload, and identifying information. /// public struct ConnectionResponse { private static readonly byte[] EmptyPayload = new byte[0]; /// /// Status codes representing the outcome of a connection request. /// public enum Status { /// /// Indicates that the connection was accepted. /// Accepted, /// /// Indicates that the connection was rejected. /// Rejected, /// /// Indicates that an internal error occurred. /// ErrorInternal, /// /// Indicates that the device is not connected to a network. /// ErrorNetworkNotConnected, /// /// Indicates that the remote endpoint is not connected. /// ErrorEndpointNotConnected, /// /// Indicates that the endpoints are already connected. /// ErrorAlreadyConnected } private readonly long mLocalClientId; private readonly string mRemoteEndpointId; private readonly Status mResponseStatus; private readonly byte[] mPayload; /// /// Initializes a new instance of the struct. /// /// The ID of the local client. /// The ID of the remote endpoint. /// The status of the connection response. /// The payload data included with the response. private ConnectionResponse(long localClientId, string remoteEndpointId, Status code, byte[] payload) { this.mLocalClientId = localClientId; this.mRemoteEndpointId = Misc.CheckNotNull(remoteEndpointId); this.mResponseStatus = code; this.mPayload = Misc.CheckNotNull(payload); } /// /// Gets the ID of the local client. /// public long LocalClientId { get { return mLocalClientId; } } /// /// Gets the ID of the remote endpoint responding to the connection request. /// public string RemoteEndpointId { get { return mRemoteEndpointId; } } /// /// Gets the status of the connection response. /// public Status ResponseStatus { get { return mResponseStatus; } } /// /// Gets the payload sent with the connection response. /// public byte[] Payload { get { return mPayload; } } /// /// Creates a response indicating the connection was rejected. /// public static ConnectionResponse Rejected(long localClientId, string remoteEndpointId) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.Rejected, EmptyPayload); } /// /// Creates a response indicating the device is not connected to a network. /// public static ConnectionResponse NetworkNotConnected(long localClientId, string remoteEndpointId) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorNetworkNotConnected, EmptyPayload); } /// /// Creates a response indicating an internal error occurred. /// public static ConnectionResponse InternalError(long localClientId, string remoteEndpointId) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorInternal, EmptyPayload); } /// /// Creates a response indicating the remote endpoint is not connected. /// public static ConnectionResponse EndpointNotConnected(long localClientId, string remoteEndpointId) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorEndpointNotConnected, EmptyPayload); } /// /// Creates a response indicating the connection was accepted with a payload. /// public static ConnectionResponse Accepted(long localClientId, string remoteEndpointId, byte[] payload) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.Accepted, payload); } /// /// Creates a response indicating the endpoints are already connected. /// public static ConnectionResponse AlreadyConnected(long localClientId, string remoteEndpointId) { return new ConnectionResponse(localClientId, remoteEndpointId, Status.ErrorAlreadyConnected, EmptyPayload); } } }