Ferreteria/v0.6/clade/IO/Aspect/Connx/run/Starter/Local/Proc/@removed

From Woozle Writes Code
Jump to navigation Jump to search
Removed Code

Commented out about an hour ago, but it feels like a good idea now to just clear it out:

#
    // ++ ACTION ++ //

    // DOCS: https://wooz.dev/Ferreteria/v0.6/clade/IO/Aspect/Connx/Runner/Local/@fx/DoCommand
    //  This may *appear* very general, but it won't work for a connection (like ssh2) where the session is created before the command is executed.
    /* 2026-04-03 Can we require the caller to use Session for this? Or does that break something? (Maybe this should be a pass-thru?)
    public function DoCommand(CLineIface &$oCmd) : OpCmdIface {
        $oOpThis = $this->OOpCmd();
        $oOpThis->Clear();

        $sData = NULL;

        $oSess = ($this->SessionClass())::FromCommand($oCmd);

        $oOpThis->SetOkay(TRUE);  // 2026-03-29 Not sure what an error condition would look like yet.
        $oOpThis->QOSession()->SetIt($oSess);
        $this->QOSession()->SetIt($oSess);

        return $oOpThis;
    }

    // -- ACTION -- //

Commented out yesterday:

#
    // ++ LIFECYCLE ++ //

    /* 2026-04-02 moved to Session\Local\Proc
    public function ActualShut() : OpShutIface {
        #$arPipes = $this->arPipes;
        // close the pipes:
        $oaPipes = $this->OAPipes();
        $oaPipes->Shut();
        // this must be *after* pipes are closed, to prevent deadlock:
        $nStatus = proc_close($this->rProc);
        $oAct = $this->OpShut();
        $oAct->SetOkay($nStatus != -1);

        #$oLog = $this->Logger();
        #$oLog->WriteEntry("PROC SHUT - status=[$nStatus]");

        return $oAct;
    }
    */

    // -- LIFECYCLE -- //

Some pieces commented out on several different dates --

On 2026-03-29:

#
    // ++ OBJECTS ++ //

    // 2026-03-29 ...what was going on here? I don't even.
    #protected function OOpCmdNew() : OpCmdIface { return ($this->oRes = OpCmdClass::FromOAPipes($this->OAPipes())); }

    // -- OBJECTS -- //

On 2026-03-27:

#
        // 2026-03-27 Does this still need to happen?
        $qoRun = $oCmd->QORunner();
        #$this->AmHere('Runner already set?['.$qoRun->HasIt().']');
        if ($qoRun->HasIt()) {
            // 2026-03-23 I'm not *quite* sure this is a deadly error, but I need to understand what's going on if it's legit:
            $this->HardAssert($qoRun->GetIt() === $this,'Internal error: trying to start new Runner when one is already open.');
        } else {
            $qoRun->SetIt($this);
        }
#
    // 2026-03-27 TODO: Remove all of this, once it has all been moved to the Session clade.
    protected function StartProcess() : OpOpenIface {
        $qoCmd = $this->QOCommand();
        if ($qoCmd->HasIt()) {
            // set up the stream-resources for proc_open() to use:
            $arConf = array(  // configuration for proc_open()
              0 => array("pipe", "r"),  // [0] -> stdin (input to process)
              1 => array("pipe", "w"),  // [1] -> stdout (output from process}
              2 => array("pipe", "w")   // [2] -> stderr (error messages from process)
            );

            $sCmd = $qoCmd->GetIt()->AsString();
            $this->AmHereShort('COMMAND: '.$sCmd);
            $rProc = proc_open($sCmd, $arConf, $arPipes);
            $this->rProc = $rProc;

            $ok = is_resource($rProc);
            $oAct = $this->OpOpen(); // get a new result object
            $oAct->SetOkay($ok);
            $oLog->WriteEntry("PROCESSING: $sCmd");
            $oLog->WriteEntry("Process created? [$ok]");
            #$this->AmHereShort('Proc OPEN result: '.$oAct->VIEW_Inline());

            $oaPipes = $this->OAPipes();
            $oaPipes->SetVals($arPipes);

            $oaPipes->CountOpen();    // 2025-04-12 For now, this is just a diagnostic check: it shows a messsage if any pipe did not open.
        }
        return $oAct;
    }

...and on 2026-03-26:

#
    // CALLBACK
    // 2026-03-26 contents moved to StartProcess(); I don't *think* this is needed anymore.
    public function ActualOpen() : OpOpenIface {
        #$oLog = $this->Logger();

    }

Finally commented this out to see if it was being used, and the answer seems to be "no". I think it's no longer compatible with how things work. Originally noted on 2026-01-19 that "I don't *think* this is currently used/called; TODO: tidy up or implement as needed":

