Beispiel #1
0
        public HaggleEventHandler(HaggleHandle hh, uint type, HaggleCallback callback)
        {
            if (type < 0 || type >= HaggleEvent.NUM_EVENTS)
            {
                throw new EventHandlerException("Bad event type");
            }
            this.callback          = callback;
            this.unmanagedCallback = new UnmanagedHaggleCallback(this.UnmanagedHandler);

            ret = UnmanagedRegisterEventHandler(hh.handle, type, this.unmanagedCallback, IntPtr.Zero);

            if (ret < 0)
            {
                throw new EventHandlerException("Could not register handler.", ret);
            }
        }
Beispiel #2
0
        private bool connectToHaggle()
        {
            bool try_again = true;

                        while (try_again)
                        {
                                try_again = false;

                                if (HaggleHandle.DaemonPid() == 0)
                                {
                                        if (!tryLaunchHaggle())
                                        {
                                                return false;
                                        }
                                }
                                try
                                {
                                        hh = new HaggleHandle("PhotoShare");

                                        interestListHandler = new HaggleEventHandler(hh,
                                              HaggleEvent.INTEREST_LIST, new HaggleCallback(this.onInterestList));

                                        hh.RequestInterests();

                                        updatedNeighborHandler = new HaggleEventHandler(hh,
                                                HaggleEvent.NEIGHBOR_UPDATE, new HaggleCallback(this.onNeighborUpdate));
                                        shutdownHandler = new HaggleEventHandler(hh,
                                               HaggleEvent.SHUTDOWN, new HaggleCallback(this.onHaggleShutdown));
                                        newDataObjectHandler = new HaggleEventHandler(hh,
                                              HaggleEvent.NEW_DATAOBJECT, new HaggleCallback(this.onNewDataObject));

                                        Utility.Vibration vib = new Utility.Vibration();

                                        Debug.WriteLine("PhotoShare successfully connected to Haggle\n");

                                        return true;
                                }
                                catch (Haggle.HaggleHandle.IPCException ex)
                                {
                                        if (ex.GetError() == HaggleHandle.HAGGLE_BUSY_ERROR)
                                        {
                                                // FIXME: Should really check if there is another photoshare application running...

                                                HaggleHandle.Unregister("PhotoShare");
                                                Thread.Sleep(2000);
                                                try_again = true;
                                        }
                                        else
                                        {
                                                Debug.WriteLine("Haggle Error: " + ex.ToString() + " errnum=" + ex.GetError());
                                                uint pid = HaggleHandle.DaemonPid();

                                                if (pid > 0)
                                                {
                                                        MessageBox.Show("A Haggle PID file exists, but could still not connect to Haggle");
                                                }
                                                else if (pid == 0)
                                                {
                                                        if (!tryLaunchHaggle())
                                                        {
                                                                HaggleHandle.Unregister("PhotoShare");
                                                                return false;
                                                        }
                                                }
                                                else
                                                {
                                                        DialogResult res = MessageBox.Show("Could not connect to Haggle.",
                                                        "Haggle Error", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                                                        return false;
                                                }
                                        }
                                }
                                catch (Haggle.HaggleEventHandler.EventHandlerException ex)
                                {
                                        MessageBox.Show(ex.ToString() + " Error=" + ex.GetError());
                                        throw ex;
                                }
                        }

                        Application.Exit();

                        return false;
        }
Beispiel #3
0
        public HaggleEventHandler(HaggleHandle hh, uint type, HaggleCallback callback)
        {
            if (type < 0 || type >= HaggleEvent.NUM_EVENTS) {
                                throw new EventHandlerException("Bad event type");
                        }
                        this.callback = callback;
                        this.unmanagedCallback = new UnmanagedHaggleCallback(this.UnmanagedHandler);

                        ret = UnmanagedRegisterEventHandler(hh.handle, type, this.unmanagedCallback, IntPtr.Zero);

                        if (ret < 0)
                        {
                                throw new EventHandlerException("Could not register handler.", ret);
                        }
        }