Exemplo n.º 1
0
        public static SmiResultCode PlayNotes(int handle,
            uint noteCount,
            HapticsNote[] notes,
            bool repeat,
            Notification callback)
        {
            CallbackItem item= new CallbackItem();
            c_Notification cN = new c_Notification(Haptics.NotificationCallbakHandler);

            item.callback   = callback;
            item.handle     = handle;
            item.notesArray = notes;
            item.c_callback = cN; // reserve callback until callback is done

            lock (_locker)
            {
                // protect the _list inside of critical section
                _list.Add(item);
            }

            SmiResultCode result = c_PlayNotes(handle,
                               noteCount,
                               notes,
                               repeat,
                               cN);

            //System.Console.WriteLine("@PlayNotes handle     = " + handle);
            //System.Console.WriteLine("@PlayNotes noteCount  = " + noteCount);
            //System.Console.WriteLine("@PlayNotes repeat     = " + repeat);
            //System.Console.WriteLine("@PlayNotes result  = " + result);

            return result;
        }
Exemplo n.º 2
0
		/// <summary>
		/// Same as protocol.registerStreamProtocol,
		/// except that it replaces an existing protocol handler.
		/// </summary>
		/// <param name="scheme"></param>
		/// <param name="handler"></param>
		/// <param name="completion"></param>
		public void interceptStreamProtocol(string scheme, Action<InterceptStreamProtocolRequest, Action<StreamProtocolResponse>> handler, Action<Error> completion = null) {
			string eventName = "_interceptStreamProtocol";
			CallbackItem item = null;
			item = API.CreateCallbackItem(eventName, (object[] args) => {
				InterceptStreamProtocolRequest request = API.CreateObject<InterceptStreamProtocolRequest>(args[0]);
				JSObject _callback = API.CreateObject<JSObject>(args[1]);
				Action<StreamProtocolResponse> callback = (stream) => {
					_callback?.API.Invoke(stream);
				};
				handler?.Invoke(request, callback);
			});
			if (completion == null) {
				API.Apply("interceptStreamProtocol", scheme, item);
			} else {
				string eventName2 = "_interceptStreamProtocol_completion";
				CallbackItem item2 = null;
				item2 = API.CreateCallbackItem(eventName2, (object[] args) => {
					Error error = API.CreateObject<Error>(args[0]);
					completion?.Invoke(error);
				});
				API.Apply("interceptStreamProtocol", scheme, item, item2);
			}
		}
Exemplo n.º 3
0
		/// <summary>
		/// Registers a protocol of scheme that will send a Buffer as a response.
		/// </summary>
		/// <param name="scheme"></param>
		/// <param name="handler"></param>
		/// <param name="completion"></param>
		public void registerBufferProtocol(string scheme, Action<RegisterBufferProtocolRequest, Action<Buffer>> handler, Action<Error> completion = null) {
			string eventName = "_registerBufferProtocol";
			CallbackItem item = null;
			item = API.CreateCallbackItem(eventName, (object[] args) => {
				RegisterBufferProtocolRequest request = API.CreateObject<RegisterBufferProtocolRequest>(args[0]);
				JSObject _callback = API.CreateObject<JSObject>(args[1]);
				Action<Buffer> callback = (buffer) => {
					_callback?.API.Invoke(buffer);
				};
				handler?.Invoke(request, callback);
			});
			if (completion == null) {
				API.Apply("registerBufferProtocol", scheme, item);
			} else {
				string eventName2 = "_registerBufferProtocol_completion";
				CallbackItem item2 = null;
				item2 = API.CreateCallbackItem(eventName2, (object[] args) => {
					Error error = API.CreateObject<Error>(args[0]);
					completion?.Invoke(error);
				});
				API.Apply("registerBufferProtocol", scheme, item, item2);
			}
		}
