Esempio n. 1
0
 protected void CallRequestReceived(IOwner owner, IValue request, ICallbacks callbacks)
 {
     if (RequestReceived != null)
     {
         RequestReceived(this, owner, request, callbacks);
     }
 }
Esempio n. 2
0
 protected void CallAuthorizeReceived(IOwner owner, string name, ICallbacks callbacks)
 {
     if (AuthorizeReceived != null)
     {
         AuthorizeReceived(this, owner, name, callbacks);
     }
 }
Esempio n. 3
0
 public virtual void Callbacks(ICallbacks cb)
 {
     lock (Lock())
     {
         CheckClosed();
         _server.Callbacks(cb);
     }
 }
Esempio n. 4
0
        public static IEnumerable <string> ResetMonitors(ICallbacks parent, ResetMonitors resetDialog, HeliosProfile profile)
        {
            Logger.Debug("resetting Monitors");

            // WARNING: monitor naming is 1-based but indexing and NewMonitor references are 0-based
            Monitor[] localMonitors = ConfigManager.DisplayManager.Displays.ToArray <Monitor>();
            yield return("acquired displays");

            foreach (Monitor localMonitor in localMonitors)
            {
                Logger.Info("detected display of size {Width} x {Height}", localMonitor.Width, localMonitor.Height);
            }

            // pass1: process all new and/or old monitors in order
            int existingMonitors = Math.Min(localMonitors.Length, profile.Monitors.Count);

            // monitors that are preserved
            for (int monitorIndex = 0; monitorIndex < existingMonitors; monitorIndex++)
            {
                ViewModel.MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                foreach (string progress in ResetExistingMonitor(monitorIndex, item))
                {
                    yield return(progress);
                }
                yield return($"reset existing monitor {monitorIndex + 1}");
            }

            // monitors added (may be zero iterations)
            for (int monitorIndex = existingMonitors; monitorIndex < localMonitors.Length; monitorIndex++)
            {
                // monitorIndex does not refer to any reset item, as we are off the end of the list
                ResetAddedMonitor(profile, monitorIndex, localMonitors[monitorIndex]);
                yield return($"reset added monitor {monitorIndex + 1}");
            }

            // monitors removed (may be zero iterations)
            for (int monitorIndex = existingMonitors; monitorIndex < resetDialog.MonitorResets.Count; monitorIndex++)
            {
                ViewModel.MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                foreach (string progress in ResetRemovedMonitor(parent, profile, monitorIndex, item, localMonitors.Length))
                {
                    yield return(progress);
                }
                yield return($"reset removed monitor {monitorIndex + 1}");
            }

            // pass2: place all controls that were temporarily lifted and
            // copy over any settings from source to target monitors
            foreach (ViewModel.MonitorResetItem item in resetDialog.MonitorResets)
            {
                Logger.Debug($"placing controls for old monitor {item.OldMonitor.Name} onto Monitor {item.NewMonitor + 1}");
                foreach (string progress in item.PlaceControls(profile.Monitors[item.NewMonitor]))
                {
                    yield return(progress);
                }
                item.CopySettings(profile.Monitors[item.NewMonitor]);
            }
        }
Esempio n. 5
0
 private static IEnumerable <string> ResetRemovedMonitor(ICallbacks parent, HeliosProfile profile, int monitorIndex, ViewModel.MonitorResetItem item, int monitorToRemove)
 {
     Logger.Debug($"removing Monitor {monitorIndex + 1} and saving its controls for replacement");
     parent.CloseProfileItem(profile.Monitors[monitorToRemove]);
     foreach (string progress in item.RemoveControls())
     {
         yield return(progress);
     }
     ConfigManager.UndoManager.AddUndoItem(new UndoEvents.DeleteMonitorUndoEvent(profile, profile.Monitors[monitorToRemove], monitorToRemove));
     profile.Monitors.RemoveAt(monitorToRemove);
 }
Esempio n. 6
0
 public override void Request(IOwner owner, IValue value, ICallbacks callbacks)
 {
     if (_toAutorized.Contains(owner.Id))
     {
         int id          = _countRequest;
         var requestInfo = new RequestInfo(owner, id, _now.Get);
         _sent.AddLast(requestInfo);
         _callbacks.Add(id, new Tuple <ICallbacks, RequestInfo>(callbacks, requestInfo));
         _protocol.Request(owner.Id, id, value);
         _countRequest++;
     }
 }
