public uint SetPropertyValue(IAdapterProperty Property, IAdapterValue Value, IAdapterSignal covSignal)
        {
            // find corresponding attribute
            foreach (var attribute in ((AdapterProperty)Property).Attributes)
            {
                if (attribute.Value.Name == Value.Name)
                {
                    //this.SetHttpValue(((AdapterValue)attribute.Value).Path, attribute.Value.Data, attribute.Value.Name);
                    attribute.Value.Data = Value.Data;

                    foreach (IAdapterValue param in covSignal.Params)
                    {
                        if (param.Name == Constants.COV__ATTRIBUTE_HANDLE)
                        {
                            IAdapterValue valueAttr_Value = (IAdapterValue)param.Data;
                            if (valueAttr_Value.Name == Value.Name)
                            {
                                param.Data = Value.Data;
                                NotifySignalListener(covSignal);
                            }
                        }
                    }

                    return(ERROR_SUCCESS);
                }
            }
            return(ERROR_INVALID_HANDLE);
        }
Exemple #2
0
        internal uint NotifySignalListener(IAdapterSignal Signal)
        {
            if (Signal == null)
            {
                return(ERROR_INVALID_HANDLE);
            }

            int signalHashCode = Signal.GetHashCode();

            lock (this.signalListeners)
            {
                if (!this.signalListeners.ContainsKey(signalHashCode))
                {
                    Debug.WriteLine("Error: Signal not found!");
                    return(ERROR_SUCCESS);
                }

                IList <SIGNAL_LISTENER_ENTRY> listenerList = this.signalListeners[signalHashCode];
                foreach (SIGNAL_LISTENER_ENTRY entry in listenerList)
                {
                    IAdapterSignalListener listener = entry.Listener;
                    object listenerContext          = entry.Context;
                    listener.AdapterSignalHandler(Signal, listenerContext);
                }
            }

            return(ERROR_SUCCESS);
        }
        public uint SetPropertyValue(IAdapterProperty Property, IAdapterValue Value, out IAdapterIoRequest RequestPtr)
        {
            RequestPtr = null;

            // find corresponding attribute
            foreach (var attribute in ((AdapterProperty)Property).Attributes)
            {
                if (attribute.Value.Name == Value.Name)
                {
                    string path   = "devices/" + ((AdapterValue)attribute.Value).Path + "/state";
                    uint   status = this.SetHttpValue(path, attribute.Value.Data, attribute.Value.Name);
                    if (status == 0)
                    {
                        attribute.Value.Data = Value.Data;

                        IAdapterDevice adapterDevice = null;
                        this.devicesDict.TryGetValue(((AdapterValue)Value).Path, out adapterDevice);

                        int SignalHashCode = ((AdapterValue)attribute.Value).SignalHashCode;

                        IAdapterSignal covSignal = null;
                        ((AdapterDevice)adapterDevice).SignalsDict.TryGetValue(SignalHashCode, out covSignal);

                        this.NotifySignalListener(covSignal);
                    }

                    return(ERROR_SUCCESS);
                }
            }
            return(ERROR_INVALID_HANDLE);
        }
Exemple #4
0
        internal void NotifySignalListeners(IAdapterSignal signal)
        {
            int signalHashCode = signal.GetHashCode();

            IList <SIGNAL_LISTENER_ENTRY> listenerList = null;

            lock (m_signalListeners)
            {
                if (m_signalListeners.ContainsKey(signalHashCode))
                {
                    // make a local copy of the listener list
                    listenerList = m_signalListeners[signalHashCode].ToArray();
                }
                else
                {
                    // can't do anything
                    return;
                }
            }

            // call out event handlers out of the lock to avoid
            // deadlock risk
            foreach (SIGNAL_LISTENER_ENTRY entry in listenerList)
            {
                IAdapterSignalListener listener = entry.Listener;
                object listenerContext          = entry.Context;
                listener.AdapterSignalHandler(signal, listenerContext);
            }
        }
