Esempio n. 1
0
        /// <summary>
        /// Processes events received from FreeSWITCH and dispatches them to the
        /// application event handlers.  This is called from <see cref="SwitchApp" />
        /// immediately after <see cref="SwitchApp.Main" /> returns on the
        /// application thread.
        /// </summary>
        internal static void EventLoop()
        {
            // Enlist in low-level global events if the application requested.

            var options = (switch_xml_section_enum_t)0;

            if (dialPlanEvent != null)
            {
                options |= switch_xml_section_enum_t.SWITCH_XML_SECTION_DIALPLAN;
            }

            if (userDirectoryEvent != null)
            {
                options |= switch_xml_section_enum_t.SWITCH_XML_SECTION_DIRECTORY;
            }

            if (options != (switch_xml_section_enum_t)0)
            {
                eventBinding = SwitchXmlSearchBinding.Bind(OnSwitchXmlSearchEvent, options);
            }

            // Decided whether we're going to actually consume NeonSwitch events based
            // on whether the application enlisted in the [EventReceived] event within
            // its [Main()] method.  Note that we we'll exit the event loop (and the
            // application's background thread) immediately if this is the case.

            if (eventReceived == null)
            {
                return;
            }

            eventConsumer = new EventConsumer("all", string.Empty, 0);

            // Loop, waiting for the application to terminate.

            while (!stopPending)
            {
                try
                {
                    var fsEvent     = eventConsumer.pop(1, 0);
                    var switchEvent = new SwitchEvent(fsEvent.InternalEvent);

                    RaiseEventReceived(new SwitchEventArgs(switchEvent));

                    if (switchEvent.EventType == SwitchEventCode.BackgroundJob)
                    {
                        RaiseJobCompletedEvent(new JobCompletedEventArgs(switchEvent.Headers.Get("Job-ID", Guid.Empty)));
                    }
                }
                catch (Exception e)
                {
                    SysLog.LogException(e);
                }
            }
        }
Esempio n. 2
0
 public ConfigHandler()
 {
     _binder = SwitchXmlSearchBinding.Bind(XmlCallback,
                                           switch_xml_section_enum_t.SWITCH_XML_SECTION_DIRECTORY |
                                           switch_xml_section_enum_t.SWITCH_XML_SECTION_DIALPLAN);
 }