/// <summary> /// Sends the request data synchronously. /// </summary> /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception> /// <exception cref="OutOfMemoryException">Thrown when the memory is insufficient.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when because of permission denied.</exception> /// <exception cref="global::System.IO.IOException">Thrown when because of I/O error.</exception> /// <param name="endpoint">The name of the endpoint</param> /// <param name="timeout">The interval of timeout</param> /// <param name="request">The serializable data to send</param> /// <returns>The received serializable data</returns> /// /// <since_tizen> 9 </since_tizen> public object SendSync(string endpoint, int timeout, object request) { if (request == null) { throw new ArgumentException("request is null"); } if (!request.GetType().IsSerializable) { throw new ArgumentException("request is not serializable"); } SafeParcelHandle resSafeHandle = null; Interop.ComponentPort.ErrorCode err; using (Parcel reqParcel = ToParcel(request)) { err = Interop.ComponentPort.SendSync(_port, endpoint, timeout, reqParcel.SafeParcelHandle, out resSafeHandle); } if (err != Interop.ComponentPort.ErrorCode.None) { throw ComponentPortErrorFactory.GetException(err, "Failed to send the request."); } using (Parcel resParcel = new Parcel(resSafeHandle)) { object response = FromParcel(resParcel); return(response); } }
/// <summary> /// Constructor for this class. /// </summary> /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception> /// <exception cref="OutOfMemoryException">Thrown when the memory is insufficient.</exception> /// <exception cref="global::System.IO.IOException">Thrown when because of I/O error.</exception> /// <param name="portName">The name of the port.</param> /// <since_tizen> 9 </since_tizen> public ComponentPort(string portName) { var ret = Interop.ComponentPort.Create(portName, out _port); if (ret != Interop.ComponentPort.ErrorCode.None) { throw ComponentPortErrorFactory.GetException(ret, "ComponentPort(" + portName + ")."); } _portName = portName; _requestEventCallback = new Interop.ComponentPort.ComponentPortRequestCallback(OnRequestEvent); _syncRequestEventCallback = new Interop.ComponentPort.ComponentPortSyncRequestCallback(OnSyncRequestEvent); Interop.ComponentPort.SetRequestCb(_port, _requestEventCallback, IntPtr.Zero); Interop.ComponentPort.SetSyncRequestCb(_port, _syncRequestEventCallback, IntPtr.Zero); }
/// <summary> /// Sends the request data. /// </summary> /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception> /// <exception cref="OutOfMemoryException">Thrown when the memory is insufficient.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when because of permission denied.</exception> /// <exception cref="global::System.IO.IOException">Thrown when because of I/O error.</exception> /// <param name="endpoint">The name of the endpoint</param> /// <param name="timeout">The interval of timeout</param> /// <param name="request">The serializable data to send</param> /// <since_tizen> 9 </since_tizen> public void Send(string endpoint, int timeout, object request) { if (request == null) { throw new ArgumentException("request is null"); } if (!request.GetType().IsSerializable) { throw new ArgumentException("request is not serializable"); } Interop.ComponentPort.ErrorCode err; using (Parcel reqParcel = ToParcel(request)) { err = Interop.ComponentPort.Send(_port, endpoint, timeout, reqParcel.SafeParcelHandle); } if (err != Interop.ComponentPort.ErrorCode.None) { throw ComponentPortErrorFactory.GetException(err, "Failed to send the request."); } }