Exemple #5
0
        public uint RegisterSignalListener(IAdapterSignal Signal, IAdapterSignalListener Listener, object ListenerContext)
        {
            if (Signal == null || Listener == null)
            {
                return(ERROR_INVALID_HANDLE);
            }

            int signalHashCode = Signal.GetHashCode();

            SIGNAL_LISTENER_ENTRY newEntry;

            newEntry.Signal   = Signal;
            newEntry.Listener = Listener;
            newEntry.Context  = ListenerContext;

            lock (this.signalListeners)
            {
                if (this.signalListeners.ContainsKey(signalHashCode))
                {
                    this.signalListeners[signalHashCode].Add(newEntry);
                }
                else
                {
                    IList <SIGNAL_LISTENER_ENTRY> newEntryList = new List <SIGNAL_LISTENER_ENTRY>();
                    newEntryList.Add(newEntry);
                    this.signalListeners.Add(signalHashCode, newEntryList);
                }
            }

            return(ERROR_SUCCESS);
        }
 public void UpdatePropertyValue(IAdapterSignal covSignal, Adapter adapter)
 {
     //This will update attribute which has been changed
     foreach (IAdapterValue param in covSignal.Params)
     {
         if (param.Name == Constants.COV__ATTRIBUTE_HANDLE)
         {
             adapter.NotifySignalListener(covSignal);
         }
     }
 }
Exemple #7
0
        public void NotifyChangeOfValueSignal(IAdapterProperty Property, IAdapterAttribute Attribute)
        {
            if (!_enableSignals)
            {
                return;
            }

            IAdapterSignal covSignal = this.Signals[CHANGE_OF_VALUE_SIGNAL_INDEX];

            covSignal.Params[0].Data = Property;
            covSignal.Params[1].Data = Attribute.Value;
            _adapter.NotifySignalListener(covSignal);
        }