#
    public function OnCheck() {
        $oScrn = self::Screen();
        $ofLogIO = self::LogFile()->InOut();

        $oaPipes = $this->OAPipes();
        $qrDestPipe = $oaPipes->DestStream(); // where we are sending the data
        $qrErrsPipe = $oaPipes->ErrsStream(); // errors from the receiver
        $qrSrcePipe = $oaPipes->SrceStream(); // non-error responses from receiver

        // Check for possible response from receiver:

        $isErr = $qrErrsPipe->PullBytes();
        if (is_string($isErr) && ($isErr !== '')) {
            $sMsg = $ok;  // $ok is received text
            $nlMsg = strlen($sMsg);
            if ($nlMsg > 64) {
                $ftMsg = '"'.substr($sMsg,32).'"'." ($nlMsg chars total)";
            } else {
                $ftMsg = $sMsg;
            }
            echo CRLF.$oScrn->ErrorIt('Received Error Message').': '.$ftMsg.CRLF;
            $ofLogIO->WriteEntry("++++ RECEIVED ERROR ++++");
            $ofLogIO->WriteEntry($ftMsg);
            $ofLogIO->WriteEntry("==== BYTES ERRORED ON:");
            $ofLogIO->WriteEntry($sPiece);
            $ofLogIO->WriteEntry("==== STATS:");
            $ofLogIO->WriteEntry("TRIED = [$nlTried] / SENT = [$nlDone]");
            $ofLogIO->WriteEntry("---- RECEIVED ERROR ----");

            // TODO: this needs to be checked by the sender, somehow, because it's target-specific
            if (str_contains($sMsg,'Unknown command')) {
                $doSendLoop = FALSE;
                echo $oScrn->ErrorIt('Stopping').' due to parsing error on remote.'.CRLF;
            }
        }
        $isReply = $qrDestPipe->PullBytes();
        if (is_string($isReply)) {
            $sMsg = $ok;  // $ok is received text
            echo CRLF.$oScrn->InfoIt('Received Reply Message').': '.$sMsg.CRLF;
            $ofLogIO->WriteEntry("==== REPLY MESSAGE: $sMsg");
        }
    }

Renamed this to DoCommandV1() on 2026-02-27, effectively commenting it out, after making a copy to retrofit for using Canal:

#
    // 2026-02-27 code *before* starting to adapt for Canal usage
    public function DoCommand(CLineIface $o) : OpCmdIface {
        #echo $this->WhoCalledMe();
        $this->OCommand($o);
        $oActOpen = $this->Open();
        $oOpCmd = $this->OOpCmd();
        $oOpCmd->Clear();

        $ofLogIO = self::LogFile()->InOut();
        $qoAud = $o->QOListener();
        $doOBuff = $qoAud->HasIt();
        if ($doOBuff) $oAud = $qoAud->GetIt();

        $sData = NULL;
        $this->OnBefore();
        if ($oActOpen->GetOkay()) {
            $rProc = $this->rProc;
            $oSrce = $this->OAPipes()->SrceStream();

            // 2026-02-22 Maybe if !$doOBuff, we should QOListener()->SetIt(...something...)

            $doLoop = $o->DoWait();
            while ($doLoop) {
                $oStat = $this->Status();
                $isGoing = $oStat->IsRunning();

                if ($isGoing) {
                    $oRes = $oSrce->PullBytes(self::IBUFF_SIZE);
                    $qoData = $oRes->QData();
                    if ($qoData->HasIt()) {
                        $sRecd = $qoData->GetIt();
                        if ($doOBuff) {
                            $oOpPush = $oAud->PushBytes($sRecd);
                            $oOpCmd->Assimilate($oOpPush);
                        } else {
                            $sData .= $sRecd;
                        }
                        $ofLogIO->WriteEntry("RECD: [$sRecd]");
                    } // 2026-02-23 Do we need to do anything if bytes *not* received?
                    $this->OnChange();
                }

                $doLoop = $isGoing;
            }
        }
        $this->OnAfter();
        $oStat = $this->Status();
        $this->Shut();

        $ok = $oStat->RanOkay();
        $nCode = $oStat->ExitCode();
        #$this->AmHere("OK=[$ok] RUNNING=[".$oStat->IsRunning()."] CODE=[$nCode] CODE !== 0? [".($nCode !== 0).']');

        $oActProc = $this->OOpCmd();
        $oActProc->QData()->SetItNz($sData);

        #$this->AmHere('COMMAND: '.$o->AsString());
        #$this->AmHere("ok=[$ok] doOBuff=[$doOBuff] sData type: ".$this->DiagnoseValue($sData));

        $oActProc->Assimilate($oActComm); // TODO 2026-02-22 review this logic. Maybe CopyFrom() instead?
        $oActProc->SetOkay($ok);
        #$this->AmHere("oActProc:".CRLF.$oActProc->VIEW_AsBlock());

        return $oActProc;
    }