Esempio n. 7
0
        public CallbacksImpl(ICallbacks callbacks)
        {
            _callbacks = callbacks;

            _isTypeValidDelegate = IsTypeValid;
            GCHandle.Alloc(_isTypeValidDelegate);

            _releaseNetReferenceDelegate = ReleaseNetReference;
            GCHandle.Alloc(_releaseNetReferenceDelegate);

            _releaseNetDelegateGCHandleDelegate = ReleaseNetDelegateGCHandle;
            GCHandle.Alloc(_releaseNetDelegateGCHandleDelegate);

            _createLazyTypeInfoDelegate = CreateLazyTypeInfo;
            GCHandle.Alloc(_createLazyTypeInfoDelegate);

            _loadTypeInfoDelegate = LoadTypeInfo;
            GCHandle.Alloc(_loadTypeInfoDelegate);

            _instantiateTypeDelgate = InstantiateType;
            GCHandle.Alloc(_instantiateTypeDelgate);

            _callComponentCompletedDelegate = CallComponentCompleted;
            GCHandle.Alloc(_callComponentCompletedDelegate);

            _callObjectDestroyedDelegate = CallObjectDestroyed;
            GCHandle.Alloc(_callObjectDestroyedDelegate);

            _readPropertyDelegate = ReadProperty;
            GCHandle.Alloc(_readPropertyDelegate);

            _writePropertyDelegate = WriteProperty;
            GCHandle.Alloc(_writePropertyDelegate);

            _invokeMethodDelegate = InvokeMethod;
            GCHandle.Alloc(_invokeMethodDelegate);

            _gcCollectDelegate = GCCollect;
            GCHandle.Alloc(_gcCollectDelegate);

            _raiseNetSignalsDelegate = RaiseNetSignals;
            GCHandle.Alloc(_raiseNetSignalsDelegate);

            _awaitTaskDelegate = AwaitTask;
            GCHandle.Alloc(_awaitTaskDelegate);

            _serializeDelegate = Serialize;
            GCHandle.Alloc(_serializeDelegate);

            _invokeDelegateDelegate = InvokeDelegate;
            GCHandle.Alloc(_invokeDelegateDelegate);
        }
Esempio n. 8
0
        public override void OnAttach(Context context)
        {
            base.OnAttach(context);

            if (this.Host is ICallbacks callbacks)
            {
                this.callbacks = callbacks;
            }
            else
            {
                throw new InvalidCastException("Parent fragment doesn't implement Callbacks!");
            }
        }
Esempio n. 9
0
        public override void Authorize(IOwner owner, string name, ICallbacks callbacks)
        {
            string address = owner.Id;

            if (!_toAutorized.Contains(address))
            {
                int id = _countRequest;
                _countRequest++;
                var requestInfo = new RequestInfo(owner, id, _now.Get);
                _sent.AddLast(requestInfo);
                _callbacks.Add(id, new Tuple <ICallbacks, RequestInfo>(callbacks, requestInfo));
                _authorizing.Add(address);
                _protocol.Authorize(address, id, name);
            }
        }
Esempio n. 10
0
 public Callbacks(Instance instance, ICallbacks callbacks)
 {
     _instance     = instance;
     CallbacksImpl = callbacks;
     _handle       = GCHandle.Alloc(this);
     _functions    = new FMI2.fmi2CallbackFunctions {
         logger               = LoggerCallback,
         allocateMemory       = Marshalling.AllocateMemory,
         freeMemory           = Marshalling.FreeMemory,
         stepFinished         = StepFinishedCallback,
         componentEnvironment = GCHandle.ToIntPtr(_handle)
     };
     Structure = Marshalling.AllocateMemory(1, (ulong)Marshal.SizeOf(_functions));
     Marshal.StructureToPtr(_functions, Structure, false);
 }
Esempio n. 11
0
        /// <summary>
        /// Returns an
        /// <see cref="IEventRegistry">IEventRegistry</see>
        /// for registering events with the specified container.
        /// </summary>
        public static IEventRegistry ForObjectContainer(IObjectContainer objectContainer)
        {
            if (null == objectContainer)
            {
                throw new ArgumentNullException();
            }
            IInternalObjectContainer container = ((IInternalObjectContainer)objectContainer);
            ICallbacks callbacks = container.Callbacks();

            if (callbacks is IEventRegistry)
            {
                return((IEventRegistry)callbacks);
            }
            if (callbacks is NullCallbacks)
            {
                EventRegistryImpl impl = container.NewEventRegistry();
                container.Callbacks(impl);
                return(impl);
            }
            // TODO: create a MulticastingCallbacks and register both
            // the current one and the new one
            throw new ArgumentException();
        }
