Exemplo n.º 1
0
Arquivo: Printer.cs Projeto: urish/M3D
        public SpoolerResult AcquireLock(AsyncCallback callback, object state, EventLockTimeOutCallBack LockTimeOutCallBack, int locktimeoutseconds)
        {
            if (HasLock && callback != null)
            {
                callback(new AsyncCallObject(callback, state, (IPrinter)this)
                {
                    callresult = CommandResult.Success_LockAcquired
                });
                return(SpoolerResult.OK);
            }
            AsyncCallObject newWaitingObject = CreateNewWaitingObject(callback, state, false);

            if (newWaitingObject == null)
            {
                return(SpoolerResult.Fail_PreviousCommandNotComplete);
            }

            newWaitingObject.callbackType = CallBackType.Special;
            lockstatus.Value         = PrinterLockStatus.OurLockPending;
            lockTimeOutSeconds.Value = locktimeoutseconds;
            lock (timeout_lock_sync)
            {
                __LockTimeOutCallBack = LockTimeOutCallBack;
            }

            return(SendRPCToSpooler(nameof(AcquireLock), newWaitingObject.callID));
        }
Exemplo n.º 2
0
Arquivo: Printer.cs Projeto: urish/M3D
 public TimeoutProperties(EventLockTimeOutCallBack callback, IPrinter printer)
 {
     this.callback = callback;
     this.printer  = printer;
 }
Exemplo n.º 3
0
Arquivo: Printer.cs Projeto: urish/M3D
        public void ProcessSpoolerMessage(SpoolerMessage message)
        {
            var asyncCallObject = (AsyncCallObject)null;
            var flag            = false;

            if (message.Type == MessageType.RawData)
            {
                lock (thread_sync)
                {
                    incoming_data = message.GetRawData();
                }
            }
            else if (message.Type == MessageType.PluginMessage)
            {
                ProcessPluginMessageFromSpooler(message);
            }
            else if (message.Type == MessageType.LoggingMessage)
            {
                AddMessageToLog(Base64Convert.Base64Decode(message.Message));
                lock (log)
                {
                    log_updated = true;
                }
            }
            else if (message.Type == MessageType.FullLoggingData)
            {
                string[] strArray = Base64Convert.Base64Decode(message.Message).Split('\n');
                log.Clear();
                foreach (var message1 in strArray)
                {
                    AddMessageToLog(message1);
                }

                lock (log)
                {
                    log_updated = true;
                }
            }
            else if (message.Type == MessageType.BedLocationMustBeCalibrated || message.Type == MessageType.BedOrientationMustBeCalibrated || message.Type == MessageType.CheckGantryClips)
            {
                mylockID         = Guid.Empty;
                lockstatus.Value = PrinterLockStatus.Unlocked;
                lock (waiting_object_lock)
                {
                    if (waiting_object != null)
                    {
                        asyncCallObject            = waiting_object;
                        waiting_object             = null;
                        asyncCallObject.callresult = CommandResult.Failed_GantryClipsOrInvalidZ;
                    }
                }
            }
            else if ((message.Type == MessageType.LockConfirmed || message.Type == MessageType.LockResult) && message.SerialNumber == Info.serial_number)
            {
                uint num = 0;
                EventLockTimeOutCallBack callback = null;
                CommandResult            commandResult;
                if (message.Type == MessageType.LockResult)
                {
                    var s   = message.Message.Substring(0, 8);
                    var str = message.Message.Substring(8);
                    try
                    {
                        num           = uint.Parse(s);
                        commandResult = (CommandResult)Enum.Parse(typeof(CommandResult), str);
                    }
                    catch (ArgumentException ex)
                    {
                        commandResult = CommandResult.Failed_Exception;
                    }
                    if (commandResult == CommandResult.Success)
                    {
                        can_check_idle.Value = true;
                        return;
                    }
                    if (commandResult == CommandResult.Pending)
                    {
                        lockstatus.Value = PrinterLockStatus.OurLockPending;
                        return;
                    }
                    if (commandResult == CommandResult.LockForcedOpen)
                    {
                        lockstatus.Value = PrinterLockStatus.Unlocked;
                    }
                    else if (commandResult == CommandResult.LockLost_TimedOut)
                    {
                        lock (timeout_lock_sync)
                        {
                            callback = __LockTimeOutCallBack;
                            __LockTimeOutCallBack = null;
                        }
                    }
                    if (commandResult != CommandResult.CommandInterruptedByM0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    mylockID         = Guid.Parse(message.Message);
                    commandResult    = CommandResult.Success_LockAcquired;
                    lockstatus.Value = PrinterLockStatus.WeOwnLocked;
                }
                lock (waiting_object_lock)
                {
                    if (waiting_object != null)
                    {
                        if (commandResult == CommandResult.SuccessfullyReceived)
                        {
                            if (waiting_object.callbackType != CallBackType.SuccessfullyReceived)
                            {
                                goto label_59;
                            }
                        }
                        asyncCallObject = waiting_object;
                        waiting_object  = null;
                    }
                }
label_59:
                if (flag)
                {
                    mylockID         = Guid.Empty;
                    lockstatus.Value = PrinterLockStatus.Unlocked;
                }
                if (asyncCallObject != null)
                {
                    if (num != 0U && (int)num != (int)asyncCallObject.callID)
                    {
                        commandResult = CommandResult.Failed_AsyncCallbackError;
                    }

                    asyncCallObject.callresult = commandResult;
                }
                if (callback != null)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(DoTimeoutCallBack), new Printer.TimeoutProperties(callback, (IPrinter)this));
                }
            }
            if (asyncCallObject != null)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(DoAsyncCallBack), asyncCallObject);
            }

            if (OnProcessSpoolerMessage == null)
            {
                return;
            }

            OnProcessSpoolerMessage(message);
        }
Exemplo n.º 4
0
 public SpoolerResult AcquireLock(AsyncCallback callback, object state, EventLockTimeOutCallBack LockTimeOutCallBack, int locktimeoutseconds)
 {
     return(base_obj.AcquireLock(callback, state, LockTimeOutCallBack, locktimeoutseconds));
 }