public bool CreateWorkerThreads(string i_sScriptUrl)
        {
            bool bRet = true;
            int  ii;

            DialogThread[] atDialogs;

            try
            {
                // Create message queues, and create and start threads.
                m_aqDMMsgs  = new ISMessaging.MsgQueue[m_NumDialogs];
                atDialogs   = new DialogThread[m_NumDialogs];
                m_atDialogs = new Thread[m_NumDialogs];

                for (ii = 0; ii < m_NumDialogs; ii++)
                {
                    // Create message queues
                    m_aqDMMsgs[ii] = new ISMessaging.MsgQueue(ii);

                    // Create & start threads
                    atDialogs[ii]        = new DialogThread(m_Logger, ii, i_sScriptUrl, m_aqDMMsgs[ii]);
                    m_atDialogs[ii]      = new Thread(new ThreadStart(atDialogs[ii].ThreadProc));
                    m_atDialogs[ii].Name = ii.ToString() + "_DialogWorkerT";
                    m_atDialogs[ii].Start();
                }
            }
            catch (Exception e)
            {
                bRet = false;
                //Console.Error.WriteLine("DialogMgr_Console.DialogMgr_srv.CreateWorkerThreads() exception '{0}'.", e);
                m_Logger.Log(e);
            }

            return(bRet);
        }
            public DialogThread(ILegacyLogger i_Logger, int i_iThreadIndex, string i_sScriptUrl, ISMessaging.MsgQueue i_qMsg)
            {
                bool bRes;

                m_Logger       = i_Logger;
                m_iThreadIndex = i_iThreadIndex;
                m_sScriptUrl   = i_sScriptUrl;
                m_qMsg         = i_qMsg;

                m_DEngine = new DialogEngine.DialogEngine(m_Logger, i_iThreadIndex);                            // FIX - Get VMC from RM, threadindex isn't valid in distributed/redundant installations.
                bRes      = m_DEngine.Init();
                if (!bRes)
                {
                    // FIX - Continue on?  Try to load from a 'safe' URL?
                }
            }
Exemple #3
0
        }         // LoadASR

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool CreateWorkerThreads(string i_sLogPath)
        {
            bool bRet = true;
            int  ii;
            ARMsgListenerThread tARMsgListener;
            AudioInThread       tAudioIn;
            AudioOutThread      tAudioOut;

            try
            {
                // Create audio listener thread array.
                m_atARMsgListenerThreads = new Thread[m_NumAudioStreams];

                // Create audio queues and ASR (audio in) wrapper thread array.
                // AudioIn thread receives audio data in messages popped from the
                // corresponding AudioEngine_srv.m_aqAudioIn queue.
                m_aqAudioIn  = new ISMessaging.MsgQueue[m_NumAudioStreams];
                m_atAudioIns = new Thread[m_NumAudioStreams];

                // Create audio out queues and TTS/WAV (audio out) wrapper thread array.
                m_aqAudioOut  = new AudioOutMsgQueue[m_NumAudioStreams];
                m_atAudioOuts = new Thread[m_NumAudioStreams];

                for (ii = 0; ii < m_NumAudioStreams; ii++)
                {
                    // Create message queues
                    m_aqAudioIn[ii]  = new ISMessaging.MsgQueue(ii);
                    m_aqAudioOut[ii] = new AudioOutMsgQueue(ii);

                    // Create and start audio in & out threads
                    tAudioIn              = new AudioInThread(m_Logger, m_RM, ii, m_aqAudioIn[ii], 2000, i_sLogPath, m_aASRs, m_aqAudioOut);            // FIX - Read the default value from a config file?
                    m_atAudioIns[ii]      = new Thread(new ThreadStart(tAudioIn.ThreadProc));
                    m_atAudioIns[ii].Name = ii.ToString() + "_AudioInT";
                    m_atAudioIns[ii].Start();

                    tAudioOut              = new AudioOutThread(m_Logger, m_RM, ii, m_aqAudioOut[ii], 2000, m_AMSocks, m_aqAudioIn, m_aqAudioOut);              // FIX - Read the default value from a config file?
                    m_atAudioOuts[ii]      = new Thread(new ThreadStart(tAudioOut.ThreadProc));
                    m_atAudioOuts[ii].Name = ii.ToString() + "_AudioOutT";
                    m_atAudioOuts[ii].Start();

                    // Create AudioRouter Msg thread (but start it later.)
                    tARMsgListener = new ARMsgListenerThread(m_Logger, m_RM, ii, ((AMSockConns.AMSockConn)(m_AMSocks.m_Socks[ii])), m_aqAudioIn, m_aqAudioOut);                         // FIX - Read the default value from a config file?
                    m_atARMsgListenerThreads[ii]      = new Thread(new ThreadStart(tARMsgListener.ThreadProc));
                    m_atARMsgListenerThreads[ii].Name = ii.ToString() + "_ARMsgListenerT";
                }

                // Start AudioRouter msg threads after all other queues & threads have been initialized and started
                // (because we don't want to start receiving messages from AR until we're ready.)
                // (Note - In the future there may be further initialization necessary before they can start.)
                for (ii = 0; ii < m_NumAudioStreams; ii++)
                {
                    m_atARMsgListenerThreads[ii].Start();
                }
            }
            catch (Exception e)
            {
                bRet = false;
                //Console.Error.WriteLine("ERROR AudioMgr.AudioEngine_srv.CreateWorkerThreads:  Caught exception '{0}'.", e.ToString());
                m_Logger.Log(e);
            }

            return(bRet);
        }
