Exemplo n.º 1
0
        static void Main()
        {
            mCallback      = new LuckyMeLib.UnmanagedCallback(eventCallback);
            mSpawnCallback = new LuckyMeLib.SpawnCallback(spawnCallback);
            mCallTimer     = new System.Threading.Timer(new TimerCallback(new myDelegateState(onTimerStatusCheck)),
                                                        null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

            if (LuckyMeLib.setCallback(mCallback) != 1)
            {
                System.Diagnostics.Debug.WriteLine("Could not set callback function");
            }

            if (LuckyMeLib.isHaggleRunning())
            {
                mCallTimer.Change(1000, 8000);
                int res = LuckyMeLib.startLuckyMe();

                if (res < 0)
                {
                    Debug.WriteLine("Could not start LuckyMe");
                }
                Debug.WriteLine("Started LuckyMe...");
            }

            main_window.updateWindowStatus();

            Application.Run(main_window);
            LuckyMeLib.stopLuckyMe(0);
        }
Exemplo n.º 2
0
        /*
         *  Calling shutdown is a more forcefull way of
         *  killing off LuckyMe and Haggle.
         *  Returns: true if the caller should call Application.exit()
         *  or, false if Application.exit() will be called automatically.
         * */
        public static bool shutdown()
        {
            bool retval = true;

            setTestStage(TestStage.SHUTDOWN);

            if (LuckyMeLib.isHaggleRunning() && LuckyMeLib.isLuckyMeRunning())
            {
                Debug.WriteLine("shutdown: Trying to stop LuckyMe and Haggle");
                LuckyMeLib.stopLuckyMe(1);
                retval = false;
            }
            else
            {
                if (LuckyMeLib.isLuckyMeRunning())
                {
                    Debug.WriteLine("shutdown: Trying to stop LuckyMe");
                    LuckyMeLib.stopLuckyMe(0);
                }
                if (LuckyMeLib.isHaggleRunning())
                {
                    Debug.WriteLine("shutdown: Trying to stop Haggle");
                    LuckyMeLib.stopHaggle();
                }
            }

            Debug.WriteLine("shutdown: completed...");
            return(retval);
        }
Exemplo n.º 3
0
 private void quit_luckyme_Click(object sender, EventArgs e)
 {
     if (LuckyMeLib.isLuckyMeRunning())
     {
         int res = LuckyMeLib.stopLuckyMe(0);
     }
     Application.Exit();
 }
Exemplo n.º 4
0
        public static void eventCallback(LuckyMeLib.EventType eventType)
        {
            bool         exitApplication = false;
            DialogResult res;

            // Make sure we execute the callbacks in the Window thread
            switch (eventType)
            {
            case LuckyMeLib.EventType.EVENT_TYPE_ERROR:
                Debug.WriteLine("main_window: got error event");
                res = MessageBox.Show("An error occurred in LuckyMe. Exit LuckyMe?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                if (res == DialogResult.Yes)
                {
                    exitApplication = true;

                    if (LuckyMeLib.isLuckyMeRunning())
                    {
                        LuckyMeLib.stopLuckyMe(0);
                    }
                }
                break;

            case LuckyMeLib.EventType.EVENT_TYPE_SHUTDOWN:
                Debug.WriteLine("callback: Haggle was shutdown");

                LuckyMeLib.stopLuckyMe(0);

                if (LuckyMe.getTestStage() == LuckyMe.TestStage.SHUTDOWN)
                {
                    Debug.WriteLine("main_window: calling Application.Exit()");
                    exitApplication = true;
                }
                else
                {
                    Debug.WriteLine("main_window: got shutdown event, but is not in shutdown stage");

                    res = MessageBox.Show("Haggle was shutdown. Exit LuckyMe?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                    if (res == DialogResult.Yes)
                    {
                        exitApplication = true;
                    }
                }

                main_window.BeginInvoke(new myDelegate(main_window.onShutdown));
                testcontrol_window.BeginInvoke(new myDelegate(testcontrol_window.onShutdown));
                uint n = 0;
                // Wait for Haggle to shutdown
                while (LuckyMeLib.isHaggleRunning() && n++ < 120)
                {
                    Debug.WriteLine("Waiting for Haggle to exit...");
                    Thread.Sleep(1000);
                }
                Debug.WriteLine("Saving log files");
                setTestStage(TestStage.SAVING_LOGS);
                archiveHaggleFiles(true);
                setTestStage(TestStage.NOT_RUNNING);

                Debug.WriteLine("Log files saved");

                break;

            case LuckyMeLib.EventType.EVENT_TYPE_NEIGHBOR_UPDATE:
                Debug.WriteLine("callback neighbor update");
                main_window.BeginInvoke(new myDelegate(main_window.onNeighborUpdate));
                neighbor_window.BeginInvoke(new myDelegate(neighbor_window.onNeighborUpdate));
                break;

            case LuckyMeLib.EventType.EVENT_TYPE_NEW_DATAOBJECT:
                Debug.WriteLine("callback new data object");
                main_window.BeginInvoke(new myDelegate(main_window.onNewDataObject));
                break;

            case LuckyMeLib.EventType.EVENT_TYPE_DATA_OBJECT_GENERATED:
                Debug.WriteLine("callback data object generated");
                numDataObjectsGenerated++;
                main_window.BeginInvoke(new myDelegate(main_window.onDataObjectGenerated));
                break;

            case LuckyMeLib.EventType.EVENT_TYPE_STATUS_UPDATE:
                Debug.WriteLine("callback status update");
                main_window.BeginInvoke(new myDelegate(main_window.onStatusUpdate));
                break;
            }

            if (exitApplication)
            {
                Application.Exit();
            }
        }
Exemplo n.º 5
0
        public static bool stopTest()
        {
            bool retval = true;             // be optimistic :)

            if (testStage != TestStage.RUNNING)
            {
                Debug.WriteLine("Cannot stop test since test stage=" + testStageString());
                return(false);
            }

            mCallTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

            setTestStage(TestStage.STOPPING);

            if (LuckyMeLib.isLuckyMeRunning())
            {
                if (LuckyMeLib.isHaggleRunning())
                {
                    int res = LuckyMeLib.stopLuckyMe(1);

                    Debug.WriteLine("stopLuckyMe() returned " + res);

                    if (res < 0)
                    {
                        Debug.WriteLine("stopTest(): stopLuckyMe failed");

                        if (LuckyMeLib.isTestRunning())
                        {
                            setTestStage(TestStage.RUNNING);
                        }
                        else
                        {
                            // Set not running although test stop failed
                            setTestStage(TestStage.NOT_RUNNING);
                            return(true);
                        }

                        return(false);
                    }

                    setTestStage(TestStage.STOPPING);
                }
                else
                {
                    Debug.WriteLine("stopTest(): Haggle was not running");
                    int res = LuckyMeLib.stopLuckyMe(0);
                    // Haggle was not running so we cannot expect a shutdown callback
                    // -> set NOT_RUNNING immediately
                    setTestStage(TestStage.NOT_RUNNING);
                }
            }
            else
            {
                if (LuckyMeLib.isHaggleRunning())
                {
                    int res = LuckyMeLib.stopHaggle();

                    if (res == 1)
                    {
                        Debug.WriteLine("stopTest(): Haggle stopped");
                    }
                    else if (res == -1)
                    {
                        Debug.WriteLine("stopTest(): Could not stop Haggle, no Haggle handle");
                    }
                    else
                    {
                        Debug.WriteLine("stopTest(): Could not stop Haggle, not running");
                    }
                }

                setTestStage(TestStage.NOT_RUNNING);
            }
            return(retval);
        }