Example #1
0
        public SbProcess AttachToProcessWithID(SbListener listener, ulong pid, out SbError error)
        {
            var request = new AttachToProcessWithIDRequest()
            {
                Target   = grpcSbTarget,
                Listener = new GrpcSbListener()
                {
                    Id = listener.GetId()
                },
                Pid = pid,
            };
            AttachToProcessWithIDResponse response = null;

            if (connection.InvokeRpc(() =>
            {
                response = client.AttachToProcessWithID(request);
            }))
            {
                error = errorFactory.Create(response.Error);
                if (response.Process == null)
                {
                    return(null);
                }
                return(processFactory.Create(connection, response.Process));
            }
            var grpcError = new GrpcSbError
            {
                Success = false,
                Error   = "Rpc error while calling AttachToProcessWithId."
            };

            error = errorFactory.Create(grpcError);
            return(null);
        }
        public override Task <AttachToProcessWithIDResponse> AttachToProcessWithID(
            AttachToProcessWithIDRequest request, ServerCallContext context)
        {
            if (!_targetStore.TryGetValue(request.Target.Id, out RemoteTarget target))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find target in store: " + request.Target.Id);
            }

            if (!_listenerStore.TryGetValue(request.Listener.Id, out SbListener listener))
            {
                ErrorUtils.ThrowError(StatusCode.Internal,
                                      "Could not find listener in store: " + request.Listener.Id);
            }

            SbProcess process =
                target.AttachToProcessWithID(listener, request.Pid, out SbError error);

            var response =
                new AttachToProcessWithIDResponse {
                Error = new GrpcSbError {
                    Success = error.Success(),
                    Error   = error.GetCString(),
                }
            };

            if (process != null)
            {
                if (!_processStore.TryAdd(process.GetUniqueId(), process))
                {
                    ErrorUtils.ThrowError(StatusCode.Internal, "Could not add process to store: " +
                                          process.GetUniqueId());
                }
                response.Process = new GrpcSbProcess {
                    Id = process.GetUniqueId()
                };
            }
            return(Task.FromResult(response));
        }