Exemple #4
0
        static int Main(string[] args)
        {
            bool          bRes = true;
            ILegacyLogger logger = null;
            string        sDisableKeyboard = "";
            string        sPrompt = "LRM> ", sCmd = "";
            string        sMonoBinPath = "", sBinPath = "", sArgs = "";
            bool          bDesktopRuntime = false;
            Process       oProc           = null;

            try
            {
                Console.Error.WriteLine(DateTime.Now.ToString() + ": In main.");
                if ((RunningSystem.RunningPlatform == CLRPlatform.Mono) && (args != null) && (args.Length > 0))
                {
                    foreach (string sArg in args)
                    {
                        if (sArg.IndexOf(g_sDesktopArg) >= 0)
                        {
                            bDesktopRuntime = true;
                        }
                    }
                }

                if ((args != null) && (args.Length > 0) && (args[0].IndexOf(g_sConsoleArg) >= 0))
                {
                    // This is the forked copy, carry on...
                    try
                    {
                        Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) Setting up event handlers...");
                        // Set up abnormal shutdown handlers
                        AppDomain.CurrentDomain.DomainUnload       += new EventHandler(CurrentDomain_DomainUnload);
                        AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);
                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                        Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) Setting up logging...");
                        // Name the main thread
                        Thread.CurrentThread.Name = "LocalRM-ForkedT";

                        // Start logging
                        bRes = StartLoggers(out logger);

                        logger.Log(Level.Info, "LRM logger started.");

                        // Check if IP address should be auto-saved to DB and config files.
                        bRes = CheckIPAutoSave(logger);

                        m_aqMsgIn = new MsgQueue(0);

                        // Start threads
                        m_tListener = StartListenerThread(logger, m_aqMsgIn);
                        m_tWorker   = StartWorkerThread(logger, m_aqMsgIn, bDesktopRuntime);

                        // Start CLI
                        sDisableKeyboard = ConfigurationManager.AppSettings["DisableKeyboard"];
                        if (sDisableKeyboard == "false")
                        {
                            Console.Write(sPrompt);
                            sCmd = Console.ReadLine();
                            while (bRes)
                            {
                                //					bRes = ProcessCmdString(sCmd);
                                if (bRes)
                                {
                                    Console.Write(sPrompt);
                                    sCmd = Console.ReadLine();
                                }
                            }
                        }

                        if (m_tListener == null)
                        {
                            logger.Log(Level.Exception, "LRM(F): Listener thread didn't start!");
                        }
                        else if (m_tWorker == null)
                        {
                            logger.Log(Level.Exception, "LRM(F): Worker thread didn't start!");
                        }
                        else
                        {
                            // Wait for threads to complete
                            m_tListener.Join();
                            m_tWorker.Join();
                        }
                    }
                    catch (Exception exc)
                    {
                        if (logger != null)
                        {
                            logger.Log(exc);
                        }
                        else
                        {
                            Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) " + exc.ToString());
                        }
                    }

                    if (logger != null)
                    {
                        logger.Log(Level.Info, "(F) LRM shutdown.");
                        logger.Close();
                    }
                }
                else
                {
                    // This is the parent, so "fork".  // Is MainWindowTitle the only way that works to get the current program file???
                    Console.Error.WriteLine(DateTime.Now.ToString() + ": (P) Setting up logging...");
                    // Name the main thread
                    Thread.CurrentThread.Name = "LocalRMT-Parent";

                    // Start logging
                    bRes = StartLoggers(out logger);

                    logger.Log(Level.Info, "LRM (P) logger started.");

                    if (RunningSystem.RunningPlatform == CLRPlatform.DotNet)
                    {
                        logger.Log(Level.Info, "LRM (P) Windows start.");

                        sBinPath = ConfigurationManager.AppSettings["DefaultBinPath"];
                        if (!(sBinPath.EndsWith("/")) && !(sBinPath.EndsWith("\\")))
                        {
                            sBinPath += "/";
                        }
                        sBinPath += "SBLocalRM.exe";
                        //Process.Start(sBinPath, g_sConsoleArg);
                        sArgs = g_sConsoleArg;
                    }
                    else if (RunningSystem.RunningPlatform == CLRPlatform.Mono)
                    {
                        logger.Log(Level.Info, "LRM (P) Mono start.");

                        sMonoBinPath = ConfigurationManager.AppSettings["MonoBinPath"];
                        if (!(sMonoBinPath.EndsWith("/")) && !(sMonoBinPath.EndsWith("\\")))
                        {
                            sMonoBinPath += "/";
                        }
                        sMonoBinPath += "mono";

                        if (bDesktopRuntime)
                        {
                            sBinPath = g_sDesktopArg + " ";
                        }
                        else
                        {
                            sBinPath = "";
                        }
                        sBinPath += ConfigurationManager.AppSettings["DefaultBinPath"];
                        if (!(sBinPath.EndsWith("/")) && !(sBinPath.EndsWith("\\")))
                        {
                            sBinPath += "/";
                        }
                        sBinPath += "SBLocalRM.exe ";

                        if (bDesktopRuntime)
                        {
                            logger.Log(Level.Info, "LRM (P) Desktop run.");

                            //Process.Start(sMonoBinPath, sBinPath + g_sConsoleArg + " " + g_sDesktopArg);
                            sArgs    = sBinPath + g_sConsoleArg + " " + g_sDesktopArg;
                            sBinPath = sMonoBinPath;
                        }
                        else
                        {
                            logger.Log(Level.Info, "LRM (P) Daemon run.");

                            //Process.Start(sMonoBinPath, sBinPath + g_sConsoleArg);
                            sArgs    = sBinPath + g_sConsoleArg;
                            sBinPath = sMonoBinPath;
                        }
                    }
                    else
                    {
                        sBinPath = "";
                        sArgs    = "";
                        logger.Log(Level.Exception, "(P) Main Start: Unknown platform '" + RunningSystem.RunningPlatform + "'.");
                    }

                    if (sBinPath.Length > 0)
                    {
                        logger.Log(Level.Info, "(P) Main Start-ing('" + sBinPath + "', '" + sArgs + "')...");
                        oProc = Process.Start(sBinPath, sArgs);
                        if (oProc == null)
                        {
                            logger.Log(Level.Exception, "(P) Main Failed to Start('" + sBinPath + "', '" + sArgs + "')!");
                        }
                        else
                        {
                            logger.Log(Level.Info, "(P) Main Start-ed('" + sBinPath + "', '" + sArgs + "').");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(DateTime.Now.ToString() + ": " + exc.ToString());
                Console.ReadLine();
            }

            return(0);
        }         // Main