Exemplo n.º 4
0
        public int showCertificateTrustDialog(BrowserWindow browserWindow, CertificateTrustDialogOptions options, Action callback)
        {
            if (callback == null)
            {
                return(showCertificateTrustDialog(browserWindow, options));
            }
            string       eventName = "_showCertificateTrustDialog";
            CallbackItem item      = null;

            item = API.CreateCallbackItem(eventName, (object[] args) => {
                API.RemoveCallbackItem(eventName, item);
                callback?.Invoke();
            });
            if (browserWindow == null)
            {
                API.Apply("showCertificateTrustDialog", options, item);
            }
            else
            {
                API.Apply("showCertificateTrustDialog", browserWindow, options, item);
            }
            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target">The <see cref="CallbackItem"/> to use.</param>
        /// <param name="args"></param>
        /// <remarks>
        /// Order of items in the <see cref="args"/> array:
        /// <list type="number">
        ///  <item><see cref="Aplus"/></item>
        ///  <item>New value for the global variable</item>
        /// </list>
        /// </remarks>
        /// <returns></returns>
        public override DYN.DynamicMetaObject Bind(DYN.DynamicMetaObject target, DYN.DynamicMetaObject[] args)
        {
            ContractUtils.RequiresNotNull(target, "target");
            ContractUtils.RequiresNotNullItems(args, "args");

            if (target.HasValue && target.Value is CallbackItem)
            {
                CallbackItem callbackItem      = (CallbackItem)target.Value;
                AFunc        callbackAFunction = (AFunc)callbackItem.CallbackFunction.Data;

                DLR.Expression callbackItemExpression = DLR.Expression.Convert(
                    target.Expression, typeof(CallbackItem)
                    );


                DYN.BindingRestrictions baseRestriction = DYN.BindingRestrictions.GetTypeRestriction(
                    target.Expression, target.LimitType
                    );

                DLR.Expression callbackAFunctionExpression = DLR.Expression.Convert(
                    DLR.Expression.Convert(target.Expression, typeof(CallbackItem))
                    .Property("CallbackFunction").Property("Data"),
                    typeof(AFunc)
                    );

                DYN.BindingRestrictions valenceRestriction =
                    DYN.BindingRestrictions.GetExpressionRestriction(
                        DLR.Expression.Equal(
                            callbackAFunctionExpression.Property("Valence"),
                            DLR.Expression.Constant(callbackAFunction.Valence)
                            )
                        );

                // TODO: refactor the argument generation, something similar is in the InvokeBinder

                IEnumerable <DLR.Expression> callbackBaseArguments = new DLR.Expression[] {
                    callbackItemExpression.Property("StaticData"),             // static data
                    DLR.Expression.Convert(args[1].Expression, typeof(AType)), // new value
                    DLR.Expression.Convert(args[2].Expression, typeof(AType)), // index/set of indices
                    DLR.Expression.Convert(args[3].Expression, typeof(AType)), // path (left argument of pick)
                    callbackItemExpression.Property("Context"),                // context of the global variable
                    callbackItemExpression.Property("UnqualifiedName")         // name of the global variable
                }.Where((item, i) => i < callbackAFunction.Valence - 1).Reverse();
                List <DLR.Expression> callbackArguments = new List <DLR.Expression>();

                // Aplus
                callbackArguments.Add(DLR.Expression.Convert(args[0].Expression, args[0].RuntimeType));
                callbackArguments.AddRange(callbackBaseArguments);


                Type[] callTypes = new Type[callbackAFunction.Valence + 1];
                callTypes[0] = typeof(Aplus);

                for (int i = 1; i < callbackAFunction.Valence; i++)
                {
                    callTypes[i] = typeof(AType);
                }

                // return type
                callTypes[callbackAFunction.Valence] = typeof(AType);


                DLR.Expression codeBlock = DLR.Expression.Invoke(
                    DLR.Expression.Convert(
                        callbackAFunctionExpression.Property("Method"),
                        DLR.Expression.GetFuncType(callTypes)
                        ),
                    callbackArguments
                    );

                DYN.DynamicMetaObject dynobj =
                    new DYN.DynamicMetaObject(codeBlock, baseRestriction.Merge(valenceRestriction));

                return(dynobj);
            }

            // Throw a non-function error
            return(new DYN.DynamicMetaObject(
                       DLR.Expression.Throw(
                           DLR.Expression.New(
                               typeof(Error.NonFunction).GetConstructor(new Type[] { typeof(string) }),
                               DLR.Expression.Call(
                                   target.Expression,
                                   typeof(object).GetMethod("ToString")
                                   )
                               ),
                           typeof(Error.NonFunction)
                           ),
                       DYN.BindingRestrictions.GetTypeRestriction(target.Expression, target.RuntimeType)
                       ));
        }
Exemplo n.º 6
0
 /// <remarks>This method is not thread-safe and may crash => Use only for debugging purposes</remarks>
 public void AddOrReplaceMessageHandler(string messageType, Action<TaskEntry,Message> callback)
 {
     HandlerCallbacks[ messageType ] = new CallbackItem{ CallbackThreaded = callback };
 }
Exemplo n.º 7
0
 /// <remarks>This method is not thread-safe and may crash => Use only for debugging purposes</remarks>
 public void AddOrReplaceMessageHandler(string messageType, Action<Message> callback)
 {
     HandlerCallbacks[ messageType ] = new CallbackItem{ CallbackDirect = callback };
 }
Exemplo n.º 8
0
            internal MessageContext(MessageHandler messageHandler, CallbackItem callbackItem, Message message)
            {
                MessageHandler = messageHandler;
                CallbackItem = callbackItem;
                Message = message;

                if( MessageHandler.SaveMessageContextObject != null )
                    try { ContextObject = MessageHandler.SaveMessageContextObject(); }
                    catch( System.Exception ex )  { MessageHandler.FAIL( "'MessageHandler.SaveMessageContextObject()' threw an exception (" + ex.GetType().FullName + "): " + ex.Message ); }
                else
                    ContextObject = null;
            }
Exemplo n.º 9
0
        public void AddMessageHandler(string messageType, Action<TaskEntry,Message> callback)
        {
            ASSERT( !string.IsNullOrEmpty(messageType), "Missing parameter 'messageType'" );
            ASSERT( callback != null, "Missing parameter 'callback'" );

            #if DEBUG
                // NB: Access to HandlerCallbacks is not thread-safe protected. All calls to this method must be performed once at application start and not after.
                ASSERT( !MessageReceived, "At least one message has already been received. AddMessageHandler() cannot be called anymore." );
            #endif

            ASSERT( !HandlerCallbacks.ContainsKey(messageType), "The message type '" + messageType + "' is already defined" );
            HandlerCallbacks[ messageType ] = new CallbackItem{ CallbackThreaded = callback };
        }