/// <summary> /// Get information of a given session /// </summary> /// <param name="Session">Session Handle</param> /// <param name="SessionInfo">The session info</param> /// <exception cref="System.ArgumentNullException">Thrown when passed a null to one of the method arguments</exception> /// <exception cref="JhiException"> /// Thrown when the operation failed. The specific error resides within the class JhiRet member /// /// <list type="table"> /// <listheader> /// <term>Possible error codes</term> /// <description>Description</description> /// </listheader> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INTERNAL_ERROR"/></term><description>Returned if the calling functions return an internal error</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SERVICE_UNAVAILABLE"/></term><description>Returned when there is no connection to the JHI service</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_SESSION_HANDLE"/></term><description>The session handle is not valid</description></item> /// </list> /// </exception> public void GetSessionInfo(JhiSession Session, out JHI_SESSION_INFO SessionInfo) { uint ret; JhiWrapper.JHI_I_SESSION_INFO info = new JhiWrapper.JHI_I_SESSION_INFO(); if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (Session == null) { throw new ArgumentNullException("Session"); } ret = JhiWrapper.JHI_GetSessionInfo(_handle, Session.SessionHandle, ref info); if (ret != 0) { throw new JhiException("JHI_GetSessionInfo() failed", ret); } SessionInfo = new JHI_SESSION_INFO(); SessionInfo.state = info.state; SessionInfo.flags = (JHI_SESSION_FLAGS)info.flags; }
/// <summary> /// Remove registration of events from a given session /// </summary> /// <param name="Session">Session Handle</param> /// <exception cref="System.ArgumentNullException">Thrown when passed a null to one of the method arguments</exception> /// <exception cref="JhiException"> /// Thrown when the operation failed. The specific error resides within the class JhiRet member /// /// <list type="table"> /// <listheader> /// <term>Possible error codes</term> /// <description>Description</description> /// </listheader> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INTERNAL_ERROR"/></term><description>Returned if the calling functions return an internal error</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SERVICE_UNAVAILABLE"/></term><description>Returned when there is no connection to the JHI service</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SESSION_NOT_REGISTERED"/></term><description>The session wasn’t registered for events</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_SESSION_HANDLE"/></term><description>The session handle is not valid</description></item> /// </list> /// </exception> public void UnRegisterEvents(JhiSession Session) { uint ret; if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (Session == null) { throw new ArgumentNullException("Session"); } ret = JhiWrapper.JHI_UnRegisterEvents(_handle, Session.SessionHandle); if (ret == 0) { lock (_eventsLock) { _eventList.Remove(Session); } } else { throw new JhiException("JHI_UnRegisterEvents() failed", ret); } }
/// <summary> /// Registers registration of one callback function to receive events from a given session /// </summary> /// <param name="Session">Session Handle</param> /// <param name="CallbackFunction">The Callback function</param> /// <exception cref="System.ArgumentNullException">Thrown when passed a null to one of the method arguments</exception> /// <exception cref="JhiException"> /// Thrown when the operation failed. The specific error resides within the class JhiRet member /// /// <list type="table"> /// <listheader> /// <term>Possible error codes</term> /// <description>Description</description> /// </listheader> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INTERNAL_ERROR"/></term><description>Returned if the calling functions return an internal error</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SERVICE_UNAVAILABLE"/></term><description>Returned when there is no connection to the JHI service</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SESSION_ALREADY_REGSITERED"/></term><description>The session is already registered for events</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_SESSION_HANDLE"/></term><description>The session handle is not valid</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_EVENTS_NOT_SUPPORTED "/></term><description>Events are not supported for this type of session</description></item> /// </list> /// </exception> public void RegisterEvents(JhiSession Session, Intel.Dal.JHI_CallbackFunction CallbackFunction) { uint ret; if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (Session == null) { throw new ArgumentNullException("Session"); } if (CallbackFunction == null) { throw new ArgumentNullException("CallbackFunction"); } //ret = JhiWrapper.JHI_RegisterEvents(_handle, SessionHandle, CallbackFunction); ret = JhiWrapper.JHI_RegisterEvents(_handle, Session.SessionHandle, /*CallbackFunc*/ JhiMainCallback); if (ret == 0) { Session.callback = CallbackFunction; lock (_eventsLock) { _eventList.Add(Session); } } else { throw new JhiException("JHI_RegisterEvents() failed", ret); } }
/// <summary> /// Create a session of an installed applet. /// a session handle is retuned by SessionHandle. /// </summary> /// <param name="AppId">Applet ID</param> /// <param name="Session">Session Handle</param> /// <param name="initBuffer">Initialization data passed to the applet onInit function</param> /// <param name="flags">session flags used for creation</param> /// <exception cref="System.ArgumentNullException">Thrown when passed a null to one of the method arguments</exception> /// <exception cref="JhiException"> /// Thrown when the operation failed. The specific error resides within the class JhiRet member /// /// <list type="table"> /// <listheader> /// <term>Possible error codes</term> /// <description>Description</description> /// </listheader> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_APPLET_GUID"/></term><description>The applet id is invalid</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INTERNAL_ERROR"/></term><description>Returned if the calling functions return an internal error</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SERVICE_UNAVAILABLE"/></term><description>Returned when there is no connection to the JHI service</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_APPLET_FATAL"/></term><description>Returned when the applet session has crashed</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_BUFFER_SIZE"/></term><description>Used a initBuffer that is larger than <see cref="Jhi.JHI_BUFFER_MAX"/></description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_APPLET_NOT_INSTALLED"/></term><description>The applet is not installed</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_MAX_SESSIONS_REACHED"/></term><description>Reached the limit of sessions in FW</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SHARED_SESSION_NOT_SUPPORTED"/></term><description>the applet does not support shared sessions</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_MAX_SHARED_SESSION_REACHED"/></term><description>Reached the limit of handles to the shared session</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_ONLY_SINGLE_INSTANCE_ALLOWED"/></term><description>Returned if more than single instance was opened</description></item> /// </list> /// </exception> public void CreateSession(string AppId, JHI_SESSION_FLAGS flags, byte[] initBuffer, out JhiSession Session) { uint ret; bool memAlocated = false; if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (AppId == null) { throw new ArgumentNullException("AppId"); } Session = new JhiSession(); JhiWrapper.DATA_BUFFER init_buffer = new JhiWrapper.DATA_BUFFER(); if (initBuffer == null) { init_buffer.length = 0; } else { init_buffer.length = (uint)initBuffer.Length; init_buffer.buffer = Marshal.AllocHGlobal(initBuffer.Length); memAlocated = true; if (initBuffer.Length > 0) { Marshal.Copy(initBuffer, 0, init_buffer.buffer, initBuffer.Length); } } ret = JhiWrapper.JHI_CreateSession(_handle, RemoveSeperators(AppId), Convert.ToUInt32(flags), ref init_buffer, ref Session.SessionHandle); if (memAlocated) { Marshal.FreeHGlobal(init_buffer.buffer); } if (ret != 0) { throw new JhiException("JHI_CreateSession() failed", ret); } }
public void ForceCloseSession(JhiSession Session) { uint ret; if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (Session == null) { throw new ArgumentNullException("Session"); } ret = JhiWrapper.JHI_ForceCloseSession(_handle, ref Session.SessionHandle); if (ret != 0) { throw new JhiException("JHI_ForceCloseSession() failed", ret); } }
/// <summary> /// send and receive data from the application to an applet session /// </summary> /// <param name="Session">Session Handle</param> /// <param name="nCommandId">Command ID to send the data to</param> /// <param name="InBuf">Input Data</param> /// <param name="OutBuf">Output Data</param> /// <param name="ResponseCode">an error code that is returned from the applet</param> /// <exception cref="System.ArgumentNullException">Thrown when passed a null to the Session argument</exception> /// <exception cref="JhiInsufficientBufferException">Thrown when OutBuf is too short to contain the response. The required size reside within the class Required_size member</exception> /// <exception cref="JhiException"> /// Thrown when the operation failed. The specific error resides within the class JhiRet member /// /// <list type="table"> /// <listheader> /// <term>Possible error codes</term> /// <description>Description</description> /// </listheader> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INTERNAL_ERROR"/></term><description>Returned if the calling functions return an internal error</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_SERVICE_UNAVAILABLE"/></term><description>Returned when there is no connection to the JHI service</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_SESSION_HANDLE"/></term><description>The session handle is not valid</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_APPLET_FATAL"/></term><description>Returned when the applet session has crashed</description></item> /// <item><term><see cref="JHI_ERROR_CODE.JHI_INVALID_BUFFER_SIZE"/></term><description>Used a buffer that is larger than <see cref="Jhi.JHI_BUFFER_MAX"/></description></item> /// </list> /// </exception> public void SendAndRecv2(JhiSession Session, Int32 nCommandId, byte[] InBuf, ref byte[] OutBuf, out Int32 ResponseCode) { uint ret; bool useEmptyOutBuffer = false; if (_handle == null) { throw new JhiException("JHI is not initalized"); } if (Session == null) { throw new ArgumentNullException("Session"); } if (InBuf == null) { InBuf = new byte[0]; } if (OutBuf == null) // allow null buffer for output { OutBuf = new byte[0]; // temporary convert the out buffer to a byte[0] array. useEmptyOutBuffer = true; } ResponseCode = 0; IntPtr tmpInBuf = Marshal.AllocHGlobal(InBuf.Length); if (InBuf.Length > 0) { Marshal.Copy(InBuf, 0, tmpInBuf, InBuf.Length); } IntPtr tmpOutBuf = Marshal.AllocHGlobal(OutBuf.Length); JhiWrapper.JVM_COMM_BUFFER comm; comm.TxBuf.buffer = tmpInBuf; comm.TxBuf.length = (uint)InBuf.Length; comm.RxBuf.buffer = tmpOutBuf; comm.RxBuf.length = (uint)OutBuf.Length; ret = JhiWrapper.JHI_SendAndRecv2(_handle, Session.SessionHandle, nCommandId, ref comm, ref ResponseCode); if (useEmptyOutBuffer) { OutBuf = null; } if (ret != 0) { Marshal.FreeHGlobal(tmpInBuf); Marshal.FreeHGlobal(tmpOutBuf); if (ret == 0x200) // insufficient buffer { throw new JhiInsufficientBufferException("JHI_SendAndRecv failed: insufficient output buffer. required size:" + comm.RxBuf.length, ret, comm.RxBuf.length); } else { throw new JhiException("JHI_SendAndRecv() failed", ret); } } if (comm.RxBuf.length >= 0) { OutBuf = new byte[comm.RxBuf.length]; if (comm.RxBuf.length > 0) { Marshal.Copy(comm.RxBuf.buffer, OutBuf, 0, (int)comm.RxBuf.length); } } Marshal.FreeHGlobal(tmpInBuf); Marshal.FreeHGlobal(tmpOutBuf); }