// detach from device events static void DetachDevice() { if (m_activeDevice != null) { if (m_deviceComEvents != null) { // unregister device event handlers m_deviceListenerEvents.HeadsetButtonPressed -= m_deviceButtonEvents; Marshal.ReleaseComObject(m_deviceComEvents); m_deviceComEvents = null; } if (m_deviceListenerEvents != null) { // unregister device listener event handlers m_deviceListenerEvents.ATDStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged -= m_deviceListenerEvents_HandlerMethods; RegisterForProximity(false); Marshal.ReleaseComObject(m_deviceListenerEvents); m_deviceListenerEvents = null; } Marshal.ReleaseComObject(m_activeDevice); m_activeDevice = null; Console.WriteLine("Detached from device"); } }
// attach to device events static private void AttachDevice() { m_activeDevice = m_comSession.ActiveDevice; if (m_activeDevice != null) { m_deviceComEvents = m_activeDevice.DeviceEvents as IDeviceCOMEvents_Event; if (m_deviceComEvents != null) { // Attach to device events Console.WriteLine("Attached to device events"); } else { Console.WriteLine("Error: unable to attach to device events"); } m_deviceListenerEvents = m_activeDevice.DeviceListener as IDeviceListenerCOMEvents_Event; if (m_deviceListenerEvents != null) { // Attach to device listener events m_deviceListenerEvents.ATDStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed += m_deviceButtonEvents; m_deviceListenerEvents.HeadsetStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged += m_deviceListenerEvents_HandlerMethods; GetLastDonnedStatus(); RegisterForProximity(true); Console.WriteLine("Attach to device listener events"); } else { Console.WriteLine("Error: unable to attach to device listener events"); } Console.WriteLine("Attached to device"); } }
// attach to device events private static void AttachDevice() { m_activeDevice = m_comSession.ActiveDevice; if (m_activeDevice != null) { m_deviceComEvents = m_activeDevice.DeviceEvents as IDeviceCOMEvents_Event; if (m_deviceComEvents != null) { // Attach to device events Console.WriteLine("Attached to device events"); } else { Console.WriteLine("Error: unable to attach to device events"); } m_deviceListenerEvents = m_activeDevice.DeviceListener as IDeviceListenerCOMEvents_Event; if (m_deviceListenerEvents != null) { // Attach to device listener events m_deviceListenerEvents.ATDStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed += m_deviceButtonEvents; m_deviceListenerEvents.HeadsetStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged += m_deviceListenerEvents_HandlerMethods; GetLastDonnedStatus(); RegisterForProximity(true); Console.WriteLine("Attach to device listener events"); } else { Console.WriteLine("Error: unable to attach to device listener events"); } Console.WriteLine("Attached to device"); } }
// detach from device events static void DetachDevice() { if (m_activeDevice != null) { if (m_deviceComEvents != null) { // unregister device event handlers m_deviceListenerEvents.HeadsetButtonPressed -= m_deviceButtonEvents; Marshal.ReleaseComObject(m_deviceComEvents); m_deviceComEvents = null; } if (m_deviceListenerEvents != null) { // unregister device listener event handlers m_deviceListenerEvents.ATDStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged -= m_deviceListenerEvents_HandlerMethods; RegisterForProximity(false); Marshal.ReleaseComObject(m_deviceListenerEvents); m_deviceListenerEvents = null; } Marshal.ReleaseComObject(m_activeDevice); m_activeDevice = null; Console.WriteLine("Detached from device"); } }
private void UnRegisterEvents() { m_deviceComEvents.ButtonPressed -= OnButtonPressed; m_deviceListenerEvents = m_device.DeviceListener as IDeviceListenerCOMEvents_Event; if (m_deviceListenerEvents != null) { m_deviceListenerEvents.HeadsetStateChanged -= OnHeadsetStateChanged; } }
private void RegisterEvents() { LogDeviceInfo(m_device); // Register for some device events m_deviceComEvents = m_device.DeviceEvents as IDeviceCOMEvents_Event; m_deviceComEvents.ButtonPressed += new IDeviceCOMEvents_ButtonPressedEventHandler(OnButtonPressed); m_deviceListenerEvents = m_device.DeviceListener as IDeviceListenerCOMEvents_Event; if (m_deviceListenerEvents != null) { m_deviceListenerEvents.HeadsetStateChanged += new IDeviceListenerCOMEvents_HeadsetStateChangedEventHandler(OnHeadsetStateChanged); } }
// detach from device events void DetachDevice() { if (m_activeDevice != null) { if (m_deviceComEvents != null) { // commented out - not using these any more (see AttachDevice comment) //// LC, new unregister the serial number events //IDeviceCOMEventsExt_Event eex = m_deviceComEvents as IDeviceCOMEventsExt_Event; //eex.HeadsetStateChanged -= eex_HeadsetStateChanged; //IBaseCOMEvents_Event be = m_deviceComEvents as IBaseCOMEvents_Event; //be.BaseEventReceived -= be_BaseEventReceived; // unregister device event handlers m_deviceComEvents.ButtonPressed -= m_deviceComEvents_Handler; m_deviceComEvents.AudioStateChanged -= m_deviceComEvents_Handler; m_deviceComEvents.FlashPressed -= m_deviceComEvents_Handler; m_deviceComEvents.MuteStateChanged -= m_deviceComEvents_Handler; m_deviceComEvents.SmartPressed -= m_deviceComEvents_Handler; m_deviceComEvents.TalkPressed -= m_deviceComEvents_Handler; Marshal.ReleaseComObject(m_deviceComEvents); m_deviceComEvents = null; } if (m_deviceListenerEvents != null) { // unregister device listener event handlers m_deviceListenerEvents.ATDStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed -= m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged -= m_deviceListenerEvents_HandlerMethods; RegisterForProximity(false); Marshal.ReleaseComObject(m_deviceListenerEvents); m_deviceListenerEvents = null; } Marshal.ReleaseComObject(m_activeDevice); m_activeDevice = null; m_hostCommand = null; m_hostCommandExt = null; m_atdCommand = null; // LC Device was disconnected, clear down the GUI state... m_mobIncoming = false; // clear mobile call direction flag m_voipIncoming = false; // clear call direction flag OnNotOnCall(new NotOnCallArgs(0,"")); OnNotOnMobileCall(EventArgs.Empty); OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Base)); OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Headset)); // LC Device was disconnected, remove capability data DeviceCapabilities = new SpokesDeviceCaps(false, false, false, false, false, false, false); // no device = no capabilities! m_devicename = ""; OnCapabilitiesChanged(EventArgs.Empty); m_lastdocked = false; m_battlevEventCount = 0; // trigger user's event handler OnDetached(EventArgs.Empty); DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: DetachedEventHandler from device"); } m_devicename = ""; }
// attach to device events private void AttachDevice() { try { m_activeDevice = m_comSession.ActiveDevice; } catch (Exception e) { DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Exception caught attaching to device: "+e.ToString()); } if (m_activeDevice != null) { // LC assume minimum first set of device capabilities... DeviceCapabilities = new SpokesDeviceCaps(false, false, false, false, false, false, false); OnCapabilitiesChanged(EventArgs.Empty); OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Base)); OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Headset)); // LC have seen case where ProductName was empty but InternalName was not... if (m_activeDevice.ProductName.Length > 0) { m_devicename = m_activeDevice.ProductName; } else if (m_activeDevice.InternalName.Length > 0) { m_devicename = m_activeDevice.InternalName; } else { m_devicename = "Could not determine device name"; } m_lastdocked = false; m_battlevEventCount = 0; m_deviceComEvents = m_activeDevice.DeviceEvents as IDeviceCOMEvents_Event; if (m_deviceComEvents != null) { // Attach to device events m_deviceComEvents.ButtonPressed += m_deviceComEvents_Handler; m_deviceComEvents.AudioStateChanged += m_deviceComEvents_Handler; //m_deviceComEvents.FlashPressed += m_deviceComEvents_Handler; m_deviceComEvents.MuteStateChanged += m_deviceComEvents_Handler; //m_deviceComEvents.SmartPressed += m_deviceComEvents_Handler; //m_deviceComEvents.TalkPressed += m_deviceComEvents_Handler; DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: AttachedEventHandler to device events"); } else { DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to attach to device events"); return; } // if the ActiveDevice is a Calisto device, need additional initialization if (m_activeDevice.HostCommand.IsSupported(FeatureType.FeatureType_DisplayDevice)) { InitDisplayDevice(); } m_deviceListenerEvents = m_activeDevice.DeviceListener as IDeviceListenerCOMEvents_Event; if (m_deviceListenerEvents != null) { // Attach to device listener events m_deviceListenerEvents.ATDStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseButtonPressed += m_deviceListenerEvents_Handler; m_deviceListenerEvents.BaseStateChanged += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetButtonPressed += m_deviceListenerEvents_Handler; m_deviceListenerEvents.HeadsetStateChanged += m_deviceListenerEvents_HandlerMethods; } else { DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to attach to device listener events"); return; } // The below call (now with exception catching) tries to register // for extended headsetstatechange and base events that were used // for reading serial numbers from device using "asyncronous" method. // Following discussion with Ramesh Feb 2013 the Spokes Wrapper // primarily tries to read serial numbers using the "syncronous" // method based on HeadsetStateChange/BaseStateChange serial number // events and GetSerialNumber_2 method. However, this has been left // in because GetSerialNumber_2 is not working! (At least this way the // base serial number is obtainable! LC 14th Mar 2013) RegisterForExtendedEvents(); m_hostCommand = m_activeDevice.HostCommand; if (m_hostCommand == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain host command interface"); m_atdCommand = m_activeDevice.HostCommand as IATDCommand; if (m_atdCommand == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain atd command interface"); m_hostCommandExt = m_activeDevice.HostCommand as IHostCommandExt; if (m_hostCommandExt == null) DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Error: unable to obtain host command ext interface"); UpdateOtherDeviceCapabilities(); // trigger user's event handler OnAttached(new AttachedArgs(m_activeDevice)); // now poll for current state (proximity, mobile call status, donned status, mute status) GetInitialDeviceState(); DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: AttachedEventHandler to device"); } }