Esempio n. 12
0
		public virtual void Callbacks(ICallbacks cb)
		{
			if (cb == null)
			{
				throw new ArgumentException();
			}
			_callbacks = cb;
		}
Esempio n. 13
0
 public void Remove(ICallbacks callback)
 {
     m_Callbacks.RemoveAll(callbackWithPriority => callbackWithPriority.Callback == callback);
 }
Esempio n. 14
0
 public abstract void Authorize(IOwner owner, string name, ICallbacks callbacks);
Esempio n. 15
0
 public void UnregisterCallbacks <T>(T testCallbacks) where T : ICallbacks
 {
     Callback = null;
 }
Esempio n. 16
0
 public IInstance CreateCoSimulationInstance(string name, ICallbacks callbacks)
 {
     return(new Instance(name, this, CoSimulation, FMI2.fmi2Type.fmi2CoSimulation, callbacks));
 }
Esempio n. 17
0
 public CallbackWithPriority(ICallbacks callback, int priority)
 {
     Callback = callback;
     Priority = priority;
 }
Esempio n. 18
0
 public void RegisterCallbacks <T>(T testCallbacks, int priority = 0) where T : ICallbacks
 {
     Callback = testCallbacks;
 }
		public virtual void Callbacks(ICallbacks cb)
		{
			lock (Lock())
			{
				CheckClosed();
				_server.Callbacks(cb);
			}
		}
Esempio n. 20
0
 public void Add(ICallbacks callback, int priority)
 {
     m_Callbacks.Add(new CallbackWithPriority(callback, priority));
 }
Esempio n. 21
0
 public override void OnDetach()
 {
     base.OnDetach();
     mCallBacks = null;
 }
 public virtual extern void SetEventCallbacks([In] ICallbacks callbacks);
Esempio n. 23
0
 public override void OnAttach(Android.App.Activity activity)
 {
     base.OnAttach(activity);
     mCallBacks = (ICallbacks)activity;
 }
Esempio n. 24
0
 public abstract void Request(IOwner owner, IValue value, ICallbacks callbacks);
Esempio n. 25
0
        private void OnRequestReceived(IUdpNetwork network, IOwner owner, IValue request, ICallbacks callbacks)
        {
            var chatValue = (ChatValue)request;

            Console.WriteLine("Server receive chat message, address: {0}, name: {1}, message: {2}", owner.Id, chatValue.Name, chatValue.Message);

            _request.Enqueue(new Tuple <IOwner, IValue, ICallbacks>(owner, request, callbacks));
        }
Esempio n. 26
0
 public override void OnAttach(Android.App.Activity activity)
 {
     base.OnAttach(activity);
     mCallbacks = (ICallbacks)activity;
 }
Esempio n. 27
0
 public override void OnDetach()
 {
     base.OnDetach();
     mCallbacks = null;
 }
Esempio n. 28
0
        private void OnAuthorizeReceived(IUdpNetwork network, IOwner owner, string name, ICallbacks callbacks)
        {
            if (string.IsNullOrEmpty(name))
            {
                Console.WriteLine("Authorized failed, empty name, address {0}", owner.Id);
                callbacks.Fail(_incorrectUsername);
                _network.Authorize(owner, false);
                return;
            }

            foreach (var item in _clients.Values)
            {
                if (item == name)
                {
                    Console.WriteLine("Authorized failed, dublicate name, address {0}", owner.Id);
                    callbacks.Fail(_dublicateUsername);
                    _network.Authorize(owner, false);
                    return;
                }
            }
            Console.WriteLine("Authorized true, address: {0}", owner.Id);

            callbacks.Ack(_ok);
            _network.Authorize(owner, true);
            _clients.Add(owner, name);
        }
Esempio n. 29
0
 public Instance(string name, ModelImpl model, Library library, FMI2.fmi2Type instanceType, ICallbacks cb)
 {
     Name        = name;
     _library    = library;
     _model      = model;
     _callbacks  = new Callbacks(this, cb);
     CurrentTime = model.DefaultStartTime;
     StopTime    = model.DefaultStopTime;
     _handle     = library.fmi2Instantiate(
         name,
         instanceType,
         model.GUID,
         model.TmpFolder,
         _callbacks.Structure,
         FMI2.fmi2Boolean.fmi2False,
         FMI2.fmi2Boolean.fmi2False
         );
     if (_handle == IntPtr.Zero)
     {
         throw new Exception("Cannot instanciate model");
     }
 }