/// <summary> /// Constructor initialises all member variables. /// </summary> /// <param name="callback"> /// The user callback implementation. /// </param> /// <param name="closure"> /// The closure supplied to the MamaBasicSubscription.createBasic function. /// </param> /// <param name="subscription"> /// The actual C# timer object. /// </param> internal MamaBasicSubscriptionImpl(MamaBasicSubscriptionCallback callback, object closure, MamaBasicSubscription subscription) { // Save arguments in member variables mCallback = callback; mClosure = closure; mSubscription = subscription; }
/// <summary> /// This function will invoke the destroy callback on the user supplied callback implementation. /// </summary> internal virtual void InvokeDestroy() { // Only the MamaBasicSubscriptionCallback class has the onDestroy function MamaBasicSubscriptionCallback callback = mCallback as MamaBasicSubscriptionCallback; if (null != callback) { // Invoke the onDestroy callback.onDestroy(mSubscription, mClosure); } }
/* ************************************************************** */ #region Internal Operations /// <summary> /// This function creates a new impl and returns an IntPtr that can then be passed to /// the native layer. /// </summary> /// <param name="callback"> /// The user callback implementation /// </param> /// <param name="closure"> /// The closure supplied to the MamaBasicSubscription.createBasic function. /// </param> /// <param name="subscription"> /// The actual C# subscription object. /// </param> /// <returns> /// The IntPtr that can then be used for the closure. /// </returns> internal static IntPtr Create(MamaBasicSubscriptionCallback callback, object closure, MamaBasicSubscription subscription) { // Allocate a new impl MamaBasicSubscriptionImpl impl = new MamaBasicSubscriptionImpl(callback, closure, subscription); // Create a GC handle GCHandle handle = GCHandle.Alloc(impl); // Return the native pointer return((IntPtr)handle); }
/// <summary> /// This function will create the basic subscription without marketdata semantics. /// </summary> /// <param name="transport"> /// The MamaTransport. /// </param> /// <param name="queue"> /// The MamaQueue. /// </param> /// <param name="callback"> /// Provide callback function implementations to be informed of events on the subscription. /// </param> /// <param name="symbol"> /// The symbol to subscribe to. /// </param> /// <param name="closure"> /// The closure that will be passed back with the callback functions. /// </param> public void createBasic(MamaTransport transport, MamaQueue queue, MamaBasicSubscriptionCallback callback, string symbol, object closure) { // Ensure that the native subscription has been allocated EnsurePeerCreated(); // Save arguments in member variables mClosure = closure; mQueue = queue; mTransport = transport; // Create the impl IntPtr impl = MamaBasicSubscriptionImpl.Create(callback, closure, this); /* Create the subscription, register for the destroy callback regardless if the client wants it or not, * this is to allow clean-up to be done whenever the timer has been fully destroyed. */ CheckResultCode(NativeMethods.mamaSubscription_createBasic( NativeHandle, transport.NativeHandle, queue.NativeHandle, ref mCallbackDelegates, symbol, impl)); }
/* ************************************************************** */ #region Public Functions /// <summary> /// This function will create the basic subscription without marketdata semantics. /// To pass a closure use the overload. /// </summary> /// <param name="transport"> /// The MamaTransport. /// </param> /// <param name="queue"> /// The MamaQueue. /// </param> /// <param name="callback"> /// Provide callback function implementations to be informed of events on the subscription. /// </param> /// <param name="symbol"> /// The symbol to subscribe to. /// </param> public void createBasic(MamaTransport transport, MamaQueue queue, MamaBasicSubscriptionCallback callback, string symbol) { // Call the overloade createBasic(transport, queue, callback, symbol, null); }
/* ************************************************************** */ #region Internal Operations /// <summary> /// This function creates a new impl and returns an IntPtr that can then be passed to /// the native layer. /// </summary> /// <param name="callback"> /// The user callback implementation /// </param> /// <param name="closure"> /// The closure supplied to the MamaBasicSubscription.createBasic function. /// </param> /// <param name="subscription"> /// The actual C# subscription object. /// </param> /// <returns> /// The IntPtr that can then be used for the closure. /// </returns> internal static IntPtr Create(MamaBasicSubscriptionCallback callback, object closure, MamaBasicSubscription subscription) { // Allocate a new impl MamaBasicSubscriptionImpl impl = new MamaBasicSubscriptionImpl(callback, closure, subscription); // Create a GC handle GCHandle handle = GCHandle.Alloc(impl); // Return the native pointer return (IntPtr)handle; }