public override void processRequest(ref byte[] buf, int num_bytes, IServiceClientLink link) { var cb = new ServiceCallback(this, helper, buf, num_bytes, link, has_tracked_object, tracked_object); this.callbackId = cb.Uid; callback.AddCallback(cb); }
public override Task <(RosMessage, bool)> ProcessRequest(byte[] buf, IServiceClientLink link) { var cb = new ServiceCallback(this, helper, buf, link); callback.AddCallback(cb, gate); return(cb.ResultTask); }
private void DispatchCallback(ServiceCallback callback) { foreach (ServiceDataObject sdo in MainListView.SelectedItems) { callback(sdo); } }
/// <summary> /// Creates a new service object. /// </summary> /// <param name="device">The immediate device for the service.</param> /// <param name="comService">The native service for the service.</param> internal Service(Device device, IUPnPService comService) { msCOMService = comService; mscCallback = new ServiceCallback(this); mdDevice = device; mbDead = false; }
public void DeleteMessageBatchAsync(SQSDeleteMessageBatchRequest request, ServiceCallback <SQSDeleteMessageBatchRequest, SQSDeleteMessageBatchResponse> callback) { string requestJson = JsonConvert.SerializeObject(request); _CallParameters[_CallId] = new CallParameters { Request = request, Callback = callback }; SQS_DeleteMessageBatchAsync(_nativeId, requestJson, DeleteMessageBatchCallback, _CallId++); }
// WARNING, NOT THREAD SAFE! SERVICES SHOULD BE REGISTERED BEFORE THE SERVER STARTS! public static void RegisterService(string key, ServiceCallback callback) { if (server != null) { throw new Exception("Can not register a service while the server is running."); } service_callbacks.Add(key, callback); }
/// <summary> /// Disposes the service. /// </summary> /// <param name="disposeManaged">True to dispose managed objects.</param> protected virtual void Dispose(bool disposeManaged) { if (disposeManaged) { if (mscCallback != null) { mscCallback.Ignore(); mscCallback = null; } } }
IEnumerator RoomStateCoroutine() { ulong lastTick = 0; while (true) { SnapshotData data; ServiceCallback <SnapshotData> callback = VrLifeCore.API.TickRate.GetSnapshot(); yield return(callback.WaitCoroutine()); if (callback.HasException) { yield break; } data = callback.Result; if (data.TickNum == lastTick) { continue; } List <SkeletonState> skeletons = data.Skeletons.Select(x => new SkeletonState(x)).ToList(); Dictionary <ulong, IAvatar> _avatarsCopy = _api.GlobalAPI.Players.GetAvatars().ToDictionary(x => x.Key, x => x.Value); foreach (SkeletonState state in skeletons) { if (state.UserId == _playerAvatar.GetUserId()) { continue; } if (!_avatarsCopy.TryGetValue(state.UserId, out IAvatar avatar)) { IAvatar tmp = new DefaultAvatar(state.UserId, state.UserId.ToString(), state.BodyLocation.ToUnity(), Quaternion.identity); _api.GlobalAPI.Players.AddAvatar(state.UserId, tmp); avatar = tmp; } _avatarsCopy.Remove(state.UserId); avatar.SetSkeleton(state); } foreach (IAvatar avatar in _avatarsCopy.Values) { _api.GlobalAPI.Players.DeleteAvatar(avatar.GetUserId()); } lastTick = data.TickNum; yield return(null); } }
IEnumerator SkeletonStateEvent() { if (Avatar != null) { while (true) { SkeletonState state = Avatar.GetCurrentSkeleton(); ServiceCallback <byte[]> callback = VrLifeCore.API.Event.SendSkeleton(state); yield return(callback.WaitCoroutine()); if (callback.HasException) { yield break; } yield return(null); } } }
async internal void CallService <A, V>(string service, A args, ServiceCallback callback) where A : ServiceArgs where V : ServiceValues { await connectionTask; var callServiceMessage = new ServiceCall <A> { op = "call_service", service = service, args = args }; if (!serviceTypes.ContainsKey(service)) { serviceTypes.Add(service, typeof(ServiceResponse <V>)); } if (!serviceCallers.ContainsKey(service)) { serviceCallers.Add(service, callback); } Send(JsonUtility.ToJson(callServiceMessage)); }
private async Task CreateNewConnection() { lock (this.connectionLock) { //TODO: Enable transport security. var binding = new NetTcpBinding() { MaxBufferSize = int.MaxValue, ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max, MaxReceivedMessageSize = int.MaxValue, Security = new NetTcpSecurity() { Message = new MessageSecurityOverTcp() { ClientCredentialType = MessageCredentialType.None }, Transport = new TcpTransportSecurity() { ClientCredentialType = TcpClientCredentialType.None }, Mode = SecurityMode.None, }, CloseTimeout = this.timeout, OpenTimeout = this.timeout, ReceiveTimeout = this.timeout, SendTimeout = this.timeout, }; // TODO: put this in a configuration file somewhere var remoteAddress = new EndpointAddress(new Uri("net.tcp://MessageBrokerProxyService:8137/MessageBrokerProxyService")); this.serviceCallback = new ServiceCallback(this.eventAggregator); this.serviceClient = new MessageBrokerProxyServiceClient(new InstanceContext(this.serviceCallback), binding, remoteAddress); this.serviceClient.InnerChannel.OperationTimeout = this.timeout; this.serviceClient.InnerChannel.Faulted += this.OnServiceClientFaulted; } await this.serviceClient.SubscribeAsync(); this.keepAliveWorker = Task.Run(this.KeepAliveWorkerLoop); await this.eventAggregator.PublishOnUIThreadAsync(new Connected()); }
public async void Run(ServiceCallback callback) { //Listen for TCP requests on the ipAddress and port ascertained earlier. TcpListener listener = new TcpListener(this.ipAddress, this.port); listener.Start(); while (true) { try { TcpClient tcpClient = await listener.AcceptTcpClientAsync(); Task t = Process(tcpClient, callback); await t; // TODO: Combine with Line Above? } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
/// <summary> /// Add a Service server to this connection. There can be many servers, but each service should only have one. /// </summary> /// <typeparam name="Tsrv">ServiceProvider type</typeparam> /// <typeparam name="Treq">Message type containing parameters for this service</typeparam> /// <typeparam name="Tres">Message type containing response data returned by this service</typeparam> /// <param name="srv">The service to advertise</param> /// <param name="callback">Method to invoke when the service is called</param> public ROSBridgeServiceProvider <Treq> Advertise <Tsrv, Treq, Tres>(string service, ROSServiceCallback <Treq, Tres> callback) where Tsrv : ROSBridgeServiceProvider <Treq> where Treq : ServiceArgs where Tres : ServiceResponse, new() { ServiceCallback CB = (ServiceArgs args, out ServiceResponse response) => { Treq request = (Treq)args; Tres res = new Tres(); bool success = callback(request, out res); response = res; return(success); }; Tsrv srv = (Tsrv)Activator.CreateInstance(typeof(Tsrv), new object[] { service }); _serviceServers.Add(srv, CB); _svcQueue.Add(srv.topic, new RenderQueue <ServiceTask>(0)); if (connected) { _ws.Send(ROSBridgeMsg.AdvertiseService(srv.topic, srv.type)); } return(srv); }
/// <summary> /// Add a Service server to this connection. There can be many servers, but each service should only have one. /// </summary> /// <typeparam name="Tsrv">ServiceProvider type</typeparam> /// <typeparam name="Targ">Message type containing parameters for this service</typeparam> /// <typeparam name="Tres">Message type containing response data returned by this service</typeparam> /// <param name="srv">The service to advertise</param> /// <param name="callback">Method to invoke when the service is called</param> public RosBridgeServiceProvider <Targ> Advertise <Tsrv, Targ, Tres>(string service, RosServiceCallback <Targ, Tres> callback) where Tsrv : RosBridgeServiceProvider <Targ> where Targ : ServiceArgs where Tres : ServiceResponse, new() { ServiceCallback ServiceCallback = (ServiceArgs args, out ServiceResponse response) => { Targ request = (Targ)args; Tres res = new Tres(); bool success = callback(request, out res); response = res; return(success); }; Tsrv srv = (Tsrv)Activator.CreateInstance(typeof(Tsrv), new object[] { service }); this.serviceProviders.Add(srv, ServiceCallback); this.svcQueue.Add(srv.Name, new RenderQueue <ServiceTask>(0)); if (this.IsConnected) { this.webSocket.Send(RosBridgeMsg.AdvertiseService(srv.Name, srv.Type)); } return(srv); }
private async Task Disconnect(bool isFault = false) { lock (this.connectionLock) { try { if (this.serviceClient != null) { this.serviceClient.InnerChannel.Faulted -= this.OnServiceClientFaulted; if (this.serviceClient.InnerChannel.State == CommunicationState.Faulted) { this.serviceClient.Abort(); } else { this.serviceClient.UnsubscribeAsync(); this.serviceClient.CloseAsync(); } } } catch { // ignore } finally { this.serviceClient = null; this.serviceCallback = null; } } if (isFault) { await this.eventAggregator.PublishOnUIThreadAsync(new Disconnected()); } }
// ================================================================================================================ // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- public BasicService(ServiceCallback __callback = null) { callback = __callback; setDefaultData(); }
public void AddService(System.Net.NetworkInformation.NetworkInterface network, string host, ServiceCallback callback) { _publishers[network].AddService(host, callback); }
public void AddService(string host, ServiceCallback callback) { DoForAll(x => x.AddService(host, callback)); }
// ================================================================================================================ // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- public UnlockMedalService(ServiceCallback __callback = null) : base(__callback) { }
//Process an incomming request. private async Task Process(TcpClient tcpClient, ServiceCallback callback) { //Print the client connection to the console. //TODO: Remove this for version 1. string clientEndPoint = tcpClient.Client.RemoteEndPoint.ToString(); Console.WriteLine("Received connection request from " + clientEndPoint); try { //Create and configure a stream we can use to send and receive data. NetworkStream networkStream = tcpClient.GetStream(); StreamReader reader = new StreamReader(networkStream); StreamWriter writer = new StreamWriter(networkStream); writer.AutoFlush = true; //Stealing Liberally from https://stackoverflow.com/questions/26058594/how-to-get-all-data-from-networkstream //If we can read information from the networkStream...read it into a StringBuilder if (networkStream.CanRead) { byte[] readBuffer = new byte[1024]; //Full webrequest. StringBuilder fullMessage = new StringBuilder(); int numberOfBytesRead = 0; //Read all data from the stream into fullMessage do { numberOfBytesRead = await networkStream.ReadAsync(readBuffer, 0, readBuffer.Length); fullMessage.AppendFormat("{0}", Encoding.ASCII.GetString(readBuffer, 0, numberOfBytesRead)); } while (networkStream.DataAvailable); //Examine the request to see if it is properly formatted. Tuple <String, String> opRequest = IsProperlyFormatted(fullMessage.ToString()); if (opRequest != null) { //Match the sent web request type with our Enum WebRequestType. WebRequestType operation; Enum.TryParse <WebRequestType>(opRequest.Item1, out operation); //Invoke the callback that corresponds to Controller.HttpRequestHandler(); string dataFromController = callback.Invoke(operation, opRequest.Item2); //Builder to prepare our response. StringBuilder res = new StringBuilder("HTTP/1.1 200 OK\r\n"); //TODO: restrict cross origin to webserver only. res.Append("Access-Control-Allow-Origin: *\r\n"); res.Append("Content-Type: text/*\r\n"); res.Append("\r\n"); res.Append(dataFromController); await writer.WriteLineAsync(res.ToString()); } } else { Console.WriteLine("Network Stream Unreadable."); } tcpClient.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (tcpClient.Connected) { tcpClient.Close(); } } } // Process
public void AddService(System.Net.NetworkInformation.NetworkInterface network, string host, ServiceCallback callback) { throw new NotImplementedException(); }
public override void processRequest(ref byte[] buf, int num_bytes, IServiceClientLink link) { CallbackInterface cb = new ServiceCallback(this, helper, buf, num_bytes, link, has_tracked_object, tracked_object); callback.addCallback(cb, ROS.getPID()); }
// ================================================================================================================ // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- public PostScoreService(ServiceCallback __callback = null) : base(__callback) { }
public void AddService(string host, ServiceCallback callback) { _callbacks.Add(Tuple.Create(host, callback)); CreateLookup(); }