Exemple #8
0
        public uint NotifyDeviceRemoval(IAdapterDevice Device)
        {
            if (Device == null)
            {
                return(ERROR_INVALID_HANDLE);
            }

            IAdapterSignal deviceRemovalSignal = this.Signals[DEVICE_REMOVAL_SIGNAL_INDEX];

            deviceRemovalSignal.Params[DEVICE_REMOVAL_SIGNAL_PARAM_INDEX].Data = Device;
            this.NotifySignalListener(deviceRemovalSignal);

            return(ERROR_SUCCESS);
        }
        //Update status/Property of a single EO abstract device
        private void updateDevice(Telegram telegram)
        {
            var deviceId  = telegram.deviceId;
            var direction = telegram.direction;
            var functions = telegram.functions;

            foreach (var funcntion in functions)
            {
                var key   = funcntion.key;
                var value = funcntion.value.ToString();

                AdapterDevice device = (AdapterDevice)GetObject(devicesDict, deviceId);

                if (direction.Equals("from"))
                {
                    if (isLamp(key))
                    {
                        if (value != ((Lamp)device).OnOff_Value_Save.ToString())
                        {
                            ((Lamp)device).updateStates(UInt16.Parse(value));
                        }
                        break;
                    }
                    ;

                    if (device != null)
                    {
                        IList <IAdapterProperty> properties = device.Properties;
                        foreach (var property in properties)
                        {
                            IList <IAdapterAttribute> attributes = property.Attributes;
                            foreach (var attribute in attributes)
                            {
                                if (attribute.Value.Name.Equals(key))
                                {
                                    attribute.Value.Data = Windows.Foundation.PropertyValue.CreateString(value);

                                    int            SignalHashCode = ((AdapterValue)attribute.Value).SignalHashCode;
                                    IAdapterSignal covSignal      = null;
                                    ((AdapterDevice)device).SignalsDict.TryGetValue(SignalHashCode, out covSignal);

                                    this.NotifySignalListener(covSignal);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        public uint NotifyDeviceArrival(IAdapterDevice Device)
        {
            if (Device == null)
            {
                return(ERROR_INVALID_HANDLE);
            }

            IAdapterSignal deviceArrivalSignal = this.Signals[DEVICE_ARRIVAL_SIGNAL_INDEX];
            IAdapterValue  signalParam         = deviceArrivalSignal.Params[DEVICE_ARRIVAL_SIGNAL_PARAM_INDEX];

            signalParam.Data = Device;
            this.NotifySignalListener(deviceArrivalSignal);

            return(ERROR_SUCCESS);
        }
        public uint NotifySignalListener(IAdapterSignal Signal)
        {
            if (Signal == null)
            {
                return(ERROR_INVALID_HANDLE);
            }

            int signalHashCode = Signal.GetHashCode();

            lock (this.signalListeners)
            {
                IList <SIGNAL_LISTENER_ENTRY> listenerList = this.signalListeners[signalHashCode];
                foreach (SIGNAL_LISTENER_ENTRY entry in listenerList)
                {
                    IAdapterSignalListener listener = entry.Listener;
                    object listenerContext          = entry.Context;
                    listener.AdapterSignalHandler(Signal, listenerContext);
                }
            }
            return(ERROR_SUCCESS);
        }
Exemple #12
0
        public uint RegisterSignalListener(
            IAdapterSignal Signal,
            IAdapterSignalListener Listener,
            object ListenerContext)
        {
            // sanity check
            if (Signal == null || Listener == null)
            {
                return(ERROR_INVALID_PARAMETER);
            }

            int signalHashCode = Signal.GetHashCode();

            SIGNAL_LISTENER_ENTRY newEntry;

            newEntry.Signal   = Signal;
            newEntry.Listener = Listener;
            newEntry.Context  = ListenerContext;

            lock (m_signalListeners)
            {
                if (m_signalListeners.ContainsKey(signalHashCode))
                {
                    m_signalListeners[signalHashCode].Add(newEntry);
                }
                else
                {
                    var newEntryList = new List <SIGNAL_LISTENER_ENTRY> {
                        newEntry
                    };
                    m_signalListeners.Add(signalHashCode, newEntryList);
                }
            }

            return(ERROR_SUCCESS);
        }
 public uint UnregisterSignalListener(
     IAdapterSignal Signal,
     IAdapterSignalListener Listener)
 {
     return ERROR_SUCCESS;
 }
        public uint RegisterSignalListener(
            IAdapterSignal Signal,
            IAdapterSignalListener Listener,
            object ListenerContext)
        {
            if (Signal == null || Listener == null)
            {
                return ERROR_INVALID_HANDLE;
            }

            int signalHashCode = Signal.GetHashCode();

            SIGNAL_LISTENER_ENTRY newEntry;
            newEntry.Signal = Signal;
            newEntry.Listener = Listener;
            newEntry.Context = ListenerContext;

            lock (this.signalListeners)
            {
                if (this.signalListeners.ContainsKey(signalHashCode))
                {
                    this.signalListeners[signalHashCode].Add(newEntry);
                }
                else
                {
                    IList<SIGNAL_LISTENER_ENTRY> newEntryList;

                    try
                    {
                        newEntryList = new List<SIGNAL_LISTENER_ENTRY>();
                    }
                    catch (OutOfMemoryException ex)
                    {
                        throw;
                    }

                    newEntryList.Add(newEntry);
                    this.signalListeners.Add(signalHashCode, newEntryList);
                }
            }

            return ERROR_SUCCESS;
        }
        public uint NotifySignalListener(IAdapterSignal Signal)
        {
            if (Signal == null)
            {
                return ERROR_INVALID_HANDLE;
            }

            int signalHashCode = Signal.GetHashCode();

            lock (this.signalListeners)
            {
                IList<SIGNAL_LISTENER_ENTRY> listenerList = this.signalListeners[signalHashCode];
                foreach (SIGNAL_LISTENER_ENTRY entry in listenerList)
                {
                    IAdapterSignalListener listener = entry.Listener;
                    object listenerContext = entry.Context;
                    listener.AdapterSignalHandler(Signal, listenerContext);
                }
            }

            return ERROR_SUCCESS;
        }
Exemple #16
0
 public uint UnregisterSignalListener(IAdapterSignal Signal, IAdapterSignalListener Listener)
 {
     return(_adapter.UnregisterSignalListener(Signal, Listener));
 }
Exemple #17
0
 public uint RegisterSignalListener(IAdapterSignal Signal, IAdapterSignalListener Listener, object ListenerContext)
 {
     return(_adapter.RegisterSignalListener(Signal, Listener, ListenerContext));
 }
Exemple #18
0
 public uint UnregisterSignalListener(
     IAdapterSignal Signal,
     IAdapterSignalListener Listener)
 {
     return(ERROR_SUCCESS);
 }
Exemple #19
0
        private void tempValueChangeEventHandler()
        {
            IAdapterSignal covSignal = devices.ElementAt(0).Signals.ElementAt(0);

            NotifySignalListener(covSignal);
        }
Exemple #20
0
 public uint RegisterSignalListener(
     IAdapterSignal Signal,
     IAdapterSignalListener Listener,
     object ListenerContext)
 {
     return ERROR_SUCCESS;
 }